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,8 @@
|
||||
# Regression test for #558:
|
||||
# Manually defining proto3:true on a field with default value incorrectly omits it when encoding.
|
||||
|
||||
Import("env")
|
||||
env.NanopbProto("mixed")
|
||||
|
||||
test = env.Program(["mixed.c", "mixed.pb.c", "$COMMON/pb_encode.o", "$COMMON/pb_decode.o", "$COMMON/pb_common.o"])
|
||||
env.RunTest(test)
|
||||
@@ -0,0 +1,49 @@
|
||||
#include <pb_encode.h>
|
||||
#include <pb_decode.h>
|
||||
|
||||
#include "mixed.pb.h"
|
||||
#include "unittests.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
int status = 0;
|
||||
pb_byte_t buf[64];
|
||||
size_t msglen;
|
||||
|
||||
{
|
||||
pb_ostream_t ostream = pb_ostream_from_buffer(buf, sizeof(buf));
|
||||
MixedMessage msg = MixedMessage_init_default;
|
||||
|
||||
msg.has_proto2_value = true;
|
||||
msg.proto2_value = 0;
|
||||
msg.proto3_value = 0;
|
||||
|
||||
if (!pb_encode(&ostream, MixedMessage_fields, &msg))
|
||||
{
|
||||
fprintf(stderr, "pb_encode() failed: %s\n", PB_GET_ERROR(&ostream));
|
||||
return 1;
|
||||
}
|
||||
|
||||
msglen = ostream.bytes_written;
|
||||
TEST(msglen > 0);
|
||||
}
|
||||
|
||||
{
|
||||
pb_istream_t istream = pb_istream_from_buffer(buf, msglen);
|
||||
MixedMessage msg = MixedMessage_init_default;
|
||||
|
||||
TEST(msg.proto2_value == 100);
|
||||
TEST(msg.proto3_value == 200);
|
||||
|
||||
if (!pb_decode(&istream, MixedMessage_fields, &msg))
|
||||
{
|
||||
fprintf(stderr, "pb_decode() failed: %s\n", PB_GET_ERROR(&istream));
|
||||
return 1;
|
||||
}
|
||||
|
||||
TEST(msg.proto2_value == 0);
|
||||
TEST(msg.proto3_value == 0);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
syntax = "proto2";
|
||||
|
||||
import "nanopb.proto";
|
||||
|
||||
message MixedMessage {
|
||||
optional int32 proto2_value = 1 [default = 100];
|
||||
optional int32 proto3_value = 2 [default = 200, (nanopb).proto3 = true];
|
||||
}
|
||||
Reference in New Issue
Block a user