summaryrefslogtreecommitdiffstats
path: root/src/net/gcdc/asn1/test
diff options
context:
space:
mode:
authorCGantert345 <57003061+CGantert345@users.noreply.github.com>2020-01-03 10:37:01 +0100
committerGitHub <noreply@github.com>2020-01-03 10:37:01 +0100
commit46039355e87825a9dce12ebaad0305d20eea3f43 (patch)
tree6b17c400a9b98d2a6ec367deeea9597ac2c78e5b /src/net/gcdc/asn1/test
parentlogging (diff)
downloadUIC-barcode-46039355e87825a9dce12ebaad0305d20eea3f43.tar
UIC-barcode-46039355e87825a9dce12ebaad0305d20eea3f43.tar.gz
UIC-barcode-46039355e87825a9dce12ebaad0305d20eea3f43.tar.bz2
UIC-barcode-46039355e87825a9dce12ebaad0305d20eea3f43.tar.lz
UIC-barcode-46039355e87825a9dce12ebaad0305d20eea3f43.tar.xz
UIC-barcode-46039355e87825a9dce12ebaad0305d20eea3f43.tar.zst
UIC-barcode-46039355e87825a9dce12ebaad0305d20eea3f43.zip
Diffstat (limited to 'src/net/gcdc/asn1/test')
-rw-r--r--src/net/gcdc/asn1/test/TestSequenceOfLong.java24
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeBooleanTest.java83
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeChoiceExtensionTest.java90
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeChoiceTest.java72
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeEnumExtensionTest.java146
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeEnumTest.java126
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeIntegerConstrainedTest.java68
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeIntegerExtensionTest.java99
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeIntegerSmallTest.java129
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeIntegerTest.java64
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeOctetStringTest.java80
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeOptionalSequenceExtensionTest.java117
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeRestrictedIntegerTest.java62
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeSequenceExtensionTest.java91
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeSequenceOfIntegerTest.java73
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeSequenceOfRestrictedIntegerTest.java77
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeSequenceOfStringListTest.java77
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeSequenceOfStringTest.java76
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeSequenceOfUtf8StringTest.java96
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeStringDefaultTest.java67
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeStringLengthTest.java151
-rw-r--r--src/net/gcdc/asn1/test/UperEncodeStringTest.java95
22 files changed, 1963 insertions, 0 deletions
diff --git a/src/net/gcdc/asn1/test/TestSequenceOfLong.java b/src/net/gcdc/asn1/test/TestSequenceOfLong.java
new file mode 100644
index 0000000..f5c295f
--- /dev/null
+++ b/src/net/gcdc/asn1/test/TestSequenceOfLong.java
@@ -0,0 +1,24 @@
+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
new file mode 100644
index 0000000..9716474
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeBooleanTest.java
@@ -0,0 +1,83 @@
+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.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 {
+
+
+ @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
new file mode 100644
index 0000000..acbbd0b
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeChoiceExtensionTest.java
@@ -0,0 +1,90 @@
+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.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 {
+
+ @RestrictedString(CharacterRestriction.IA5String)
+ String value1 = null;
+
+ @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
new file mode 100644
index 0000000..d35e717
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeChoiceTest.java
@@ -0,0 +1,72 @@
+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.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 {
+
+ @RestrictedString(CharacterRestriction.UTF8String)
+ String valueUtf8;
+
+ @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
new file mode 100644
index 0000000..c098839
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeEnumExtensionTest.java
@@ -0,0 +1,146 @@
+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.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 {
+
+ @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
new file mode 100644
index 0000000..66fbc05
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeEnumTest.java
@@ -0,0 +1,126 @@
+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.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 {
+
+ @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/UperEncodeIntegerConstrainedTest.java b/src/net/gcdc/asn1/test/UperEncodeIntegerConstrainedTest.java
new file mode 100644
index 0000000..9450406
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeIntegerConstrainedTest.java
@@ -0,0 +1,68 @@
+package net.gcdc.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+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 {
+
+ @IntRange(minValue=1, maxValue=999)
+ public Long value1;
+
+ @IntRange(minValue=0, maxValue=999)
+ public Long value2;
+
+ @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
new file mode 100644
index 0000000..5a33368
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeIntegerExtensionTest.java
@@ -0,0 +1,99 @@
+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.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 {
+
+
+ Asn1BigInteger value1;
+
+ @IsExtension
+ Asn1BigInteger value2;
+
+ @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/UperEncodeIntegerSmallTest.java b/src/net/gcdc/asn1/test/UperEncodeIntegerSmallTest.java
new file mode 100644
index 0000000..9ad0e63
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeIntegerSmallTest.java
@@ -0,0 +1,129 @@
+package net.gcdc.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+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 {
+
+ public Long value1;
+
+ 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
new file mode 100644
index 0000000..4eab78a
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeIntegerTest.java
@@ -0,0 +1,64 @@
+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.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 {
+
+ 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/UperEncodeOctetStringTest.java b/src/net/gcdc/asn1/test/UperEncodeOctetStringTest.java
new file mode 100644
index 0000000..7604d6a
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeOctetStringTest.java
@@ -0,0 +1,80 @@
+package net.gcdc.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+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 {
+
+ 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
new file mode 100644
index 0000000..1b2fa09
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeOptionalSequenceExtensionTest.java
@@ -0,0 +1,117 @@
+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.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 {
+
+ @RestrictedString(CharacterRestriction.IA5String)
+ String value1;
+
+ @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
new file mode 100644
index 0000000..27dc5f4
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeRestrictedIntegerTest.java
@@ -0,0 +1,62 @@
+package net.gcdc.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+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 {
+
+ @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
new file mode 100644
index 0000000..7934354
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeSequenceExtensionTest.java
@@ -0,0 +1,91 @@
+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.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 {
+
+ @RestrictedString(CharacterRestriction.IA5String)
+ @Asn1Optional() String value1 = "regular";
+
+ @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
new file mode 100644
index 0000000..6028a29
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeSequenceOfIntegerTest.java
@@ -0,0 +1,73 @@
+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.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 {
+
+
+ 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
new file mode 100644
index 0000000..5ac9834
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeSequenceOfRestrictedIntegerTest.java
@@ -0,0 +1,77 @@
+package net.gcdc.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+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 {
+
+ @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
new file mode 100644
index 0000000..1a8f68e
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeSequenceOfStringListTest.java
@@ -0,0 +1,77 @@
+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.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 {
+
+ @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
new file mode 100644
index 0000000..c7c82f7
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeSequenceOfStringTest.java
@@ -0,0 +1,76 @@
+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.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 {
+
+
+ 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
new file mode 100644
index 0000000..b2c855d
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeSequenceOfUtf8StringTest.java
@@ -0,0 +1,96 @@
+package net.gcdc.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+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 {
+
+
+ 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
new file mode 100644
index 0000000..e43d76d
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeStringDefaultTest.java
@@ -0,0 +1,67 @@
+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.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 {
+
+ @RestrictedString(CharacterRestriction.UTF8String)
+ @Asn1Optional() String valueUtf8;
+
+ @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");
+ }
+
+
+
+
+}
diff --git a/src/net/gcdc/asn1/test/UperEncodeStringLengthTest.java b/src/net/gcdc/asn1/test/UperEncodeStringLengthTest.java
new file mode 100644
index 0000000..378bc06
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeStringLengthTest.java
@@ -0,0 +1,151 @@
+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.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 {
+
+ @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
new file mode 100644
index 0000000..521075c
--- /dev/null
+++ b/src/net/gcdc/asn1/test/UperEncodeStringTest.java
@@ -0,0 +1,95 @@
+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.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 {
+
+ @RestrictedString(CharacterRestriction.UTF8String)
+ @Asn1Optional() String valueUtf8;
+
+ @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 {
+ TestRecord record = new TestRecord("Müller", "Meier");
+ byte[] encoded = UperEncoder.encode(record);
+ String hex = UperEncoder.hexStringFromBytes(encoded);
+ UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex));
+ assertEquals("C1D370EF1B1B195C8166E5D39790",hex);
+ }
+
+ @Test public void testEncodeUtf8() throws IllegalArgumentException, IllegalAccessException {
+ TestRecord record = new TestRecord("你好å—", "Meier");
+ byte[] encoded = UperEncoder.encode(record);
+ String hex = UperEncoder.hexStringFromBytes(encoded);
+ UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex));
+ assertEquals("C2792F6839696F796425C166E5D39790",hex);
+ }
+
+
+
+ @Test public void testDecode() throws IllegalArgumentException, IllegalAccessException {
+ TestRecord record = new TestRecord("Müller", "Meier");
+ byte[] encoded = UperEncoder.encode(record);
+ String hex = UperEncoder.hexStringFromBytes(encoded);
+ UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex));
+ assertEquals("C1D370EF1B1B195C8166E5D39790",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 {
+ TestRecord record = new TestRecord("你好å—", "Meier");
+ byte[] encoded = UperEncoder.encode(record);
+ String hex = UperEncoder.hexStringFromBytes(encoded);
+ UperEncoder.logger.log(Level.FINEST,String.format("data hex: %s", hex));
+ assertEquals("C2792F6839696F796425C166E5D39790",hex);
+ TestRecord result = UperEncoder.decode(encoded, TestRecord.class);
+ assertEquals(result.valueUtf8,record.valueUtf8);
+ assertEquals(result.valueIA5,record.valueIA5);
+ }
+
+
+
+
+
+}