summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/alltypes.proto24
-rw-r--r--tests/test_decode3.c27
-rw-r--r--tests/test_encode3.c77
3 files changed, 104 insertions, 24 deletions
diff --git a/tests/alltypes.proto b/tests/alltypes.proto
index 744a0fca..edaaa621 100644
--- a/tests/alltypes.proto
+++ b/tests/alltypes.proto
@@ -6,6 +6,7 @@ message SubMessage {
}
enum MyEnum {
+ Zero = 0;
First = 1;
Second = 2;
Truth = 42;
@@ -33,6 +34,29 @@ message AllTypes {
required SubMessage req_submsg = 16;
required MyEnum req_enum = 17;
+
+ repeated int32 rep_int32 = 21 [(nanopb).max_count = 5];
+ repeated int64 rep_int64 = 22 [(nanopb).max_count = 5];
+ repeated uint32 rep_uint32 = 23 [(nanopb).max_count = 5];
+ repeated uint64 rep_uint64 = 24 [(nanopb).max_count = 5];
+ repeated sint32 rep_sint32 = 25 [(nanopb).max_count = 5];
+ repeated sint64 rep_sint64 = 26 [(nanopb).max_count = 5];
+ repeated bool rep_bool = 27 [(nanopb).max_count = 5];
+
+ repeated fixed32 rep_fixed32 = 28 [(nanopb).max_count = 5];
+ repeated sfixed32 rep_sfixed32= 29 [(nanopb).max_count = 5];
+ repeated float rep_float = 30 [(nanopb).max_count = 5];
+
+ repeated fixed64 rep_fixed64 = 31 [(nanopb).max_count = 5];
+ repeated sfixed64 rep_sfixed64= 32 [(nanopb).max_count = 5];
+ repeated double rep_double = 33 [(nanopb).max_count = 5];
+
+ repeated string rep_string = 34 [(nanopb).max_size = 16, (nanopb).max_count = 5];
+ repeated bytes rep_bytes = 35 [(nanopb).max_size = 16, (nanopb).max_count = 5];
+ repeated SubMessage rep_submsg = 36 [(nanopb).max_count = 5];
+ repeated MyEnum rep_enum = 37 [(nanopb).max_count = 5];
+
+
// Just to make sure that the size of the fields has been calculated
// properly, i.e. otherwise a bug in last field might not be detected.
required int32 end = 99;
diff --git a/tests/test_decode3.c b/tests/test_decode3.c
index a7106dee..30a8afa7 100644
--- a/tests/test_decode3.c
+++ b/tests/test_decode3.c
@@ -45,6 +45,33 @@ bool check_alltypes(pb_istream_t *stream)
TEST(alltypes.req_submsg.substuff2 == 1016);
TEST(alltypes.req_enum == MyEnum_Truth);
+ TEST(alltypes.rep_int32_count == 5 && alltypes.rep_int32[4] == 2001 && alltypes.rep_int32[0] == 0);
+ TEST(alltypes.rep_int64_count == 5 && alltypes.rep_int64[4] == 2002 && alltypes.rep_int64[0] == 0);
+ TEST(alltypes.rep_uint32_count == 5 && alltypes.rep_uint32[4] == 2003 && alltypes.rep_uint32[0] == 0);
+ TEST(alltypes.rep_uint64_count == 5 && alltypes.rep_uint64[4] == 2004 && alltypes.rep_uint64[0] == 0);
+ TEST(alltypes.rep_sint32_count == 5 && alltypes.rep_sint32[4] == 2005 && alltypes.rep_sint32[0] == 0);
+ TEST(alltypes.rep_sint64_count == 5 && alltypes.rep_sint64[4] == 2006 && alltypes.rep_sint64[0] == 0);
+ TEST(alltypes.rep_bool_count == 5 && alltypes.rep_bool[4] == true && alltypes.rep_bool[0] == false);
+
+ TEST(alltypes.rep_fixed32_count == 5 && alltypes.rep_fixed32[4] == 2008 && alltypes.rep_fixed32[0] == 0);
+ TEST(alltypes.rep_sfixed32_count == 5 && alltypes.rep_sfixed32[4] == 2009 && alltypes.rep_sfixed32[0] == 0);
+ TEST(alltypes.rep_float_count == 5 && alltypes.rep_float[4] == 2010.0f && alltypes.rep_float[0] == 0.0f);
+
+ TEST(alltypes.rep_fixed64_count == 5 && alltypes.rep_fixed64[4] == 2011 && alltypes.rep_fixed64[0] == 0);
+ TEST(alltypes.rep_sfixed64_count == 5 && alltypes.rep_sfixed64[4] == 2012 && alltypes.rep_sfixed64[0] == 0);
+ TEST(alltypes.rep_double_count == 5 && alltypes.rep_double[4] == 2013.0 && alltypes.rep_double[0] == 0.0);
+
+ TEST(alltypes.rep_string_count == 5 && strcmp(alltypes.rep_string[4], "2014") == 0 && alltypes.rep_string[0][0] == '\0');
+ TEST(alltypes.rep_bytes_count == 5 && alltypes.rep_bytes[4].size == 4 && alltypes.rep_bytes[0].size == 0);
+ TEST(memcmp(alltypes.rep_bytes[4].bytes, "2015", 4) == 0);
+
+ TEST(alltypes.rep_submsg_count == 5);
+ TEST(strcmp(alltypes.rep_submsg[4].substuff1, "2016") == 0 && alltypes.rep_submsg[0].substuff1[0] == '\0');
+ TEST(alltypes.rep_submsg[4].substuff2 == 2016 && alltypes.rep_submsg[0].substuff2 == 0);
+
+ TEST(alltypes.rep_enum_count == 5 && alltypes.rep_enum[4] == MyEnum_Truth && alltypes.rep_enum[0] == MyEnum_Zero);
+
+
TEST(alltypes.end == 1099);
return true;
diff --git a/tests/test_encode3.c b/tests/test_encode3.c
index 5e94be51..8128ea4a 100644
--- a/tests/test_encode3.c
+++ b/tests/test_encode3.c
@@ -3,36 +3,65 @@
*/
#include <stdio.h>
+#include <string.h>
#include <pb_encode.h>
#include "alltypes.pb.h"
int main()
{
/* Initialize the structure with constants */
- AllTypes alltypes = {
- 1001,
- 1002,
- 1003,
- 1004,
- 1005,
- 1006,
- true,
-
- 1008,
- 1009,
- 1010.0f,
-
- 1011,
- 1012,
- 1013.0,
-
- "1014",
- {4, "1015"},
- {"1016", 1016},
- MyEnum_Truth,
-
- 1099
- };
+ AllTypes alltypes = {0};
+
+ alltypes.req_int32 = 1001;
+ alltypes.req_int64 = 1002;
+ alltypes.req_uint32 = 1003;
+ alltypes.req_uint64 = 1004;
+ alltypes.req_sint32 = 1005;
+ alltypes.req_sint64 = 1006;
+ alltypes.req_bool = true;
+
+ alltypes.req_fixed32 = 1008;
+ alltypes.req_sfixed32 = 1009;
+ alltypes.req_float = 1010.0f;
+
+ alltypes.req_fixed64 = 1011;
+ alltypes.req_sfixed64 = 1012;
+ alltypes.req_double = 1013.0;
+
+ strcpy(alltypes.req_string, "1014");
+ alltypes.req_bytes.size = 4;
+ memcpy(alltypes.req_bytes.bytes, "1015", 4);
+ strcpy(alltypes.req_submsg.substuff1, "1016");
+ alltypes.req_submsg.substuff2 = 1016;
+ alltypes.req_enum = MyEnum_Truth;
+
+ alltypes.rep_int32_count = 5; alltypes.rep_int32[4] = 2001;
+ alltypes.rep_int64_count = 5; alltypes.rep_int64[4] = 2002;
+ alltypes.rep_uint32_count = 5; alltypes.rep_uint32[4] = 2003;
+ alltypes.rep_uint64_count = 5; alltypes.rep_uint64[4] = 2004;
+ alltypes.rep_sint32_count = 5; alltypes.rep_sint32[4] = 2005;
+ alltypes.rep_sint64_count = 5; alltypes.rep_sint64[4] = 2006;
+ alltypes.rep_bool_count = 5; alltypes.rep_bool[4] = true;
+
+ alltypes.rep_fixed32_count = 5; alltypes.rep_fixed32[4] = 2008;
+ alltypes.rep_sfixed32_count = 5; alltypes.rep_sfixed32[4] = 2009;
+ alltypes.rep_float_count = 5; alltypes.rep_float[4] = 2010.0f;
+
+ alltypes.rep_fixed64_count = 5; alltypes.rep_fixed64[4] = 2011;
+ alltypes.rep_sfixed64_count = 5; alltypes.rep_sfixed64[4] = 2012;
+ alltypes.rep_double_count = 5; alltypes.rep_double[4] = 2013.0;
+
+ alltypes.rep_string_count = 5; strcpy(alltypes.rep_string[4], "2014");
+ alltypes.rep_bytes_count = 5; alltypes.rep_bytes[4].size = 4;
+ memcpy(alltypes.rep_bytes[4].bytes, "2015", 4);
+
+ alltypes.rep_submsg_count = 5;
+ strcpy(alltypes.rep_submsg[4].substuff1, "2016");
+ alltypes.rep_submsg[4].substuff2 = 2016;
+
+ alltypes.rep_enum_count = 5; alltypes.rep_enum[4] = MyEnum_Truth;
+
+ alltypes.end = 1099;
uint8_t buffer[512];
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));