upgrade: PER related changes


git-svn-id: https://asn1c.svn.sourceforge.net/svnroot/asn1c/trunk@1011 59561ff5-6e30-0410-9f3c-9617f08c8826
diff --git a/skeletons/tests/Makefile.am b/skeletons/tests/Makefile.am
index c374438..a664a6f 100644
--- a/skeletons/tests/Makefile.am
+++ b/skeletons/tests/Makefile.am
@@ -10,7 +10,8 @@
 	check-UTCTime		\
 	check-INTEGER		\
 	check-REAL		\
-	check-XER
+	check-XER		\
+	check-PER
 
 LDADD = -lm
 
diff --git a/skeletons/tests/Makefile.in b/skeletons/tests/Makefile.in
index f5a3c68..d0f980f 100644
--- a/skeletons/tests/Makefile.in
+++ b/skeletons/tests/Makefile.in
@@ -13,7 +13,7 @@
 # PARTICULAR PURPOSE.
 
 @SET_MAKE@
-SOURCES = check-GeneralizedTime.c check-INTEGER.c check-OCTET_STRING.c check-OIDs.c check-REAL.c check-UTCTime.c check-UTF8String.c check-XER.c check-ber_tlv_tag.c check-length.c
+SOURCES = check-GeneralizedTime.c check-INTEGER.c check-OCTET_STRING.c check-OIDs.c check-PER.c check-REAL.c check-UTCTime.c check-UTF8String.c check-XER.c check-ber_tlv_tag.c check-length.c
 
 srcdir = @srcdir@
 top_srcdir = @top_srcdir@
@@ -40,7 +40,7 @@
 	check-OIDs$(EXEEXT) check-GeneralizedTime$(EXEEXT) \
 	check-OCTET_STRING$(EXEEXT) check-UTF8String$(EXEEXT) \
 	check-UTCTime$(EXEEXT) check-INTEGER$(EXEEXT) \
-	check-REAL$(EXEEXT) check-XER$(EXEEXT)
+	check-REAL$(EXEEXT) check-XER$(EXEEXT) check-PER$(EXEEXT)
 subdir = skeletons/tests
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -66,6 +66,10 @@
 check_OIDs_OBJECTS = check-OIDs.$(OBJEXT)
 check_OIDs_LDADD = $(LDADD)
 check_OIDs_DEPENDENCIES =
+check_PER_SOURCES = check-PER.c
+check_PER_OBJECTS = check-PER.$(OBJEXT)
+check_PER_LDADD = $(LDADD)
+check_PER_DEPENDENCIES =
 check_REAL_SOURCES = check-REAL.c
 check_REAL_OBJECTS = check-REAL.$(OBJEXT)
 check_REAL_LDADD = $(LDADD)
@@ -96,7 +100,7 @@
 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/check-GeneralizedTime.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/check-INTEGER.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/check-OCTET_STRING.Po \
-@AMDEP_TRUE@	./$(DEPDIR)/check-OIDs.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/check-OIDs.Po ./$(DEPDIR)/check-PER.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/check-REAL.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/check-UTCTime.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/check-UTF8String.Po \
@@ -112,12 +116,13 @@
 LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
 	$(AM_LDFLAGS) $(LDFLAGS) -o $@
 SOURCES = check-GeneralizedTime.c check-INTEGER.c check-OCTET_STRING.c \
-	check-OIDs.c check-REAL.c check-UTCTime.c check-UTF8String.c \
-	check-XER.c check-ber_tlv_tag.c check-length.c
-DIST_SOURCES = check-GeneralizedTime.c check-INTEGER.c \
-	check-OCTET_STRING.c check-OIDs.c check-REAL.c check-UTCTime.c \
+	check-OIDs.c check-PER.c check-REAL.c check-UTCTime.c \
 	check-UTF8String.c check-XER.c check-ber_tlv_tag.c \
 	check-length.c
