Test case for enum_to_string
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Tue, 22 Nov 2016 15:25:00 +0000 (17:25 +0200)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Tue, 22 Nov 2016 15:25:00 +0000 (17:25 +0200)
tests/enum_to_string/SConscript [new file with mode: 0644]
tests/enum_to_string/enum.proto [new file with mode: 0644]
tests/enum_to_string/enum_to_string.c [new file with mode: 0644]

diff --git a/tests/enum_to_string/SConscript b/tests/enum_to_string/SConscript
new file mode 100644 (file)
index 0000000..e86fcca
--- /dev/null
@@ -0,0 +1,7 @@
+# Test enum to string functionality
+
+Import('env')
+env.NanopbProto("enum.proto")
+p = env.Program(["enum_to_string.c", "enum.pb.c"])
+env.RunTest(p)
+
diff --git a/tests/enum_to_string/enum.proto b/tests/enum_to_string/enum.proto
new file mode 100644 (file)
index 0000000..07c6736
--- /dev/null
@@ -0,0 +1,19 @@
+/* Test enum to string function generation */
+
+syntax = "proto2";
+
+import "nanopb.proto";
+
+option (nanopb_fileopt).enum_to_string = true;
+
+enum MyEnum {
+    VALUE1 = 1;
+    VALUE2 = 2;
+    VALUE15 = 15;
+}
+
+enum MyShortNameEnum {
+    option (nanopb_enumopt).long_names = false;
+    MSNE_VALUE256 = 256;
+}
+
diff --git a/tests/enum_to_string/enum_to_string.c b/tests/enum_to_string/enum_to_string.c
new file mode 100644 (file)
index 0000000..c4fb31d
--- /dev/null
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include "unittests.h"
+#include "enum.pb.h"
+
+int main()
+{
+    int status = 0;
+    TEST(strcmp(MyEnum_name(MyEnum_VALUE1), "VALUE1") == 0);
+    TEST(strcmp(MyEnum_name(MyEnum_VALUE2), "VALUE2") == 0);
+    TEST(strcmp(MyEnum_name(MyEnum_VALUE15), "VALUE15") == 0);
+    TEST(strcmp(MyShortNameEnum_name(MSNE_VALUE256), "MSNE_VALUE256") == 0);
+    TEST(strcmp(MyShortNameEnum_name(9999), "unknown") == 0);
+    
+    if (status != 0)
+        fprintf(stdout, "\n\nSome tests FAILED!\n");
+
+    return status;
+}
+