01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * @version $Revision$
21: */package org.apache.harmony.security.tests.x509;
22:
23: import org.apache.harmony.security.x509.GeneralName;
24: import org.apache.harmony.security.x509.GeneralNames;
25: import org.apache.harmony.security.x509.ORAddress;
26:
27: import junit.framework.Test;
28: import junit.framework.TestCase;
29: import junit.framework.TestSuite;
30:
31: /**
32: * ORAddressTest
33: */
34: public class ORAddressTest extends TestCase {
35:
36: public static void printAsHex(int perLine, String prefix,
37: String delimiter, byte[] data) {
38: for (int i = 0; i < data.length; i++) {
39: String tail = Integer.toHexString(0x000000ff & data[i]);
40: if (tail.length() == 1) {
41: tail = "0" + tail;
42: }
43: System.out.print(prefix + "0x" + tail + delimiter);
44:
45: if (((i + 1) % perLine) == 0) {
46: System.out.println();
47: }
48: }
49: System.out.println();
50: }
51:
52: /**
53: * ORAddress() method testing.
54: */
55: public void testORAddress() {
56: ORAddress ora = new ORAddress();
57: System.out.println("");
58: System.out.println("ORAddress:");
59: printAsHex(8, "", " ", ora.getEncoded());
60: System.out.println("");
61:
62: GeneralName gName = new GeneralName(ora);
63: System.out.println("GeneralName:");
64: printAsHex(8, "", " ", gName.getEncoded());
65: System.out.println("");
66:
67: GeneralNames gNames = new GeneralNames();
68: gNames.addName(gName);
69: System.out.println("GeneralNames:");
70: printAsHex(8, "", " ", gNames.getEncoded());
71: System.out.println("");
72: }
73:
74: public static Test suite() {
75: return new TestSuite(ORAddressTest.class);
76: }
77:
78: public static void main(String[] args) {
79: junit.textui.TestRunner.run(suite());
80: }
81: }
|