Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nanopb/nanopb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKrzysztof Rosinski <krzysiek@jrdltd.co.uk>2022-06-30 19:31:54 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2022-07-04 15:39:04 +0300
commit1c9c30db53fab836ec6eb5fab49e947650f7fd96 (patch)
treeb613951290c0a935fdb198a4c5a2f62251223cf4 /tests
parentf84ad7f7178c24bb14761e6011a3fa68d5879d1b (diff)
Add --c-style command line option for naming style (#199, #533, #791)
This option converts the type names from .proto files to a style that is commonly used in C code. Enum entries are in upper case, and camel case is converted to underscore separated names.
Diffstat (limited to 'tests')
-rw-r--r--tests/namingstyle/SConscript11
-rw-r--r--tests/namingstyle/naming_style.options14
-rw-r--r--tests/namingstyle/naming_style.proto62
-rw-r--r--tests/namingstyle/test_naming_style_c.c25
4 files changed, 112 insertions, 0 deletions
diff --git a/tests/namingstyle/SConscript b/tests/namingstyle/SConscript
new file mode 100644
index 0000000..d92f92d
--- /dev/null
+++ b/tests/namingstyle/SConscript
@@ -0,0 +1,11 @@
+# Test namingstyle option
+
+Import('env')
+
+env = env.Clone()
+env.Replace(NANOPBFLAGS = "-C")
+
+env.NanopbProto(["naming_style", "naming_style.options"])
+
+test = env.Program(["test_naming_style_c.c", "naming_style.pb.c", '$COMMON/pb_common.o'])
+env.RunTest(test)
diff --git a/tests/namingstyle/naming_style.options b/tests/namingstyle/naming_style.options
new file mode 100644
index 0000000..8643e5b
--- /dev/null
+++ b/tests/namingstyle/naming_style.options
@@ -0,0 +1,14 @@
+* long_names:true
+* enum_to_string:true
+
+MainMessage.repeatedNumber max_count:4, fixed_count:true
+MainMessage.string_Values1 type:FT_POINTER
+MainMessage.stringValues2 max_length:40, max_count:5
+MainMessage.repeatedFixed32 max_count:10
+MainMessage.requiredBytes1 max_size:10, fixed_length:true
+MainMessage.requiredBytes2 max_size:10
+MainMessage.repeatedBytes1 type:FT_POINTER
+MainMessage.repeatedBytes2 type:FT_POINTER, fixed_count:true, max_count:5
+MainMessage.repeatedInts type:FT_POINTER
+MainMessage.SUB_MESSAGE2 type:FT_CALLBACK
+MainMessage.oneOfName2 anonymous_oneof:true
diff --git a/tests/namingstyle/naming_style.proto b/tests/namingstyle/naming_style.proto
new file mode 100644
index 0000000..7e626e8
--- /dev/null
+++ b/tests/namingstyle/naming_style.proto
@@ -0,0 +1,62 @@
+syntax = "proto2";
+
+enum MyEnum1 {
+ ENTRY_FIRST = 0;
+ ENTRY_Second = 1;
+ EnumThird = 2;
+}
+
+enum MY_ENUM2 {
+ ENUM2_ENTRY = 0;
+}
+
+message SubMessage {
+ optional int32 test_value = 1;
+}
+
+message MainMessage {
+ optional int32 LUCKY_number = 1;
+ required int32 REQUIRED_NUMBER = 2;
+ repeated int32 repeatedNumber = 3;
+ repeated int32 repeatedInts = 4;
+
+ optional MyEnum1 MyEnum1 = 5;
+ optional MY_ENUM2 My_Enum2 = 6;
+ required MY_ENUM2 MY_ENUM3 = 7;
+ repeated MY_ENUM2 MY_ENUM4 = 8;
+
+ repeated string string_Values1 = 9;
+ repeated string stringValues2 = 10;
+ optional string OPTIONAL_String = 11;
+ required string requiredString = 12;
+
+ repeated fixed32 repeatedFixed32 = 13;
+
+ required bytes requiredBytes1 = 14;
+ required bytes requiredBytes2 = 15;
+ repeated bytes repeatedBytes1 = 16;
+ repeated bytes repeatedBytes2 = 17;
+
+ optional SubMessage subMessage1 = 18;
+ repeated SubMessage SUB_MESSAGE2 = 19;
+ required SubMessage sub_message3 = 20;
+
+ oneof oneOfName {
+ SubMessage testMessage1 = 21;
+ SubMessage testMessage2 = 22;
+ }
+
+ oneof oneOfName2 {
+ SubMessage testMessage4 = 23;
+ SubMessage testMessage5 = 24;
+ }
+
+ extensions 200 to 255;
+}
+
+message TestExtension {
+ extend MainMessage {
+ optional TestExtension testExtension = 250;
+ }
+ optional string stringValue = 1;
+}
diff --git a/tests/namingstyle/test_naming_style_c.c b/tests/namingstyle/test_naming_style_c.c
new file mode 100644
index 0000000..a3d15fd
--- /dev/null
+++ b/tests/namingstyle/test_naming_style_c.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+#include <assert.h>
+#include "unittests.h"
+#include "naming_style.pb.h"
+
+int main()
+{
+ main_message_t message = MAIN_MESSAGE_INIT_ZERO;
+
+ message.lucky_number = 13;
+ message.my_enum1 = MY_ENUM1_ENUM_THIRD;
+ message.my_enum2 = MY_ENUM2_ENUM2_ENTRY;
+ message.one_of_name.test_message2.has_test_value = true;
+ message.one_of_name.test_message2.test_value = 5;
+ message.which_one_of_name = 1;
+ message.repeated_fixed32[0] = 1;
+ message.test_message5.test_value = 5;
+
+ assert(strcmp("ENTRY_FIRST", my_enum1_name(MY_ENUM1_ENTRY_FIRST)) == 0);
+
+ (void)message.lucky_number;
+ return 0;
+}