Expand the multiple_files test case to include oneofs and enums
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Sat, 12 Sep 2015 10:27:56 +0000 (13:27 +0300)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Sat, 12 Sep 2015 10:27:56 +0000 (13:27 +0300)
tests/multiple_files/SConscript
tests/multiple_files/callbacks2.proto [deleted file]
tests/multiple_files/multifile1.proto [moved from tests/multiple_files/callbacks.proto with 78% similarity]
tests/multiple_files/multifile2.proto [new file with mode: 0644]
tests/multiple_files/test_multiple_files.c

index 6b4f6b6..c3a82eb 100644 (file)
@@ -5,9 +5,9 @@ Import("env")
 incpath = env.Clone()
 incpath.Append(PROTOCPATH = '#multiple_files')
 
-incpath.NanopbProto("callbacks")
-incpath.NanopbProto("callbacks2")
-test = incpath.Program(["test_multiple_files.c", "callbacks.pb.c", "callbacks2.pb.c"])
+incpath.NanopbProto("multifile1")
+incpath.NanopbProto("multifile2")
+test = incpath.Program(["test_multiple_files.c", "multifile1.pb.c", "multifile2.pb.c"])
 
 env.RunTest(test)
 
diff --git a/tests/multiple_files/callbacks2.proto b/tests/multiple_files/callbacks2.proto
deleted file mode 100644 (file)
index 9a55e15..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-// Test if including generated header file for this file + implicit include of
-// callbacks.pb.h still compiles. Used with test_compiles.c.
-import "callbacks.proto";
-
-message Callback2Message {
-    required TestMessage tstmsg = 1;
-    required SubMessage submsg = 2;
-}
-
similarity index 78%
rename from tests/multiple_files/callbacks.proto
rename to tests/multiple_files/multifile1.proto
index ccd1edd..79cf038 100644 (file)
@@ -14,3 +14,15 @@ message TestMessage {
     repeated string repeatedstring = 6;
 }
 
+enum SignedEnum {
+    SE_MIN = -128;
+    SE_MAX = 127;
+}
+
+enum UnsignedEnum {
+    UE_MIN = 0;
+    UE_MAX = 255;
+}
+
+
+
diff --git a/tests/multiple_files/multifile2.proto b/tests/multiple_files/multifile2.proto
new file mode 100644 (file)
index 0000000..c5dcd40
--- /dev/null
@@ -0,0 +1,21 @@
+// Test if including generated header file for this file + implicit include of
+// multifile2.pb.h still compiles. Used with test_compiles.c.
+import "multifile1.proto";
+
+message Callback2Message {
+    required TestMessage tstmsg = 1;
+    required SubMessage submsg = 2;
+}
+
+message OneofMessage {
+    oneof msgs {
+        TestMessage tstmsg = 1;
+        SubMessage submsg = 2;
+    }
+}
+
+message Enums {
+    required SignedEnum senum = 1;
+    required UnsignedEnum uenum = 2;
+}
+
index 05722dc..5134f03 100644 (file)
@@ -4,9 +4,19 @@
 
 #include <stdio.h>
 #include <pb_encode.h>
-#include "callbacks2.pb.h"
+#include "unittests.h"
+#include "multifile2.pb.h"
+
+/* Check that the size definition is obtained properly */
+static const int foo = OneofMessage_size;
 
 int main()
 {
-       return 0;
+    int status = 0;
+    
+    /* Check that enum signedness is detected properly */
+    TEST(PB_LTYPE(Enums_fields[0].type) == PB_LTYPE_VARINT);
+    TEST(PB_LTYPE(Enums_fields[0].type) == PB_LTYPE_UVARINT);
+    
+    return status;
 }