summaryrefslogtreecommitdiffstats
path: root/tests/decode_unittests.c
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-08-10 17:54:15 +0000
committerPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-08-10 17:54:15 +0000
commit0c5bc4caf9cfb221822fead442b462be2f47b97b (patch)
treef8e86d3c0bde869bf93df4ec439f83936742c79e /tests/decode_unittests.c
parenta8d0172507d59b73b95f766aa7644147fd060f20 (diff)
Unittests for encode
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@952 e3a754e5-d11d-0410-8d38-ebb782a927b9
Diffstat (limited to 'tests/decode_unittests.c')
-rw-r--r--tests/decode_unittests.c26
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");