From 3fccff9381515b85f0992d4751f4144e22c3315d Mon Sep 17 00:00:00 2001 From: Robert Edmonds Date: Thu, 3 Apr 2014 12:09:54 -0400 Subject: [PATCH] t/: add test case test_field_flags --- t/generated-code2/test-generated-code2.c | 38 ++++++++++++++++++++++++ t/test-full.proto | 9 ++++++ 2 files changed, 47 insertions(+) diff --git a/t/generated-code2/test-generated-code2.c b/t/generated-code2/test-generated-code2.c index 1ca046d..eb736f7 100644 --- a/t/generated-code2/test-generated-code2.c +++ b/t/generated-code2/test-generated-code2.c @@ -1612,6 +1612,42 @@ static void test_required_fields_bitmap(void) assert (msg == NULL); } +static void +test_field_flags (void) +{ + const ProtobufCFieldDescriptor *f; + + f = protobuf_c_message_descriptor_get_field_by_name( + &foo__test_field_flags__descriptor, "no_flags1"); + assert(f != NULL); + assert(!(f->flags & PROTOBUF_C_FIELD_FLAG_PACKED)); + assert(!(f->flags & PROTOBUF_C_FIELD_FLAG_DEPRECATED)); + + f = protobuf_c_message_descriptor_get_field_by_name( + &foo__test_field_flags__descriptor, "no_flags2"); + assert(f != NULL); + assert(!(f->flags & PROTOBUF_C_FIELD_FLAG_PACKED)); + assert(!(f->flags & PROTOBUF_C_FIELD_FLAG_DEPRECATED)); + + f = protobuf_c_message_descriptor_get_field_by_name( + &foo__test_field_flags__descriptor, "no_flags3"); + assert(f != NULL); + assert(!(f->flags & PROTOBUF_C_FIELD_FLAG_PACKED)); + assert(!(f->flags & PROTOBUF_C_FIELD_FLAG_DEPRECATED)); + + f = protobuf_c_message_descriptor_get_field_by_name( + &foo__test_field_flags__descriptor, "packed"); + assert(f != NULL); + assert((f->flags & PROTOBUF_C_FIELD_FLAG_PACKED)); + assert(!(f->flags & PROTOBUF_C_FIELD_FLAG_DEPRECATED)); + + f = protobuf_c_message_descriptor_get_field_by_name( + &foo__test_field_flags__descriptor, "packed_deprecated"); + assert(f != NULL); + assert((f->flags & PROTOBUF_C_FIELD_FLAG_PACKED)); + assert((f->flags & PROTOBUF_C_FIELD_FLAG_DEPRECATED)); +} + /* === simple testing framework === */ typedef void (*TestFunc) (void); @@ -1718,6 +1754,8 @@ static Test tests[] = { "test alloc failure", test_alloc_fail }, { "test required_fields_bitmap", test_required_fields_bitmap }, + + { "test field flags", test_field_flags }, }; #define n_tests (sizeof(tests)/sizeof(Test)) diff --git a/t/test-full.proto b/t/test-full.proto index e7be827..a97103e 100644 --- a/t/test-full.proto +++ b/t/test-full.proto @@ -353,3 +353,12 @@ message TestRequiredFieldsBitmap { optional string field128 = 128; required string field129 = 129; } + +message TestFieldFlags { + optional int32 no_flags1 = 1; + required int32 no_flags2 = 2; + repeated int32 no_flags3 = 3; + repeated int32 packed = 4 [packed=true]; + repeated int32 packed_deprecated = 5 [packed=true, deprecated=true]; + repeated int32 deprecated = 6 [deprecated=true]; +}