Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nanopb/nanopb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-12-21 14:14:20 +0400
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-12-21 14:14:20 +0400
commit9cc19a5e998d93fbe6d7a7c18fba1e37a36076d5 (patch)
tree6fb10fa8670dc3197a2effb2fbe71a8550a6afac /tests/alltypes
parenteff9e11150c0bfb6baf5d6bec2351034b72d95ed (diff)
Modify the alltypes test to check re-encoding through protoc.
This way we can verify that the message is encoded exactly the same way as the official protobuf implementation would do it.
Diffstat (limited to 'tests/alltypes')
-rw-r--r--tests/alltypes/SConscript23
-rw-r--r--tests/alltypes/alltypes.proto28
2 files changed, 37 insertions, 14 deletions
diff --git a/tests/alltypes/SConscript b/tests/alltypes/SConscript
index 1dc6f87..9c9072b 100644
--- a/tests/alltypes/SConscript
+++ b/tests/alltypes/SConscript
@@ -7,6 +7,29 @@ env.NanopbProto(["alltypes", "alltypes.options"])
enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o"])
dec = env.Program(["decode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_decode.o"])
+# Test the round-trip from nanopb encoder to nanopb decoder
env.RunTest(enc)
env.RunTest([dec, "encode_alltypes.output"])
+# Re-encode the data using protoc, and check that the results from nanopb
+# match byte-per-byte to the protoc output.
+env.Decode("encode_alltypes.output.decoded",
+ ["encode_alltypes.output", "alltypes.proto"],
+ MESSAGE='AllTypes')
+env.Encode("encode_alltypes.output.recoded",
+ ["encode_alltypes.output.decoded", "alltypes.proto"],
+ MESSAGE='AllTypes')
+env.Compare(["encode_alltypes.output", "encode_alltypes.output.recoded"])
+
+# Do the same checks with the optional fields present.
+env.RunTest("optionals.output", enc, ARGS = ['1'])
+env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1'])
+env.Decode("optionals.output.decoded",
+ ["optionals.output", "alltypes.proto"],
+ MESSAGE='AllTypes')
+env.Encode("optionals.output.recoded",
+ ["optionals.output.decoded", "alltypes.proto"],
+ MESSAGE='AllTypes')
+env.Compare(["optionals.output", "optionals.output.recoded"])
+
+
diff --git a/tests/alltypes/alltypes.proto b/tests/alltypes/alltypes.proto
index a2cf8bb..2bc8efc 100644
--- a/tests/alltypes/alltypes.proto
+++ b/tests/alltypes/alltypes.proto
@@ -39,26 +39,26 @@ message AllTypes {
required EmptyMessage req_emptymsg = 18;
- repeated int32 rep_int32 = 21;
- repeated int64 rep_int64 = 22;
- repeated uint32 rep_uint32 = 23;
- repeated uint64 rep_uint64 = 24;
- repeated sint32 rep_sint32 = 25;
- repeated sint64 rep_sint64 = 26;
- repeated bool rep_bool = 27;
+ repeated int32 rep_int32 = 21 [packed = true];
+ repeated int64 rep_int64 = 22 [packed = true];
+ repeated uint32 rep_uint32 = 23 [packed = true];
+ repeated uint64 rep_uint64 = 24 [packed = true];
+ repeated sint32 rep_sint32 = 25 [packed = true];
+ repeated sint64 rep_sint64 = 26 [packed = true];
+ repeated bool rep_bool = 27 [packed = true];
- repeated fixed32 rep_fixed32 = 28;
- repeated sfixed32 rep_sfixed32= 29;
- repeated float rep_float = 30;
+ repeated fixed32 rep_fixed32 = 28 [packed = true];
+ repeated sfixed32 rep_sfixed32= 29 [packed = true];
+ repeated float rep_float = 30 [packed = true];
- repeated fixed64 rep_fixed64 = 31;
- repeated sfixed64 rep_sfixed64= 32;
- repeated double rep_double = 33;
+ repeated fixed64 rep_fixed64 = 31 [packed = true];
+ repeated sfixed64 rep_sfixed64= 32 [packed = true];
+ repeated double rep_double = 33 [packed = true];
repeated string rep_string = 34;
repeated bytes rep_bytes = 35;
repeated SubMessage rep_submsg = 36;
- repeated MyEnum rep_enum = 37;
+ repeated MyEnum rep_enum = 37 [packed = true];
repeated EmptyMessage rep_emptymsg = 38;
optional int32 opt_int32 = 41 [default = 4041];