Commit ae1422b1 authored by Lev Walkin's avatar Lev Walkin
Browse files
parent da161988
......@@ -74,17 +74,7 @@ doc/docsrc/*.xdv
# /skeletons/tests/
/skeletons/tests/Makefile
/skeletons/tests/check-OCTET_STRING
/skeletons/tests/check-UTCTime
/skeletons/tests/check-length
/skeletons/tests/check-REAL
/skeletons/tests/check-GeneralizedTime
/skeletons/tests/check-UTF8String
/skeletons/tests/check-PER
/skeletons/tests/check-ber_tlv_tag
/skeletons/tests/check-INTEGER
/skeletons/tests/check-OIDs
/skeletons/tests/check-XER
/skeletons/tests/check-*
# /tests/
/tests/Makefile
......@@ -11,7 +11,8 @@ check_PROGRAMS = \
check-INTEGER \
check-REAL \
check-XER \
check-PER
check-PER \
check-PER-INTEGER
AM_LDFLAGS = $(top_srcdir)/skeletons/libasn1cskeletons.la
LDADD = -lm
......
......@@ -37,7 +37,8 @@ check_PROGRAMS = check-ber_tlv_tag$(EXEEXT) check-length$(EXEEXT) \
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-PER$(EXEEXT)
check-REAL$(EXEEXT) check-XER$(EXEEXT) check-PER$(EXEEXT) \
check-PER-INTEGER$(EXEEXT)
subdir = skeletons/tests
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
......@@ -71,6 +72,10 @@ check_PER_SOURCES = check-PER.c
check_PER_OBJECTS = check-PER.$(OBJEXT)
check_PER_LDADD = $(LDADD)
check_PER_DEPENDENCIES =
check_PER_INTEGER_SOURCES = check-PER-INTEGER.c
check_PER_INTEGER_OBJECTS = check-PER-INTEGER.$(OBJEXT)
check_PER_INTEGER_LDADD = $(LDADD)
check_PER_INTEGER_DEPENDENCIES =
check_REAL_SOURCES = check-REAL.c
check_REAL_OBJECTS = check-REAL.$(OBJEXT)
check_REAL_LDADD = $(LDADD)
......@@ -109,13 +114,14 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--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-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-OIDs.c check-PER.c check-PER-INTEGER.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-PER-INTEGER.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
am__tty_colors = \
......@@ -298,6 +304,9 @@ check-OIDs$(EXEEXT): $(check_OIDs_OBJECTS) $(check_OIDs_DEPENDENCIES)
check-PER$(EXEEXT): $(check_PER_OBJECTS) $(check_PER_DEPENDENCIES)
@rm -f check-PER$(EXEEXT)
$(LINK) $(check_PER_OBJECTS) $(check_PER_LDADD) $(LIBS)
check-PER-INTEGER$(EXEEXT): $(check_PER_INTEGER_OBJECTS) $(check_PER_INTEGER_DEPENDENCIES)
@rm -f check-PER-INTEGER$(EXEEXT)
$(LINK) $(check_PER_INTEGER_OBJECTS) $(check_PER_INTEGER_LDADD) $(LIBS)
check-REAL$(EXEEXT): $(check_REAL_OBJECTS) $(check_REAL_DEPENDENCIES)
@rm -f check-REAL$(EXEEXT)
$(LINK) $(check_REAL_OBJECTS) $(check_REAL_LDADD) $(LIBS)
......@@ -327,6 +336,7 @@ distclean-compile:
@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-INTEGER.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@
......
#include <stdio.h>
#include <assert.h>
#define EMIT_ASN_DEBUG 1
#include <INTEGER.h>
#include <INTEGER.c>
#include <per_support.c>
#include <per_support.h>
static int FailOut(const void *data, size_t size, void *op_key) {
assert(!"UNREACHABLE");
return 0;
}
static void normalize(asn_per_outp_t *po) {
if(po->nboff >= 8) {
po->buffer += (po->nboff >> 3);
po->nbits -= (po->nboff & ~0x07);
po->nboff &= 0x07;
}
}
static void
check_per_encode_constrained(int lineno, int unsigned_, long value, long lbound, unsigned long ubound, int bit_range) {
INTEGER_t st;
INTEGER_t *reconstructed_st = 0;
asn_INTEGER_specifics_t specs;
asn_per_constraints_t cts;
asn_enc_rval_t enc_rval;
asn_dec_rval_t dec_rval;
asn_per_outp_t po;
asn_per_data_t pd;
long reconstructed_value;
printf("%d: Recoding %s %ld [%ld..%lu]\n", lineno,
unsigned_ ? "unsigned" : "signed", value, lbound, ubound);
memset(&st, 0, sizeof(st));
memset(&po, 0, sizeof(po));
memset(&pd, 0, sizeof(pd));
memset(&cts, 0, sizeof(cts));
memset(&specs, 0, sizeof(specs));
cts.value.flags = APC_CONSTRAINED;
cts.value.range_bits = bit_range;
cts.value.effective_bits = bit_range;
cts.value.lower_bound = lbound;
cts.value.upper_bound = ubound;
asn_long2INTEGER(&st, value);
po.buffer = po.tmpspace;
po.nboff = 0;
po.nbits = 8 * sizeof(po.tmpspace);
po.outper = FailOut;
specs.field_width = sizeof(long);
specs.field_unsigned = unsigned_;
asn_DEF_INTEGER.specifics = &specs;
enc_rval = INTEGER_encode_uper(&asn_DEF_INTEGER, &cts, &st, &po);
assert(enc_rval.encoded == 0);
normalize(&po);
assert(po.buffer == &po.tmpspace[bit_range / 8]);
long recovered_value =
((uint32_t)po.tmpspace[0] << 24)
| ((uint32_t)po.tmpspace[1] << 16)
| ((uint32_t)po.tmpspace[2] << 8)
| ((uint32_t)po.tmpspace[3] << 0);
recovered_value >>= (32 - bit_range);
recovered_value += cts.value.lower_bound;
assert(recovered_value == value);
assert(po.nboff == ((bit_range == 32) ? 0 : (8 - (32 - bit_range))));
assert(po.nbits == 8 * (sizeof(po.tmpspace) - (po.buffer-po.tmpspace)));
assert(po.flushed_bytes == 0);
pd.buffer = po.tmpspace;
pd.nboff = 0;
pd.nbits = 8 * (po.buffer - po.tmpspace) + po.nboff;
pd.moved = 0;
dec_rval = INTEGER_decode_uper(0, &asn_DEF_INTEGER, &cts,
(void **)&reconstructed_st, &pd);
reconstructed_value = 0;
asn_INTEGER2long(reconstructed_st, &reconstructed_value);
assert(reconstructed_value == value);
}
#define CHECK(u, v, l, r, b) \
check_per_encode_constrained(__LINE__, u, v, l, r, b)
int
main() {
int unsigned_;
for(unsigned_ = 0; unsigned_ < 2; unsigned_++) {
int u = unsigned_;
/* Encode a signed 0x8babab into a range constrained by 0..2^29-1 */
CHECK(u, 0x8babab, 0, 536870911UL, 29);
CHECK(u, 0x8babab, 0, 1073741823UL, 30);
CHECK(u, 0x8babab, 0, 2147483647UL, 31);
CHECK(u, 0x8babab, 0, 4294967295UL, 32);
CHECK(u, 0x8babab, 10, 536870901UL, 29);
CHECK(u, 0x8babab, 10, 1073741803UL, 30);
CHECK(u, 0x8babab, 10, 2147483607UL, 31);
CHECK(u, 0x8babab, 10, 4294967205UL, 32);
CHECK(0, 0x8babab, -10, 536870901UL, 29);
CHECK(0, 0x8babab, -10, 1073741803UL, 30);
CHECK(0, 0x8babab, -10, 2147483607UL, 31);
CHECK(0, 0x8babab, -10, 4294967205UL, 32);
CHECK(u, 11, 10, 536870901UL, 29);
CHECK(u, 11, 10, 1073741803UL, 30);
CHECK(u, 11, 10, 2147483607UL, 31);
CHECK(u, 11, 10, 4294967205UL, 32);
CHECK(0, 1, -10, 536870901UL, 29);
CHECK(0, 1, -10, 1073741803UL, 30);
CHECK(0, 1, -10, 2147483607UL, 31);
CHECK(0, 1, -10, 4294967205UL, 32);
CHECK(u, 10, 10, 536870901UL, 29);
CHECK(u, 10, 10, 1073741803UL, 30);
CHECK(u, 10, 10, 2147483607UL, 31);
CHECK(u, 10, 10, 4294967205UL, 32);
CHECK(0, 0, -10, 536870901UL, 29);
CHECK(0, 0, -10, 1073741803UL, 30);
CHECK(0, 0, -10, 2147483607UL, 31);
CHECK(0, 0, -10, 4294967205UL, 32);
CHECK(0, -1, -10, 536870901UL, 29);
CHECK(0, -1, -10, 1073741803UL, 30);
CHECK(0, -1, -10, 2147483607UL, 31);
CHECK(0, -1, -10, 4294967205UL, 32);
CHECK(0, -10, -10, 536870901UL, 29);
CHECK(0, -10, -10, 1073741803UL, 30);
CHECK(0, -10, -10, 2147483607UL, 31);
CHECK(0, -10, -10, 4294967205UL, 32);
CHECK(u, 536870901UL, 10, 536870901UL, 29);
CHECK(u, 1073741803UL, 10, 1073741803UL, 30);
CHECK(u, 2147483607UL, 10, 2147483607UL, 31);
CHECK(u, 4294967205UL, 10, 4294967205UL, 32);
CHECK(0, 536870901UL, -10, 536870901UL, 29);
CHECK(0, 1073741803UL, -10, 1073741803UL, 30);
CHECK(0, 2147483607UL, -10, 2147483607UL, 31);
CHECK(0, 4294967205UL, -10, 4294967205UL, 32);
CHECK(u, 2000000000, 0, 4294967295UL, 32);
CHECK(u, 2147483647, 0, 4294967295UL, 32);
CHECK(u, 2147483648, 0, 4294967295UL, 32);
CHECK(u, 4000000000, 0, 4294967295UL, 32);
CHECK(u, 4294967295UL, 1, 4294967295UL, 32);
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment