diff --git a/Makefile.am b/Makefile.am index 310aa09..605ba83 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 # diff --git a/t/generated-code2/test-generated-code2.c b/t/generated-code2/test-generated-code2.c index aa2ad56..2809b70 100644 --- a/t/generated-code2/test-generated-code2.c +++ b/t/generated-code2/test-generated-code2.c @@ -2,6 +2,7 @@ #include #include #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,9 +1566,10 @@ 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); - assert (sv == vn); + 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,9 +1639,10 @@ 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); - assert (f == fn); + fn = protobuf_c_message_descriptor_get_field_by_name (desc, f->name); + if (desc->fields_sorted_by_name != NULL) + assert (f == fn); } } static void @@ -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 diff --git a/t/test-optimized.proto b/t/test-optimized.proto new file mode 100644 index 0000000..d9fde89 --- /dev/null +++ b/t/test-optimized.proto @@ -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; +}