9 #include "asn1p_integer.h"
11 static void check(int lineno, asn1c_integer_t value, const char *expected);
14 uint8_t *buf; size_t size;
21 check(__LINE__, 0, "{ (uint8_t *)\"\\x00\\0\", 1 }");
22 check(__LINE__, 1, "{ (uint8_t *)\"\\x01\\0\", 1 }");
23 check(__LINE__, 127, "{ (uint8_t *)\"\\x7f\\0\", 1 }");
24 check(__LINE__, 128, "{ (uint8_t *)\"\\x00\\x80\\0\", 2 }");
25 check(__LINE__, 129, "{ (uint8_t *)\"\\x00\\x81\\0\", 2 }");
27 check(__LINE__, -1, "{ (uint8_t *)\"\\xff\\0\", 1 }");
28 check(__LINE__, -2, "{ (uint8_t *)\"\\xfe\\0\", 1 }");
29 check(__LINE__, -127, "{ (uint8_t *)\"\\x81\\0\", 1 }");
30 check(__LINE__, -128, "{ (uint8_t *)\"\\x80\\0\", 1 }");
31 check(__LINE__, -129, "{ (uint8_t *)\"\\xff\\x7f\\0\", 2 }");
32 check(__LINE__, -254, "{ (uint8_t *)\"\\xff\\x02\\0\", 2 }");
33 check(__LINE__, -255, "{ (uint8_t *)\"\\xff\\x01\\0\", 2 }");
34 check(__LINE__, -256, "{ (uint8_t *)\"\\xff\\x00\\0\", 2 }");
35 check(__LINE__, -257, "{ (uint8_t *)\"\\xfe\\xff\\0\", 2 }");
37 check(__LINE__, ~(asn1c_integer_t)0, "{ (uint8_t *)\"\\xff\\0\", 1 }");
39 switch(sizeof(asn1c_integer_t)) {
43 & ~((asn1c_integer_t)1 << (8 * sizeof(asn1c_integer_t) - 1)),
45 "\\x7f\\xff\\xff\\xff"
51 & ~((asn1c_integer_t)1 << (8 * sizeof(asn1c_integer_t) - 1)),
53 "\\x7f\\xff\\xff\\xff\\xff\\xff\\xff\\xff"
59 & ~((asn1c_integer_t)1 << (8 * sizeof(asn1c_integer_t) - 1)),
61 "\\x7f\\xff\\xff\\xff\\xff\\xff\\xff\\xff"
62 "\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff"
67 assert(!"Unreachable");
73 static void check(int lineno, asn1c_integer_t value, const char *expected) {
75 ab = asn1p_integer_as_INTEGER(value);
77 if(strcmp(ab->buffer, expected)) {
78 fprintf(stderr, "%02d: %s -> [%s], expected [%s]\n", lineno,
79 asn1p_itoa(value), ab->buffer, expected);
80 assert(strcmp(ab->buffer, expected) == 0);
82 printf("%02d: %s -> %s\n", lineno, asn1p_itoa(value), ab->buffer);