Commit c5ff06cc authored by kenton@google.com's avatar kenton@google.com

Add second run of cpp_unittest which verifies that descriptors are constructed…

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.
parent 503a4dd7
......@@ -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)
......@@ -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));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment