mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-27 13:31:02 +08:00
t/: add test case test_field_flags
This commit is contained in:
parent
e962705437
commit
3fccff9381
@ -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))
|
||||
|
||||
|
@ -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];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user