forked from nanopb/nanopb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case for nanopb#422 (nanopb package name option)
- Loading branch information
1 parent
bbf1aa7
commit 3e101b9
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Check that alltypes test case works also when the .proto file defines | ||
# a package name using the (nanopb_fileopt).package option. | ||
|
||
Import("env") | ||
|
||
def set_pkgname(src, dst, pkgname): | ||
data = open(str(src)).read() | ||
placeholder = '// package name placeholder' | ||
assert placeholder in data | ||
data = data.replace(placeholder, 'package foopkg;\n' + | ||
'import "nanopb.proto";\n' + | ||
'option (nanopb_fileopt).package="%s";' % pkgname) | ||
open(str(dst), 'w').write(data) | ||
|
||
# Build a modified alltypes.proto | ||
env.Command("alltypes.proto", "#alltypes/alltypes.proto", | ||
lambda target, source, env: set_pkgname(source[0], target[0], 'test.package')) | ||
env.Command("alltypes.options", "#alltypes/alltypes.options", Copy("$TARGET", "$SOURCE")) | ||
env.NanopbProto(["alltypes", "alltypes.options"]) | ||
|
||
# Build a modified encode_alltypes.c | ||
def modify_c(target, source, env): | ||
'''Add package name to type names in .c file.''' | ||
|
||
data = open(str(source[0]), 'r').read() | ||
|
||
type_names = ['AllTypes', 'MyEnum', 'HugeEnum'] | ||
for name in type_names: | ||
data = data.replace(name, 'test_package_' + name) | ||
|
||
open(str(target[0]), 'w').write(data) | ||
return 0 | ||
env.Command("encode_alltypes.c", "#alltypes/encode_alltypes.c", modify_c) | ||
|
||
# Encode and compare results to original alltypes testcase | ||
enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"]) | ||
refdec = "$BUILD/alltypes/decode_alltypes$PROGSUFFIX" | ||
env.RunTest(enc) | ||
env.Compare(["encode_alltypes.output", "$BUILD/alltypes/encode_alltypes.output"]) | ||
|