aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-12-21 12:14:20 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-12-21 12:14:20 +0200
commit9cc19a5e998d93fbe6d7a7c18fba1e37a36076d5 (patch)
tree6fb10fa8670dc3197a2effb2fbe71a8550a6afac
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.
-rw-r--r--tests/alltypes/SConscript23
-rw-r--r--tests/alltypes/alltypes.proto28
-rw-r--r--tests/site_scons/site_init.py17
3 files changed, 53 insertions, 15 deletions
diff --git a/tests/alltypes/SConscript b/tests/alltypes/SConscript
index 1dc6f871..9c9072ba 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 a2cf8bbc..2bc8efcd 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];
diff --git a/tests/site_scons/site_init.py b/tests/site_scons/site_init.py
index 1f811153..38aa1a44 100644
--- a/tests/site_scons/site_init.py
+++ b/tests/site_scons/site_init.py
@@ -55,7 +55,11 @@ def add_nanopb_builders(env):
else:
infile = None
- pipe = subprocess.Popen(str(source[0]),
+ args = [str(source[0])]
+ if env.has_key('ARGS'):
+ args.extend(env['ARGS'])
+
+ pipe = subprocess.Popen(args,
stdin = infile,
stdout = open(str(target[0]), 'w'),
stderr = sys.stderr)
@@ -81,6 +85,17 @@ def add_nanopb_builders(env):
suffix = '.decoded')
env.Append(BUILDERS = {'Decode': decode_builder})
+ # Build command that encodes a message using protoc
+ def encode_actions(source, target, env, for_signature):
+ esc = env['ESCAPE']
+ dirs = ' '.join(['-I' + esc(env.GetBuildPath(d)) for d in env['PROTOCPATH']])
+ return '$PROTOC $PROTOCFLAGS %s --encode=%s %s <%s >%s' % (
+ dirs, env['MESSAGE'], esc(str(source[1])), esc(str(source[0])), esc(str(target[0])))
+
+ encode_builder = Builder(generator = encode_actions,
+ suffix = '.encoded')
+ env.Append(BUILDERS = {'Encode': encode_builder})
+
# Build command that asserts that two files be equal
def compare_files(target, source, env):
data1 = open(str(source[0]), 'rb').read()