summaryrefslogtreecommitdiffstats
path: root/tests/options
diff options
context:
space:
mode:
Diffstat (limited to 'tests/options')
-rw-r--r--tests/options/options.expected7
-rw-r--r--tests/options/options.proto73
2 files changed, 80 insertions, 0 deletions
diff --git a/tests/options/options.expected b/tests/options/options.expected
new file mode 100644
index 00000000..e6179a27
--- /dev/null
+++ b/tests/options/options.expected
@@ -0,0 +1,7 @@
+char filesize\[20\];
+char msgsize\[30\];
+char fieldsize\[40\];
+pb_callback_t int32_callback;
+\sEnumValue1 = 1
+Message5_EnumValue1
+} pb_packed my_packed_struct;
diff --git a/tests/options/options.proto b/tests/options/options.proto
new file mode 100644
index 00000000..b5badcfd
--- /dev/null
+++ b/tests/options/options.proto
@@ -0,0 +1,73 @@
+/* Test nanopb option parsing.
+ * options.expected lists the patterns that are searched for in the output.
+ */
+
+import "nanopb.proto";
+
+// File level options
+option (nanopb_fileopt).max_size = 20;
+
+message Message1
+{
+ required string filesize = 1;
+}
+
+// Message level options
+message Message2
+{
+ option (nanopb_msgopt).max_size = 30;
+ required string msgsize = 1;
+}
+
+// Field level options
+message Message3
+{
+ required string fieldsize = 1 [(nanopb).max_size = 40];
+}
+
+// Forced callback field
+message Message4
+{
+ required int32 int32_callback = 1 [(nanopb).type = FT_CALLBACK];
+}
+
+// Short enum names
+enum Enum1
+{
+ option (nanopb_enumopt).long_names = false;
+ EnumValue1 = 1;
+ EnumValue2 = 2;
+}
+
+message EnumTest
+{
+ required Enum1 field = 1 [default = EnumValue2];
+}
+
+// Short enum names inside message
+message Message5
+{
+ enum Enum2
+ {
+ option (nanopb_enumopt).long_names = false;
+ EnumValue1 = 1;
+ }
+ required Enum2 field = 1 [default = EnumValue1];
+}
+
+// Packed structure
+message my_packed_struct
+{
+ option (nanopb_msgopt).packed_struct = true;
+ optional int32 myfield = 1;
+}
+
+// Message with ignored field
+// Note: doesn't really test if the field is missing in the output,
+// but atleast tests that the output compiles.
+message Message6
+{
+ required int32 field1 = 1;
+ optional int32 field2 = 2 [(nanopb).type = FT_IGNORE];
+}
+