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 /base/util/test/com/netscape/security/util/UTF8StringTest.java | |
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 'base/util/test/com/netscape/security/util/UTF8StringTest.java')
-rw-r--r-- | base/util/test/com/netscape/security/util/UTF8StringTest.java | 262 |
1 files changed, 262 insertions, 0 deletions
diff --git a/base/util/test/com/netscape/security/util/UTF8StringTest.java b/base/util/test/com/netscape/security/util/UTF8StringTest.java new file mode 100644 index 000000000..6bffb28b6 --- /dev/null +++ b/base/util/test/com/netscape/security/util/UTF8StringTest.java @@ -0,0 +1,262 @@ +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"); + } +} |