diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2017-02-22 21:11:01 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2017-02-22 21:11:01 +0200 |
commit | 91dcdf573707a823bc450d3913b8b87c7adba212 (patch) | |
tree | 391bb20bd71a9365af9fca78b9f6698a6b154354 /tests/alltypes | |
parent | 07375a126337916f3a34ea94f8085b8f89d789a1 (diff) | |
download | nanopb-c-91dcdf573707a823bc450d3913b8b87c7adba212.tar.gz |
Add fixed length bytes to alltypes test case (issue #244)
Diffstat (limited to 'tests/alltypes')
-rw-r--r-- | tests/alltypes/alltypes.options | 2 | ||||
-rw-r--r-- | tests/alltypes/alltypes.proto | 8 | ||||
-rw-r--r-- | tests/alltypes/decode_alltypes.c | 8 | ||||
-rw-r--r-- | tests/alltypes/encode_alltypes.c | 6 |
4 files changed, 20 insertions, 4 deletions
diff --git a/tests/alltypes/alltypes.options b/tests/alltypes/alltypes.options index b31e3cf..0d5ab12 100644 --- a/tests/alltypes/alltypes.options +++ b/tests/alltypes/alltypes.options @@ -1,3 +1,3 @@ * max_size:16 * max_count:5 - +*.*fbytes fixed_length:true max_size:4 diff --git a/tests/alltypes/alltypes.proto b/tests/alltypes/alltypes.proto index 3995c55..b2250c0 100644 --- a/tests/alltypes/alltypes.proto +++ b/tests/alltypes/alltypes.proto @@ -58,7 +58,7 @@ message AllTypes { required SubMessage req_submsg = 16; required MyEnum req_enum = 17; required EmptyMessage req_emptymsg = 18; - + required bytes req_fbytes = 19; repeated int32 rep_int32 = 21 [packed = true]; repeated int64 rep_int64 = 22 [packed = true]; @@ -81,6 +81,7 @@ message AllTypes { repeated SubMessage rep_submsg = 36; repeated MyEnum rep_enum = 37 [packed = true]; repeated EmptyMessage rep_emptymsg = 38; + repeated bytes rep_fbytes = 39; optional int32 opt_int32 = 41 [default = 4041]; optional int64 opt_int64 = 42 [default = 4042]; @@ -103,11 +104,12 @@ message AllTypes { optional SubMessage opt_submsg = 56; optional MyEnum opt_enum = 57 [default = Second]; optional EmptyMessage opt_emptymsg = 58; + optional bytes opt_fbytes = 59 [default = "4059"]; oneof oneof { - SubMessage oneof_msg1 = 59; - EmptyMessage oneof_msg2 = 60; + SubMessage oneof_msg1 = 60; + EmptyMessage oneof_msg2 = 61; } // Check that extreme integer values are handled correctly diff --git a/tests/alltypes/decode_alltypes.c b/tests/alltypes/decode_alltypes.c index 458e511..2e609e5 100644 --- a/tests/alltypes/decode_alltypes.c +++ b/tests/alltypes/decode_alltypes.c @@ -52,6 +52,7 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.req_submsg.substuff2 == 1016); TEST(alltypes.req_submsg.substuff3 == 3); TEST(alltypes.req_enum == MyEnum_Truth); + TEST(memcmp(alltypes.req_fbytes, "1019", 4) == 0); 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); @@ -80,6 +81,9 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.rep_enum_count == 5 && alltypes.rep_enum[4] == MyEnum_Truth && alltypes.rep_enum[0] == MyEnum_Zero); TEST(alltypes.rep_emptymsg_count == 5); + TEST(alltypes.rep_fbytes_count == 5); + TEST(alltypes.rep_fbytes[0][0] == 0 && alltypes.rep_fbytes[0][3] == 0); + TEST(memcmp(alltypes.rep_fbytes[4], "2019", 4) == 0); if (mode == 0) { @@ -125,6 +129,8 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.has_opt_enum == false); TEST(alltypes.opt_enum == MyEnum_Second); TEST(alltypes.has_opt_emptymsg == false); + TEST(alltypes.has_opt_fbytes == false); + TEST(memcmp(alltypes.opt_fbytes, "4059", 4) == 0); TEST(alltypes.which_oneof == 0); } @@ -172,6 +178,8 @@ bool check_alltypes(pb_istream_t *stream, int mode) TEST(alltypes.has_opt_enum == true); TEST(alltypes.opt_enum == MyEnum_Truth); TEST(alltypes.has_opt_emptymsg == true); + TEST(alltypes.has_opt_fbytes == true); + TEST(memcmp(alltypes.opt_fbytes, "3059", 4) == 0); TEST(alltypes.which_oneof == AllTypes_oneof_msg1_tag); TEST(strcmp(alltypes.oneof.oneof_msg1.substuff1, "4059") == 0); diff --git a/tests/alltypes/encode_alltypes.c b/tests/alltypes/encode_alltypes.c index 16f4b29..1b86355 100644 --- a/tests/alltypes/encode_alltypes.c +++ b/tests/alltypes/encode_alltypes.c @@ -37,6 +37,7 @@ int main(int argc, char **argv) strcpy(alltypes.req_submsg.substuff1, "1016"); alltypes.req_submsg.substuff2 = 1016; alltypes.req_enum = MyEnum_Truth; + memcpy(alltypes.req_fbytes, "1019", 4); alltypes.rep_int32_count = 5; alltypes.rep_int32[4] = -2001; alltypes.rep_int64_count = 5; alltypes.rep_int64[4] = -2002; @@ -67,6 +68,9 @@ int main(int argc, char **argv) alltypes.rep_enum_count = 5; alltypes.rep_enum[4] = MyEnum_Truth; alltypes.rep_emptymsg_count = 5; + alltypes.rep_fbytes_count = 5; + memcpy(alltypes.rep_fbytes[4], "2019", 4); + alltypes.req_limits.int32_min = INT32_MIN; alltypes.req_limits.int32_max = INT32_MAX; alltypes.req_limits.uint32_min = 0; @@ -121,6 +125,8 @@ int main(int argc, char **argv) alltypes.has_opt_enum = true; alltypes.opt_enum = MyEnum_Truth; alltypes.has_opt_emptymsg = true; + alltypes.has_opt_fbytes = true; + memcpy(alltypes.opt_fbytes, "3059", 4); alltypes.which_oneof = AllTypes_oneof_msg1_tag; strcpy(alltypes.oneof.oneof_msg1.substuff1, "4059"); |