SConscript 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Check that alltypes test case works also when the .proto file defines
  2. # a package name.
  3. Import("env")
  4. def set_pkgname(src, dst, pkgname):
  5. data = open(str(src)).read()
  6. placeholder = '// package name placeholder'
  7. assert placeholder in data
  8. data = data.replace(placeholder, 'package %s;' % pkgname)
  9. open(str(dst), 'w').write(data)
  10. # Build a modified alltypes.proto
  11. env.Command("alltypes.proto", "#alltypes/alltypes.proto",
  12. lambda target, source, env: set_pkgname(source[0], target[0], 'test.package'))
  13. env.Command("alltypes.options", "#alltypes/alltypes.options", Copy("$TARGET", "$SOURCE"))
  14. env.NanopbProto(["alltypes", "alltypes.options"])
  15. # Build a modified encode_alltypes.c
  16. def modify_c(target, source, env):
  17. '''Add package name to type names in .c file.'''
  18. data = open(str(source[0]), 'r').read()
  19. type_names = ['AllTypes', 'MyEnum', 'HugeEnum', 'NonZeroBasedEnum']
  20. for name in type_names:
  21. data = data.replace(name, 'test_package_' + name)
  22. open(str(target[0]), 'w').write(data)
  23. return 0
  24. env.Command("encode_alltypes.c", "#alltypes/encode_alltypes.c", modify_c)
  25. # Encode and compare results to original alltypes testcase
  26. enc = env.Program(["encode_alltypes.c", "alltypes.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"])
  27. refdec = "$BUILD/alltypes/decode_alltypes$PROGSUFFIX"
  28. env.RunTest(enc)
  29. env.Compare(["encode_alltypes.output", "$BUILD/alltypes/encode_alltypes.output"])