mirror of
https://github.com/google/pebble.git
synced 2025-07-18 20:16:39 -04:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
52
third_party/nanopb/tests/regression/issue_342/test_extensions.c
vendored
Normal file
52
third_party/nanopb/tests/regression/issue_342/test_extensions.c
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pb_encode.h>
|
||||
#include <pb_decode.h>
|
||||
#include "extensions.pb.h"
|
||||
#include "unittests.h"
|
||||
|
||||
static bool write_string(pb_ostream_t *stream, const pb_field_t *field, void * const *arg)
|
||||
{
|
||||
return pb_encode_tag_for_field(stream, field) &&
|
||||
pb_encode_string(stream, (const void*)"abc", 3);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int status = 0;
|
||||
uint8_t buffer[64];
|
||||
pb_size_t msglen = 0;
|
||||
|
||||
{
|
||||
pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer));
|
||||
pb_callback_t callback_def = {{0}};
|
||||
pb_extension_t ext = {0};
|
||||
BaseMessage msg = {0};
|
||||
|
||||
callback_def.funcs.encode = &write_string;
|
||||
ext.type = &string_extension;
|
||||
ext.dest = &callback_def;
|
||||
msg.extensions = &ext;
|
||||
|
||||
TEST(pb_encode(&stream, BaseMessage_fields, &msg));
|
||||
|
||||
msglen = stream.bytes_written;
|
||||
TEST(msglen > 3);
|
||||
}
|
||||
|
||||
{
|
||||
pb_istream_t stream = pb_istream_from_buffer(buffer, msglen);
|
||||
pb_extension_t ext = {0};
|
||||
BaseMessage msg = {0};
|
||||
|
||||
ext.type = &string_extension;
|
||||
/* Note: ext.dest remains null to trigger bug #342 */
|
||||
msg.extensions = &ext;
|
||||
|
||||
TEST(pb_decode(&stream, BaseMessage_fields, &msg));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue