From c5ff06cc74e03e6846218b750b99c77d72a39a75 Mon Sep 17 00:00:00 2001 From: "kenton@google.com" Date: Tue, 28 Apr 2009 03:06:41 +0000 Subject: Add second run of cpp_unittest which verifies that descriptors are constructed lazily. This is accomplished by avoiding any use of descriptors while testing a bunch of other operations, then checking at the end that descriptors have not been constructed. --- src/Makefile.am | 34 ++++++++++++++++++++++++---------- src/google/protobuf/test_util.cc | 16 ++++++++++++++++ 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 9206d094..902e6af8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -220,7 +220,15 @@ unittest_proto_middleman: protoc$(EXEEXT) $(protoc_inputs) $(protoc_outputs): unittest_proto_middleman -check_PROGRAMS = protobuf-test $(GZCHECKPROGRAMS) +COMMON_TEST_SOURCES = \ + google/protobuf/test_util.cc \ + google/protobuf/test_util.h \ + google/protobuf/testing/googletest.cc \ + google/protobuf/testing/googletest.h \ + google/protobuf/testing/file.cc \ + google/protobuf/testing/file.h + +check_PROGRAMS = protobuf-test protobuf-lazy-descriptor-test $(GZCHECKPROGRAMS) protobuf_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la libprotoc.la \ $(top_builddir)/gtest/lib/libgtest.la \ $(top_builddir)/gtest/lib/libgtest_main.la @@ -251,12 +259,20 @@ protobuf_test_SOURCES = \ google/protobuf/compiler/parser_unittest.cc \ google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc \ google/protobuf/compiler/cpp/cpp_unittest.cc \ - google/protobuf/test_util.cc \ - google/protobuf/test_util.h \ - google/protobuf/testing/googletest.cc \ - google/protobuf/testing/googletest.h \ - google/protobuf/testing/file.cc \ - google/protobuf/testing/file.h + $(COMMON_TEST_SOURCES) +nodist_protobuf_test_SOURCES = $(protoc_outputs) + +# Run cpp_unittest again with PROTOBUF_TEST_NO_DESCRIPTORS defined. +protobuf_lazy_descriptor_test_LDADD = $(PTHREAD_LIBS) libprotobuf.la \ + $(top_builddir)/gtest/lib/libgtest.la \ + $(top_builddir)/gtest/lib/libgtest_main.la +protobuf_lazy_descriptor_test_CPPFLAGS = -I$(top_srcdir)/gtest/include \ + -I$(top_builddir)/gtest/include \ + -DPROTOBUF_TEST_NO_DESCRIPTORS +protobuf_lazy_descriptor_test_SOURCES = \ + google/protobuf/compiler/cpp/cpp_unittest.cc \ + $(COMMON_TEST_SOURCES) +nodist_protobuf_lazy_descriptor_test_SOURCES = $(protoc_outputs) if HAVE_ZLIB zcgzip_LDADD = $(PTHREAD_LIBS) libprotobuf.la @@ -266,6 +282,4 @@ zcgunzip_LDADD = $(PTHREAD_LIBS) libprotobuf.la zcgunzip_SOURCES = google/protobuf/testing/zcgunzip.cc endif -nodist_protobuf_test_SOURCES = $(protoc_outputs) - -TESTS = protobuf-test $(GZTESTS) +TESTS = protobuf-test protobuf-lazy-descriptor-test $(GZTESTS) diff --git a/src/google/protobuf/test_util.cc b/src/google/protobuf/test_util.cc index 8b15ce5e..7cf5cc2f 100644 --- a/src/google/protobuf/test_util.cc +++ b/src/google/protobuf/test_util.cc @@ -77,6 +77,7 @@ void TestUtil::SetAllFields(unittest::TestAllTypes* message) { // StringPiece and Cord fields are only accessible via reflection in the // open source release; see comments in compiler/cpp/string_field.cc. +#ifndef PROTOBUF_TEST_NO_DESCRIPTORS message->GetReflection()->SetString( message, message->GetDescriptor()->FindFieldByName("optional_string_piece"), @@ -85,6 +86,7 @@ void TestUtil::SetAllFields(unittest::TestAllTypes* message) { message, message->GetDescriptor()->FindFieldByName("optional_cord"), "125"); +#endif // ----------------------------------------------------------------- @@ -113,6 +115,7 @@ void TestUtil::SetAllFields(unittest::TestAllTypes* message) { message->add_repeated_foreign_enum(unittest::FOREIGN_BAR ); message->add_repeated_import_enum (unittest_import::IMPORT_BAR); +#ifndef PROTOBUF_TEST_NO_DESCRIPTORS message->GetReflection()->AddString( message, message->GetDescriptor()->FindFieldByName("repeated_string_piece"), @@ -121,6 +124,7 @@ void TestUtil::SetAllFields(unittest::TestAllTypes* message) { message, message->GetDescriptor()->FindFieldByName("repeated_cord"), "225"); +#endif // Add a second one of each field. message->add_repeated_int32 (301); @@ -148,6 +152,7 @@ void TestUtil::SetAllFields(unittest::TestAllTypes* message) { message->add_repeated_foreign_enum(unittest::FOREIGN_BAZ ); message->add_repeated_import_enum (unittest_import::IMPORT_BAZ); +#ifndef PROTOBUF_TEST_NO_DESCRIPTORS message->GetReflection()->AddString( message, message->GetDescriptor()->FindFieldByName("repeated_string_piece"), @@ -156,6 +161,7 @@ void TestUtil::SetAllFields(unittest::TestAllTypes* message) { message, message->GetDescriptor()->FindFieldByName("repeated_cord"), "325"); +#endif // ----------------------------------------------------------------- @@ -179,6 +185,7 @@ void TestUtil::SetAllFields(unittest::TestAllTypes* message) { message->set_default_foreign_enum(unittest::FOREIGN_FOO ); message->set_default_import_enum (unittest_import::IMPORT_FOO); +#ifndef PROTOBUF_TEST_NO_DESCRIPTORS message->GetReflection()->SetString( message, message->GetDescriptor()->FindFieldByName("default_string_piece"), @@ -187,6 +194,7 @@ void TestUtil::SetAllFields(unittest::TestAllTypes* message) { message, message->GetDescriptor()->FindFieldByName("default_cord"), "425"); +#endif } // ------------------------------------------------------------------- @@ -217,6 +225,7 @@ void TestUtil::ModifyRepeatedFields(unittest::TestAllTypes* message) { message->set_repeated_foreign_enum(1, unittest::FOREIGN_FOO ); message->set_repeated_import_enum (1, unittest_import::IMPORT_FOO); +#ifndef PROTOBUF_TEST_NO_DESCRIPTORS message->GetReflection()->SetRepeatedString( message, message->GetDescriptor()->FindFieldByName("repeated_string_piece"), @@ -225,6 +234,7 @@ void TestUtil::ModifyRepeatedFields(unittest::TestAllTypes* message) { message, message->GetDescriptor()->FindFieldByName("repeated_cord"), 1, "425"); +#endif } // ------------------------------------------------------------------- @@ -260,8 +270,10 @@ void TestUtil::ExpectAllFieldsSet(const unittest::TestAllTypes& message) { EXPECT_TRUE(message.has_optional_foreign_enum()); EXPECT_TRUE(message.has_optional_import_enum ()); +#ifndef PROTOBUF_TEST_NO_DESCRIPTORS EXPECT_TRUE(message.has_optional_string_piece()); EXPECT_TRUE(message.has_optional_cord()); +#endif EXPECT_EQ(101 , message.optional_int32 ()); EXPECT_EQ(102 , message.optional_int64 ()); @@ -315,8 +327,10 @@ void TestUtil::ExpectAllFieldsSet(const unittest::TestAllTypes& message) { ASSERT_EQ(2, message.repeated_foreign_enum_size ()); ASSERT_EQ(2, message.repeated_import_enum_size ()); +#ifndef PROTOBUF_TEST_NO_DESCRIPTORS ASSERT_EQ(2, message.repeated_string_piece_size()); ASSERT_EQ(2, message.repeated_cord_size()); +#endif EXPECT_EQ(201 , message.repeated_int32 (0)); EXPECT_EQ(202 , message.repeated_int64 (0)); @@ -585,8 +599,10 @@ void TestUtil::ExpectRepeatedFieldsModified( ASSERT_EQ(2, message.repeated_foreign_enum_size ()); ASSERT_EQ(2, message.repeated_import_enum_size ()); +#ifndef PROTOBUF_TEST_NO_DESCRIPTORS ASSERT_EQ(2, message.repeated_string_piece_size()); ASSERT_EQ(2, message.repeated_cord_size()); +#endif EXPECT_EQ(201 , message.repeated_int32 (0)); EXPECT_EQ(202 , message.repeated_int64 (0)); -- cgit v1.2.3