• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Build and run a test that encodes and decodes a message that contains
2# all of the Protocol Buffers data types.
3
4Import("env")
5
6env.NanopbProto(["alltypes", "alltypes.options"])
7enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o"])
8dec = env.Program(["decode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_decode.o"])
9
10# Test the round-trip from nanopb encoder to nanopb decoder
11env.RunTest(enc)
12env.RunTest([dec, "encode_alltypes.output"])
13
14# Re-encode the data using protoc, and check that the results from nanopb
15# match byte-per-byte to the protoc output.
16env.Decode("encode_alltypes.output.decoded",
17           ["encode_alltypes.output", "alltypes.proto"],
18           MESSAGE='AllTypes')
19env.Encode("encode_alltypes.output.recoded",
20           ["encode_alltypes.output.decoded", "alltypes.proto"],
21           MESSAGE='AllTypes')
22env.Compare(["encode_alltypes.output", "encode_alltypes.output.recoded"])
23
24# Do the same checks with the optional fields present.
25env.RunTest("optionals.output", enc, ARGS = ['1'])
26env.RunTest("optionals.decout", [dec, "optionals.output"], ARGS = ['1'])
27env.Decode("optionals.output.decoded",
28           ["optionals.output", "alltypes.proto"],
29           MESSAGE='AllTypes')
30env.Encode("optionals.output.recoded",
31           ["optionals.output.decoded", "alltypes.proto"],
32           MESSAGE='AllTypes')
33env.Compare(["optionals.output", "optionals.output.recoded"])
34
35
36