aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/nanopb/tests/package_name
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2016-10-07 09:02:28 -0700
committerGravatar Mark D. Roth <roth@google.com>2016-10-07 09:02:28 -0700
commit15195741d7758a80bcf901e7db05b3c57654c4a3 (patch)
tree1a7cd9f6b80235306559176a34bcf0e5c7ec4407 /third_party/nanopb/tests/package_name
parent2137cd8e9b84fd2f602a369ee5922a6fefce2efc (diff)
parente5c744d9850a763639b2e7001cf2487e1c76133b (diff)
Merge remote-tracking branch 'upstream/master' into rename_client_config
Diffstat (limited to 'third_party/nanopb/tests/package_name')
-rw-r--r--third_party/nanopb/tests/package_name/SConscript38
1 files changed, 38 insertions, 0 deletions
diff --git a/third_party/nanopb/tests/package_name/SConscript b/third_party/nanopb/tests/package_name/SConscript
new file mode 100644
index 0000000000..4afc503737
--- /dev/null
+++ b/third_party/nanopb/tests/package_name/SConscript
@@ -0,0 +1,38 @@
+# Check that alltypes test case works also when the .proto file defines
+# a package name.
+
+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 %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"])
+