diff options
author | Endi Sukma Dewata <edewata@redhat.com> | 2012-03-24 02:27:47 -0500 |
---|---|---|
committer | Endi Sukma Dewata <edewata@redhat.com> | 2012-03-26 11:43:54 -0500 |
commit | 621d9e5c413e561293d7484b93882d985b3fe15f (patch) | |
tree | 638f3d75761c121d9a8fb50b52a12a6686c5ac5c /pki/base/util/test/com | |
parent | 40d3643b8d91886bf210aa27f711731c81a11e49 (diff) | |
download | pki-621d9e5c413e561293d7484b93882d985b3fe15f.tar.gz pki-621d9e5c413e561293d7484b93882d985b3fe15f.tar.xz pki-621d9e5c413e561293d7484b93882d985b3fe15f.zip |
Removed unnecessary pki folder.
Previously the source code was located inside a pki folder.
This folder was created during svn migration and is no longer
needed. This folder has now been removed and the contents have
been moved up one level.
Ticket #131
Diffstat (limited to 'pki/base/util/test/com')
14 files changed, 0 insertions, 2323 deletions
diff --git a/pki/base/util/test/com/netscape/security/extensions/GenericASN1ExtensionTest.java b/pki/base/util/test/com/netscape/security/extensions/GenericASN1ExtensionTest.java deleted file mode 100644 index 74d082f09..000000000 --- a/pki/base/util/test/com/netscape/security/extensions/GenericASN1ExtensionTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.netscape.security.extensions; - -import java.io.ByteArrayOutputStream; -import java.io.OutputStream; -import java.util.Hashtable; - -import netscape.security.extensions.GenericASN1Extension; -import netscape.security.x509.OIDMap; - -import org.junit.Assert; -import org.junit.Test; - -public class GenericASN1ExtensionTest { - - //@Test - public void testConstructorArgs() throws Exception { - String name1 = "testExtension1"; - String oid1 = "1.2.3.4"; - String pattern = ""; - Hashtable<String, String> config = new Hashtable<String, String>(); - GenericASN1Extension extension1 = new GenericASN1Extension(name1, oid1, - pattern, false, config); - Assert.assertEquals(name1, extension1.getName()); - Assert.assertNotNull(OIDMap.getClass(name1)); - - String name2 = "testExtension2"; - String oid2 = "2.4.6.8"; - GenericASN1Extension extension2 = new GenericASN1Extension(name2, oid2, - pattern, false, config); - Assert.assertEquals(name2, extension2.getName()); - Assert.assertNotNull(OIDMap.getClass(name2)); - } - - @Test - public void testConstructorJustConfig() throws Exception { - String name1 = "testExtension1"; - String oid1 = "1.2.3.4"; - String pattern = ""; - Hashtable<String, String> config = new Hashtable<String, String>(); - config.put("oid", oid1); - config.put("name", name1); - config.put("pattern", pattern); - config.put("critical", "true"); - - GenericASN1Extension extension1 = new GenericASN1Extension(config); - Assert.assertEquals(name1, extension1.getName()); - //Assert.assertNotNull(OIDMap.getClass(name1)); - - String name2 = "testExtension2"; - String oid2 = "2.4.6.8"; - config.put("oid", oid2); - config.put("name", name2); - - GenericASN1Extension extension2 = new GenericASN1Extension(config); - Assert.assertEquals(name2, extension2.getName()); - //Assert.assertNotNull(OIDMap.getClass(name2)); - OutputStream outputStream = new ByteArrayOutputStream(); - extension1.encode(outputStream); - extension2.encode(outputStream); - - } - - @Test - public void testConstructorDER() throws Exception { - byte[] value = new byte[0]; - GenericASN1Extension extension = new GenericASN1Extension(true, value); - - OutputStream outputStream = new ByteArrayOutputStream(); - extension.encode(outputStream); - - } -} diff --git a/pki/base/util/test/com/netscape/security/util/BMPStringTest.java b/pki/base/util/test/com/netscape/security/util/BMPStringTest.java deleted file mode 100644 index ffe13b238..000000000 --- a/pki/base/util/test/com/netscape/security/util/BMPStringTest.java +++ /dev/null @@ -1,274 +0,0 @@ -package com.netscape.security.util; - -import netscape.security.util.DerValue; - -import org.junit.Test; -import org.junit.Assert; - -public class BMPStringTest { - - public byte tag = DerValue.tag_BMPString; - - @Test - public void testEncodingEmptyString() throws Exception { - - String string = ""; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingEmptyString() throws Exception { - - String input = ""; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingNullCharacters() throws Exception { - - String string = StringTestUtil.NULL_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - actual = StringTestUtil.normalizeUnicode(actual); - System.out.println(" - norm. : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingNullCharacters() throws Exception { - - String input = StringTestUtil.NULL_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingPrintableCharacters() throws Exception { - - String string = StringTestUtil.PRINTABLE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - actual = StringTestUtil.normalizeUnicode(actual); - System.out.println(" - norm. : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingPrintableCharacters() throws Exception { - - String input = StringTestUtil.PRINTABLE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingNonPrintableCharacters() throws Exception { - - String string = StringTestUtil.NON_PRINTABLE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - actual = StringTestUtil.normalizeUnicode(actual); - System.out.println(" - norm. : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingNonPrintableCharacters() throws Exception { - - String input = StringTestUtil.NON_PRINTABLE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingControlCharacters() throws Exception { - - String string = StringTestUtil.CONTROL_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - actual = StringTestUtil.normalizeUnicode(actual); - System.out.println(" - norm. : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingControlCharacters() throws Exception { - - String input = StringTestUtil.CONTROL_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingMultibyteCharacters() throws Exception { - - String string = StringTestUtil.MULTIBYTE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - actual = StringTestUtil.normalizeUnicode(actual); - System.out.println(" - norm. : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingMultibyteCharacters() throws Exception { - - String input = StringTestUtil.MULTIBYTE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingTime() throws Exception { - - System.out.println("Encoding time:"); - - String string = StringTestUtil.NULL_CHARS + - StringTestUtil.PRINTABLE_CHARS + - StringTestUtil.NON_PRINTABLE_CHARS + - StringTestUtil.CONTROL_CHARS + - StringTestUtil.MULTIBYTE_CHARS; - - long t0 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - JSSUtil.encode(tag, string); - - long t1 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - StringTestUtil.encode(tag, string); - - long t2 = System.currentTimeMillis(); - - long time1 = t1 - t0; - long time2 = t2 - t1; - - System.out.println(" - JSS : " + time1 + " ms"); - System.out.println(" - Internal: " + time2 + " ms"); - } - - @Test - public void testDecodingTime() throws Exception { - - System.out.println("Decoding time:"); - - String string = StringTestUtil.NULL_CHARS + - StringTestUtil.PRINTABLE_CHARS + - StringTestUtil.NON_PRINTABLE_CHARS + - StringTestUtil.CONTROL_CHARS + - StringTestUtil.MULTIBYTE_CHARS; - - byte[] data = JSSUtil.encode(tag, string); - - long t0 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - JSSUtil.decode(tag, data); - - long t1 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - StringTestUtil.decode(tag, data); - - long t2 = System.currentTimeMillis(); - - long time1 = t1 - t0; - long time2 = t2 - t1; - - System.out.println(" - JSS : " + time1 + " ms"); - System.out.println(" - Internal: " + time2 + " ms"); - } -} diff --git a/pki/base/util/test/com/netscape/security/util/IA5StringTest.java b/pki/base/util/test/com/netscape/security/util/IA5StringTest.java deleted file mode 100644 index dd0af242c..000000000 --- a/pki/base/util/test/com/netscape/security/util/IA5StringTest.java +++ /dev/null @@ -1,273 +0,0 @@ -package com.netscape.security.util; - -import java.io.IOException; - -import org.junit.Test; -import org.junit.Assert; - -import sun.security.util.DerValue; - -public class IA5StringTest { - - public byte tag = DerValue.tag_IA5String; - - @Test - public void testEncodingEmptyString() throws Exception { - - String string = ""; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingEmptyString() throws Exception { - - String input = ""; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingNullCharacters() throws Exception { - - String string = StringTestUtil.NULL_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - actual = StringTestUtil.normalizeUnicode(actual); - System.out.println(" - norm. : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingNullCharacters() throws Exception { - - String input = StringTestUtil.NULL_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingPrintableCharacters() throws Exception { - - String string = StringTestUtil.PRINTABLE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingPrintableCharacters() throws Exception { - - String input = StringTestUtil.PRINTABLE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingNonPrintableCharacters() throws Exception { - - String string = StringTestUtil.NON_PRINTABLE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingNonPrintableCharacters() throws Exception { - - String input = StringTestUtil.NON_PRINTABLE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingControlCharacters() throws Exception { - - String string = StringTestUtil.CONTROL_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingControlCharacters() throws Exception { - - String input = StringTestUtil.CONTROL_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingMultibyteCharacters() throws Exception { - - String string = StringTestUtil.MULTIBYTE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - System.out.println(" - expected: IOException"); - - try { - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IOException); - } - } - - @Test - public void testDecodingMultibyteCharacters() throws Exception { - - String input = StringTestUtil.MULTIBYTE_CHARS; - byte[] data = JSSUtil.encode(DerValue.tag_UTF8String, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: IOException"); - - try { - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IOException); - } - } - - @Test - public void testEncodingTime() throws Exception { - - System.out.println("Encoding time:"); - - String string = StringTestUtil.NULL_CHARS + - StringTestUtil.PRINTABLE_CHARS + - StringTestUtil.NON_PRINTABLE_CHARS + - StringTestUtil.CONTROL_CHARS; - - long t0 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - JSSUtil.encode(tag, string); - - long t1 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - StringTestUtil.encode(tag, string); - - long t2 = System.currentTimeMillis(); - - long time1 = t1 - t0; - long time2 = t2 - t1; - - System.out.println(" - JSS : " + time1 + " ms"); - System.out.println(" - Internal: " + time2 + " ms"); - } - - @Test - public void testDecodingTime() throws Exception { - - System.out.println("Decoding time:"); - - String string = StringTestUtil.NULL_CHARS + - StringTestUtil.PRINTABLE_CHARS + - StringTestUtil.NON_PRINTABLE_CHARS + - StringTestUtil.CONTROL_CHARS; - - byte[] data = JSSUtil.encode(tag, string); - - long t0 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - JSSUtil.decode(tag, data); - - long t1 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - StringTestUtil.decode(tag, data); - - long t2 = System.currentTimeMillis(); - - long time1 = t1 - t0; - long time2 = t2 - t1; - - System.out.println(" - JSS : " + time1 + " ms"); - System.out.println(" - Internal: " + time2 + " ms"); - } -} diff --git a/pki/base/util/test/com/netscape/security/util/JSSUtil.java b/pki/base/util/test/com/netscape/security/util/JSSUtil.java deleted file mode 100644 index bbbabbf14..000000000 --- a/pki/base/util/test/com/netscape/security/util/JSSUtil.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.netscape.security.util; - -import netscape.security.util.DerValue; - -import org.mozilla.jss.asn1.ASN1Template; -import org.mozilla.jss.asn1.ASN1Util; -import org.mozilla.jss.asn1.ASN1Value; -import org.mozilla.jss.asn1.BMPString; -import org.mozilla.jss.asn1.IA5String; -import org.mozilla.jss.asn1.PrintableString; -import org.mozilla.jss.asn1.Tag; -import org.mozilla.jss.asn1.TeletexString; -import org.mozilla.jss.asn1.UTF8String; -import org.mozilla.jss.asn1.UniversalString; - -public class JSSUtil { - - public static byte[] encode(byte tag, String string) throws Exception { - ASN1Value value; - - switch (tag) { - case DerValue.tag_BMPString: - value = new BMPString(string); - break; - case DerValue.tag_IA5String: - value = new IA5String(string); - break; - case DerValue.tag_PrintableString: - value = new PrintableString(string); - break; - case DerValue.tag_T61String: - value = new TeletexString(string); - break; - case DerValue.tag_UniversalString: - value = new UniversalString(string); - break; - case DerValue.tag_UTF8String: - value = new UTF8String(string); - break; - default: - throw new Exception("Unsupported tag: " + tag); - } - return ASN1Util.encode(value); - } - - public static String decode(byte tag, byte[] bytes) throws Exception { - ASN1Template template; - - switch (tag) { - case DerValue.tag_BMPString: - template = new BMPString.Template(); - break; - case DerValue.tag_IA5String: - template = new IA5String.Template(); - break; - case DerValue.tag_PrintableString: - template = new PrintableString.Template(); - break; - case DerValue.tag_T61String: - template = new TeletexString.Template(); - break; - case DerValue.tag_UniversalString: - template = new UniversalString.Template(); - break; - case DerValue.tag_UTF8String: - template = new UTF8String.Template(); - break; - default: - throw new Exception("Unsupported tag: " + tag); - } - return ASN1Util.decode(new Tag(Tag.UNIVERSAL, tag), template, bytes).toString(); - } -} diff --git a/pki/base/util/test/com/netscape/security/util/PrintableStringTest.java b/pki/base/util/test/com/netscape/security/util/PrintableStringTest.java deleted file mode 100644 index 5808a2650..000000000 --- a/pki/base/util/test/com/netscape/security/util/PrintableStringTest.java +++ /dev/null @@ -1,290 +0,0 @@ -package com.netscape.security.util; - -import java.io.IOException; - -import org.junit.Test; -import org.junit.Assert; - -import sun.security.util.DerValue; - -public class PrintableStringTest { - - public byte tag = DerValue.tag_PrintableString; - - @Test - public void testEncodingEmptyString() throws Exception { - - String string = ""; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingEmptyString() throws Exception { - - String input = ""; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingNullCharacters() throws Exception { - - String string = StringTestUtil.NULL_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - System.out.println(" - expected: IOException"); - - try { - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IOException); - } - } - - @Test - public void testDecodingNullCharacters() throws Exception { - - byte[] data = { 0x13, 0x01, 0x00 }; - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - String expected = ""; // skip null chars (bug 359010) - System.out.println(" - expected: [" + expected + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(expected, output); - } - - @Test - public void testEncodingPrintableCharacters() throws Exception { - - String string = StringTestUtil.PRINTABLE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingPrintableCharacters() throws Exception { - - String input = StringTestUtil.PRINTABLE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingNonPrintableCharacters() throws Exception { - - String string = StringTestUtil.NON_PRINTABLE_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - System.out.println(" - expected: IOException"); - - try { - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IOException); - } - } - - @Test - public void testDecodingNonPrintableCharacters() throws Exception { - - String input = StringTestUtil.NON_PRINTABLE_CHARS; - byte[] data = JSSUtil.encode(DerValue.tag_UTF8String, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: IOException"); - - try { - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IOException); - } - } - - @Test - public void testEncodingControlCharacters() throws Exception { - - String string = StringTestUtil.CONTROL_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - System.out.println(" - expected: IOException"); - - try { - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IOException); - } - } - - @Test - public void testDecodingControlCharacters() throws Exception { - - String input = StringTestUtil.CONTROL_CHARS; - byte[] data = JSSUtil.encode(DerValue.tag_UTF8String, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: IOException"); - - try { - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IOException); - } - } - - @Test - public void testEncodingMultibyteCharacters() throws Exception { - - String string = StringTestUtil.MULTIBYTE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - System.out.println(" - expected: IOException"); - - try { - byte[] actual = StringTestUtil.encode(tag, StringTestUtil.MULTIBYTE_CHARS); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IOException); - } - } - - @Test - public void testDecodingMultibyteCharacters() throws Exception { - - String input = StringTestUtil.MULTIBYTE_CHARS; - byte[] data = JSSUtil.encode(DerValue.tag_UTF8String, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: IOException"); - - try { - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IOException); - } - } - - @Test - public void testEncodingTime() throws Exception { - - System.out.println("Encoding time:"); - - String string = StringTestUtil.PRINTABLE_CHARS; - - long t0 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - JSSUtil.encode(tag, string); - - long t1 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - StringTestUtil.encode(tag, string); - - long t2 = System.currentTimeMillis(); - - long time1 = t1 - t0; - long time2 = t2 - t1; - - System.out.println(" - JSS : " + time1 + " ms"); - System.out.println(" - Internal: " + time2 + " ms"); - } - - @Test - public void testDecodingTime() throws Exception { - - System.out.println("Decoding time:"); - - String string = StringTestUtil.PRINTABLE_CHARS; - - byte[] data = JSSUtil.encode(tag, string); - - long t0 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - JSSUtil.decode(tag, data); - - long t1 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - StringTestUtil.decode(tag, data); - - long t2 = System.currentTimeMillis(); - - long time1 = t1 - t0; - long time2 = t2 - t1; - - System.out.println(" - JSS : " + time1 + " ms"); - System.out.println(" - Internal: " + time2 + " ms"); - } -} diff --git a/pki/base/util/test/com/netscape/security/util/StringTestUtil.java b/pki/base/util/test/com/netscape/security/util/StringTestUtil.java deleted file mode 100644 index 16810581c..000000000 --- a/pki/base/util/test/com/netscape/security/util/StringTestUtil.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.netscape.security.util; - -import netscape.security.util.DerInputStream; -import netscape.security.util.DerOutputStream; -import netscape.security.util.DerValue; - -public class StringTestUtil { - - public final static String NULL_CHARS = "\u0000"; - - public final static String PRINTABLE_CHARS = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 \'()+,-./:=?"; - - public final static String NON_PRINTABLE_CHARS = "\"\\"; - - public final static String CONTROL_CHARS = "\b\t\n\f\r"; - - public final static String MULTIBYTE_CHARS = "æˆ‘çˆ±ä½ "; // I love you - - public static String toString(byte[] array) { - - StringBuffer sb = new StringBuffer(); - for (int i = 0; i < array.length; i++) { - if (i > 0) - sb.append(" "); - sb.append(Integer.toHexString(0xff & array[i] | 0x100).substring(1).toUpperCase()); - } - - return sb.toString(); - } - - public static byte[] normalizeUnicode(byte[] data) throws Exception { - - DerValue value = new DerValue(data); - byte[] tmp = value.data.toByteArray(); - - if (tmp[0] == -2 && tmp[1] == -1) { // remove optional big-endian byte-order mark - - byte tag = value.tag; - int length = value.length() - 2; - - DerOutputStream os = new DerOutputStream(); - os.putTag((byte) 0, false, tag); - os.putLength(length); - os.write(tmp, 2, length); - - return os.toByteArray(); - } - - return data; - } - - public static byte[] encode(byte tag, String string) throws Exception { - DerOutputStream os = new DerOutputStream(); - os.putStringType(tag, string); - return os.toByteArray(); - } - - public static String decode(byte tag, byte[] bytes) throws Exception { - DerInputStream is = new DerInputStream(bytes); - - switch (tag) { - case DerValue.tag_BMPString: - return is.getBMPString(); - case DerValue.tag_IA5String: - return is.getIA5String(); - case DerValue.tag_PrintableString: - return is.getPrintableString(); - case DerValue.tag_T61String: - return is.getT61String(); - case DerValue.tag_UniversalString: - return is.getUniversalString(); - case DerValue.tag_UTF8String: - return is.getDerValue().getUTF8String(); - default: - throw new Exception("Unsupported tag: " + tag); - } - } -} diff --git a/pki/base/util/test/com/netscape/security/util/TeletexStringTest.java b/pki/base/util/test/com/netscape/security/util/TeletexStringTest.java deleted file mode 100644 index 69f46c220..000000000 --- a/pki/base/util/test/com/netscape/security/util/TeletexStringTest.java +++ /dev/null @@ -1,273 +0,0 @@ -package com.netscape.security.util; - -import java.io.IOException; - -import org.junit.Test; -import org.junit.Assert; - -import sun.security.util.DerValue; - -public class TeletexStringTest { - - public byte tag = DerValue.tag_T61String; - - @Test - public void testEncodingEmptyString() throws Exception { - - String string = ""; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingEmptyString() throws Exception { - - String input = ""; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingNullCharacters() throws Exception { - - String string = StringTestUtil.NULL_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - actual = StringTestUtil.normalizeUnicode(actual); - System.out.println(" - norm. : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingNullCharacters() throws Exception { - - String input = StringTestUtil.NULL_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingPrintableCharacters() throws Exception { - - String string = StringTestUtil.PRINTABLE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingPrintableCharacters() throws Exception { - - String input = StringTestUtil.PRINTABLE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingNonPrintableCharacters() throws Exception { - - String string = StringTestUtil.NON_PRINTABLE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingNonPrintableCharacters() throws Exception { - - String input = StringTestUtil.NON_PRINTABLE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingControlCharacters() throws Exception { - - String string = StringTestUtil.CONTROL_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingControlCharacters() throws Exception { - - String input = StringTestUtil.CONTROL_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingMultibyteCharacters() throws Exception { - - String string = StringTestUtil.MULTIBYTE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - System.out.println(" - expected: IOException"); - - try { - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IOException); - } - } - - @Test - public void testDecodingMultibyteCharacters() throws Exception { - - String input = StringTestUtil.MULTIBYTE_CHARS; - byte[] data = JSSUtil.encode(DerValue.tag_UTF8String, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: IOException"); - - try { - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IOException); - } - } - - @Test - public void testEncodingTime() throws Exception { - - System.out.println("Encoding time:"); - - String string = StringTestUtil.NULL_CHARS + - StringTestUtil.PRINTABLE_CHARS + - StringTestUtil.NON_PRINTABLE_CHARS + - StringTestUtil.CONTROL_CHARS; - - long t0 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - JSSUtil.encode(tag, string); - - long t1 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - StringTestUtil.encode(tag, string); - - long t2 = System.currentTimeMillis(); - - long time1 = t1 - t0; - long time2 = t2 - t1; - - System.out.println(" - JSS : " + time1 + " ms"); - System.out.println(" - Internal: " + time2 + " ms"); - } - - @Test - public void testDecodingTime() throws Exception { - - System.out.println("Decoding time:"); - - String string = StringTestUtil.NULL_CHARS + - StringTestUtil.PRINTABLE_CHARS + - StringTestUtil.NON_PRINTABLE_CHARS + - StringTestUtil.CONTROL_CHARS; - - byte[] data = JSSUtil.encode(tag, string); - - long t0 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - JSSUtil.decode(tag, data); - - long t1 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - StringTestUtil.decode(tag, data); - - long t2 = System.currentTimeMillis(); - - long time1 = t1 - t0; - long time2 = t2 - t1; - - System.out.println(" - JSS : " + time1 + " ms"); - System.out.println(" - Internal: " + time2 + " ms"); - } -} diff --git a/pki/base/util/test/com/netscape/security/util/UTF8StringTest.java b/pki/base/util/test/com/netscape/security/util/UTF8StringTest.java deleted file mode 100644 index 6bffb28b6..000000000 --- a/pki/base/util/test/com/netscape/security/util/UTF8StringTest.java +++ /dev/null @@ -1,262 +0,0 @@ -package com.netscape.security.util; - -import org.junit.Test; -import org.junit.Assert; - -import sun.security.util.DerValue; - -public class UTF8StringTest { - - public byte tag = DerValue.tag_UTF8String; - - @Test - public void testEncodingEmptyString() throws Exception { - - String string = ""; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, ""); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, ""); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingEmptyString() throws Exception { - - String input = ""; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingNullCharacters() throws Exception { - - String string = StringTestUtil.NULL_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - actual = StringTestUtil.normalizeUnicode(actual); - System.out.println(" - norm. : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingNullCharacters() throws Exception { - - String input = StringTestUtil.NULL_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingPrintableCharacters() throws Exception { - - String string = StringTestUtil.PRINTABLE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingPrintableCharacters() throws Exception { - - String input = StringTestUtil.PRINTABLE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingNonPrintableCharacters() throws Exception { - - String string = StringTestUtil.NON_PRINTABLE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingNonPrintableCharacters() throws Exception { - - String input = StringTestUtil.NON_PRINTABLE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingControlCharacters() throws Exception { - - String string = StringTestUtil.CONTROL_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingControlCharacters() throws Exception { - - String input = StringTestUtil.CONTROL_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingMultibyteCharacters() throws Exception { - - String string = StringTestUtil.MULTIBYTE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingMultibyteCharacters() throws Exception { - - String input = StringTestUtil.MULTIBYTE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingTime() throws Exception { - - System.out.println("Encoding time:"); - - String string = StringTestUtil.NULL_CHARS + - StringTestUtil.PRINTABLE_CHARS + - StringTestUtil.NON_PRINTABLE_CHARS + - StringTestUtil.CONTROL_CHARS + - StringTestUtil.MULTIBYTE_CHARS; - - long t0 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - JSSUtil.encode(tag, string); - - long t1 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - StringTestUtil.encode(tag, string); - - long t2 = System.currentTimeMillis(); - - long time1 = t1 - t0; - long time2 = t2 - t1; - - System.out.println(" - JSS : " + time1 + " ms"); - System.out.println(" - Internal: " + time2 + " ms"); - } - - @Test - public void testDecodingTime() throws Exception { - - System.out.println("Decoding time:"); - - String string = StringTestUtil.NULL_CHARS + - StringTestUtil.PRINTABLE_CHARS + - StringTestUtil.NON_PRINTABLE_CHARS + - StringTestUtil.CONTROL_CHARS + - StringTestUtil.MULTIBYTE_CHARS; - - byte[] data = JSSUtil.encode(tag, string); - - long t0 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - JSSUtil.decode(tag, data); - - long t1 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - StringTestUtil.decode(tag, data); - - long t2 = System.currentTimeMillis(); - - long time1 = t1 - t0; - long time2 = t2 - t1; - - System.out.println(" - JSS : " + time1 + " ms"); - System.out.println(" - Internal: " + time2 + " ms"); - } -} diff --git a/pki/base/util/test/com/netscape/security/util/UniversalStringTest.java b/pki/base/util/test/com/netscape/security/util/UniversalStringTest.java deleted file mode 100644 index 5f09f1f8e..000000000 --- a/pki/base/util/test/com/netscape/security/util/UniversalStringTest.java +++ /dev/null @@ -1,262 +0,0 @@ -package com.netscape.security.util; - -import org.junit.Test; -import org.junit.Assert; - -import sun.security.util.DerValue; - -public class UniversalStringTest { - - public byte tag = DerValue.tag_UniversalString; - - @Test - public void testEncodingEmptyString() throws Exception { - - String string = ""; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingEmptyString() throws Exception { - - String input = ""; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingNullCharacters() throws Exception { - - String string = StringTestUtil.NULL_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - actual = StringTestUtil.normalizeUnicode(actual); - System.out.println(" - norm. : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingNullCharacters() throws Exception { - - String input = StringTestUtil.NULL_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingPrintableCharacters() throws Exception { - - String string = StringTestUtil.PRINTABLE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingPrintableCharacters() throws Exception { - - String input = StringTestUtil.PRINTABLE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingNonPrintableCharacters() throws Exception { - - String string = StringTestUtil.NON_PRINTABLE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingNonPrintableCharacters() throws Exception { - - String input = StringTestUtil.NON_PRINTABLE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + input + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + output + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingControlCharacters() throws Exception { - - String string = StringTestUtil.CONTROL_CHARS; - System.out.println("Encoding: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingControlCharacters() throws Exception { - - String input = StringTestUtil.CONTROL_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingMultibyteCharacters() throws Exception { - - String string = StringTestUtil.MULTIBYTE_CHARS; - System.out.println("Encoding: [" + string + "]"); - - byte[] expected = JSSUtil.encode(tag, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = StringTestUtil.encode(tag, string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testDecodingMultibyteCharacters() throws Exception { - - String input = StringTestUtil.MULTIBYTE_CHARS; - byte[] data = JSSUtil.encode(tag, input); - - System.out.println("Decoding: [" + StringTestUtil.toString(data) + "]"); - - System.out.println(" - expected: [" + StringTestUtil.toString(input.getBytes()) + "]"); - - String output = StringTestUtil.decode(tag, data); - System.out.println(" - actual : [" + StringTestUtil.toString(output.getBytes()) + "]"); - - Assert.assertEquals(input, output); - } - - @Test - public void testEncodingTime() throws Exception { - - System.out.println("Encoding time:"); - - String string = StringTestUtil.NULL_CHARS + - StringTestUtil.PRINTABLE_CHARS + - StringTestUtil.NON_PRINTABLE_CHARS + - StringTestUtil.CONTROL_CHARS + - StringTestUtil.MULTIBYTE_CHARS; - - long t0 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - JSSUtil.encode(tag, string); - - long t1 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - StringTestUtil.encode(tag, string); - - long t2 = System.currentTimeMillis(); - - long time1 = t1 - t0; - long time2 = t2 - t1; - - System.out.println(" - JSS : " + time1 + " ms"); - System.out.println(" - Internal: " + time2 + " ms"); - } - - @Test - public void testDecodingTime() throws Exception { - - System.out.println("Decoding time:"); - - String string = StringTestUtil.NULL_CHARS + - StringTestUtil.PRINTABLE_CHARS + - StringTestUtil.NON_PRINTABLE_CHARS + - StringTestUtil.CONTROL_CHARS + - StringTestUtil.MULTIBYTE_CHARS; - - byte[] data = JSSUtil.encode(tag, string); - - long t0 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - JSSUtil.decode(tag, data); - - long t1 = System.currentTimeMillis(); - - for (int i = 0; i < 10000; i++) - StringTestUtil.decode(tag, data); - - long t2 = System.currentTimeMillis(); - - long time1 = t1 - t0; - long time2 = t2 - t1; - - System.out.println(" - JSS : " + time1 + " ms"); - System.out.println(" - Internal: " + time2 + " ms"); - } -} diff --git a/pki/base/util/test/com/netscape/security/x509/ConverterTestUtil.java b/pki/base/util/test/com/netscape/security/x509/ConverterTestUtil.java deleted file mode 100644 index 748c1b284..000000000 --- a/pki/base/util/test/com/netscape/security/x509/ConverterTestUtil.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.netscape.security.x509; - -import netscape.security.util.DerOutputStream; -import netscape.security.util.DerValue; -import netscape.security.x509.AVAValueConverter; - -public class ConverterTestUtil { - - public static byte[] convert(AVAValueConverter converter, String string, byte[] tags) throws Exception { - - DerOutputStream os = new DerOutputStream(); - - DerValue value = converter.getValue(string, tags); - value.encode(os); - - return os.toByteArray(); - } - - public static byte[] convert(AVAValueConverter converter, String string) throws Exception { - return convert(converter, string, null); - } -} diff --git a/pki/base/util/test/com/netscape/security/x509/DirStrConverterTest.java b/pki/base/util/test/com/netscape/security/x509/DirStrConverterTest.java deleted file mode 100644 index 0549dec9c..000000000 --- a/pki/base/util/test/com/netscape/security/x509/DirStrConverterTest.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.netscape.security.x509; - -import org.junit.Test; -import org.junit.Assert; - -import com.netscape.security.util.JSSUtil; -import com.netscape.security.util.StringTestUtil; - -import netscape.security.util.DerValue; -import netscape.security.x509.DirStrConverter; - -public class DirStrConverterTest { - - @Test - public void testEmptyString() throws Exception { - - String string = ""; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_PrintableString, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new DirStrConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testNullCharacters() throws Exception { - - String string = StringTestUtil.NULL_CHARS; - System.out.println("Converting: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_T61String, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new DirStrConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testPrintableCharacters() throws Exception { - - String string = StringTestUtil.PRINTABLE_CHARS; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_PrintableString, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new DirStrConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testControlCharacters() throws Exception { - - String string = StringTestUtil.CONTROL_CHARS; - System.out.println("Converting: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_T61String, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new DirStrConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testMultibyteCharacters() throws Exception { - - String string = StringTestUtil.MULTIBYTE_CHARS; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_UniversalString, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new DirStrConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testPrintableCharactersWithTags() throws Exception { - - String string = StringTestUtil.PRINTABLE_CHARS; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_IA5String, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new DirStrConverter(), string, new byte[] { - DerValue.tag_IA5String, DerValue.tag_UTF8String - }); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testMultibyteCharactersWithTags() throws Exception { - - String string = StringTestUtil.MULTIBYTE_CHARS; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_UTF8String, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new DirStrConverter(), string, new byte[] { - DerValue.tag_IA5String, DerValue.tag_UTF8String - }); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } -} diff --git a/pki/base/util/test/com/netscape/security/x509/GenericValueConverterTest.java b/pki/base/util/test/com/netscape/security/x509/GenericValueConverterTest.java deleted file mode 100644 index 46ea86cc7..000000000 --- a/pki/base/util/test/com/netscape/security/x509/GenericValueConverterTest.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.netscape.security.x509; - -import org.junit.Test; -import org.junit.Assert; - -import com.netscape.security.util.JSSUtil; -import com.netscape.security.util.StringTestUtil; - -import netscape.security.util.DerValue; -import netscape.security.x509.GenericValueConverter; - -public class GenericValueConverterTest { - - @Test - public void testEmptyString() throws Exception { - - String string = ""; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_PrintableString, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new GenericValueConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testNullCharacters() throws Exception { - - String string = StringTestUtil.NULL_CHARS; - System.out.println("Converting: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_IA5String, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new GenericValueConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testPrintableCharacters() throws Exception { - - String string = StringTestUtil.PRINTABLE_CHARS; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_PrintableString, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new GenericValueConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testControlCharacters() throws Exception { - - String string = StringTestUtil.CONTROL_CHARS; - System.out.println("Converting: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_IA5String, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new GenericValueConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testMultibyteCharacters() throws Exception { - - String string = StringTestUtil.MULTIBYTE_CHARS; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_BMPString, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new GenericValueConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - actual = StringTestUtil.normalizeUnicode(actual); - System.out.println(" - norm. : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testPrintableCharactersWithTags() throws Exception { - - String string = StringTestUtil.PRINTABLE_CHARS; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_T61String, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new GenericValueConverter(), string, new byte[] { - DerValue.tag_T61String, DerValue.tag_UniversalString - }); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testMultibyteCharactersWithTags() throws Exception { - - String string = StringTestUtil.MULTIBYTE_CHARS; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_UniversalString, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new GenericValueConverter(), string, new byte[] { - DerValue.tag_T61String, DerValue.tag_UniversalString - }); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } -} diff --git a/pki/base/util/test/com/netscape/security/x509/IA5StringConverterTest.java b/pki/base/util/test/com/netscape/security/x509/IA5StringConverterTest.java deleted file mode 100644 index ba99218ad..000000000 --- a/pki/base/util/test/com/netscape/security/x509/IA5StringConverterTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.netscape.security.x509; - -import org.junit.Test; -import org.junit.Assert; - -import com.netscape.security.util.JSSUtil; -import com.netscape.security.util.StringTestUtil; - -import netscape.security.util.DerValue; -import netscape.security.x509.IA5StringConverter; - -public class IA5StringConverterTest { - - @Test - public void testEmptyString() throws Exception { - - String string = ""; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_IA5String, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new IA5StringConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testNullCharacters() throws Exception { - - String string = StringTestUtil.NULL_CHARS; - System.out.println("Converting: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_IA5String, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new IA5StringConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testPrintableCharacters() throws Exception { - - String string = StringTestUtil.PRINTABLE_CHARS; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_IA5String, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new IA5StringConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testControlCharacters() throws Exception { - - String string = StringTestUtil.CONTROL_CHARS; - System.out.println("Converting: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_IA5String, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new IA5StringConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testMultibyteCharacters() throws Exception { - - String string = StringTestUtil.MULTIBYTE_CHARS; - System.out.println("Converting: [" + string + "]"); - - System.out.println(" - expected: IllegalArgumentException"); - - try { - byte[] actual = ConverterTestUtil.convert(new IA5StringConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IllegalArgumentException); - } - } -} diff --git a/pki/base/util/test/com/netscape/security/x509/PrintableConverterTest.java b/pki/base/util/test/com/netscape/security/x509/PrintableConverterTest.java deleted file mode 100644 index a7acc9c90..000000000 --- a/pki/base/util/test/com/netscape/security/x509/PrintableConverterTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.netscape.security.x509; - -import org.junit.Test; -import org.junit.Assert; - -import com.netscape.security.util.JSSUtil; -import com.netscape.security.util.StringTestUtil; - -import netscape.security.util.DerValue; -import netscape.security.x509.PrintableConverter; - -public class PrintableConverterTest { - - @Test - public void testEmptyString() throws Exception { - - String string = ""; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_PrintableString, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new PrintableConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testNullCharacters() throws Exception { - - String string = StringTestUtil.NULL_CHARS; - System.out.println("Converting: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - System.out.println(" - expected: IllegalArgumentException"); - - try { - byte[] actual = ConverterTestUtil.convert(new PrintableConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IllegalArgumentException); - } - } - - @Test - public void testPrintableCharacters() throws Exception { - - String string = StringTestUtil.PRINTABLE_CHARS; - System.out.println("Converting: [" + string + "]"); - - byte[] expected = JSSUtil.encode(DerValue.tag_PrintableString, string); - System.out.println(" - expected: " + StringTestUtil.toString(expected)); - - byte[] actual = ConverterTestUtil.convert(new PrintableConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.assertArrayEquals(expected, actual); - } - - @Test - public void testControlCharacters() throws Exception { - - String string = StringTestUtil.CONTROL_CHARS; - System.out.println("Converting: [" + StringTestUtil.toString(string.getBytes()) + "]"); - - System.out.println(" - expected: IllegalArgumentException"); - - try { - byte[] actual = ConverterTestUtil.convert(new PrintableConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IllegalArgumentException); - } - } - - @Test - public void testMultibyteCharacters() throws Exception { - - String string = StringTestUtil.MULTIBYTE_CHARS; - System.out.println("Converting: [" + string + "]"); - - System.out.println(" - expected: IllegalArgumentException"); - - try { - byte[] actual = ConverterTestUtil.convert(new PrintableConverter(), string); - System.out.println(" - actual : " + StringTestUtil.toString(actual)); - - Assert.fail(); - - } catch (Exception e) { - System.out.println(" - actual : " + e.getClass().getSimpleName()); - Assert.assertTrue(e instanceof IllegalArgumentException); - } - } -} |