summaryrefslogtreecommitdiffstats
path: root/tests/decode_unittests.c
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-07-31 12:55:09 +0000
committerPetteri Aimonen <jpa@npb.mail.kapsi.fi>2011-07-31 12:55:09 +0000
commit3959290bc77ae26772bc107128b0a4edd3930361 (patch)
treefefcf27423aeb7fd100b52802f5c519def3a8cc7 /tests/decode_unittests.c
parentf8364310d3ca85d2cf59019bb4bc5e9ff4c52dc3 (diff)
First version of header generator
git-svn-id: https://svn.kapsi.fi/jpa/nanopb@950 e3a754e5-d11d-0410-8d38-ebb782a927b9
Diffstat (limited to 'tests/decode_unittests.c')
-rw-r--r--tests/decode_unittests.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/decode_unittests.c b/tests/decode_unittests.c
index 746b7e96..7d3b13e5 100644
--- a/tests/decode_unittests.c
+++ b/tests/decode_unittests.c
@@ -104,6 +104,31 @@ int main()
TEST((s = S("\x04""testfoobar"), pb_skip_string(&s) && s.bytes_left == 7))
}
+ {
+ pb_istream_t s = S("\x01\xFF\xFF\x03");
+ pb_field_t f = {1, PB_LTYPE_VARINT, 0, 0, 4, 0, 0};
+ uint32_t d;
+ COMMENT("Test pb_dec_varint using uint32_t")
+ TEST(pb_dec_varint(&s, &f, &d) && d == 1)
+
+ /* Verify that no more than data_size is written. */
+ d = 0;
+ f.data_size = 1;
+ TEST(pb_dec_varint(&s, &f, &d) && d == 0xFF)
+ }
+
+ {
+ pb_istream_t s;
+ pb_field_t f = {1, PB_LTYPE_SVARINT, 0, 0, 4, 0, 0};
+ int32_t d;
+
+ COMMENT("Test pb_dec_svarint using int32_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\x0f"), pb_dec_svarint(&s, &f, &d) && d == INT32_MAX))
+ TEST((s = S("\xff\xff\xff\xff\x0f"), pb_dec_svarint(&s, &f, &d) && d == INT32_MIN))
+ }
+
if (status != 0)
fprintf(stdout, "\n\nSome tests FAILED!\n");