summaryrefslogtreecommitdiffstats
path: root/src/org/uic/barcode/asn1/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/uic/barcode/asn1/test')
-rw-r--r--src/org/uic/barcode/asn1/test/TestSequenceOfLong.java24
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeBooleanTest.java82
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeChoiceExtensionTest.java92
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeChoiceTest.java74
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeEnumExtensionTest.java146
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeEnumTest.java126
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeExtensionFieldOrderTest.java100
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeFieldOrderTest.java66
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeIntegerConstrainedTest.java71
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeIntegerExtensionTest.java89
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeIntegerSmallTest.java130
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeIntegerTest.java64
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeObjectIdentifierTest.java76
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeOctetStringTest.java80
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeOptionalSequenceExtensionTest.java118
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeRestrictedIntegerTest.java62
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeSequenceExtensionTest.java93
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeSequenceOfIntegerTest.java72
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeSequenceOfRestrictedIntegerTest.java77
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeSequenceOfStringListTest.java78
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeSequenceOfStringTest.java76
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeSequenceOfUtf8StringTest.java96
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeStringDefaultTest.java76
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeStringLengthTest.java151
-rw-r--r--src/org/uic/barcode/asn1/test/UperEncodeStringTest.java110
25 files changed, 2229 insertions, 0 deletions
diff --git a/src/org/uic/barcode/asn1/test/TestSequenceOfLong.java b/src/org/uic/barcode/asn1/test/TestSequenceOfLong.java
new file mode 100644
index 0000000..61af5fa
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/TestSequenceOfLong.java
@@ -0,0 +1,24 @@
+package org.uic.barcode.asn1.test;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.uic.barcode.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/org/uic/barcode/asn1/test/UperEncodeBooleanTest.java b/src/org/uic/barcode/asn1/test/UperEncodeBooleanTest.java
new file mode 100644
index 0000000..b5e73b0
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeBooleanTest.java
@@ -0,0 +1,82 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1Optional;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeChoiceExtensionTest.java b/src/org/uic/barcode/asn1/test/UperEncodeChoiceExtensionTest.java
new file mode 100644
index 0000000..3833ff2
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeChoiceExtensionTest.java
@@ -0,0 +1,92 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1Optional;
+import org.uic.barcode.asn1.datatypes.CharacterRestriction;
+import org.uic.barcode.asn1.datatypes.Choice;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.HasExtensionMarker;
+import org.uic.barcode.asn1.datatypes.IsExtension;
+import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeChoiceTest.java b/src/org/uic/barcode/asn1/test/UperEncodeChoiceTest.java
new file mode 100644
index 0000000..69b92d1
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeChoiceTest.java
@@ -0,0 +1,74 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.CharacterRestriction;
+import org.uic.barcode.asn1.datatypes.Choice;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeEnumExtensionTest.java b/src/org/uic/barcode/asn1/test/UperEncodeEnumExtensionTest.java
new file mode 100644
index 0000000..a2ecbe1
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeEnumExtensionTest.java
@@ -0,0 +1,146 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1Optional;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.HasExtensionMarker;
+import org.uic.barcode.asn1.datatypes.IsExtension;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeEnumTest.java b/src/org/uic/barcode/asn1/test/UperEncodeEnumTest.java
new file mode 100644
index 0000000..d1d2d82
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeEnumTest.java
@@ -0,0 +1,126 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1Default;
+import org.uic.barcode.asn1.datatypes.Asn1Optional;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeExtensionFieldOrderTest.java b/src/org/uic/barcode/asn1/test/UperEncodeExtensionFieldOrderTest.java
new file mode 100644
index 0000000..ff97c27
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeExtensionFieldOrderTest.java
@@ -0,0 +1,100 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1BigInteger;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.HasExtensionMarker;
+import org.uic.barcode.asn1.datatypes.IsExtension;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeFieldOrderTest.java b/src/org/uic/barcode/asn1/test/UperEncodeFieldOrderTest.java
new file mode 100644
index 0000000..5a23f24
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeFieldOrderTest.java
@@ -0,0 +1,66 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1Optional;
+import org.uic.barcode.asn1.datatypes.CharacterRestriction;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeIntegerConstrainedTest.java b/src/org/uic/barcode/asn1/test/UperEncodeIntegerConstrainedTest.java
new file mode 100644
index 0000000..575597f
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeIntegerConstrainedTest.java
@@ -0,0 +1,71 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.IntRange;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeIntegerExtensionTest.java b/src/org/uic/barcode/asn1/test/UperEncodeIntegerExtensionTest.java
new file mode 100644
index 0000000..d0acd20
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeIntegerExtensionTest.java
@@ -0,0 +1,89 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1BigInteger;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.HasExtensionMarker;
+import org.uic.barcode.asn1.datatypes.IsExtension;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeIntegerSmallTest.java b/src/org/uic/barcode/asn1/test/UperEncodeIntegerSmallTest.java
new file mode 100644
index 0000000..5ada54d
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeIntegerSmallTest.java
@@ -0,0 +1,130 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeIntegerTest.java b/src/org/uic/barcode/asn1/test/UperEncodeIntegerTest.java
new file mode 100644
index 0000000..d57fd00
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeIntegerTest.java
@@ -0,0 +1,64 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1BigInteger;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeObjectIdentifierTest.java b/src/org/uic/barcode/asn1/test/UperEncodeObjectIdentifierTest.java
new file mode 100644
index 0000000..edf3348
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeObjectIdentifierTest.java
@@ -0,0 +1,76 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+import java.util.logging.Level;
+
+import org.junit.jupiter.api.Test;
+import org.uic.barcode.asn1.datatypes.Asn1Optional;
+import org.uic.barcode.asn1.datatypes.CharacterRestriction;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.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/org/uic/barcode/asn1/test/UperEncodeOctetStringTest.java b/src/org/uic/barcode/asn1/test/UperEncodeOctetStringTest.java
new file mode 100644
index 0000000..af2a42e
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeOctetStringTest.java
@@ -0,0 +1,80 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.datatypesimpl.OctetString;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeOptionalSequenceExtensionTest.java b/src/org/uic/barcode/asn1/test/UperEncodeOptionalSequenceExtensionTest.java
new file mode 100644
index 0000000..55e6026
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeOptionalSequenceExtensionTest.java
@@ -0,0 +1,118 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1Optional;
+import org.uic.barcode.asn1.datatypes.CharacterRestriction;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.HasExtensionMarker;
+import org.uic.barcode.asn1.datatypes.IsExtension;
+import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeRestrictedIntegerTest.java b/src/org/uic/barcode/asn1/test/UperEncodeRestrictedIntegerTest.java
new file mode 100644
index 0000000..bc82621
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeRestrictedIntegerTest.java
@@ -0,0 +1,62 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.IntRange;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeSequenceExtensionTest.java b/src/org/uic/barcode/asn1/test/UperEncodeSequenceExtensionTest.java
new file mode 100644
index 0000000..29d203b
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeSequenceExtensionTest.java
@@ -0,0 +1,93 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1Optional;
+import org.uic.barcode.asn1.datatypes.CharacterRestriction;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.HasExtensionMarker;
+import org.uic.barcode.asn1.datatypes.IsExtension;
+import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeSequenceOfIntegerTest.java b/src/org/uic/barcode/asn1/test/UperEncodeSequenceOfIntegerTest.java
new file mode 100644
index 0000000..9194dca
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeSequenceOfIntegerTest.java
@@ -0,0 +1,72 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.datatypesimpl.SequenceOfUnrestrictedLong;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeSequenceOfRestrictedIntegerTest.java b/src/org/uic/barcode/asn1/test/UperEncodeSequenceOfRestrictedIntegerTest.java
new file mode 100644
index 0000000..d1834d0
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeSequenceOfRestrictedIntegerTest.java
@@ -0,0 +1,77 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.IntRange;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeSequenceOfStringListTest.java b/src/org/uic/barcode/asn1/test/UperEncodeSequenceOfStringListTest.java
new file mode 100644
index 0000000..49350cc
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeSequenceOfStringListTest.java
@@ -0,0 +1,78 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.CharacterRestriction;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeSequenceOfStringTest.java b/src/org/uic/barcode/asn1/test/UperEncodeSequenceOfStringTest.java
new file mode 100644
index 0000000..f8eccc6
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeSequenceOfStringTest.java
@@ -0,0 +1,76 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.CharacterRestriction;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringIA5;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeSequenceOfUtf8StringTest.java b/src/org/uic/barcode/asn1/test/UperEncodeSequenceOfUtf8StringTest.java
new file mode 100644
index 0000000..ab8fa2a
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeSequenceOfUtf8StringTest.java
@@ -0,0 +1,96 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.datatypesimpl.SequenceOfStringUTF8;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeStringDefaultTest.java b/src/org/uic/barcode/asn1/test/UperEncodeStringDefaultTest.java
new file mode 100644
index 0000000..d8e5029
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeStringDefaultTest.java
@@ -0,0 +1,76 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1Default;
+import org.uic.barcode.asn1.datatypes.Asn1Optional;
+import org.uic.barcode.asn1.datatypes.CharacterRestriction;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeStringLengthTest.java b/src/org/uic/barcode/asn1/test/UperEncodeStringLengthTest.java
new file mode 100644
index 0000000..9dd4389
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeStringLengthTest.java
@@ -0,0 +1,151 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1Optional;
+import org.uic.barcode.asn1.datatypes.CharacterRestriction;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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/org/uic/barcode/asn1/test/UperEncodeStringTest.java b/src/org/uic/barcode/asn1/test/UperEncodeStringTest.java
new file mode 100644
index 0000000..5f4edc8
--- /dev/null
+++ b/src/org/uic/barcode/asn1/test/UperEncodeStringTest.java
@@ -0,0 +1,110 @@
+package org.uic.barcode.asn1.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.logging.Level;
+
+import org.junit.Test;
+import org.uic.barcode.asn1.datatypes.Asn1Optional;
+import org.uic.barcode.asn1.datatypes.CharacterRestriction;
+import org.uic.barcode.asn1.datatypes.FieldOrder;
+import org.uic.barcode.asn1.datatypes.RestrictedString;
+import org.uic.barcode.asn1.datatypes.Sequence;
+import org.uic.barcode.asn1.uper.UperEncoder;
+
+
+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);
+ }
+
+
+
+
+
+}