ORAddressTest.java revision 561ee011997c6c2f1befbfaa9d5f0a99771c1d63
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/** 19* @author Alexander Y. Kleymenov 20*/ 21 22package org.apache.harmony.security.tests.x509; 23 24import org.apache.harmony.security.x509.GeneralName; 25import org.apache.harmony.security.x509.GeneralNames; 26import org.apache.harmony.security.x509.ORAddress; 27 28import junit.framework.Test; 29import junit.framework.TestCase; 30import junit.framework.TestSuite; 31 32/** 33 * ORAddressTest 34 */ 35public class ORAddressTest extends TestCase { 36 37 public static void printAsHex(int perLine, String prefix, 38 String delimiter, byte[] data) { 39 for (int i=0; i<data.length; i++) { 40 String tail = Integer.toHexString(0x000000ff & data[i]); 41 if (tail.length() == 1) { 42 tail = "0" + tail; 43 } 44 System.out.print(prefix + "0x" + tail + delimiter); 45 46 if (((i+1)%perLine) == 0) { 47 System.out.println(); 48 } 49 } 50 System.out.println(); 51 } 52 53 /** 54 * ORAddress() method testing. 55 */ 56 public void testORAddress() { 57 ORAddress ora = new ORAddress(); 58 System.out.println(""); 59 System.out.println("ORAddress:"); 60 printAsHex(8, "", " ", ora.getEncoded()); 61 System.out.println(""); 62 63 GeneralName gName = new GeneralName(ora); 64 System.out.println("GeneralName:"); 65 printAsHex(8, "", " ", gName.getEncoded()); 66 System.out.println(""); 67 68 GeneralNames gNames = new GeneralNames(); 69 gNames.addName(gName); 70 System.out.println("GeneralNames:"); 71 printAsHex(8, "", " ", gNames.getEncoded()); 72 System.out.println(""); 73 } 74 75 public static Test suite() { 76 return new TestSuite(ORAddressTest.class); 77 } 78 79 public static void main(String[] args) { 80 junit.textui.TestRunner.run(suite()); 81 } 82} 83 84