diff options
Diffstat (limited to 'tests/decode_unittests.c')
-rw-r--r-- | tests/decode_unittests.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/tests/decode_unittests.c b/tests/decode_unittests.c index 7d3b13e5..ff4c6b46 100644 --- a/tests/decode_unittests.c +++ b/tests/decode_unittests.c @@ -1,17 +1,7 @@ #include <stdio.h> #include <string.h> #include "pb_decode.h" - -#define COMMENT(x) printf("\n----" x "----\n"); -#define STR(x) #x -#define STR2(x) STR(x) -#define TEST(x) \ - if (!(x)) { \ - fprintf(stderr, __FILE__ ":" STR2(__LINE__) " FAILED:" #x "\n"); \ - status = 1; \ - } else { \ - printf("OK: " #x "\n"); \ - } +#include "unittests.h" #define S(x) pb_istream_from_buffer((uint8_t*)x, sizeof(x)) @@ -114,7 +104,7 @@ int main() /* Verify that no more than data_size is written. */ d = 0; f.data_size = 1; - TEST(pb_dec_varint(&s, &f, &d) && d == 0xFF) + TEST(pb_dec_varint(&s, &f, &d) && (d == 0xFF || d == 0xFF000000)) } { @@ -129,6 +119,18 @@ int main() TEST((s = S("\xff\xff\xff\xff\x0f"), pb_dec_svarint(&s, &f, &d) && d == INT32_MIN)) } + { + pb_istream_t s; + pb_field_t f = {1, PB_LTYPE_SVARINT, 0, 0, 8, 0, 0}; + uint64_t d; + + COMMENT("Test pb_dec_svarint using uint64_t") + TEST((s = S("\x01"), pb_dec_svarint(&s, &f, &d) && d == -1)) + TEST((s = S("\x02"), pb_dec_svarint(&s, &f, &d) && d == 1)) + TEST((s = S("\xFE\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x01"), pb_dec_svarint(&s, &f, &d) && d == INT64_MAX)) + TEST((s = S("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x01"), pb_dec_svarint(&s, &f, &d) && d == INT64_MIN)) + } + if (status != 0) fprintf(stdout, "\n\nSome tests FAILED!\n"); |