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:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2022-07-04 16:12:37 +0300
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2022-07-04 16:12:37 +0300
commit89081e997edd6d3f986da0e2d37272c6f7b82063 (patch)
tree786bbca946848fac8dd162ed55830929056ff47d /tests
parent1c9c30db53fab836ec6eb5fab49e947650f7fd96 (diff)
Expand naming style test coverage
Diffstat (limited to 'tests')
-rw-r--r--tests/namingstyle/SConscript2
-rw-r--r--tests/namingstyle/naming_style.options1
-rw-r--r--tests/namingstyle/test_naming_style_c.c62
3 files changed, 59 insertions, 6 deletions
diff --git a/tests/namingstyle/SConscript b/tests/namingstyle/SConscript
index d92f92d..3922340 100644
--- a/tests/namingstyle/SConscript
+++ b/tests/namingstyle/SConscript
@@ -7,5 +7,5 @@ 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'])
+test = env.Program(["test_naming_style_c.c", "naming_style.pb.c", "$COMMON/pb_decode.o", "$COMMON/pb_encode.o", '$COMMON/pb_common.o'])
env.RunTest(test)
diff --git a/tests/namingstyle/naming_style.options b/tests/namingstyle/naming_style.options
index 8643e5b..0026b0b 100644
--- a/tests/namingstyle/naming_style.options
+++ b/tests/namingstyle/naming_style.options
@@ -4,6 +4,7 @@
MainMessage.repeatedNumber max_count:4, fixed_count:true
MainMessage.string_Values1 type:FT_POINTER
MainMessage.stringValues2 max_length:40, max_count:5
+MainMessage.requiredString max_length:10
MainMessage.repeatedFixed32 max_count:10
MainMessage.requiredBytes1 max_size:10, fixed_length:true
MainMessage.requiredBytes2 max_size:10
diff --git a/tests/namingstyle/test_naming_style_c.c b/tests/namingstyle/test_naming_style_c.c
index a3d15fd..f28bdce 100644
--- a/tests/namingstyle/test_naming_style_c.c
+++ b/tests/namingstyle/test_naming_style_c.c
@@ -2,24 +2,76 @@
#include <stdbool.h>
#include <string.h>
#include <assert.h>
+#include <pb_encode.h>
+#include <pb_decode.h>
#include "unittests.h"
#include "naming_style.pb.h"
int main()
{
+ int status = 0;
main_message_t message = MAIN_MESSAGE_INIT_ZERO;
+ /* Verify that all members have the expected names */
message.lucky_number = 13;
+ message.required_number = 1;
+ message.repeated_number[0] = 1;
+ message.repeated_ints = NULL;
+
message.my_enum1 = MY_ENUM1_ENUM_THIRD;
message.my_enum2 = MY_ENUM2_ENUM2_ENTRY;
+ message.my_enum3 = MY_ENUM2_ENUM2_ENTRY;
+ message.my_enum4.arg = NULL;
+
+ message.string_values1 = NULL;
+ message.string_values2[0][0] = 'a';
+ message.optional_string.arg = NULL;
+ message.required_string[0] = 'a';
+
+ message.repeated_fixed32[0] = 1;
+
+ message.required_bytes1[0] = 0;
+ message.required_bytes2.size = 0;
+ message.repeated_bytes1_count = 0;
+ message.repeated_bytes2 = NULL;
+
+ message.has_sub_message1 = true;
+ message.sub_message1.has_test_value = true;
+ message.sub_message1.test_value = 0;
+ message.sub_message2.arg = NULL;
+ message.sub_message3.test_value = 0;
+
+ message.which_one_of_name = MAIN_MESSAGE_TEST_MESSAGE2_TAG;
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.which_one_of_name2 = MAIN_MESSAGE_TEST_MESSAGE5_TAG;
message.test_message5.test_value = 5;
- assert(strcmp("ENTRY_FIRST", my_enum1_name(MY_ENUM1_ENTRY_FIRST)) == 0);
+ TEST(strcmp("ENTRY_FIRST", my_enum1_name(MY_ENUM1_ENTRY_FIRST)) == 0);
+
+ /* Verify that the descriptor structure is at least mostly correct
+ * by doing a round-trip encoding test.
+ */
+ {
+ uint8_t buffer1[256];
+ uint8_t buffer2[256];
+ pb_ostream_t ostream1 = pb_ostream_from_buffer(buffer1, sizeof(buffer1));
+ pb_ostream_t ostream2 = pb_ostream_from_buffer(buffer2, sizeof(buffer2));
+ pb_istream_t istream;
+ main_message_t message2 = MAIN_MESSAGE_INIT_ZERO;
+
+ TEST(pb_encode(&ostream1, &main_message_t_msg, &message));
+
+ istream = pb_istream_from_buffer(buffer1, ostream1.bytes_written);
+ TEST(pb_decode(&istream, &main_message_t_msg, &message2));
+
+ /* Encoding a second time should produce same output */
+ TEST(pb_encode(&ostream2, &main_message_t_msg, &message2));
+
+ TEST(ostream2.bytes_written == ostream1.bytes_written);
+ TEST(memcmp(buffer1, buffer2, ostream1.bytes_written) == 0);
+ }
- (void)message.lucky_number;
- return 0;
+ return status;
}