Fix bugs in proto3 mode encoding of submessages (#256)
[apps/agl-service-can-low-level.git] / tests / alltypes_proto3 / SConscript
1 # Version of AllTypes test case for protobuf 3 file format.
2
3 Import("env")
4
5 import re
6 match = None
7 if 'PROTOC_VERSION' in env:
8     match = re.search('([0-9]+).([0-9]+).([0-9]+)', env['PROTOC_VERSION'])
9
10 if match:
11     version = map(int, match.groups())
12
13 # proto3 syntax is supported by protoc >= 3.0.0
14 if env.GetOption('clean') or (match and version[0] >= 3):
15
16     env.NanopbProto(["alltypes", "alltypes.options"])
17     enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"])
18     dec = env.Program(["decode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"])
19
20     # Test the round-trip from nanopb encoder to nanopb decoder
21     env.RunTest(enc)
22     env.RunTest([dec, "encode_alltypes.output"])
23
24     # Re-encode the data using protoc, and check that the results from nanopb
25     # match byte-per-byte to the protoc output.
26     env.Decode("encode_alltypes.output.decoded",
27                ["encode_alltypes.output", "alltypes.proto"],
28                MESSAGE='AllTypes')
29     env.Encode("encode_alltypes.output.recoded",
30                ["encode_alltypes.output.decoded", "alltypes.proto"],
31                MESSAGE='AllTypes')
32     env.Compare(["encode_alltypes.output", "encode_alltypes.output.recoded"])
33
34     # Do the same checks with the optional fields present.
35     env.RunTest("optionals.output", enc, ARGS = ['1'])
36     env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1'])
37     env.Decode("optionals.output.decoded",
38                ["optionals.output", "alltypes.proto"],
39                MESSAGE='AllTypes')
40     env.Encode("optionals.output.recoded",
41                ["optionals.output.decoded", "alltypes.proto"],
42                MESSAGE='AllTypes')
43     env.Compare(["optionals.output", "optionals.output.recoded"])
44
45