+DIST_SOURCES = check-GeneralizedTime.c check-INTEGER.c \
+	check-OCTET_STRING.c check-OIDs.c check-PER.c check-REAL.c \
+	check-UTCTime.c check-UTF8String.c check-XER.c \
+	check-ber_tlv_tag.c check-length.c
 ETAGS = etags
 CTAGS = ctags
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -285,6 +290,9 @@
 check-OIDs$(EXEEXT): $(check_OIDs_OBJECTS) $(check_OIDs_DEPENDENCIES) 
 	@rm -f check-OIDs$(EXEEXT)
 	$(LINK) $(check_OIDs_LDFLAGS) $(check_OIDs_OBJECTS) $(check_OIDs_LDADD) $(LIBS)
+check-PER$(EXEEXT): $(check_PER_OBJECTS) $(check_PER_DEPENDENCIES) 
+	@rm -f check-PER$(EXEEXT)
+	$(LINK) $(check_PER_LDFLAGS) $(check_PER_OBJECTS) $(check_PER_LDADD) $(LIBS)
 check-REAL$(EXEEXT): $(check_REAL_OBJECTS) $(check_REAL_DEPENDENCIES) 
 	@rm -f check-REAL$(EXEEXT)
 	$(LINK) $(check_REAL_LDFLAGS) $(check_REAL_OBJECTS) $(check_REAL_LDADD) $(LIBS)
@@ -314,6 +322,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-INTEGER.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-OCTET_STRING.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-OIDs.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-PER.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-REAL.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-UTCTime.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check-UTF8String.Po@am__quote@
diff --git a/skeletons/tests/check-INTEGER.c b/skeletons/tests/check-INTEGER.c
index bb692c5..fccce28 100644
--- a/skeletons/tests/check-INTEGER.c
+++ b/skeletons/tests/check-INTEGER.c
@@ -6,6 +6,7 @@
 #include <der_encoder.c>
 #include <xer_decoder.c>
 #include <xer_support.c>
+#include <per_support.c>
 #include <constraints.c>
 
 static char *shared_scratch_start;
diff --git a/skeletons/tests/check-OCTET_STRING.c b/skeletons/tests/check-OCTET_STRING.c
index 51f6eb3..b3e298f 100644
--- a/skeletons/tests/check-OCTET_STRING.c
+++ b/skeletons/tests/check-OCTET_STRING.c
@@ -3,6 +3,7 @@
 #include <BIT_STRING.c>
 #include <xer_decoder.c>
 #include <xer_support.c>
+#include <per_support.c>
 #include <ber_decoder.c>
 #include <ber_tlv_length.c>
 #include <ber_tlv_tag.c>
