mirror of
https://github.com/protobuf-c/protobuf-c.git
synced 2024-12-27 13:31:02 +08:00
t: Add tests for the LITE_RUNTIME optimization option
This commit is contained in:
parent
603e431864
commit
be99a7ac31
@ -131,7 +131,8 @@ t_generated_code_test_generated_code_LDADD = \
|
||||
|
||||
t_generated_code2_test_generated_code2_SOURCES = \
|
||||
t/generated-code2/test-generated-code2.c \
|
||||
t/test-full.pb-c.c
|
||||
t/test-full.pb-c.c \
|
||||
t/test-optimized.pb-c.c
|
||||
t_generated_code2_test_generated_code2_LDADD = \
|
||||
protobuf-c/libprotobuf-c.la
|
||||
|
||||
@ -151,6 +152,9 @@ t_generated_code2_cxx_generate_packed_data_LDADD = \
|
||||
t/test.pb-c.c t/test.pb-c.h: $(top_builddir)/protoc-c/protoc-c$(EXEEXT) $(top_srcdir)/t/test.proto
|
||||
$(AM_V_GEN)$(top_builddir)/protoc-c/protoc-c$(EXEEXT) -I$(top_srcdir) --c_out=$(top_builddir) $(top_srcdir)/t/test.proto
|
||||
|
||||
t/test-optimized.pb-c.c t/test-optimized.pb-c.h: $(top_builddir)/protoc-c/protoc-c$(EXEEXT) $(top_srcdir)/t/test-optimized.proto
|
||||
$(AM_V_GEN)$(top_builddir)/protoc-c/protoc-c$(EXEEXT) -I$(top_srcdir) --c_out=$(top_builddir) $(top_srcdir)/t/test-optimized.proto
|
||||
|
||||
t/test-full.pb-c.c t/test-full.pb-c.h: $(top_builddir)/protoc-c/protoc-c$(EXEEXT) $(top_srcdir)/t/test-full.proto
|
||||
$(AM_V_GEN)$(top_builddir)/protoc-c/protoc-c$(EXEEXT) -I$(top_srcdir) --c_out=$(top_builddir) $(top_srcdir)/t/test-full.proto
|
||||
|
||||
@ -163,6 +167,7 @@ t/generated-code2/test-full-cxx-output.inc: t/generated-code2/cxx-generate-packe
|
||||
BUILT_SOURCES += \
|
||||
t/test.pb-c.c t/test.pb-c.h \
|
||||
t/test-full.pb-c.c t/test-full.pb-c.h \
|
||||
t/test-optimized.pb-c.c t/test-optimized.pb-c.h \
|
||||
t/test-full.pb.cc t/test-full.pb.h \
|
||||
t/generated-code2/test-full-cxx-output.inc
|
||||
|
||||
@ -176,6 +181,7 @@ endif # BUILD_COMPILER
|
||||
EXTRA_DIST += \
|
||||
t/test.proto \
|
||||
t/test-full.proto \
|
||||
t/test-optimized.proto \
|
||||
t/generated-code2/common-test-arrays.h
|
||||
|
||||
#
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "t/test-full.pb-c.h"
|
||||
#include "t/test-optimized.pb-c.h"
|
||||
#include "t/generated-code2/test-full-cxx-output.inc"
|
||||
|
||||
#define TEST_ENUM_SMALL_TYPE_NAME Foo__TestEnumSmall
|
||||
@ -1565,8 +1566,9 @@ test_enum_descriptor (const ProtobufCEnumDescriptor *desc)
|
||||
const ProtobufCEnumValue *vv;
|
||||
const ProtobufCEnumValue *vn;
|
||||
vv = protobuf_c_enum_descriptor_get_value (desc, sv->value);
|
||||
vn = protobuf_c_enum_descriptor_get_value_by_name (desc, sv->name);
|
||||
assert (sv == vv);
|
||||
vn = protobuf_c_enum_descriptor_get_value_by_name (desc, sv->name);
|
||||
if (sv->name != NULL)
|
||||
assert (sv == vn);
|
||||
}
|
||||
for (i = 0; i < desc->n_value_names; i++)
|
||||
@ -1588,12 +1590,31 @@ test_enum_by_name (const ProtobufCEnumDescriptor *desc,
|
||||
assert (v->value == expected_value);
|
||||
}
|
||||
|
||||
static void
|
||||
test_lite_enum (void)
|
||||
{
|
||||
const ProtobufCEnumDescriptor *desc = &foo__test_enum_lite__descriptor;
|
||||
const ProtobufCEnumValue *v;
|
||||
|
||||
v = protobuf_c_enum_descriptor_get_value_by_name (desc, "BOO");
|
||||
assert (v == NULL);
|
||||
|
||||
v = protobuf_c_enum_descriptor_get_value (desc, 0);
|
||||
assert (v != NULL);
|
||||
assert (v->value == 0);
|
||||
|
||||
v = protobuf_c_enum_descriptor_get_value (desc, 3);
|
||||
assert (v == NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
test_enum_lookups (void)
|
||||
{
|
||||
test_enum_descriptor (&foo__test_enum__descriptor);
|
||||
test_enum_descriptor (&foo__test_enum_small__descriptor);
|
||||
test_enum_descriptor (&foo__test_enum_dup_values__descriptor);
|
||||
test_enum_descriptor (&foo__test_enum_lite__descriptor);
|
||||
test_lite_enum ();
|
||||
#define TEST_ENUM_DUP_VALUES(str, shortname) \
|
||||
test_enum_by_name (&foo__test_enum_dup_values__descriptor, \
|
||||
str, FOO__TEST_ENUM_DUP_VALUES__##shortname)
|
||||
@ -1618,8 +1639,9 @@ test_message_descriptor (const ProtobufCMessageDescriptor *desc)
|
||||
const ProtobufCFieldDescriptor *fv;
|
||||
const ProtobufCFieldDescriptor *fn;
|
||||
fv = protobuf_c_message_descriptor_get_field (desc, f->id);
|
||||
fn = protobuf_c_message_descriptor_get_field_by_name (desc, f->name);
|
||||
assert (f == fv);
|
||||
fn = protobuf_c_message_descriptor_get_field_by_name (desc, f->name);
|
||||
if (desc->fields_sorted_by_name != NULL)
|
||||
assert (f == fn);
|
||||
}
|
||||
}
|
||||
@ -1629,6 +1651,7 @@ test_message_lookups (void)
|
||||
test_message_descriptor (&foo__test_mess__descriptor);
|
||||
test_message_descriptor (&foo__test_mess_optional__descriptor);
|
||||
test_message_descriptor (&foo__test_mess_required_enum__descriptor);
|
||||
test_message_descriptor (&foo__test_mess_lite__descriptor);
|
||||
}
|
||||
|
||||
static void
|
||||
|
13
t/test-optimized.proto
Normal file
13
t/test-optimized.proto
Normal file
@ -0,0 +1,13 @@
|
||||
package foo;
|
||||
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
enum TestEnumLite {
|
||||
LITE = 0;
|
||||
LITE1 = 1;
|
||||
}
|
||||
|
||||
message TestMessLite {
|
||||
required int32 field1 = 1;
|
||||
required TestEnumLite field2 = 2;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user