summaryrefslogtreecommitdiffstats
path: root/CAN-binder/libs/nanopb/tests/regression/issue_242
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-05-19 16:20:02 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-05-19 16:20:02 +0200
commit2d574dc77f68ecb5150016989900860e8b74be50 (patch)
treed691a8345a58dcd080131c58d028f77df51a45ed /CAN-binder/libs/nanopb/tests/regression/issue_242
parent48a2605965af1f05ba7f01f6e8c1758a4c9b0522 (diff)
parent278ffb890e3d8722e4c7d824baaf221a1e375fc4 (diff)
Add 'CAN-binder/libs/nanopb/' from commit '278ffb890e3d8722e4c7d824baaf221a1e375fc4'
git-subtree-dir: CAN-binder/libs/nanopb git-subtree-mainline: 48a2605965af1f05ba7f01f6e8c1758a4c9b0522 git-subtree-split: 278ffb890e3d8722e4c7d824baaf221a1e375fc4
Diffstat (limited to 'CAN-binder/libs/nanopb/tests/regression/issue_242')
-rw-r--r--CAN-binder/libs/nanopb/tests/regression/issue_242/SConscript13
-rw-r--r--CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.c51
-rw-r--r--CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.proto15
3 files changed, 79 insertions, 0 deletions
diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_242/SConscript b/CAN-binder/libs/nanopb/tests/regression/issue_242/SConscript
new file mode 100644
index 00000000..000063ef
--- /dev/null
+++ b/CAN-binder/libs/nanopb/tests/regression/issue_242/SConscript
@@ -0,0 +1,13 @@
+# Regression test for Issue 242: pb_encode does not encode tag for
+# extension fields that is all zeros
+Import('env')
+
+env.NanopbProto('zero_value')
+
+p = env.Program(["zero_value.c",
+ "zero_value.pb.c",
+ "$COMMON/pb_decode.o",
+ "$COMMON/pb_encode.o",
+ "$COMMON/pb_common.o"])
+env.RunTest(p)
+
diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.c b/CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.c
new file mode 100644
index 00000000..b3d96b7a
--- /dev/null
+++ b/CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.c
@@ -0,0 +1,51 @@
+#include <unittests.h>
+#include <pb_encode.h>
+#include <pb_decode.h>
+#include <string.h>
+#include "zero_value.pb.h"
+
+int main()
+{
+ int status = 0;
+
+ COMMENT("Test extension fields with zero values");
+ {
+ uint8_t buffer[256] = {0};
+ pb_ostream_t ostream;
+ int32_t value = 0;
+ Extendable source = {0};
+
+ pb_extension_t source_ext = {0};
+ source_ext.type = &opt_int32;
+ source_ext.dest = &value;
+ source.extensions = &source_ext;
+
+ ostream = pb_ostream_from_buffer(buffer, sizeof(buffer));
+ TEST(pb_encode(&ostream, Extendable_fields, &source));
+
+ TEST(ostream.bytes_written == 2);
+ TEST(memcmp(buffer, "\x58\x00", 2) == 0);
+ }
+
+ /* Note: There never was a bug here, but this check is included
+ * in the regression test because the logic is closely related.
+ */
+ COMMENT("Test pointer fields with zero values");
+ {
+ uint8_t buffer[256] = {0};
+ pb_ostream_t ostream;
+ int32_t value = 0;
+ PointerMessage source = {0};
+
+ source.opt_int32 = &value;
+
+ ostream = pb_ostream_from_buffer(buffer, sizeof(buffer));
+ TEST(pb_encode(&ostream, PointerMessage_fields, &source));
+
+ TEST(ostream.bytes_written == 2);
+ TEST(memcmp(buffer, "\x58\x00", 2) == 0);
+ }
+
+ return status;
+}
+
diff --git a/CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.proto b/CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.proto
new file mode 100644
index 00000000..020a39a5
--- /dev/null
+++ b/CAN-binder/libs/nanopb/tests/regression/issue_242/zero_value.proto
@@ -0,0 +1,15 @@
+syntax = "proto2";
+import "nanopb.proto";
+
+message Extendable {
+ extensions 10 to 100;
+}
+
+extend Extendable {
+ optional int32 opt_int32 = 11;
+}
+
+message PointerMessage {
+ optional int32 opt_int32 = 11 [(nanopb).type = FT_POINTER];
+}
+