diff --git a/skeletons/tests/check-PER.c b/skeletons/tests/check-PER.c
new file mode 100644
index 0000000..94f5fe4
--- /dev/null
+++ b/skeletons/tests/check-PER.c
@@ -0,0 +1,105 @@
+#include <per_support.c>
+#include <assert.h>
+
+int
+main() {
+	uint8_t buf[] = { 0xB7, 0x19, 0x2F, 0xEE, 0xAD };
+	uint8_t tmpbuf[10];
+	int32_t z;
+	asn_per_data_t pos;
+
+	pos.buffer = buf;
+	pos.nboff = 0;
+	pos.nbits = sizeof(buf) * 8;
+
+	z = per_get_few_bits(&pos, 32);
+	assert(z == -1);
+
+	z = per_get_few_bits(&pos, 0);
+	assert(z == 0);
+	assert(pos.nboff == 0);
+
+	z = per_get_few_bits(&pos, 1);
+	assert(z == 1);
+	assert(pos.nboff == 1);
+
+	z = per_get_few_bits(&pos, 2);
+	assert(z == 1);
+	assert(pos.nboff == 3);
+
+	z = per_get_few_bits(&pos, 2);
+	assert(z == 2);
+	assert(pos.nboff == 5);
+
+	z = per_get_few_bits(&pos, 3);
+	assert(z == 7);
+	assert(pos.nboff == 8);
+	assert(pos.nbits == sizeof(buf) * 8);
+
+	z = per_get_few_bits(&pos, 8);
+	assert(z == 0x19);
+	assert(pos.nboff == 8);
+	assert(pos.nbits == (sizeof(buf) - 1) * 8);
+
+	z = per_get_few_bits(&pos, 1);
+	assert(z == 0);
+	assert(pos.nboff == 1);
+	assert(pos.nbits == (sizeof(buf) - 2) * 8);
+
+	z = per_get_few_bits(&pos, 3);
+	assert(z == 2);
+	assert(pos.nboff == 4);
+	assert(pos.nbits == (sizeof(buf) - 2) * 8);
+
+	z = per_get_few_bits(&pos, 8);
+	assert(z == 254);
+	assert(pos.nboff == 12);
+
+	pos.buffer = buf;
+	pos.nboff = 2;
+	pos.nbits = sizeof(buf) * 8;
+	z = per_get_few_bits(&pos, 24);
+	assert(z == 14443711);
+
+	pos.buffer = buf;
+	pos.nboff = 0;
+	pos.nbits = sizeof(buf) * 8;
+	z = per_get_many_bits(&pos, tmpbuf, 0, sizeof(buf) * 8);
+	assert(z == 0);
+	assert(buf[0] == tmpbuf[0]);
+	assert(buf[1] == tmpbuf[1]);
+	assert(buf[2] == tmpbuf[2]);
+	assert(buf[3] == tmpbuf[3]);
+	assert(buf[4] == tmpbuf[4]);
+
+	pos.buffer = buf;
+	pos.nboff = 1;
+	pos.nbits = sizeof(buf) * 8;
+	z = per_get_many_bits(&pos, tmpbuf, 0, sizeof(buf) * 8);
+	assert(z == -1);
+
+	pos.buffer = buf;
+	pos.nboff = 1;
+	pos.nbits = sizeof(buf) * 8;
+	z = per_get_many_bits(&pos, tmpbuf, 0, sizeof(buf) * 8 - 1);
+	assert(z == 0);
+	assert(tmpbuf[0] == 110);
+	assert(tmpbuf[1] == 50);
+	assert(tmpbuf[2] == 95);
+	assert(tmpbuf[3] == 221);
+	assert(tmpbuf[4] == 90);
+
+	pos.buffer = buf;
+	pos.nboff = 1;
+	pos.nbits = sizeof(buf) * 8;
+	z = per_get_many_bits(&pos, tmpbuf, 1, sizeof(buf) * 8 - 1);
+	assert(z == 0);
+	assert(tmpbuf[0] == 55);
+	assert(tmpbuf[0] != buf[0]);
+	assert(tmpbuf[1] == buf[1]);
+	assert(tmpbuf[2] == buf[2]);
+	assert(tmpbuf[3] == buf[3]);
+	assert(tmpbuf[4] == buf[4]);
+
+	return 0;
+}
diff --git a/skeletons/tests/check-UTF8String.c b/skeletons/tests/check-UTF8String.c
index 10592a1..8a90b24 100644
--- a/skeletons/tests/check-UTF8String.c
+++ b/skeletons/tests/check-UTF8String.c
@@ -6,6 +6,7 @@
 #include <der_encoder.c>
 #include <xer_decoder.c>
 #include <xer_support.c>
+#include <per_support.c>
 #include <constraints.c>
 #include <sys/time.h>
 
diff --git a/skeletons/tests/check-length.c b/skeletons/tests/check-length.c
index 9a6d8d6..cf10405 100644
--- a/skeletons/tests/check-length.c
+++ b/skeletons/tests/check-length.c
@@ -4,6 +4,7 @@
 #include <der_encoder.c>
 #include <xer_decoder.c>
 #include <xer_support.c>
+#include <per_support.c>
 #include <constraints.c>
 #undef	ADVANCE
 #undef	RETURN