mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-01-06 08:39:03 +03:00
add nanopb (manual)
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
# Test that the generator options work as expected.
|
||||
|
||||
Import("env")
|
||||
|
||||
env.NanopbProto("options")
|
||||
env.Object('options.pb.c')
|
||||
env.Match('options_h.matched', ['options.pb.h', 'options_h.expected'])
|
||||
env.Match('options_c.matched', ['options.pb.c', 'options_c.expected'])
|
||||
|
||||
env.NanopbProto("proto3_options")
|
||||
env.Object('proto3_options.pb.c')
|
||||
env.Match(['proto3_options.pb.h', 'proto3_options.expected'])
|
||||
|
||||
p = env.Program(["options.c", "options.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_encode.o", "$COMMON/pb_common.o"])
|
||||
env.RunTest(p)
|
||||
28
components/spotify/cspot/bell/nanopb/tests/options/options.c
Normal file
28
components/spotify/cspot/bell/nanopb/tests/options/options.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "options.pb.h"
|
||||
#include "unittests.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
{
|
||||
HasFieldMessage msg1 = HasFieldMessage_init_default;
|
||||
HasFieldMessage msg2 = HasFieldMessage_init_zero;
|
||||
|
||||
COMMENT("Test default_has option");
|
||||
|
||||
/* Default initializer should obey has_default setting */
|
||||
TEST(msg1.has_present == true);
|
||||
TEST(msg1.has_missing == false);
|
||||
TEST(msg1.has_normal == false);
|
||||
|
||||
/* Zero initializer should always have false */
|
||||
TEST(msg2.has_present == false);
|
||||
TEST(msg2.has_missing == false);
|
||||
TEST(msg2.has_normal == false);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
127
components/spotify/cspot/bell/nanopb/tests/options/options.proto
Normal file
127
components/spotify/cspot/bell/nanopb/tests/options/options.proto
Normal file
@@ -0,0 +1,127 @@
|
||||
/* Test nanopb option parsing.
|
||||
* options.expected lists the patterns that are searched for in the output.
|
||||
*/
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
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
|
||||
{
|
||||
option (nanopb_msgopt).msgid = 103;
|
||||
required string fieldsize = 1 [(nanopb).max_size = 40];
|
||||
required string fieldlen = 2 [(nanopb).max_length = 40];
|
||||
}
|
||||
|
||||
// Forced callback field
|
||||
message Message4
|
||||
{
|
||||
option (nanopb_msgopt).msgid = 104;
|
||||
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
|
||||
{
|
||||
option (nanopb_msgopt).msgid = 105;
|
||||
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
|
||||
message Message6
|
||||
{
|
||||
required int32 field1 = 1;
|
||||
optional int32 skipped_field = 2 [(nanopb).type = FT_IGNORE];
|
||||
}
|
||||
|
||||
// Message that is skipped
|
||||
message SkippedMessage
|
||||
{
|
||||
option (nanopb_msgopt).skip_message = true;
|
||||
required int32 foo = 1;
|
||||
}
|
||||
|
||||
// Message with oneof field
|
||||
message OneofMessage
|
||||
{
|
||||
oneof foo {
|
||||
int32 bar = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Proto3-style optional field in proto2 file
|
||||
message Proto3Field
|
||||
{
|
||||
optional int32 proto3field = 1 [(nanopb).proto3 = true];
|
||||
}
|
||||
|
||||
// Wide descriptors
|
||||
message WideMessage
|
||||
{
|
||||
option (nanopb_msgopt).descriptorsize = DS_4;
|
||||
required int32 foo = 1;
|
||||
}
|
||||
|
||||
// Wide descriptor option in a single field
|
||||
message WideMessage2
|
||||
{
|
||||
required int32 foo = 1 [(nanopb).descriptorsize = DS_8];
|
||||
required int32 foo2 = 2 [(nanopb).descriptorsize = DS_4];
|
||||
required int32 foo3 = 3;
|
||||
}
|
||||
|
||||
// Default value for has_ field
|
||||
message HasFieldMessage
|
||||
{
|
||||
optional int32 present = 1 [(nanopb).default_has = true];
|
||||
optional int32 missing = 2 [(nanopb).default_has = false];
|
||||
optional int32 normal = 3;
|
||||
}
|
||||
|
||||
// Overridden type in generated C code
|
||||
message TypeOverrideMessage
|
||||
{
|
||||
required Enum1 normal = 1;
|
||||
required Enum1 overridden = 2 [(nanopb).type_override = TYPE_UINT32];
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
PB_BIND\(Message1, Message1, AUTO\)
|
||||
PB_BIND\(WideMessage, WideMessage, 4\)
|
||||
PB_BIND\(WideMessage2, WideMessage2, 8\)
|
||||
@@ -0,0 +1,24 @@
|
||||
char filesize\[20\];
|
||||
char msgsize\[30\];
|
||||
char fieldsize\[40\];
|
||||
char fieldlen\[41\];
|
||||
pb_callback_t int32_callback;
|
||||
\sEnumValue1 = 1
|
||||
Message5_EnumValue1
|
||||
} pb_packed my_packed_struct;
|
||||
! skipped_field
|
||||
! SkippedMessage
|
||||
#define PB_MSG_103 Message3
|
||||
#define PB_MSG_104 Message4
|
||||
#define PB_MSG_105 Message5
|
||||
#define OPTIONS_MESSAGES \\
|
||||
\s+PB_MSG\(103,[0-9]*,Message3\) \\
|
||||
\s+PB_MSG\(104,-1,Message4\) \\
|
||||
\s+PB_MSG\(105,[0-9]*,Message5\) \\
|
||||
#define Message5_msgid 105
|
||||
! has_proto3field
|
||||
Enum1 normal
|
||||
uint32_t overridden
|
||||
#define TypeOverrideMessage_init_default[ ]*\{_Enum1_MIN, 0\}
|
||||
#define TypeOverrideMessage_init_zero[ ]*\{_Enum1_MIN, 0\}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
! bool has_proto3_default
|
||||
bool has_proto3_off
|
||||
! bool has_proto3_on
|
||||
bool has_normal_submsg
|
||||
! bool has_sng_submsg
|
||||
@@ -0,0 +1,18 @@
|
||||
syntax = "proto3";
|
||||
|
||||
import "nanopb.proto";
|
||||
|
||||
message SubMsg
|
||||
{
|
||||
int32 field = 1;
|
||||
}
|
||||
|
||||
message Message1
|
||||
{
|
||||
int32 proto3_default = 1;
|
||||
int32 proto3_off = 2 [(nanopb).proto3 = false];
|
||||
int32 proto3_on = 3 [(nanopb).proto3 = true];
|
||||
SubMsg normal_submsg = 4;
|
||||
SubMsg sng_submsg = 5 [(nanopb).proto3_singular_msgs = true];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user