summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/common/unittestproto.proto5
-rw-r--r--tests/decode_unittests/decode_unittests.c14
-rw-r--r--tests/encode_unittests/encode_unittests.c17
3 files changed, 36 insertions, 0 deletions
diff --git a/tests/common/unittestproto.proto b/tests/common/unittestproto.proto
index eb3e7dec..0ecb1f0b 100644
--- a/tests/common/unittestproto.proto
+++ b/tests/common/unittestproto.proto
@@ -34,3 +34,8 @@ message CallbackContainer {
message CallbackContainerContainer {
required CallbackContainer submsg = 1;
}
+
+message StringPointerContainer {
+ repeated string rep_str = 1 [(nanopb).type = FT_POINTER];
+}
+
diff --git a/tests/decode_unittests/decode_unittests.c b/tests/decode_unittests/decode_unittests.c
index 97212aff..8c12f1cd 100644
--- a/tests/decode_unittests/decode_unittests.c
+++ b/tests/decode_unittests/decode_unittests.c
@@ -87,6 +87,20 @@ int main()
pb_decode_varint(&s, (uint64_t*)&i) && i == -1));
TEST((s = S("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x01"),
pb_decode_varint(&s, &u) && u == UINT64_MAX));
+ TEST((s = S("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x01"),
+ !pb_decode_varint(&s, &u)));
+ }
+
+ {
+ pb_istream_t s;
+ uint32_t u;
+
+ COMMENT("Test pb_decode_varint32");
+ TEST((s = S("\x00"), pb_decode_varint32(&s, &u) && u == 0));
+ TEST((s = S("\x01"), pb_decode_varint32(&s, &u) && u == 1));
+ TEST((s = S("\xAC\x02"), pb_decode_varint32(&s, &u) && u == 300));
+ TEST((s = S("\xFF\xFF\xFF\xFF\x0F"), pb_decode_varint32(&s, &u) && u == UINT32_MAX));
+ TEST((s = S("\xFF\xFF\xFF\xFF\xFF\x01"), !pb_decode_varint32(&s, &u)));
}
{
diff --git a/tests/encode_unittests/encode_unittests.c b/tests/encode_unittests/encode_unittests.c
index 78fbb8b1..583af5c6 100644
--- a/tests/encode_unittests/encode_unittests.c
+++ b/tests/encode_unittests/encode_unittests.c
@@ -331,6 +331,23 @@ int main()
TEST(s.bytes_written == StringMessage_size);
}
+ {
+ uint8_t buffer[128];
+ pb_ostream_t s;
+ StringPointerContainer msg = StringPointerContainer_init_zero;
+ char *strs[1] = {NULL};
+ char zstr[] = "Z";
+
+ COMMENT("Test string pointer encoding.");
+
+ msg.rep_str = strs;
+ msg.rep_str_count = 1;
+ TEST(WRITES(pb_encode(&s, StringPointerContainer_fields, &msg), "\x0a\x00"))
+
+ strs[0] = zstr;
+ TEST(WRITES(pb_encode(&s, StringPointerContainer_fields, &msg), "\x0a\x01Z"))
+ }
+
if (status != 0)
fprintf(stdout, "\n\nSome tests FAILED!\n");