X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=tests%2Ftests-c-compiler%2Fcheck-src%2Fcheck-127.-gen-PER.c;fp=tests%2Ftests-c-compiler%2Fcheck-src%2Fcheck-127.-gen-PER.c;h=eca680b384220115b916fdbd788d3f2678cb85f9;hb=70ee6fc793ec8e828067a3569849b6c216054497;hp=0000000000000000000000000000000000000000;hpb=59f84608ec15c016958a6e0e0ddd813f376c0925;p=com%2Fasn1c.git diff --git a/tests/tests-c-compiler/check-src/check-127.-gen-PER.c b/tests/tests-c-compiler/check-src/check-127.-gen-PER.c new file mode 100644 index 0000000..eca680b --- /dev/null +++ b/tests/tests-c-compiler/check-src/check-127.-gen-PER.c @@ -0,0 +1,89 @@ +#undef NDEBUG +#include +#include +#include +#include +#include +#include +#include + +#include + +static void +verify(int testNo, T_t *ti) { + asn_enc_rval_t er; + asn_dec_rval_t rv; + unsigned char buf[16]; + T_t *to = 0; + + fprintf(stderr, "%d IN: { %ld, %ld, %lu, %lu }\n", testNo, + ti->small32range, ti->full32range, + ti->unsigned32, ti->unsplit32); + + er = uper_encode_to_buffer(&asn_DEF_T, 0, ti, buf, sizeof buf); + assert(er.encoded == 8 * sizeof(buf)); + + rv = uper_decode(0, &asn_DEF_T, (void *)&to, buf, sizeof buf, 0, 0); + assert(rv.code == RC_OK); + + fprintf(stderr, "%d ENC: %2x%2x%2x%2x %2x%2x%2x%2x\n", testNo, + buf[0], buf[1], buf[2], buf[3], + buf[4], buf[5], buf[6], buf[7]); + fprintf(stderr, "%d OUT: { %ld, %ld, %lu, %lu } vs { %ld, %ld, %lu, %lu }\n", + testNo, + ti->small32range, ti->full32range, + ti->unsigned32, ti->unsplit32, + to->small32range, to->full32range, + to->unsigned32, to->unsplit32); + assert(ti->small32range == to->small32range); + assert(ti->full32range == to->full32range); + assert(ti->unsigned32 == to->unsigned32); + assert(ti->unsplit32 == to->unsplit32); + + xer_fprint(stderr, &asn_DEF_T, ti); + xer_fprint(stderr, &asn_DEF_T, to); + + ASN_STRUCT_FREE(asn_DEF_T, to); +} + +int main() { + T_t ti; + + ti.small32range = 0; + ti.full32range = 0; + ti.unsigned32 = 0; + ti.unsplit32 = 5; + verify(1, &ti); + + ti.small32range = -1; + ti.full32range = -1; + ti.unsigned32 = 1; + ti.unsplit32 = 300; + verify(2, &ti); + + ti.small32range = -2000000000; + ti.full32range = (-2147483647L - 1); + ti.unsigned32 = 4000000000; + ti.unsplit32 = 500; + verify(3, &ti); + + ti.small32range = -1999999999; + ti.full32range = (-2147483647L); + ti.unsigned32 = 4294967295UL; + ti.unsplit32 = 600; + verify(4, &ti); + + ti.small32range = 2000000000; + ti.full32range = 2147483647; + ti.unsigned32 = 4294967295UL - 100; + ti.unsplit32 = 4294967290UL; + verify(5, &ti); + + ti.small32range = 1999999999; + ti.full32range = 2147483647 - 1; + ti.unsigned32 = 4294967295UL - 1; + ti.unsplit32 = 4294967290UL - 1; + verify(6, &ti); + + return 0; +}