diff options
Diffstat (limited to 'src/net/gcdc/asn1/test')
25 files changed, 0 insertions, 2269 deletions
diff --git a/src/net/gcdc/asn1/test/TestSequenceOfLong.java b/src/net/gcdc/asn1/test/TestSequenceOfLong.java deleted file mode 100644 index f5c295f..0000000 --- a/src/net/gcdc/asn1/test/TestSequenceOfLong.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.gcdc.asn1.test;
-
-import java.util.Collection;
-import java.util.List;
-
-import net.gcdc.asn1.datatypes.Asn1SequenceOf;
-
-public class TestSequenceOfLong extends Asn1SequenceOf<Long> {
- public TestSequenceOfLong() { super(); }
- public TestSequenceOfLong(Collection<Long> coll) { super(coll); }
-
-
- public TestSequenceOfLong(List<Long> numbers) {
- super();
- for (Long number: numbers){
- this.add(new Long(number));
- }
- }
-
- public static TestSequenceOfLong getSequence(List<Long> numList) {
- if (numList == null || numList.isEmpty()) return null;
- return new TestSequenceOfLong(numList);
- }
-}
diff --git a/src/net/gcdc/asn1/test/UperEncodeBooleanTest.java b/src/net/gcdc/asn1/test/UperEncodeBooleanTest.java deleted file mode 100644 index b9ca590..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeBooleanTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1Optional; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeBooleanTest { - - /** - * Example from the Standard on UPER. - <pre> - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - value BOOLEAN OPTIONAL, -} - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - @Asn1Optional() Boolean value; - - public TestRecord() { - this(false); - } - - public TestRecord(Boolean value) { - this.value = value; - } - } - - - @Test public void testTrue() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord(new Boolean(true)); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("C0",hex); - } - - @Test public void testFalse() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord(new Boolean(false)); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("80",hex); - } - - @Test public void testDecodeTrue() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord(new Boolean(true)); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("C0",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value,record.value); - - } - - @Test public void testDecodeFalse() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord(new Boolean(false)); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("80",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value,record.value); - } - - - - - - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeChoiceExtensionTest.java b/src/net/gcdc/asn1/test/UperEncodeChoiceExtensionTest.java deleted file mode 100644 index 19cdb63..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeChoiceExtensionTest.java +++ /dev/null @@ -1,93 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1Optional; -import net.gcdc.asn1.datatypes.CharacterRestriction; -import net.gcdc.asn1.datatypes.Choice; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.HasExtensionMarker; -import net.gcdc.asn1.datatypes.IsExtension; -import net.gcdc.asn1.datatypes.RestrictedString; -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeChoiceExtensionTest { - - /** Example for extended sequence - TestRecord ::= [APPLICATION 0] CHOICE { - value1 IA5String - ,... - ,value2 IA5String - } - - value TestRecord ::= value2: "extension" - */ - @Choice - @HasExtensionMarker - public static class TestRecordExtended { - - @FieldOrder(order = 0) - @RestrictedString(CharacterRestriction.IA5String) - String value1 = null; - - @FieldOrder(order = 1) - @IsExtension - @RestrictedString(CharacterRestriction.IA5String) - String value2 = "extension"; - - public TestRecordExtended() { } - } - - /** Example for extended sequence - TestRecord ::= [APPLICATION 0] CHOICE { - value1 IA5String, - ,... - } - */ - @Choice - @HasExtensionMarker - public static class TestRecord { - - @RestrictedString(CharacterRestriction.IA5String) - @Asn1Optional() String value1 = "regular"; - - public TestRecord() { } - } - - - @Test public void testEncode() throws IllegalArgumentException, IllegalAccessException { - TestRecordExtended record = new TestRecordExtended(); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("800909CBE3A65DDCF4EFDC",hex); - } - - @Test public void testDecodeExtended() throws IllegalArgumentException, IllegalAccessException { - TestRecordExtended record = new TestRecordExtended(); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("800909CBE3A65DDCF4EFDC",hex); - TestRecordExtended result = UperEncoder.decode(encoded, TestRecordExtended.class); - assertEquals(result.value2,record.value2); - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - TestRecordExtended record = new TestRecordExtended(); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("800909CBE3A65DDCF4EFDC",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assert(result == null); - } - - - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeChoiceTest.java b/src/net/gcdc/asn1/test/UperEncodeChoiceTest.java deleted file mode 100644 index 8dc8ce1..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeChoiceTest.java +++ /dev/null @@ -1,75 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.CharacterRestriction; -import net.gcdc.asn1.datatypes.Choice; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.RestrictedString; -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeChoiceTest { - - /** - * Example from the Standard on UPER. - <pre> - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - value EnumType DEFAULT value2, - } - - EnumType ::= ENUMERATED { - value1 (0), - value2 (1) - ,... - } - </pre> - */ - @Choice - public static class TestRecord { - - @FieldOrder(order = 0) - @RestrictedString(CharacterRestriction.UTF8String) - String valueUtf8; - - @FieldOrder(order = 1) - @RestrictedString(CharacterRestriction.IA5String) - String valueIA5; - - public TestRecord() { - } - - public TestRecord(String utf8, String ia5) { - this.valueUtf8 = utf8; - this.valueIA5 = ia5; - } - } - - @Test public void testEncode() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord(null, "Meier"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("82CDCBA72F20",hex); - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord(null, "Meier"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("82CDCBA72F20",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(null,record.valueUtf8); - assertEquals(result.valueIA5,record.valueIA5); - } - - - - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeEnumExtensionTest.java b/src/net/gcdc/asn1/test/UperEncodeEnumExtensionTest.java deleted file mode 100644 index 4b91f8e..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeEnumExtensionTest.java +++ /dev/null @@ -1,148 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1Optional; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.HasExtensionMarker; -import net.gcdc.asn1.datatypes.IsExtension; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeEnumExtensionTest { - - /*** Example from the Standard on UPER. - <pre> - World-Schema DEFINITIONS AUTOMATIC TAGS ::= - BEGIN - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - value EnumType DEFAULT value2 - } - - EnumType ::= ENUMERATED { - value1 (0), - value2 (1) - ,... - } - END - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - @Asn1Optional EnumType value = EnumType.value1; - public TestRecord() {} - public void setValue(EnumType value) { - this.value = value; - } - } - - - /*** Example from the Standard on UPER. - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - value EnumType DEFAULT value2, - } - - EnumType ::= ENUMERATED { - value1 (0), - value2 (1) - ,... - value3 (2) - } - */ - @Sequence - public static class TestRecordExtended { - - @Asn1Optional EnumTypeExtended value = EnumTypeExtended.value3; - - public TestRecordExtended() {} - - public void setValue(EnumTypeExtended value) { - this.value = value; - } - - - } - - @HasExtensionMarker - public enum EnumType { - value1("value1"), - value2("value2"); - - public String text; - - EnumType(String text) { - this.text = text; - } - - public String toString(){ - return text; - } - } - - - @HasExtensionMarker - public enum EnumTypeExtended { - value1("value1"), - value2("value2"), - - @IsExtension - value3("value3"); - - public String text; - - EnumTypeExtended(String text) { - this.text = text; - } - - public String toString(){ - return text; - } - } - - - - @Test public void testExtension() throws IllegalArgumentException, IllegalAccessException { - - TestRecordExtended record = new TestRecordExtended(); - record.setValue(EnumTypeExtended.value3); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("Enum value3: data hex: %s", hex)); - assertEquals("C000", hex); - } - - @Test public void testExtensionDecoding() throws IllegalArgumentException, IllegalAccessException { - - TestRecordExtended record = new TestRecordExtended(); - record.setValue(EnumTypeExtended.value3); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("Enum value3: data hex: %s", hex)); - assertEquals("C000", hex); - - TestRecordExtended result = UperEncoder.decode(encoded, TestRecordExtended.class); - assertEquals(result.value,EnumTypeExtended.value3); - } - - @Test public void testUnknownExtensionDecoding() throws IllegalArgumentException, IllegalAccessException { - - TestRecordExtended record = new TestRecordExtended(); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("Enum value3: data hex: %s", hex)); - assertEquals("C000", hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assert(result.value == null); - } - - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeEnumTest.java b/src/net/gcdc/asn1/test/UperEncodeEnumTest.java deleted file mode 100644 index ce41e7a..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeEnumTest.java +++ /dev/null @@ -1,128 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1Default; -import net.gcdc.asn1.datatypes.Asn1Optional; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeEnumTest { - - /** - * Example from the Standard on UPER. - <pre> - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - value EnumType DEFAULT value2, - } - - EnumType ::= ENUMERATED { - value1 (0), - value2 (1) - ,... - } - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - @Asn1Default(value="value2") - @Asn1Optional EnumType value = EnumType.value2; - - - public TestRecord() {} - - public TestRecord(EnumType value) { - this.value = value; - } - } - - public enum EnumType { - value1("value1"), - value2("value2"), - value3("value3"), - value4("value4"), - value5("value5"), - value6("value6"), - value7("value7"), - value8("value8"), - value9("value9"), - value10("value10"), - value11("value11"), - value12("value12"), - value13("value13"), - value14("value14"), - value15("value15"), - value16("value16"), - value17("value17"), - value18("value18"), - value19("value19"), - value20("value20"), - value21("value21"), - value22("value22"); - - - public String text; - - EnumType(String text) { - this.text = text; - } - - public String toString(){ - return text; - } - } - - - - @Test public void testNonDefaultValue() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(EnumType.value4); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("Enum value4: data hex: %s", hex)); - assertEquals("8C", hex); - } - - @Test public void testDefaultValue() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(EnumType.value2); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("Enum value2: data hex: %s", hex)); - assertEquals("00", UperEncoder.hexStringFromBytes(encoded)); - } - - @Test public void testDecodeNonDefaultValue() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(EnumType.value4); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("Enum value4: data hex: %s", hex)); - assertEquals("8C", hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value,EnumType.value4); - } - - @Test public void testDecodeDefaultValue() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(EnumType.value2); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("Enum value2: data hex: %s", hex)); - assertEquals("00", UperEncoder.hexStringFromBytes(encoded)); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value,EnumType.value2); - } - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeExtensionFieldOrderTest.java b/src/net/gcdc/asn1/test/UperEncodeExtensionFieldOrderTest.java deleted file mode 100644 index 3c60e9c..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeExtensionFieldOrderTest.java +++ /dev/null @@ -1,102 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1BigInteger; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.HasExtensionMarker; -import net.gcdc.asn1.datatypes.IsExtension; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeExtensionFieldOrderTest { - - /** - * Example from the Standard on UPER. - <pre> - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - number1 INTEGER, - ..., - number2 INTEGER, - number3 INTEGER - } - - value TestRecord ::= { - value1 12345678909999899, - value2 5555555555, - value3 32001 - } - -Encoding to the file 'data.uper' using PER UNALIGNED encoding rule... -TestRecord SEQUENCE [root fieldcount (not encoded) = 1] - value1 INTEGER [length = 7.0] - 12345678909999899 - value2 INTEGER [length = 5.0] - 5555555555 - value3 INTEGER [length = 2.0] - 32001 -Total encoded length = 20.2 -Encoded successfully in 21 bytes: -8395EE2A 2EF8858D 81C18140 52C8C338 C0C09F40 40 - - - </pre> - */ - @Sequence - @HasExtensionMarker - public static class TestRecord { - - @FieldOrder(order = 0) - Asn1BigInteger value1; - - @FieldOrder(order = 1) - @IsExtension - Asn1BigInteger value2; - - @FieldOrder(order = 2) - @IsExtension - Asn1BigInteger value3; - - public TestRecord() { - value1 = new Asn1BigInteger(12345678909999899L); - value2 = new Asn1BigInteger(5555555555L); - value3 = new Asn1BigInteger(32001L); - } - - - } - - - @Test public void test() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("8395EE2A2EF8858D81C1814052C8C338C0C09F4040",hex); - - - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("8395EE2A2EF8858D81C1814052C8C338C0C09F4040",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value1.longValue(),record.value1.longValue()); - assertEquals(result.value2.longValue(),record.value2.longValue()); - assertEquals(result.value3.longValue(),record.value3.longValue()); - - } - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeFieldOrderTest.java b/src/net/gcdc/asn1/test/UperEncodeFieldOrderTest.java deleted file mode 100644 index e535356..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeFieldOrderTest.java +++ /dev/null @@ -1,68 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1Optional; -import net.gcdc.asn1.datatypes.CharacterRestriction; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.RestrictedString; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeFieldOrderTest { - - /** - * Example from the Standard on UPER. - <pre> - World-Schema DEFINITIONS AUTOMATIC TAGS ::= - BEGIN - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - testString1 UTF8String OPTIONAL, - testString2 IA5String OPTIONAL - } - END - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 1) - @RestrictedString(CharacterRestriction.IA5String) - @Asn1Optional() String string2; - - @FieldOrder(order = 0) - @RestrictedString(CharacterRestriction.UTF8String) - @Asn1Optional() String string1; - - - public TestRecord() { - } - - public TestRecord(String utf8, String ia5) { - this.string1 = utf8; - this.string2 = ia5; - } - } - - - @Test public void test() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord("String1", "String2"); - byte[] encoded = UperEncoder.encode(record); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.string1,"String1"); - assertEquals(result.string2,"String2"); - } - - - - - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeIntegerConstrainedTest.java b/src/net/gcdc/asn1/test/UperEncodeIntegerConstrainedTest.java deleted file mode 100644 index 6c6a4af..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeIntegerConstrainedTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.IntRange; -import net.gcdc.asn1.datatypes.Sequence; -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeIntegerConstrainedTest { - - /** - * Example from the Standard on UPER. - <pre> - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - number1 INTEGER (1..999), - number2 INTEGER (0..999), - number3 INTEGER (63..999) - } - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - @IntRange(minValue=1, maxValue=999) - public Long value1; - - @FieldOrder(order = 1) - @IntRange(minValue=0, maxValue=999) - public Long value2; - - @FieldOrder(order = 2) - @IntRange(minValue=63, maxValue=999) - public Long value3; - - - public TestRecord() { - this(new Long(63L)); - } - - public TestRecord(Long num) { - value1 = num; - value2 = num; - value3 = num; - } - } - - - - @Test public void test() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(63L); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("0F83F000",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value1.longValue(),record.value1.longValue()); - assertEquals(result.value2.longValue(),record.value2.longValue()); - assertEquals(result.value3.longValue(),record.value3.longValue()); - - } - - - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeIntegerExtensionTest.java b/src/net/gcdc/asn1/test/UperEncodeIntegerExtensionTest.java deleted file mode 100644 index 4c87bae..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeIntegerExtensionTest.java +++ /dev/null @@ -1,91 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1BigInteger; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.HasExtensionMarker; -import net.gcdc.asn1.datatypes.IsExtension; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeIntegerExtensionTest { - - /** - * Example from the Standard on UPER. - <pre> - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - number1 INTEGER, - ..., - number2 INTEGER, - number3 INTEGER - } - - value TestRecord ::= { - value1 12345678909999899, - value2 5555555555, - value3 32001 - } - -Encoding to the file 'data.uper' using PER UNALIGNED encoding rule... -TestRecord SEQUENCE [root fieldcount (not encoded) = 1] - value1 INTEGER [length = 7.0] - 12345678909999899 - value2 INTEGER [length = 5.0] - 5555555555 - value3 INTEGER [length = 2.0] - 32001 -Total encoded length = 20.2 -Encoded successfully in 21 bytes: -8395EE2A 2EF8858D 81C18140 52C8C338 C0C09F40 40 - - - </pre> - */ - @Sequence - @HasExtensionMarker - public static class TestRecord { - - @FieldOrder(order = 0) - Asn1BigInteger value1; - - @FieldOrder(order = 2) - @IsExtension - Asn1BigInteger value3; - - @FieldOrder(order = 1) - @IsExtension - Asn1BigInteger value2; - - - public TestRecord() { - value1 = new Asn1BigInteger(12345678909999899L); - value2 = new Asn1BigInteger(5555555555L); - value3 = new Asn1BigInteger(32001L); - } - - - } - - - @Test public void test() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - byte[] encoded = UperEncoder.encode(record); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value1.longValue(),record.value1.longValue()); - assertEquals(result.value2.longValue(),record.value2.longValue()); - assertEquals(result.value3.longValue(),record.value3.longValue()); - - - } - - - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeIntegerSmallTest.java b/src/net/gcdc/asn1/test/UperEncodeIntegerSmallTest.java deleted file mode 100644 index c34918f..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeIntegerSmallTest.java +++ /dev/null @@ -1,132 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeIntegerSmallTest { - - /** - * Example from the Standard on UPER. - <pre> - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - number1 INTEGER, - number2 INTEGER - } - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - public Long value1; - - @FieldOrder(order = 1) - public Integer value2; - - public TestRecord() { - this(new Long(12345678909999899L)); - } - - public TestRecord(Long num) { - value1 = num; - value2 = Integer.valueOf(num.intValue()); - } - } - - - - @Test public void test1() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(1L); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("01010101",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value1.longValue(),record.value1.longValue()); - assertEquals(result.value2.longValue(),record.value2.longValue()); - - } - - @Test public void test16() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(16L); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("01100110",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value1.longValue(),record.value1.longValue()); - assertEquals(result.value2.longValue(),record.value2.longValue()); - - } - - - @Test public void test63() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(63L); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("013F013F",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value1.longValue(),record.value1.longValue()); - assertEquals(result.value2.longValue(),record.value2.longValue()); - - } - - @Test public void test64() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(64L); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("01400140",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value1.longValue(),record.value1.longValue()); - assertEquals(result.value2.longValue(),record.value2.longValue()); - - } - - @Test public void test127() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(127L); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("017F017F",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value1.longValue(),record.value1.longValue()); - assertEquals(result.value2.longValue(),record.value2.longValue()); - - } - - @Test public void test128() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(128L); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("020080020080",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value1.longValue(),record.value1.longValue()); - assertEquals(result.value2.longValue(),record.value2.longValue()); - - } - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeIntegerTest.java b/src/net/gcdc/asn1/test/UperEncodeIntegerTest.java deleted file mode 100644 index f4f56f6..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeIntegerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1BigInteger; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeIntegerTest { - - /** - * Example from the Standard on UPER. - <pre> - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - number INTEGER, - } - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - Asn1BigInteger value; - - public TestRecord() { - this(new Long(12345678909999899L)); - } - - public TestRecord(Long num) { - value = new Asn1BigInteger(num); - } - } - - - - @Test public void test() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(12345678909999899L); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("072BDC545DF10B1B",hex); - - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(12345678909999899L); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("072BDC545DF10B1B",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value.longValue(),record.value.longValue()); - - } - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeObjectIdentifierTest.java b/src/net/gcdc/asn1/test/UperEncodeObjectIdentifierTest.java deleted file mode 100644 index d36cfe6..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeObjectIdentifierTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package net.gcdc.asn1.test;
-
-import static org.junit.Assert.assertEquals;
-import java.util.logging.Level;
-
-import org.junit.jupiter.api.Test;
-
-import net.gcdc.asn1.datatypes.Asn1Optional;
-import net.gcdc.asn1.datatypes.CharacterRestriction;
-import net.gcdc.asn1.datatypes.FieldOrder;
-import net.gcdc.asn1.datatypes.RestrictedString;
-import net.gcdc.asn1.datatypes.Sequence;
-import net.gcdc.asn1.uper.UperEncoder;
-
-class UperEncodeObjectIdentifierTest {
-
-
- /**
- * Example from the Standard on UPER.
- <pre>
- TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE {
- value1 OBJECT IDENTIFIER,
- value2 OBJECT IDENTIFIER,
- value3 OBJECT IDENTIFIER
- }
-
- value TestRecord ::= {
- value1 2.16.840.1.101.3.4.3.1,
- value2 2.16.840.1.101.3.4.3.2,
- value3 1.2.840.10045.3.1.7
- }
- </pre>
- */
-
- @Sequence
- public static class TestRecord {
-
- @FieldOrder(order = 0)
- @RestrictedString(CharacterRestriction.ObjectIdentifier)
- String value1 = "2.16.840.1.101.3.4.3.1"; //DSA SHA224
-
- @FieldOrder(order = 1)
- @RestrictedString(CharacterRestriction.ObjectIdentifier)
- String value2 = "2.16.840.1.101.3.4.3.2"; //DSA SHA248
-
- @FieldOrder(order = 2)
- @RestrictedString(CharacterRestriction.ObjectIdentifier)
- String value3 = "1.2.840.10045.3.1.7"; //ECC
-
- public TestRecord() {}
-
- }
-
- @Test
- public void testEncode() throws IllegalArgumentException, IllegalAccessException {
- TestRecord record = new TestRecord();
- byte[] encoded = UperEncoder.encode(record);
- String hex = UperEncoder.hexStringFromBytes(encoded);
- UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex));
- assertEquals("0960864801650304030109608648016503040302082A8648CE3D030107",hex);
- }
-
- @Test
- public void testDecode() throws IllegalArgumentException, IllegalAccessException {
- TestRecord record = new TestRecord();
- byte[] encoded = UperEncoder.encode(record);
- String hex = UperEncoder.hexStringFromBytes(encoded);
- UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex));
- assertEquals("0960864801650304030109608648016503040302082A8648CE3D030107",hex);
- TestRecord result = UperEncoder.decode(encoded, TestRecord.class);
- assertEquals(result.value1,record.value1);
- assertEquals(result.value2,record.value2);
- assertEquals(result.value3,record.value3);
- }
-
-
-}
diff --git a/src/net/gcdc/asn1/test/UperEncodeOctetStringTest.java b/src/net/gcdc/asn1/test/UperEncodeOctetStringTest.java deleted file mode 100644 index eb92373..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeOctetStringTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.Sequence; -import net.gcdc.asn1.datatypesimpl.OctetString; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeOctetStringTest { - - /** - * Example from the Standard on UPER. - <pre> - World-Schema DEFINITIONS AUTOMATIC TAGS ::= - BEGIN - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - value OCTET STRING - } - END - - value TestRecord ::= { value '83DA'H } - - Encoding to the file 'data.uper' using PER UNALIGNED encoding rule... - TestRecord SEQUENCE [fieldcount (not encoded) = 1] - value OCTET STRING [length = 2.0] - 0x83da - Total encoded length = 3.0 - Encoded successfully in 3 bytes: - 0283DA - - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - OctetString value; - - public TestRecord() { - value = new OctetString(); - value.add(hexToByte("83")); - value.add(hexToByte("DA")); - } - } - - - @Test public void test() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("0283DA",hex); - - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("0283DA",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value,record.value); - - } - - public static byte hexToByte(String s){ - return (byte) ((Character.digit(s.charAt(0), 16) << 4) - + Character.digit(s.charAt(1), 16)); - } - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeOptionalSequenceExtensionTest.java b/src/net/gcdc/asn1/test/UperEncodeOptionalSequenceExtensionTest.java deleted file mode 100644 index 4e82a82..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeOptionalSequenceExtensionTest.java +++ /dev/null @@ -1,120 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1Optional; -import net.gcdc.asn1.datatypes.CharacterRestriction; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.HasExtensionMarker; -import net.gcdc.asn1.datatypes.IsExtension; -import net.gcdc.asn1.datatypes.RestrictedString; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeOptionalSequenceExtensionTest { - - /** Example for extended sequence including extension - World-Schema DEFINITIONS AUTOMATIC TAGS ::= - BEGIN - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - value1 IA5String, - ..., - value2 IA5String OPTIONAL - } - END - */ - @Sequence - @HasExtensionMarker - public static class TestRecordExtended { - - @FieldOrder(order = 0) - @RestrictedString(CharacterRestriction.IA5String) - String value1; - - @FieldOrder(order = 1) - @IsExtension - @RestrictedString(CharacterRestriction.IA5String) - @Asn1Optional() String value2; - - public TestRecordExtended() { } - - public void setValue1(String value1) { - this.value1 = value1; - } - - public void setValue2(String value2) { - this.value2 = value2; - } - - - - } - - /** Example for extended sequence - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - value1 IA5String, - ,... - } - */ - @Sequence - @HasExtensionMarker - public static class TestRecord { - - @RestrictedString(CharacterRestriction.IA5String) - String value1 = "regular"; - public TestRecord() { } - } - - - @Test public void testEncode() throws IllegalArgumentException, IllegalAccessException { - TestRecordExtended record = new TestRecordExtended(); - record.setValue1("regular"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("03F2CB9FAECC3C80",hex); - } - - @Test public void testEncodeWithoutOptionalElement() throws IllegalArgumentException, IllegalAccessException { - TestRecordExtended record = new TestRecordExtended(); - record.setValue1("regular"); - record.setValue2("extension"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("83F2CB9FAECC3C80424272F8E997773D3BF700",hex); - } - - @Test public void testDecodeExtended() throws IllegalArgumentException, IllegalAccessException { - TestRecordExtended record = new TestRecordExtended(); - record.setValue1("regular"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("03F2CB9FAECC3C80",hex); - TestRecordExtended result = UperEncoder.decode(encoded, TestRecordExtended.class); - assertEquals(result.value1,record.value1); - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - TestRecordExtended record = new TestRecordExtended(); - record.setValue1("regular"); - record.setValue2("extension"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("83F2CB9FAECC3C80424272F8E997773D3BF700",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value1,record.value1); - } - - - - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeRestrictedIntegerTest.java b/src/net/gcdc/asn1/test/UperEncodeRestrictedIntegerTest.java deleted file mode 100644 index 7463214..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeRestrictedIntegerTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.IntRange; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeRestrictedIntegerTest { - - /** - * Example from the Standard on UPER. - <pre> -TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - number INTEGER(32000..63000), -} - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - @IntRange(maxValue = 63000, minValue = 33000) - Long value; - - public TestRecord() { - this(new Long(33005)); - } - - public TestRecord(Long num) { - value = num; - } - } - - - @Test public void test() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(33005L); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("000A",hex); - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(33005L); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("000A",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value,record.value); - } - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeSequenceExtensionTest.java b/src/net/gcdc/asn1/test/UperEncodeSequenceExtensionTest.java deleted file mode 100644 index 8c5131b..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeSequenceExtensionTest.java +++ /dev/null @@ -1,95 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1Optional; -import net.gcdc.asn1.datatypes.CharacterRestriction; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.HasExtensionMarker; -import net.gcdc.asn1.datatypes.IsExtension; -import net.gcdc.asn1.datatypes.RestrictedString; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeSequenceExtensionTest { - - /** Example for extended sequence including extension - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - value1 IA5String, - ,... - value2 IA5String - } - */ - @Sequence - @HasExtensionMarker - public static class TestRecordExtended { - - @FieldOrder(order = 0) - @RestrictedString(CharacterRestriction.IA5String) - @Asn1Optional() String value1 = "regular"; - - @FieldOrder(order = 1) - @IsExtension - @RestrictedString(CharacterRestriction.IA5String) - @Asn1Optional() String value2 = "extension"; - - - public TestRecordExtended() { } - } - - /** Example for extended sequence - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - value1 IA5String, - ,... - } - */ - @Sequence - @HasExtensionMarker - public static class TestRecord { - - @RestrictedString(CharacterRestriction.IA5String) - @Asn1Optional() String value1 = "regular"; - - public TestRecord() { } - } - - - @Test public void testEncode() throws IllegalArgumentException, IllegalAccessException { - TestRecordExtended record = new TestRecordExtended(); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("C1F965CFD7661E402121397C74CBBB9E9DFB80",hex); - } - - @Test public void testDecodeExtended() throws IllegalArgumentException, IllegalAccessException { - TestRecordExtended record = new TestRecordExtended(); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("C1F965CFD7661E402121397C74CBBB9E9DFB80",hex); - TestRecordExtended result = UperEncoder.decode(encoded, TestRecordExtended.class); - assertEquals(result.value1,record.value1); - assertEquals(result.value2,record.value2); - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - TestRecordExtended record = new TestRecordExtended(); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("C1F965CFD7661E402121397C74CBBB9E9DFB80",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.value1,record.value1); - } - - - - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeSequenceOfIntegerTest.java b/src/net/gcdc/asn1/test/UperEncodeSequenceOfIntegerTest.java deleted file mode 100644 index 40a3772..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeSequenceOfIntegerTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.Sequence; -import net.gcdc.asn1.datatypesimpl.SequenceOfUnrestrictedLong; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeSequenceOfIntegerTest { - - /** - * Example from the Standard on UPER. - <pre> -TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - number INTEGER, -} - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - SequenceOfUnrestrictedLong numbers; - - public TestRecord() { - } - - public TestRecord(List<Long> nums) { - numbers = new SequenceOfUnrestrictedLong(nums); - } - } - - - @Test public void test() throws IllegalArgumentException, IllegalAccessException { - - ArrayList<Long> nums = new ArrayList<Long>(); - nums.add(new Long(12345678909999899L)); - nums.add(new Long(12345678909999899L)); - TestRecord record = new TestRecord(nums); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", UperEncoder.hexStringFromBytes(encoded))); - assertEquals("02072BDC545DF10B1B072BDC545DF10B1B",hex); - - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - - ArrayList<Long> nums = new ArrayList<Long>(); - nums.add(new Long(12345678909999899L)); - nums.add(new Long(12345678909999899L)); - TestRecord record = new TestRecord(nums); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", UperEncoder.hexStringFromBytes(encoded))); - assertEquals("02072BDC545DF10B1B072BDC545DF10B1B",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.numbers.get(0).longValue(),record.numbers.get(0).longValue()); - assertEquals(result.numbers.get(1).longValue(),record.numbers.get(1).longValue()); - - - } - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeSequenceOfRestrictedIntegerTest.java b/src/net/gcdc/asn1/test/UperEncodeSequenceOfRestrictedIntegerTest.java deleted file mode 100644 index c1feece..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeSequenceOfRestrictedIntegerTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.IntRange; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeSequenceOfRestrictedIntegerTest { - - /** - * Example from the Standard on UPER. - <pre> -TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - numbers SEQUENCE OF INTEGER(0..9999999), -} - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - @IntRange(minValue=9500000,maxValue=99900001) - TestSequenceOfLong numbers = null;; - - public TestRecord() { - } - - public void addNumber(Long longValue){ - if (numbers == null) { - numbers = new TestSequenceOfLong(); - } - numbers.add(longValue); - } - } - - - @Test public void test() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - - record.addNumber(new Long(9500001L)); - record.addNumber(new Long(9699999L)); - - - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", UperEncoder.hexStringFromBytes(encoded))); - assertEquals("02000000200C34FC",hex); - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - - record.addNumber(new Long(9500001L)); - record.addNumber(new Long(9699999L)); - - - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", UperEncoder.hexStringFromBytes(encoded))); - assertEquals("02000000200C34FC",hex); - - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.numbers.get(0).longValue(),record.numbers.get(0).longValue()); - assertEquals(result.numbers.get(1).longValue(),record.numbers.get(1).longValue()); - } - - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeSequenceOfStringListTest.java b/src/net/gcdc/asn1/test/UperEncodeSequenceOfStringListTest.java deleted file mode 100644 index 4bc0cb9..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeSequenceOfStringListTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.CharacterRestriction; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.RestrictedString; -import net.gcdc.asn1.datatypes.Sequence; -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeSequenceOfStringListTest { - - /** - * Example from the Standard on UPER. - <pre> - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - strings SEQUENCE OF IA5String, - } - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - @RestrictedString(CharacterRestriction.IA5String) - ArrayList<String> strings = new ArrayList<String>(); - - public TestRecord() { - } - - public List<String> getStrings() { - return strings; - } - - - } - - - @Test public void test() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - record.getStrings().add("test1"); - record.getStrings().add("test2"); - record.getStrings().add("test3"); - - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", UperEncoder.hexStringFromBytes(encoded))); - assertEquals("0305E9979F4620BD32F3E8C817A65E7D1980",hex); - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - record.getStrings().add("test1"); - record.getStrings().add("test2"); - record.getStrings().add("test3"); - - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", UperEncoder.hexStringFromBytes(encoded))); - assertEquals("0305E9979F4620BD32F3E8C817A65E7D1980",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class, null); - assert(result.getStrings().contains("test1")); - assert(result.getStrings().contains("test2")); - assert(result.getStrings().contains("test3")); - - - } - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeSequenceOfStringTest.java b/src/net/gcdc/asn1/test/UperEncodeSequenceOfStringTest.java deleted file mode 100644 index 3ddf93e..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeSequenceOfStringTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.CharacterRestriction; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.RestrictedString; -import net.gcdc.asn1.datatypes.Sequence; -import net.gcdc.asn1.datatypesimpl.SequenceOfStringIA5; -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeSequenceOfStringTest { - - /** - * Example from the Standard on UPER. - <pre> - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - strings SEQUENCE OF IA5String, - } - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - SequenceOfStringIA5 strings = new SequenceOfStringIA5(); - - public TestRecord() { - } - - public SequenceOfStringIA5 getStrings() { - return strings; - } - - - } - - - @Test public void test() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - record.getStrings().add("test1"); - record.getStrings().add("test2"); - record.getStrings().add("test3"); - - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", UperEncoder.hexStringFromBytes(encoded))); - assertEquals("0305E9979F4620BD32F3E8C817A65E7D1980",hex); - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - record.getStrings().add("test1"); - record.getStrings().add("test2"); - record.getStrings().add("test3"); - - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", UperEncoder.hexStringFromBytes(encoded))); - assertEquals("0305E9979F4620BD32F3E8C817A65E7D1980",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assert(result.getStrings().contains("test1")); - assert(result.getStrings().contains("test2")); - assert(result.getStrings().contains("test3")); - - - } - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeSequenceOfUtf8StringTest.java b/src/net/gcdc/asn1/test/UperEncodeSequenceOfUtf8StringTest.java deleted file mode 100644 index 88d5050..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeSequenceOfUtf8StringTest.java +++ /dev/null @@ -1,97 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.Sequence; -import net.gcdc.asn1.datatypesimpl.SequenceOfStringUTF8; -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeSequenceOfUtf8StringTest { - - /** - * Example from the Standard on UPER. - <pre> - World-Schema DEFINITIONS AUTOMATIC TAGS ::= - BEGIN - TestRecord ::= SEQUENCE { - strings SEQUENCE OF UTF8String - } - END - - value TestRecord ::= { - strings {"test1" , "test2" , "test3" } - } - - -Encoding to the file 'data.uper' using PER UNALIGNED encoding rule... -TestRecord SEQUENCE [fieldcount (not encoded) = 1] - strings SEQUENCE OF [count = 3] - UTF8String [length = 5.0] - 0x7465737431 - UTF8String [length = 5.0] - 0x7465737432 - UTF8String [length = 5.0] - 0x7465737433 -Total encoded length = 19.0 -Encoded successfully in 19 bytes: -03057465 73743105 74657374 32057465 737433 - - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - SequenceOfStringUTF8 strings = new SequenceOfStringUTF8(); - - public TestRecord() { - } - - public SequenceOfStringUTF8 getStrings() { - return strings; - } - - - } - - - @Test public void test() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - record.getStrings().add("test1"); - record.getStrings().add("test2"); - record.getStrings().add("test3"); - - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", UperEncoder.hexStringFromBytes(encoded))); - assertEquals("03057465737431057465737432057465737433",hex); - } - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - - TestRecord record = new TestRecord(); - record.getStrings().add("test1"); - record.getStrings().add("test2"); - record.getStrings().add("test3"); - - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", UperEncoder.hexStringFromBytes(encoded))); - assertEquals("03057465737431057465737432057465737433",hex); - - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assert(result.getStrings().contains("test1")); - assert(result.getStrings().contains("test2")); - assert(result.getStrings().contains("test3")); - - - } - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeStringDefaultTest.java b/src/net/gcdc/asn1/test/UperEncodeStringDefaultTest.java deleted file mode 100644 index 46f2ba9..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeStringDefaultTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1Default; -import net.gcdc.asn1.datatypes.Asn1Optional; -import net.gcdc.asn1.datatypes.CharacterRestriction; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.RestrictedString; -import net.gcdc.asn1.datatypes.Sequence; -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeStringDefaultTest { - - /** - * Example from the Standard on UPER. - <pre> - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - testString1 UTF8String OPTIONAL, - testString2 IA5String DEFAULT("TestString") - } - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - @RestrictedString(CharacterRestriction.UTF8String) - @Asn1Optional() String valueUtf8; - - @FieldOrder(order = 1) - @RestrictedString(CharacterRestriction.IA5String) - @Asn1Default(value="testString") String valueIA5; - - public TestRecord() { - } - - public TestRecord(String utf8, String ia5) { - this.valueUtf8 = utf8; - this.valueIA5 = ia5; - } - } - - - @Test public void testEncode() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord("Müller", "testString"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("81D370EF1B1B195C80",hex); - } - - @Test public void testEncodeDefault() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord("Müller", "testString"); - byte[] encoded = UperEncoder.encode(record); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals(result.valueIA5,"testString"); - } - - @Test public void testEncodeDefault2() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord("Müller", null); - byte[] encoded = UperEncoder.encode(record); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals(result.valueIA5,"testString"); - } - - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeStringLengthTest.java b/src/net/gcdc/asn1/test/UperEncodeStringLengthTest.java deleted file mode 100644 index 9db6229..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeStringLengthTest.java +++ /dev/null @@ -1,153 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1Optional; -import net.gcdc.asn1.datatypes.CharacterRestriction; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.RestrictedString; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeStringLengthTest { - - /** - * Example from the Standard on UPER. - <pre> - World-Schema DEFINITIONS AUTOMATIC TAGS ::= - BEGIN - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - testString1 UTF8String OPTIONAL - } - END - - value TestRecord ::= { - testString1 "A" - } - - </pre> - */ - - - - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - @RestrictedString(CharacterRestriction.UTF8String) - @Asn1Optional() String valueUtf8; - - public TestRecord() { - } - - public TestRecord(String utf8) { - this.valueUtf8 = utf8; - } - } - - - @Test public void testEncode1() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord("A"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("80A080",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(record.valueUtf8,result.valueUtf8); - } - - - @Test public void testEncode63() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord("123456789012345678901234567890123456789012345678901234567890123"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("9F9899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C9818991980",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(record.valueUtf8,result.valueUtf8); - } - - @Test public void testEncode64() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord("1234567890123456789012345678901234567890123456789012345678901234"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("A01899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A00",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(record.valueUtf8,result.valueUtf8); - } - - @Test public void testEncode65() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord("12345678901234567890123456789012345678901234567890123456789012345"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("A09899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A80",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(record.valueUtf8,result.valueUtf8); - } - - @Test public void testEncode126() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("BF1899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C9818" + - "99199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C98189919" + - "9A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A" + - "9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B00",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(record.valueUtf8,result.valueUtf8); - } - - - @Test public void testEncode127() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("BF9899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C9818" + - "99199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C98189919" + - "9A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A" + - "9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B" + - "80",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(record.valueUtf8,result.valueUtf8); - } - - @Test public void testEncode128() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord("12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678"); - - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("C0401899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C98" + - "1899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899" + - "199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A" + - "1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B" + - "1B9C00",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(record.valueUtf8,result.valueUtf8); - } - - @Test public void testEncode129() throws IllegalArgumentException, IllegalAccessException { - TestRecord record = new TestRecord("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("C0409899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C98" + - "1899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899" + - "199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A" + - "1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B1B9C1C981899199A1A9B" + - "1B9C1C80",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(record.valueUtf8,result.valueUtf8); - } - -} diff --git a/src/net/gcdc/asn1/test/UperEncodeStringTest.java b/src/net/gcdc/asn1/test/UperEncodeStringTest.java deleted file mode 100644 index 29e6c99..0000000 --- a/src/net/gcdc/asn1/test/UperEncodeStringTest.java +++ /dev/null @@ -1,112 +0,0 @@ -package net.gcdc.asn1.test; - -import static org.junit.Assert.assertEquals; - -import java.util.logging.Level; - -import net.gcdc.asn1.datatypes.Asn1Optional; -import net.gcdc.asn1.datatypes.CharacterRestriction; -import net.gcdc.asn1.datatypes.FieldOrder; -import net.gcdc.asn1.datatypes.RestrictedString; -import net.gcdc.asn1.datatypes.Sequence; - -import net.gcdc.asn1.uper.UperEncoder; - -import org.junit.Test; - - -public class UperEncodeStringTest { - - /** - * Example from the Standard on UPER. - <pre> - World-Schema DEFINITIONS AUTOMATIC TAGS ::= - BEGIN - TestRecord ::= [APPLICATION 0] IMPLICIT SEQUENCE { - testString1 UTF8String OPTIONAL, - testString2 IA5String OPTIONAL - } - END - </pre> - */ - @Sequence - public static class TestRecord { - - @FieldOrder(order = 0) - @RestrictedString(CharacterRestriction.UTF8String) - @Asn1Optional() String valueUtf8; - - @FieldOrder(order = 1) - @RestrictedString(CharacterRestriction.IA5String) - @Asn1Optional() String valueIA5; - - public TestRecord() { - } - - public TestRecord(String utf8, String ia5) { - this.valueUtf8 = utf8; - this.valueIA5 = ia5; - } - } - - - @Test public void testEncode() throws IllegalArgumentException, IllegalAccessException { - - //Teststring: AêñüC - String original = new String("A" + "\u00ea" + "\u00f1" + "\u00fc" + "C"); - - TestRecord record = new TestRecord(original, "Meier"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("C21070EAB0EC70EF10C166E5D39790",hex); - - } - - @Test public void testEncodeUtf8() throws IllegalArgumentException, IllegalAccessException { - - //"ä½ å¥½å—" - String original = new String("\u00e4" + "\u00bd" + "\u00a0" + "\u00e5" + "\u00a5" + "\u00bd" + "\u00e5" + "\u0090" + "\u0097"); - TestRecord record = new TestRecord(original, "Meier"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("C4B0E930AF70A830E970A970AF70E970A430A5C166E5D39790",hex); - } - - - - @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException { - - //Teststring: AêñüC - String original = new String("A" + "\u00ea" + "\u00f1" + "\u00fc" + "C"); - - TestRecord record = new TestRecord(original, "Meier"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("C21070EAB0EC70EF10C166E5D39790",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.valueUtf8,record.valueUtf8); - assertEquals(result.valueIA5,record.valueIA5); - } - - - @Test public void testDecodeUtf8() throws IllegalArgumentException, IllegalAccessException { - //"ä½ å¥½å—" - String original = new String("\u00e4" + "\u00bd" + "\u00a0" + "\u00e5" + "\u00a5" + "\u00bd" + "\u00e5" + "\u0090" + "\u0097"); - TestRecord record = new TestRecord(original, "Meier"); - byte[] encoded = UperEncoder.encode(record); - String hex = UperEncoder.hexStringFromBytes(encoded); - UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex)); - assertEquals("C4B0E930AF70A830E970A970AF70E970A430A5C166E5D39790",hex); - TestRecord result = UperEncoder.decode(encoded, TestRecord.class); - assertEquals(result.valueUtf8,record.valueUtf8); - assertEquals(result.valueIA5,record.valueIA5); - } - - - - - -} |