Use "#if GTEST_HAS_DEATH_TEST" instead of "#ifdef GTEST_HAS_DEATH_TEST"

This is consistent with the example in gtest-port.h.

PiperOrigin-RevId: 500846191
pull/11444/head
Tom Hughes 2 years ago committed by Copybara-Service
parent 969ec469f6
commit 7cf6479295
  1. 2
      src/google/protobuf/any_test.cc
  2. 12
      src/google/protobuf/arena_align_test.cc
  3. 2
      src/google/protobuf/compiler/cpp/unittest.inc
  4. 2
      src/google/protobuf/extension_set_unittest.cc
  5. 2
      src/google/protobuf/generated_message_reflection_unittest.cc
  6. 2
      src/google/protobuf/io/printer_death_test.cc
  7. 4
      src/google/protobuf/io/tokenizer_unittest.cc
  8. 4
      src/google/protobuf/map_test.inc
  9. 2
      src/google/protobuf/message_unittest.inc
  10. 2
      src/google/protobuf/reflection_ops_unittest.cc
  11. 4
      src/google/protobuf/repeated_field_reflection_unittest.cc
  12. 4
      src/google/protobuf/repeated_field_unittest.cc
  13. 2
      src/google/protobuf/util/time_util_test.cc

@ -178,7 +178,7 @@ TEST(AnyTest, MoveAssignment) {
EXPECT_EQ(12345, payload.int32_value()); EXPECT_EQ(12345, payload.int32_value());
} }
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
#ifndef NDEBUG #ifndef NDEBUG
TEST(AnyTest, PackSelfDeath) { TEST(AnyTest, PackSelfDeath) {
google::protobuf::Any any; google::protobuf::Any any;

@ -72,7 +72,7 @@ TEST(ArenaAlignDefault, Padded) {
EXPECT_THAT(align_default.Padded(0), Eq(0)); EXPECT_THAT(align_default.Padded(0), Eq(0));
EXPECT_THAT(align_default.Padded(8), Eq(8)); EXPECT_THAT(align_default.Padded(8), Eq(8));
EXPECT_THAT(align_default.Padded(64), Eq(64)); EXPECT_THAT(align_default.Padded(64), Eq(64));
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
EXPECT_DEBUG_DEATH(align_default.Padded(1), ".*"); EXPECT_DEBUG_DEATH(align_default.Padded(1), ".*");
#endif // PROTOBUF_HAS_DEATH_TEST #endif // PROTOBUF_HAS_DEATH_TEST
} }
@ -95,7 +95,7 @@ TEST(ArenaAlignDefault, CheckAligned) {
EXPECT_THAT(align_default.CheckAligned(p + 0), Eq(p + 0)); EXPECT_THAT(align_default.CheckAligned(p + 0), Eq(p + 0));
EXPECT_THAT(align_default.CheckAligned(p + 8), Eq(p + 8)); EXPECT_THAT(align_default.CheckAligned(p + 8), Eq(p + 8));
EXPECT_THAT(align_default.CheckAligned(p + 16), Eq(p + 16)); EXPECT_THAT(align_default.CheckAligned(p + 16), Eq(p + 16));
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
EXPECT_DEBUG_DEATH(align_default.CheckAligned(p + 1), ".*"); EXPECT_DEBUG_DEATH(align_default.CheckAligned(p + 1), ".*");
EXPECT_DEBUG_DEATH(align_default.CheckAligned(p + 7), ".*"); EXPECT_DEBUG_DEATH(align_default.CheckAligned(p + 7), ".*");
EXPECT_DEBUG_DEATH(align_default.CheckAligned(p + 9), ".*"); EXPECT_DEBUG_DEATH(align_default.CheckAligned(p + 9), ".*");
@ -110,7 +110,7 @@ TEST(ArenaAlignDefault, CeilDefaultAligned) {
EXPECT_THAT(align_default.CeilDefaultAligned(p + 0), Eq(p + 0)); EXPECT_THAT(align_default.CeilDefaultAligned(p + 0), Eq(p + 0));
EXPECT_THAT(align_default.CeilDefaultAligned(p + 8), Eq(p + 8)); EXPECT_THAT(align_default.CeilDefaultAligned(p + 8), Eq(p + 8));
EXPECT_THAT(align_default.CeilDefaultAligned(p + 16), Eq(p + 16)); EXPECT_THAT(align_default.CeilDefaultAligned(p + 16), Eq(p + 16));
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
EXPECT_DEBUG_DEATH(align_default.CeilDefaultAligned(p + 1), ".*"); EXPECT_DEBUG_DEATH(align_default.CeilDefaultAligned(p + 1), ".*");
EXPECT_DEBUG_DEATH(align_default.CeilDefaultAligned(p + 7), ".*"); EXPECT_DEBUG_DEATH(align_default.CeilDefaultAligned(p + 7), ".*");
EXPECT_DEBUG_DEATH(align_default.CeilDefaultAligned(p + 9), ".*"); EXPECT_DEBUG_DEATH(align_default.CeilDefaultAligned(p + 9), ".*");
@ -161,7 +161,7 @@ TEST(ArenaAlign, Padded) {
auto align_64 = ArenaAlignAs(64); auto align_64 = ArenaAlignAs(64);
EXPECT_THAT(align_64.Padded(64), Eq(64 + 64 - ArenaAlignDefault::align)); EXPECT_THAT(align_64.Padded(64), Eq(64 + 64 - ArenaAlignDefault::align));
EXPECT_THAT(align_64.Padded(128), Eq(128 + 64 - ArenaAlignDefault::align)); EXPECT_THAT(align_64.Padded(128), Eq(128 + 64 - ArenaAlignDefault::align));
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
// TODO(mvels): there are direct callers of AllocateAligned() that violate // TODO(mvels): there are direct callers of AllocateAligned() that violate
// `size` being a multiple of `align`: that should be an error / assert. // `size` being a multiple of `align`: that should be an error / assert.
// EXPECT_DEBUG_DEATH(align_64.Padded(16), ".*"); // EXPECT_DEBUG_DEATH(align_64.Padded(16), ".*");
@ -187,7 +187,7 @@ TEST(ArenaAlign, CheckAligned) {
EXPECT_THAT(align_64.CheckAligned(p + 0), Eq(p)); EXPECT_THAT(align_64.CheckAligned(p + 0), Eq(p));
EXPECT_THAT(align_64.CheckAligned(p + 64), Eq(p + 64)); EXPECT_THAT(align_64.CheckAligned(p + 64), Eq(p + 64));
EXPECT_THAT(align_64.CheckAligned(p + 128), Eq(p + 128)); EXPECT_THAT(align_64.CheckAligned(p + 128), Eq(p + 128));
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 1), ".*"); EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 1), ".*");
EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 7), ".*"); EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 7), ".*");
EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 8), ".*"); EXPECT_DEBUG_DEATH(align_64.CheckAligned(p + 8), ".*");
@ -210,7 +210,7 @@ TEST(ArenaAlign, CeilDefaultAligned) {
EXPECT_THAT(align_64.CeilDefaultAligned(p + 72), Eq(p + 128)); EXPECT_THAT(align_64.CeilDefaultAligned(p + 72), Eq(p + 128));
EXPECT_THAT(align_64.CeilDefaultAligned(p + 120), Eq(p + 128)); EXPECT_THAT(align_64.CeilDefaultAligned(p + 120), Eq(p + 128));
EXPECT_THAT(align_64.CeilDefaultAligned(p + 128), Eq(p + 128)); EXPECT_THAT(align_64.CeilDefaultAligned(p + 128), Eq(p + 128));
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
EXPECT_DEBUG_DEATH(align_64.CeilDefaultAligned(p + 1), ".*"); EXPECT_DEBUG_DEATH(align_64.CeilDefaultAligned(p + 1), ".*");
EXPECT_DEBUG_DEATH(align_64.CeilDefaultAligned(p + 7), ".*"); EXPECT_DEBUG_DEATH(align_64.CeilDefaultAligned(p + 7), ".*");
EXPECT_DEBUG_DEATH(align_64.CeilDefaultAligned(p + 63), ".*"); EXPECT_DEBUG_DEATH(align_64.CeilDefaultAligned(p + 63), ".*");

@ -1331,7 +1331,7 @@ TEST_F(GENERATED_SERVICE_TEST_NAME, CallMethod) {
TEST_F(GENERATED_SERVICE_TEST_NAME, CallMethodTypeFailure) { TEST_F(GENERATED_SERVICE_TEST_NAME, CallMethodTypeFailure) {
// Verify death if we call Foo() with Bar's message types. // Verify death if we call Foo() with Bar's message types.
#ifdef PROTOBUF_HAS_DEATH_TEST // death tests do not work on Windows yet #if 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()),

@ -1186,7 +1186,7 @@ TEST(ExtensionSetTest, AbsentExtension) {
.bb()); .bb());
} }
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
TEST(ExtensionSetTest, InvalidEnumDeath) { TEST(ExtensionSetTest, InvalidEnumDeath) {
unittest::TestAllExtensions message; unittest::TestAllExtensions message;

@ -1273,7 +1273,7 @@ TEST(GeneratedMessageReflectionTest, ArenaReleaseOneofMessageTest) {
EXPECT_TRUE(released == nullptr); EXPECT_TRUE(released == nullptr);
} }
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
TEST(GeneratedMessageReflectionTest, UsageErrors) { TEST(GeneratedMessageReflectionTest, UsageErrors) {
unittest::TestAllTypes message; unittest::TestAllTypes message;

@ -95,7 +95,7 @@ class FakeAnnotationCollector : public AnnotationCollector {
} }
}; };
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
TEST_F(PrinterTest, Death) { TEST_F(PrinterTest, Death) {
Printer printer(output(), '$'); Printer printer(output(), '$');

@ -1020,7 +1020,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 PROTOBUF_HAS_DEATH_TEST // death tests do not work on Windows yet #if PROTOBUF_HAS_DEATH_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( EXPECT_DEBUG_DEATH(
Tokenizer::ParseFloat("zxy"), Tokenizer::ParseFloat("zxy"),
@ -1075,7 +1075,7 @@ TEST_F(TokenizerTest, ParseString) {
EXPECT_EQ("\\U00110000\\U00200000\\Uffffffff", output); EXPECT_EQ("\\U00110000\\U00200000\\Uffffffff", output);
// Test invalid strings that will never be tokenized as strings. // Test invalid strings that will never be tokenized as strings.
#ifdef PROTOBUF_HAS_DEATH_TEST // death tests do not work on Windows yet #if PROTOBUF_HAS_DEATH_TEST // death tests do not work on Windows yet
EXPECT_DEBUG_DEATH( EXPECT_DEBUG_DEATH(
Tokenizer::ParseString("", &output), 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");

@ -327,7 +327,7 @@ TEST_F(MapImplTest, MutableAt) {
ExpectSingleElement(key, value2); ExpectSingleElement(key, value2);
} }
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
TEST_F(MapImplTest, MutableAtNonExistDeathTest) { TEST_F(MapImplTest, MutableAtNonExistDeathTest) {
EXPECT_DEATH(map_.at(0), ""); EXPECT_DEATH(map_.at(0), "");
@ -1380,7 +1380,7 @@ void TestTransparent(const Key& key, const Key& miss_key) {
EXPECT_EQ(m.at(key), 1); EXPECT_EQ(m.at(key), 1);
EXPECT_EQ(cm.at(key), 1); EXPECT_EQ(cm.at(key), 1);
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
EXPECT_DEATH(m.at(miss_key), ""); EXPECT_DEATH(m.at(miss_key), "");
EXPECT_DEATH(cm.at(miss_key), ""); EXPECT_DEATH(cm.at(miss_key), "");
#endif // PROTOBUF_HAS_DEATH_TEST #endif // PROTOBUF_HAS_DEATH_TEST

@ -689,7 +689,7 @@ TEST(MESSAGE_TEST_NAME, DynamicCastToGenerated) {
test_all_types_pointer_nullptr)); test_all_types_pointer_nullptr));
} }
#ifdef PROTOBUF_HAS_DEATH_TEST // death tests do not work on Windows yet. #if PROTOBUF_HAS_DEATH_TEST // death tests do not work on Windows yet.
TEST(MESSAGE_TEST_NAME, SerializeFailsIfNotInitialized) { TEST(MESSAGE_TEST_NAME, SerializeFailsIfNotInitialized) {
UNITTEST::TestRequired message; UNITTEST::TestRequired message;

@ -184,7 +184,7 @@ TEST(ReflectionOpsTest, MergeOneof) {
TestUtil::ExpectOneofSet2(message2); TestUtil::ExpectOneofSet2(message2);
} }
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
TEST(ReflectionOpsTest, MergeFromSelf) { TEST(ReflectionOpsTest, MergeFromSelf) {
// Note: Copy is implemented in terms of Merge() so technically the Copy // Note: Copy is implemented in terms of Merge() so technically the Copy

@ -139,7 +139,7 @@ TEST(RepeatedFieldReflectionTest, RegularFields) {
EXPECT_EQ(message.repeated_foreign_message(i).c(), Func(i, 7)); EXPECT_EQ(message.repeated_foreign_message(i).c(), Func(i, 7));
} }
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
// Make sure types are checked correctly at runtime. // Make sure types are checked correctly at runtime.
const FieldDescriptor* fd_optional_int32 = const FieldDescriptor* fd_optional_int32 =
desc->FindFieldByName("optional_int32"); desc->FindFieldByName("optional_int32");
@ -421,7 +421,7 @@ TEST(RepeatedFieldReflectionTest, RepeatedFieldRefForRegularFields) {
EXPECT_TRUE(rf_message.empty()); EXPECT_TRUE(rf_message.empty());
EXPECT_TRUE(mrf_message.empty()); EXPECT_TRUE(mrf_message.empty());
#ifdef PROTOBUF_HAS_DEATH_TEST #if PROTOBUF_HAS_DEATH_TEST
// Make sure types are checked correctly at runtime. // Make sure types are checked correctly at runtime.
const FieldDescriptor* fd_optional_int32 = const FieldDescriptor* fd_optional_int32 =

@ -951,7 +951,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 PROTOBUF_HAS_DEATH_TEST #if 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
} }
@ -1010,7 +1010,7 @@ TEST(RepeatedField, TruncateCords) {
// Truncating to the current size should be fine (no-op), but truncating // Truncating to the current size should be fine (no-op), but truncating
// to a larger size should crash. // to a larger size should crash.
field.Truncate(field.size()); field.Truncate(field.size());
#ifdef PROTOBUF_HAS_DEATH_TEST #if 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
} }

@ -428,7 +428,7 @@ TEST(TimeUtilTest, IsTimestampValid) {
EXPECT_FALSE(TimeUtil::IsTimestampValid(underflow_nanos)); EXPECT_FALSE(TimeUtil::IsTimestampValid(underflow_nanos));
} }
#ifdef PROTOBUF_HAS_DEATH_TEST // death tests do not work on Windows yet. #if PROTOBUF_HAS_DEATH_TEST // death tests do not work on Windows yet.
#ifndef NDEBUG #ifndef NDEBUG
TEST(TimeUtilTest, DurationBounds) { TEST(TimeUtilTest, DurationBounds) {

Loading…
Cancel
Save