• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Test the 'oneof' feature for generating C unions.
2
3Import('env')
4
5import re
6
7match = None
8if 'PROTOC_VERSION' in env:
9    match = re.search('([0-9]+).([0-9]+).([0-9]+)', env['PROTOC_VERSION'])
10
11if match:
12    version = map(int, match.groups())
13
14# Oneof is supported by protoc >= 2.6.0
15if env.GetOption('clean') or (match and (version[0] > 2 or (version[0] == 2 and version[1] >= 6))):
16    env.NanopbProto('oneof')
17
18    enc = env.Program(['encode_oneof.c',
19                    'oneof.pb.c',
20                    '$COMMON/pb_encode.o',
21                    '$COMMON/pb_common.o'])
22
23    dec = env.Program(['decode_oneof.c',
24                    'oneof.pb.c',
25                    '$COMMON/pb_decode.o',
26                    '$COMMON/pb_common.o'])
27
28    env.RunTest("message1.pb", enc, ARGS = ['1'])
29    env.RunTest("message1.txt", [dec, 'message1.pb'], ARGS = ['1'])
30    env.RunTest("message2.pb", enc, ARGS = ['2'])
31    env.RunTest("message2.txt", [dec, 'message2.pb'], ARGS = ['2'])
32    env.RunTest("message3.pb", enc, ARGS = ['3'])
33    env.RunTest("message3.txt", [dec, 'message3.pb'], ARGS = ['3'])
34