Commit 2e6fdf62 authored by Pau Espin Pedrol's avatar Pau Espin Pedrol Committed by Mouse

tests-skeleteons: Add initial check-APER-support.c

parent e818e32e
...@@ -15,6 +15,7 @@ check_PROGRAMS = \ ...@@ -15,6 +15,7 @@ check_PROGRAMS = \
check-OER-support \ check-OER-support \
check-OER-INTEGER \ check-OER-INTEGER \
check-OER-NativeEnumerated \ check-OER-NativeEnumerated \
check-APER-support \
check-UPER-support \ check-UPER-support \
check-UPER-UniversalString \ check-UPER-UniversalString \
check-UPER-INTEGER \ check-UPER-INTEGER \
...@@ -36,6 +37,7 @@ check_PROGRAMS += \ ...@@ -36,6 +37,7 @@ check_PROGRAMS += \
check-32-OER-support \ check-32-OER-support \
check-32-OER-INTEGER \ check-32-OER-INTEGER \
check-32-OER-NativeEnumerated \ check-32-OER-NativeEnumerated \
check-32-APER-support \
check-32-UPER-support \ check-32-UPER-support \
check-32-UPER-UniversalString \ check-32-UPER-UniversalString \
check-32-UPER-INTEGER \ check-32-UPER-INTEGER \
...@@ -83,6 +85,9 @@ check_32_OER_INTEGER_SOURCES=check-OER-INTEGER.c ...@@ -83,6 +85,9 @@ check_32_OER_INTEGER_SOURCES=check-OER-INTEGER.c
check_32_OER_NativeEnumerated_CFLAGS=$(CFLAGS_M32) check_32_OER_NativeEnumerated_CFLAGS=$(CFLAGS_M32)
check_32_OER_NativeEnumerated_LDADD=$(LDADD_32) check_32_OER_NativeEnumerated_LDADD=$(LDADD_32)
check_32_OER_NativeEnumerated_SOURCES=check-OER-NativeEnumerated.c check_32_OER_NativeEnumerated_SOURCES=check-OER-NativeEnumerated.c
check_32_APER_support_CFLAGS=$(CFLAGS_M32)
check_32_APER_support_LDADD=$(LDADD_32)
check_32_APER_support_SOURCES=check-APER-support.c
check_32_UPER_support_CFLAGS=$(CFLAGS_M32) check_32_UPER_support_CFLAGS=$(CFLAGS_M32)
check_32_UPER_support_LDADD=$(LDADD_32) check_32_UPER_support_LDADD=$(LDADD_32)
check_32_UPER_support_SOURCES=check-UPER-support.c check_32_UPER_support_SOURCES=check-UPER-support.c
......
#include <assert.h>
#include <aper_support.h>
static void put(asn_per_outp_t *po, int range, size_t length) {
fprintf(stderr, "put(%zd)\n", length);
do {
int need_eom = 123;
ssize_t may_write = aper_put_length(po, range, length, &need_eom);
fprintf(stderr, " put %zu\n", may_write);
assert(may_write >= 0);
assert((size_t)may_write <= length);
assert(need_eom != 123);
length -= may_write;
if(need_eom) {
assert(length == 0);
if(aper_put_length(po, range, 0, 0)) {
assert(!"Unreachable");
}
fprintf(stderr, " put EOM 0\n");
}
} while(length);
fprintf(stderr, "put(...) in %zu bits\n", po->nboff);
assert(po->nboff != 0);
assert(po->flushed_bytes == 0);
}
static size_t get(asn_per_outp_t *po, int range) {
asn_bit_data_t data;
memset(&data, 0, sizeof(data));
data.buffer = po->tmpspace;
data.nboff = 0;
data.nbits = 8 * (po->buffer - po->tmpspace) + po->nboff;
fprintf(stderr, "get(): %s\n", asn_bit_data_string(&data));
size_t length = 0;
int repeat = 0;
do {
ssize_t n = aper_get_length(&data, range, -1, &repeat);
fprintf(stderr, " get = %zu +%zd\n", length, n);
assert(n >= 0);
length += n;
} while(repeat);
fprintf(stderr, "get() = %zu\n", length);
return length;
}
static void
check_round_trip(int range, size_t length) {
fprintf(stderr, "\nRound-trip for range=%d len=%zu\n", range, length);
asn_per_outp_t po;
memset(&po, 0, sizeof(po));
po.buffer = po.tmpspace;
po.nbits = 8 * sizeof(po.tmpspace);
put(&po, range, length);
size_t recovered = get(&po, range);
assert(recovered == length);
}
/*
* Checks that we can get the PER length that we have just put,
* and receive the same value.
*/
static void
check_round_trips_range65536() {
check_round_trip(65536, 0);
check_round_trip(65536, 1);
check_round_trip(65536, 127);
check_round_trip(65536, 128);
check_round_trip(65536, 129);
check_round_trip(65536, 255);
check_round_trip(65536, 256);
check_round_trip(65536, 65534);
check_round_trip(65536, 65535);
check_round_trip(65536, 65536);
}
int main() {
check_round_trips_range65536();
}
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