Skip to content
Snippets Groups Projects
Commit 3ce31b76 authored by Petteri Aimonen's avatar Petteri Aimonen
Browse files

Add testcase for issue #322

parent a3aae563
No related branches found
No related tags found
No related merge requests found
# Check that default values with special characters are
# correctly handled.
Import('env')
env.NanopbProto('defaults')
p = env.Program(["defaults.c",
"defaults.pb.c",
"$COMMON/pb_decode.o",
"$COMMON/pb_common.o"])
env.RunTest(p)
#include "defaults.pb.h"
#include <unittests.h>
#include <pb_decode.h>
int check_defaults(const DefaultsMsg *msg)
{
int status = 0;
TEST(msg->b1[0] == 0xDE && msg->b1[1] == 0xAD && msg->b1[2] == 0x00 &&
msg->b1[3] == 0xBE && msg->b1[4] == 0xEF);
TEST(msg->b2.bytes[0] == 0xDE && msg->b2.bytes[1] == 0xAD &&
msg->b2.bytes[2] == 0x00 && msg->b2.bytes[3] == 0xBE &&
msg->b2.bytes[4] == 0xEF && msg->b2.size == 5);
TEST(msg->b3.bytes[0] == 0xDE && msg->b3.bytes[1] == 0xAD &&
msg->b3.bytes[2] == 0x00 && msg->b3.bytes[3] == 0xBE &&
msg->b3.bytes[4] == 0xEF && msg->b2.size == 5);
TEST(msg->s1[0] == (char)0xC3 && msg->s1[1] == (char)0xA4 &&
msg->s1[2] == (char)0xC3 && msg->s1[3] == (char)0xB6 &&
msg->s1[4] == '\0');
return status;
}
int main()
{
int status = 0;
{
DefaultsMsg msg = DefaultsMsg_init_default;
COMMENT("Checking defaults from static initializer");
status += check_defaults(&msg);
}
{
DefaultsMsg msg = DefaultsMsg_init_zero;
pb_istream_t empty = {0,0,0};
pb_decode(&empty, DefaultsMsg_fields, &msg);
COMMENT("Checking defaults set at runtime");
status += check_defaults(&msg);
}
return status;
}
syntax = "proto2";
import 'nanopb.proto';
message DefaultsMsg {
optional bytes b1 = 1 [default = "\xDE\xAD\x00\xBE\xEF", (nanopb).max_size = 5, (nanopb).fixed_length=true];
optional bytes b2 = 2 [default = "\xDE\xAD\x00\xBE\xEF", (nanopb).max_size = 5];
optional bytes b3 = 3 [default = "\xDE\xAD\000\xBE\xEF", (nanopb).max_size = 15];
optional string s1 = 4 [default = "äö", (nanopb).max_size = 8];
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment