mirror of
https://github.com/google/pebble
synced 2026-10-18 01:04:12 +02:00
Import of the watch repository from Pebble
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
# 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)
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user