Commit f5d5b4de authored by liujisi@google.com's avatar liujisi@google.com

Make custom option able to work for -f-no-rtti; Fix remaining death tests for gtest 1.6

parent e34f1f63
...@@ -382,6 +382,8 @@ TEST(GeneratedMessageTest, StringCharStarLength) { ...@@ -382,6 +382,8 @@ TEST(GeneratedMessageTest, StringCharStarLength) {
} }
#if !defined(PROTOBUF_TEST_NO_DESCRIPTORS) || \
!defined(GOOGLE_PROTOBUF_NO_RTTI)
TEST(GeneratedMessageTest, CopyFrom) { TEST(GeneratedMessageTest, CopyFrom) {
unittest::TestAllTypes message1, message2; unittest::TestAllTypes message1, message2;
...@@ -393,7 +395,7 @@ TEST(GeneratedMessageTest, CopyFrom) { ...@@ -393,7 +395,7 @@ TEST(GeneratedMessageTest, CopyFrom) {
message2.CopyFrom(message2); message2.CopyFrom(message2);
TestUtil::ExpectAllFieldsSet(message2); TestUtil::ExpectAllFieldsSet(message2);
} }
#endif
TEST(GeneratedMessageTest, SwapWithEmpty) { TEST(GeneratedMessageTest, SwapWithEmpty) {
unittest::TestAllTypes message1, message2; unittest::TestAllTypes message1, message2;
...@@ -493,6 +495,8 @@ TEST(GeneratedMessageTest, CopyAssignmentOperator) { ...@@ -493,6 +495,8 @@ TEST(GeneratedMessageTest, CopyAssignmentOperator) {
TestUtil::ExpectAllFieldsSet(message2); TestUtil::ExpectAllFieldsSet(message2);
} }
#if !defined(PROTOBUF_TEST_NO_DESCRIPTORS) || \
!defined(GOOGLE_PROTOBUF_NO_RTTI)
TEST(GeneratedMessageTest, UpcastCopyFrom) { TEST(GeneratedMessageTest, UpcastCopyFrom) {
// Test the CopyFrom method that takes in the generic const Message& // Test the CopyFrom method that takes in the generic const Message&
// parameter. // parameter.
...@@ -505,6 +509,7 @@ TEST(GeneratedMessageTest, UpcastCopyFrom) { ...@@ -505,6 +509,7 @@ TEST(GeneratedMessageTest, UpcastCopyFrom) {
TestUtil::ExpectAllFieldsSet(message2); TestUtil::ExpectAllFieldsSet(message2);
} }
#endif
#ifndef PROTOBUF_TEST_NO_DESCRIPTORS #ifndef PROTOBUF_TEST_NO_DESCRIPTORS
...@@ -530,6 +535,8 @@ TEST(GeneratedMessageTest, DynamicMessageCopyFrom) { ...@@ -530,6 +535,8 @@ TEST(GeneratedMessageTest, DynamicMessageCopyFrom) {
#endif // !PROTOBUF_TEST_NO_DESCRIPTORS #endif // !PROTOBUF_TEST_NO_DESCRIPTORS
#if !defined(PROTOBUF_TEST_NO_DESCRIPTORS) || \
!defined(GOOGLE_PROTOBUF_NO_RTTI)
TEST(GeneratedMessageTest, NonEmptyMergeFrom) { TEST(GeneratedMessageTest, NonEmptyMergeFrom) {
// Test merging with a non-empty message. Code is a modified form // Test merging with a non-empty message. Code is a modified form
// of that found in google/protobuf/reflection_ops_unittest.cc. // of that found in google/protobuf/reflection_ops_unittest.cc.
...@@ -566,6 +573,7 @@ TEST(GeneratedMessageTest, MergeFromSelf) { ...@@ -566,6 +573,7 @@ TEST(GeneratedMessageTest, MergeFromSelf) {
} }
#endif // PROTOBUF_HAS_DEATH_TEST #endif // PROTOBUF_HAS_DEATH_TEST
#endif // !PROTOBUF_TEST_NO_DESCRIPTORS || !GOOGLE_PROTOBUF_NO_RTTI
// Test the generated SerializeWithCachedSizesToArray(), // Test the generated SerializeWithCachedSizesToArray(),
TEST(GeneratedMessageTest, SerializationToArray) { TEST(GeneratedMessageTest, SerializationToArray) {
...@@ -1199,7 +1207,7 @@ TEST_F(GeneratedServiceTest, CallMethod) { ...@@ -1199,7 +1207,7 @@ TEST_F(GeneratedServiceTest, CallMethod) {
TEST_F(GeneratedServiceTest, CallMethodTypeFailure) { TEST_F(GeneratedServiceTest, CallMethodTypeFailure) {
// Verify death if we call Foo() with Bar's message types. // Verify death if we call Foo() with Bar's message types.
#ifdef GTEST_HAS_DEATH_TEST // death tests do not work on Windows yet #ifdef PROTOBUF_HAS_DEATH_TEST // death tests do not work on Windows yet
EXPECT_DEBUG_DEATH( EXPECT_DEBUG_DEATH(
mock_service_.CallMethod(foo_, &mock_controller_, mock_service_.CallMethod(foo_, &mock_controller_,
&foo_request_, &bar_response_, done_.get()), &foo_request_, &bar_response_, done_.get()),
...@@ -1210,7 +1218,7 @@ TEST_F(GeneratedServiceTest, CallMethodTypeFailure) { ...@@ -1210,7 +1218,7 @@ TEST_F(GeneratedServiceTest, CallMethodTypeFailure) {
mock_service_.CallMethod(foo_, &mock_controller_, mock_service_.CallMethod(foo_, &mock_controller_,
&bar_request_, &foo_response_, done_.get()), &bar_request_, &foo_response_, done_.get()),
"dynamic_cast"); "dynamic_cast");
#endif // GTEST_HAS_DEATH_TEST #endif // PROTOBUF_HAS_DEATH_TEST
} }
TEST_F(GeneratedServiceTest, GetPrototypes) { TEST_F(GeneratedServiceTest, GetPrototypes) {
......
...@@ -2987,7 +2987,11 @@ template<class DescriptorT> void DescriptorBuilder::AllocateOptionsImpl( ...@@ -2987,7 +2987,11 @@ template<class DescriptorT> void DescriptorBuilder::AllocateOptionsImpl(
// tables_->AllocateMessage<typename DescriptorT::OptionsType>(); // tables_->AllocateMessage<typename DescriptorT::OptionsType>();
typename DescriptorT::OptionsType* const dummy = NULL; typename DescriptorT::OptionsType* const dummy = NULL;
typename DescriptorT::OptionsType* options = tables_->AllocateMessage(dummy); typename DescriptorT::OptionsType* options = tables_->AllocateMessage(dummy);
options->CopyFrom(orig_options); // Avoid using MergeFrom()/CopyFrom() in this class to make it -fno-rtti
// friendly. Without RTTI, MergeFrom() and CopyFrom() will fallback to the
// reflection based method, which requires the Descriptor. However, we are in
// the middle of building the descriptors, thus the deadlock.
options->ParseFromString(orig_options.SerializeAsString());
descriptor->options_ = options; descriptor->options_ = options;
// Don't add to options_to_interpret_ unless there were uninterpreted // Don't add to options_to_interpret_ unless there were uninterpreted
......
...@@ -550,7 +550,7 @@ TEST(ExtensionSetTest, SpaceUsedExcludingSelf) { ...@@ -550,7 +550,7 @@ TEST(ExtensionSetTest, SpaceUsedExcludingSelf) {
} }
} }
#ifdef GTEST_HAS_DEATH_TEST #ifdef PROTOBUF_HAS_DEATH_TEST
TEST(ExtensionSetTest, InvalidEnumDeath) { TEST(ExtensionSetTest, InvalidEnumDeath) {
unittest::TestAllExtensions message; unittest::TestAllExtensions message;
...@@ -560,7 +560,7 @@ TEST(ExtensionSetTest, InvalidEnumDeath) { ...@@ -560,7 +560,7 @@ TEST(ExtensionSetTest, InvalidEnumDeath) {
"IsValid"); "IsValid");
} }
#endif // GTEST_HAS_DEATH_TEST #endif // PROTOBUF_HAS_DEATH_TEST
TEST(ExtensionSetTest, DynamicExtensions) { TEST(ExtensionSetTest, DynamicExtensions) {
// Test adding a dynamic extension to a compiled-in message object. // Test adding a dynamic extension to a compiled-in message object.
...@@ -695,7 +695,11 @@ TEST(ExtensionSetTest, DynamicExtensions) { ...@@ -695,7 +695,11 @@ TEST(ExtensionSetTest, DynamicExtensions) {
const Message& sub_message = const Message& sub_message =
message.GetReflection()->GetMessage(message, message_extension); message.GetReflection()->GetMessage(message, message_extension);
const unittest::ForeignMessage* typed_sub_message = const unittest::ForeignMessage* typed_sub_message =
#ifdef GOOGLE_PROTOBUF_NO_RTTI
static_cast<const unittest::ForeignMessage*>(&sub_message);
#else
dynamic_cast<const unittest::ForeignMessage*>(&sub_message); dynamic_cast<const unittest::ForeignMessage*>(&sub_message);
#endif
ASSERT_TRUE(typed_sub_message != NULL); ASSERT_TRUE(typed_sub_message != NULL);
EXPECT_EQ(456, typed_sub_message->c()); EXPECT_EQ(456, typed_sub_message->c());
} }
......
...@@ -220,7 +220,7 @@ TEST(Printer, Indenting) { ...@@ -220,7 +220,7 @@ TEST(Printer, Indenting) {
} }
// Death tests do not work on Windows as of yet. // Death tests do not work on Windows as of yet.
#ifdef GTEST_HAS_DEATH_TEST #ifdef PROTOBUF_HAS_DEATH_TEST
TEST(Printer, Death) { TEST(Printer, Death) {
char buffer[8192]; char buffer[8192];
...@@ -231,7 +231,7 @@ TEST(Printer, Death) { ...@@ -231,7 +231,7 @@ TEST(Printer, Death) {
EXPECT_DEBUG_DEATH(printer.Print("$unclosed"), "Unclosed variable name"); EXPECT_DEBUG_DEATH(printer.Print("$unclosed"), "Unclosed variable name");
EXPECT_DEBUG_DEATH(printer.Outdent(), "without matching Indent"); EXPECT_DEBUG_DEATH(printer.Outdent(), "without matching Indent");
} }
#endif // GTEST_HAS_DEATH_TEST #endif // PROTOBUF__HAS_DEATH_TEST
TEST(Printer, WriteFailurePartial) { TEST(Printer, WriteFailurePartial) {
char buffer[17]; char buffer[17];
......
...@@ -741,7 +741,7 @@ TEST_F(TokenizerTest, ParseInteger) { ...@@ -741,7 +741,7 @@ TEST_F(TokenizerTest, ParseInteger) {
EXPECT_EQ(0, ParseInteger("0x")); EXPECT_EQ(0, ParseInteger("0x"));
uint64 i; uint64 i;
#ifdef GTEST_HAS_DEATH_TEST // death tests do not work on Windows yet #ifdef PROTOBUF_HASDEATH_TEST // death tests do not work on Windows yet
// Test invalid integers that will never be tokenized as integers. // Test invalid integers that will never be tokenized as integers.
EXPECT_DEBUG_DEATH(Tokenizer::ParseInteger("zxy", kuint64max, &i), EXPECT_DEBUG_DEATH(Tokenizer::ParseInteger("zxy", kuint64max, &i),
"passed text that could not have been tokenized as an integer"); "passed text that could not have been tokenized as an integer");
...@@ -753,7 +753,7 @@ TEST_F(TokenizerTest, ParseInteger) { ...@@ -753,7 +753,7 @@ TEST_F(TokenizerTest, ParseInteger) {
"passed text that could not have been tokenized as an integer"); "passed text that could not have been tokenized as an integer");
EXPECT_DEBUG_DEATH(Tokenizer::ParseInteger("-1", kuint64max, &i), EXPECT_DEBUG_DEATH(Tokenizer::ParseInteger("-1", kuint64max, &i),
"passed text that could not have been tokenized as an integer"); "passed text that could not have been tokenized as an integer");
#endif // GTEST_HAS_DEATH_TEST #endif // PROTOBUF_HASDEATH_TEST
// Test overflows. // Test overflows.
EXPECT_TRUE (Tokenizer::ParseInteger("0", 0, &i)); EXPECT_TRUE (Tokenizer::ParseInteger("0", 0, &i));
...@@ -796,7 +796,7 @@ TEST_F(TokenizerTest, ParseFloat) { ...@@ -796,7 +796,7 @@ TEST_F(TokenizerTest, ParseFloat) {
EXPECT_EQ( 0.0, Tokenizer::ParseFloat("1e-9999999999999999999999999999")); EXPECT_EQ( 0.0, Tokenizer::ParseFloat("1e-9999999999999999999999999999"));
EXPECT_EQ(HUGE_VAL, Tokenizer::ParseFloat("1e+9999999999999999999999999999")); EXPECT_EQ(HUGE_VAL, Tokenizer::ParseFloat("1e+9999999999999999999999999999"));
#ifdef GTEST_HAS_DEATH_TEST // death tests do not work on Windows yet #ifdef PROTOBUF_HASDEATH_TEST // death tests do not work on Windows yet
// Test invalid integers that will never be tokenized as integers. // Test invalid integers that will never be tokenized as integers.
EXPECT_DEBUG_DEATH(Tokenizer::ParseFloat("zxy"), EXPECT_DEBUG_DEATH(Tokenizer::ParseFloat("zxy"),
"passed text that could not have been tokenized as a float"); "passed text that could not have been tokenized as a float");
...@@ -804,7 +804,7 @@ TEST_F(TokenizerTest, ParseFloat) { ...@@ -804,7 +804,7 @@ TEST_F(TokenizerTest, ParseFloat) {
"passed text that could not have been tokenized as a float"); "passed text that could not have been tokenized as a float");
EXPECT_DEBUG_DEATH(Tokenizer::ParseFloat("-1.0"), EXPECT_DEBUG_DEATH(Tokenizer::ParseFloat("-1.0"),
"passed text that could not have been tokenized as a float"); "passed text that could not have been tokenized as a float");
#endif // GTEST_HAS_DEATH_TEST #endif // PROTOBUF_HASDEATH_TEST
} }
TEST_F(TokenizerTest, ParseString) { TEST_F(TokenizerTest, ParseString) {
...@@ -843,10 +843,10 @@ TEST_F(TokenizerTest, ParseString) { ...@@ -843,10 +843,10 @@ TEST_F(TokenizerTest, ParseString) {
EXPECT_EQ("u0", output); EXPECT_EQ("u0", output);
// Test invalid strings that will never be tokenized as strings. // Test invalid strings that will never be tokenized as strings.
#ifdef GTEST_HAS_DEATH_TEST // death tests do not work on Windows yet #ifdef PROTOBUF_HASDEATH_TEST // death tests do not work on Windows yet
EXPECT_DEBUG_DEATH(Tokenizer::ParseString("", &output), EXPECT_DEBUG_DEATH(Tokenizer::ParseString("", &output),
"passed text that could not have been tokenized as a string"); "passed text that could not have been tokenized as a string");
#endif // GTEST_HAS_DEATH_TEST #endif // PROTOBUF_HASDEATH_TEST
} }
TEST_F(TokenizerTest, ParseStringAppend) { TEST_F(TokenizerTest, ParseStringAppend) {
......
...@@ -331,7 +331,7 @@ TEST(RepeatedField, Truncate) { ...@@ -331,7 +331,7 @@ TEST(RepeatedField, Truncate) {
// Truncations that don't change the size are allowed, but growing is not // Truncations that don't change the size are allowed, but growing is not
// allowed. // allowed.
field.Truncate(field.size()); field.Truncate(field.size());
#ifdef GTEST_HAS_DEATH_TEST #ifdef PROTOBUF_HAS_DEATH_TEST
EXPECT_DEBUG_DEATH(field.Truncate(field.size() + 1), "new_size"); EXPECT_DEBUG_DEATH(field.Truncate(field.size() + 1), "new_size");
#endif #endif
} }
......
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