41 #if GTEST_HAS_DEATH_TEST
49 # include <sys/wait.h>
50 # endif // GTEST_OS_WINDOWS
57 # include <sys/time.h>
58 # endif // GTEST_OS_LINUX
63 namespace posix = ::testing::internal::posix;
65 using testing::ContainsRegex;
68 using testing::internal::DeathTest;
69 using testing::internal::DeathTestFactory;
70 using testing::internal::FilePath;
71 using testing::internal::GetLastErrnoDescription;
72 using testing::internal::GetUnitTestImpl;
73 using testing::internal::InDeathTestChild;
74 using testing::internal::ParseNaturalNumber;
81 class ReplaceDeathTestFactory {
83 explicit ReplaceDeathTestFactory(DeathTestFactory* new_factory)
84 : unit_test_impl_(GetUnitTestImpl()) {
85 old_factory_ = unit_test_impl_->death_test_factory_.release();
86 unit_test_impl_->death_test_factory_.reset(new_factory);
89 ~ReplaceDeathTestFactory() {
90 unit_test_impl_->death_test_factory_.release();
91 unit_test_impl_->death_test_factory_.reset(old_factory_);
95 ReplaceDeathTestFactory(
const ReplaceDeathTestFactory&);
96 void operator=(
const ReplaceDeathTestFactory&);
98 UnitTestImpl* unit_test_impl_;
99 DeathTestFactory* old_factory_;
107 void DieWithMessage(const ::std::string& message) {
108 fprintf(stderr,
"%s", message.c_str());
123 void DieInside(const ::std::string&
function) {
124 DieWithMessage(
"death inside " +
function +
"().");
131 TestForDeathTest() : original_dir_(FilePath::GetCurrentDir()) {}
133 ~TestForDeathTest()
override {
posix::ChDir(original_dir_.c_str()); }
136 static void StaticMemberFunction() { DieInside(
"StaticMemberFunction"); }
139 void MemberFunction() {
141 DieInside(
"MemberFunction");
146 const FilePath original_dir_;
152 explicit MayDie(
bool should_die) : should_die_(should_die) {}
155 void MemberFunction()
const {
157 DieInside(
"MayDie::MemberFunction");
166 void GlobalFunction() { DieInside(
"GlobalFunction"); }
169 int NonVoidFunction() {
170 DieInside(
"NonVoidFunction");
175 void DieIf(
bool should_die) {
181 bool DieIfLessThan(
int x,
int y) {
183 DieInside(
"DieIfLessThan");
189 void DeathTestSubroutine() {
190 EXPECT_DEATH(GlobalFunction(),
"death.*GlobalFunction");
191 ASSERT_DEATH(GlobalFunction(),
"death.*GlobalFunction");
195 int DieInDebugElse12(
int* sideeffect) {
196 if (sideeffect) *sideeffect = 12;
200 DieInside(
"DieInDebugElse12");
207 # if GTEST_OS_WINDOWS
210 int DieInCRTDebugElse12(
int* sideeffect) {
211 if (sideeffect) *sideeffect = 12;
215 EXPECT_EQ(_pipe(fdpipe, 256, O_BINARY), 0);
225 #endif // GTEST_OS_WINDOWS
227 # if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
230 TEST(ExitStatusPredicateTest, ExitedWithCode) {
245 static int NormalExitStatus(
int exit_code) {
246 pid_t child_pid = fork();
247 if (child_pid == 0) {
251 waitpid(child_pid, &status, 0);
260 static int KilledExitStatus(
int signum) {
261 pid_t child_pid = fork();
262 if (child_pid == 0) {
267 waitpid(child_pid, &status, 0);
272 TEST(ExitStatusPredicateTest, ExitedWithCode) {
273 const int status0 = NormalExitStatus(0);
274 const int status1 = NormalExitStatus(1);
275 const int status42 = NormalExitStatus(42);
276 const testing::ExitedWithCode pred0(0);
277 const testing::ExitedWithCode pred1(1);
278 const testing::ExitedWithCode pred42(42);
288 TEST(ExitStatusPredicateTest, KilledBySignal) {
289 const int status_segv = KilledExitStatus(SIGSEGV);
290 const int status_kill = KilledExitStatus(SIGKILL);
291 const testing::KilledBySignal pred_segv(SIGSEGV);
292 const testing::KilledBySignal pred_kill(SIGKILL);
299 # endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
304 TEST_F(TestForDeathTest, SingleStatement) {
307 ASSERT_DEATH(
return,
"");
310 EXPECT_DEATH(_exit(1),
"");
317 ASSERT_DEATH(
return,
"") <<
"did not die";
322 EXPECT_DEATH(_exit(1),
"") << 1 << 2 << 3;
327 void DieWithEmbeddedNul() {
328 fprintf(stderr,
"Hello%cmy null world.\n",
'\0');
335 TEST_F(TestForDeathTest, EmbeddedNulInMessage) {
336 EXPECT_DEATH(DieWithEmbeddedNul(),
"my null world");
337 ASSERT_DEATH(DieWithEmbeddedNul(),
"my null world");
340 # endif // GTEST_USES_PCRE
344 TEST_F(TestForDeathTest, SwitchStatement) {
351 ASSERT_DEATH(_exit(1), "") << "exit in default
switch handler";
355 EXPECT_DEATH(_exit(1), "") << "exit in
switch case";
362 TEST_F(TestForDeathTest, StaticMemberFunctionFastStyle) {
364 ASSERT_DEATH(StaticMemberFunction(),
"death.*StaticMember");
369 TEST_F(TestForDeathTest, MemberFunctionFastStyle) {
372 EXPECT_DEATH(MemberFunction(),
"inside.*MemberFunction");
379 TEST_F(TestForDeathTest, FastDeathTestInChangedDir) {
383 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
386 ASSERT_DEATH(_exit(1),
"");
390 void SigprofAction(
int, siginfo_t*,
void*) { }
393 void SetSigprofActionAndTimer() {
394 struct sigaction signal_action;
395 memset(&signal_action, 0,
sizeof(signal_action));
396 sigemptyset(&signal_action.sa_mask);
397 signal_action.sa_sigaction = SigprofAction;
398 signal_action.sa_flags = SA_RESTART | SA_SIGINFO;
399 ASSERT_EQ(0, sigaction(SIGPROF, &signal_action,
nullptr));
402 struct itimerval timer;
403 timer.it_interval.tv_sec = 0;
404 timer.it_interval.tv_usec = 1;
405 timer.it_value = timer.it_interval;
406 ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer,
nullptr));
410 void DisableSigprofActionAndTimer(
struct sigaction* old_signal_action) {
411 struct itimerval timer;
412 timer.it_interval.tv_sec = 0;
413 timer.it_interval.tv_usec = 0;
414 timer.it_value = timer.it_interval;
415 ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer,
nullptr));
416 struct sigaction signal_action;
417 memset(&signal_action, 0,
sizeof(signal_action));
418 sigemptyset(&signal_action.sa_mask);
419 signal_action.sa_handler = SIG_IGN;
420 ASSERT_EQ(0, sigaction(SIGPROF, &signal_action, old_signal_action));
424 TEST_F(TestForDeathTest, FastSigprofActionSet) {
426 SetSigprofActionAndTimer();
427 EXPECT_DEATH(_exit(1),
"");
428 struct sigaction old_signal_action;
429 DisableSigprofActionAndTimer(&old_signal_action);
430 EXPECT_TRUE(old_signal_action.sa_sigaction == SigprofAction);
433 TEST_F(TestForDeathTest, ThreadSafeSigprofActionSet) {
435 SetSigprofActionAndTimer();
436 EXPECT_DEATH(_exit(1),
"");
437 struct sigaction old_signal_action;
438 DisableSigprofActionAndTimer(&old_signal_action);
439 EXPECT_TRUE(old_signal_action.sa_sigaction == SigprofAction);
441 # endif // GTEST_OS_LINUX
445 TEST_F(TestForDeathTest, StaticMemberFunctionThreadsafeStyle) {
447 ASSERT_DEATH(StaticMemberFunction(),
"death.*StaticMember");
450 TEST_F(TestForDeathTest, MemberFunctionThreadsafeStyle) {
453 EXPECT_DEATH(MemberFunction(),
"inside.*MemberFunction");
456 TEST_F(TestForDeathTest, ThreadsafeDeathTestInLoop) {
459 for (
int i = 0;
i < 3; ++
i)
460 EXPECT_EXIT(_exit(
i), testing::ExitedWithCode(
i),
"") <<
": i = " <<
i;
463 TEST_F(TestForDeathTest, ThreadsafeDeathTestInChangedDir) {
467 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
470 ASSERT_DEATH(_exit(1),
"");
473 TEST_F(TestForDeathTest, MixedStyles) {
475 EXPECT_DEATH(_exit(1),
"");
477 EXPECT_DEATH(_exit(1),
"");
480 # if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
484 void SetPthreadFlag() {
488 TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) {
491 pthread_flag =
false;
492 ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag,
nullptr,
nullptr));
493 ASSERT_DEATH(_exit(1),
"");
498 # endif // GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
501 TEST_F(TestForDeathTest, MethodOfAnotherClass) {
502 const MayDie
x(
true);
503 ASSERT_DEATH(x.MemberFunction(),
"MayDie\\:\\:MemberFunction");
507 TEST_F(TestForDeathTest, GlobalFunction) {
508 EXPECT_DEATH(GlobalFunction(),
"GlobalFunction");
513 TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) {
514 static const char regex_c_str[] =
"GlobalFunction";
515 EXPECT_DEATH(GlobalFunction(), regex_c_str);
518 EXPECT_DEATH(GlobalFunction(), regex);
520 # if !GTEST_USES_PCRE
522 const ::std::string regex_std_str(regex_c_str);
523 EXPECT_DEATH(GlobalFunction(), regex_std_str);
527 EXPECT_DEATH(GlobalFunction(), ::std::string(regex_c_str).c_str());
529 # endif // !GTEST_USES_PCRE
533 TEST_F(TestForDeathTest, NonVoidFunction) {
534 ASSERT_DEATH(NonVoidFunction(),
"NonVoidFunction");
538 TEST_F(TestForDeathTest, FunctionWithParameter) {
539 EXPECT_DEATH(DieIf(
true),
"DieIf\\(\\)");
540 EXPECT_DEATH(DieIfLessThan(2, 3),
"DieIfLessThan");
544 TEST_F(TestForDeathTest, OutsideFixture) {
545 DeathTestSubroutine();
549 TEST_F(TestForDeathTest, InsideLoop) {
550 for (
int i = 0;
i < 5;
i++) {
551 EXPECT_DEATH(DieIfLessThan(-1,
i),
"DieIfLessThan") <<
"where i == " <<
i;
556 TEST_F(TestForDeathTest, CompoundStatement) {
566 TEST_F(TestForDeathTest, DoesNotDie) {
572 TEST_F(TestForDeathTest, ErrorMessageMismatch) {
574 EXPECT_DEATH(DieIf(
true),
"DieIfLessThan") <<
"End of death test message.";
575 },
"died but not with expected error");
580 void ExpectDeathTestHelper(
bool* aborted) {
582 EXPECT_DEATH(DieIf(
false),
"DieIf");
587 TEST_F(TestForDeathTest, EXPECT_DEATH) {
595 TEST_F(TestForDeathTest, ASSERT_DEATH) {
599 ASSERT_DEATH(DieIf(
false),
"DieIf");
606 TEST_F(TestForDeathTest, SingleEvaluation) {
608 EXPECT_DEATH(DieIf((++x) == 4),
"DieIf");
610 const char* regex =
"DieIf";
611 const char* regex_save = regex;
612 EXPECT_DEATH(DieIfLessThan(3, 4), regex++);
617 TEST_F(TestForDeathTest, RunawayIsFailure) {
624 TEST_F(TestForDeathTest, ReturnIsFailure) {
626 "illegal return in test statement.");
636 TEST_F(TestForDeathTest, TestExpectDebugDeath) {
641 const char* regex =
"death.*DieInDebugElse12";
643 EXPECT_DEBUG_DEATH(DieInDebugElse12(&sideeffect), regex)
644 <<
"Must accept a streamed message";
659 # if GTEST_OS_WINDOWS
668 TEST_F(TestForDeathTest, CRTDebugDeath) {
673 const char* regex =
"dup.* : Assertion failed";
675 EXPECT_DEBUG_DEATH(DieInCRTDebugElse12(&sideeffect), regex)
676 <<
"Must accept a streamed message";
691 # endif // GTEST_OS_WINDOWS
700 TEST_F(TestForDeathTest, TestAssertDebugDeath) {
703 ASSERT_DEBUG_DEATH(DieInDebugElse12(&sideeffect),
"death.*DieInDebugElse12")
704 <<
"Must accept a streamed message";
721 void ExpectDebugDeathHelper(
bool* aborted) {
723 EXPECT_DEBUG_DEATH(
return,
"") <<
"This is expected to fail.";
727 # if GTEST_OS_WINDOWS
728 TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) {
729 printf(
"This test should be considered failing if it shows "
730 "any pop-up dialogs.\n");
738 # endif // GTEST_OS_WINDOWS
742 TEST_F(TestForDeathTest, ExpectDebugDeathDoesNotAbort) {
748 void AssertDebugDeathHelper(
bool* aborted) {
750 GTEST_LOG_(INFO) <<
"Before ASSERT_DEBUG_DEATH";
751 ASSERT_DEBUG_DEATH(
GTEST_LOG_(INFO) <<
"In ASSERT_DEBUG_DEATH";
return,
"")
752 <<
"This is expected to fail.";
753 GTEST_LOG_(INFO) <<
"After ASSERT_DEBUG_DEATH";
759 TEST_F(TestForDeathTest, AssertDebugDeathAborts) {
766 TEST_F(TestForDeathTest, AssertDebugDeathAborts2) {
773 TEST_F(TestForDeathTest, AssertDebugDeathAborts3) {
780 TEST_F(TestForDeathTest, AssertDebugDeathAborts4) {
787 TEST_F(TestForDeathTest, AssertDebugDeathAborts5) {
794 TEST_F(TestForDeathTest, AssertDebugDeathAborts6) {
801 TEST_F(TestForDeathTest, AssertDebugDeathAborts7) {
808 TEST_F(TestForDeathTest, AssertDebugDeathAborts8) {
815 TEST_F(TestForDeathTest, AssertDebugDeathAborts9) {
822 TEST_F(TestForDeathTest, AssertDebugDeathAborts10) {
832 static void TestExitMacros() {
833 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
834 ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42),
"");
836 # if GTEST_OS_WINDOWS
841 EXPECT_EXIT(
raise(SIGABRT), testing::ExitedWithCode(3),
"") <<
"b_ar";
843 # elif !GTEST_OS_FUCHSIA
846 EXPECT_EXIT(
raise(SIGKILL), testing::KilledBySignal(SIGKILL),
"") <<
"foo";
847 ASSERT_EXIT(
raise(SIGUSR2), testing::KilledBySignal(SIGUSR2),
"") <<
"bar";
850 ASSERT_EXIT(_exit(0), testing::KilledBySignal(SIGSEGV),
"")
851 <<
"This failure is expected, too.";
852 },
"This failure is expected, too.");
854 # endif // GTEST_OS_WINDOWS
857 EXPECT_EXIT(
raise(SIGSEGV), testing::ExitedWithCode(0),
"")
858 <<
"This failure is expected.";
859 },
"This failure is expected.");
862 TEST_F(TestForDeathTest, ExitMacros) {
866 TEST_F(TestForDeathTest, ExitMacrosUsingFork) {
871 TEST_F(TestForDeathTest, InvalidStyle) {
874 EXPECT_DEATH(_exit(0),
"") <<
"This failure is expected.";
875 },
"This failure is expected.");
878 TEST_F(TestForDeathTest, DeathTestFailedOutput) {
881 EXPECT_DEATH(DieWithMessage(
"death\n"),
884 "[ DEATH ] death\n");
887 TEST_F(TestForDeathTest, DeathTestUnexpectedReturnOutput) {
891 fprintf(stderr,
"returning\n");
895 " Result: illegal return in test statement.\n"
897 "[ DEATH ] returning\n");
900 TEST_F(TestForDeathTest, DeathTestBadExitCodeOutput) {
903 EXPECT_EXIT(DieWithMessage(
"exiting with rc 1\n"),
904 testing::ExitedWithCode(3),
906 " Result: died but not with expected exit code:\n"
907 " Exited with exit status 1\n"
909 "[ DEATH ] exiting with rc 1\n");
912 TEST_F(TestForDeathTest, DeathTestMultiLineMatchFail) {
915 EXPECT_DEATH(DieWithMessage(
"line 1\nline 2\nline 3\n"),
916 "line 1\nxyz\nline 3\n"),
920 "[ DEATH ] line 3\n");
923 TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) {
925 EXPECT_DEATH(DieWithMessage(
"line 1\nline 2\nline 3\n"),
926 "line 1\nline 2\nline 3\n");
930 class MockDeathTestFactory :
public DeathTestFactory {
932 MockDeathTestFactory();
933 bool Create(
const char* statement,
935 int line, DeathTest** test)
override;
938 void SetParameters(
bool create, DeathTest::TestRole role,
939 int status,
bool passed);
942 int AssumeRoleCalls()
const {
return assume_role_calls_; }
943 int WaitCalls()
const {
return wait_calls_; }
944 size_t PassedCalls()
const {
return passed_args_.size(); }
945 bool PassedArgument(
int n)
const {
946 return passed_args_[
static_cast<size_t>(n)];
948 size_t AbortCalls()
const {
return abort_args_.size(); }
949 DeathTest::AbortReason AbortArgument(
int n)
const {
950 return abort_args_[
static_cast<size_t>(n)];
952 bool TestDeleted()
const {
return test_deleted_; }
955 friend class MockDeathTest;
960 DeathTest::TestRole role_;
967 int assume_role_calls_;
972 std::vector<bool> passed_args_;
975 std::vector<DeathTest::AbortReason> abort_args_;
986 class MockDeathTest :
public DeathTest {
988 MockDeathTest(MockDeathTestFactory *parent,
989 TestRole role,
int status,
bool passed) :
990 parent_(parent), role_(role), status_(status), passed_(passed) {
992 ~MockDeathTest()
override { parent_->test_deleted_ =
true; }
993 TestRole AssumeRole()
override {
994 ++parent_->assume_role_calls_;
997 int Wait()
override {
998 ++parent_->wait_calls_;
1001 bool Passed(
bool exit_status_ok)
override {
1002 parent_->passed_args_.push_back(exit_status_ok);
1005 void Abort(AbortReason reason)
override {
1006 parent_->abort_args_.push_back(reason);
1010 MockDeathTestFactory*
const parent_;
1011 const TestRole role_;
1018 MockDeathTestFactory::MockDeathTestFactory()
1020 role_(DeathTest::OVERSEE_TEST),
1023 assume_role_calls_(0),
1031 void MockDeathTestFactory::SetParameters(
bool create,
1032 DeathTest::TestRole role,
1033 int status,
bool passed) {
1039 assume_role_calls_ = 0;
1041 passed_args_.clear();
1042 abort_args_.clear();
1049 bool MockDeathTestFactory::Create(
1051 const char* ,
int , DeathTest** test) {
1052 test_deleted_ =
false;
1054 *test =
new MockDeathTest(
this, role_, status_, passed_);
1066 static testing::internal::ReplaceDeathTestFactory* replacer_;
1067 static MockDeathTestFactory* factory_;
1070 factory_ =
new MockDeathTestFactory;
1071 replacer_ =
new testing::internal::ReplaceDeathTestFactory(factory_);
1076 replacer_ =
nullptr;
1084 static void RunReturningDeathTest(
bool* flag) {
1092 testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_ =
1094 MockDeathTestFactory* MacroLogicDeathTest::factory_ =
nullptr;
1097 TEST_F(MacroLogicDeathTest, NothingHappens) {
1099 factory_->SetParameters(
false, DeathTest::OVERSEE_TEST, 0,
true);
1100 EXPECT_DEATH(flag =
true,
"");
1102 EXPECT_EQ(0, factory_->AssumeRoleCalls());
1112 TEST_F(MacroLogicDeathTest, ChildExitsSuccessfully) {
1114 factory_->SetParameters(
true, DeathTest::OVERSEE_TEST, 0,
true);
1115 EXPECT_DEATH(flag =
true,
"");
1117 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1127 TEST_F(MacroLogicDeathTest, ChildExitsUnsuccessfully) {
1129 factory_->SetParameters(
true, DeathTest::OVERSEE_TEST, 1,
true);
1130 EXPECT_DEATH(flag =
true,
"");
1132 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1143 TEST_F(MacroLogicDeathTest, ChildPerformsReturn) {
1145 factory_->SetParameters(
true, DeathTest::EXECUTE_TEST, 0,
true);
1146 RunReturningDeathTest(&flag);
1148 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1152 EXPECT_EQ(DeathTest::TEST_ENCOUNTERED_RETURN_STATEMENT,
1153 factory_->AbortArgument(0));
1159 TEST_F(MacroLogicDeathTest, ChildDoesNotDie) {
1161 factory_->SetParameters(
true, DeathTest::EXECUTE_TEST, 0,
true);
1162 EXPECT_DEATH(flag =
true,
"");
1164 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1174 factory_->AbortArgument(0));
1175 EXPECT_EQ(DeathTest::TEST_ENCOUNTERED_RETURN_STATEMENT,
1176 factory_->AbortArgument(1));
1182 TEST(SuccessRegistrationDeathTest, NoSuccessPart) {
1183 EXPECT_DEATH(_exit(1),
"");
1184 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
1187 TEST(StreamingAssertionsDeathTest, DeathTest) {
1188 EXPECT_DEATH(_exit(1),
"") <<
"unexpected failure";
1189 ASSERT_DEATH(_exit(1),
"") <<
"unexpected failure";
1191 EXPECT_DEATH(_exit(0),
"") <<
"expected failure";
1192 },
"expected failure");
1194 ASSERT_DEATH(_exit(0),
"") <<
"expected failure";
1195 },
"expected failure");
1200 TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) {
1207 # if GTEST_OS_WINDOWS
1208 TEST(AutoHandleTest, AutoHandleWorks) {
1209 HANDLE handle = ::CreateEvent(NULL, FALSE, FALSE, NULL);
1210 ASSERT_NE(INVALID_HANDLE_VALUE, handle);
1213 testing::internal::AutoHandle auto_handle(handle);
1218 auto_handle.Reset();
1219 EXPECT_EQ(INVALID_HANDLE_VALUE, auto_handle.Get());
1223 handle = ::CreateEvent(NULL, FALSE, FALSE, NULL);
1224 ASSERT_NE(INVALID_HANDLE_VALUE, handle);
1225 auto_handle.Reset(handle);
1229 testing::internal::AutoHandle auto_handle2;
1230 EXPECT_EQ(INVALID_HANDLE_VALUE, auto_handle2.Get());
1232 # endif // GTEST_OS_WINDOWS
1234 # if GTEST_OS_WINDOWS
1235 typedef unsigned __int64 BiggestParsable;
1236 typedef signed __int64 BiggestSignedParsable;
1238 typedef unsigned long long BiggestParsable;
1239 typedef signed long long BiggestSignedParsable;
1240 # endif // GTEST_OS_WINDOWS
1244 const BiggestParsable kBiggestParsableMax = ULLONG_MAX;
1245 const BiggestSignedParsable kBiggestSignedParsableMax = LLONG_MAX;
1247 TEST(ParseNaturalNumberTest, RejectsInvalidFormat) {
1248 BiggestParsable result = 0;
1251 EXPECT_FALSE(ParseNaturalNumber(
"non-number string", &result));
1264 TEST(ParseNaturalNumberTest, RejectsOverflownNumbers) {
1265 BiggestParsable result = 0;
1267 EXPECT_FALSE(ParseNaturalNumber(
"99999999999999999999999", &result));
1269 signed char char_result = 0;
1274 TEST(ParseNaturalNumberTest, AcceptsValidNumbers) {
1275 BiggestParsable result = 0;
1287 ASSERT_TRUE(ParseNaturalNumber(
"00000", &result));
1291 TEST(ParseNaturalNumberTest, AcceptsTypeLimits) {
1293 msg << kBiggestParsableMax;
1295 BiggestParsable result = 0;
1296 EXPECT_TRUE(ParseNaturalNumber(msg.GetString(), &result));
1300 msg2 << kBiggestSignedParsableMax;
1302 BiggestSignedParsable signed_result = 0;
1303 EXPECT_TRUE(ParseNaturalNumber(msg2.GetString(), &signed_result));
1304 EXPECT_EQ(kBiggestSignedParsableMax, signed_result);
1310 EXPECT_TRUE(ParseNaturalNumber(msg3.GetString(), &int_result));
1316 unsigned int uint_result = 0;
1317 EXPECT_TRUE(ParseNaturalNumber(msg4.GetString(), &uint_result));
1321 TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
1322 short short_result = 0;
1323 ASSERT_TRUE(ParseNaturalNumber(
"123", &short_result));
1326 signed char char_result = 0;
1327 ASSERT_TRUE(ParseNaturalNumber(
"123", &char_result));
1331 # if GTEST_OS_WINDOWS
1332 TEST(EnvironmentTest, HandleFitsIntoSizeT) {
1335 # endif // GTEST_OS_WINDOWS
1339 TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) {
1341 "death inside CondDeathTestExpectMacro");
1343 "death inside CondDeathTestAssertMacro");
1350 TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
1354 fprintf(stderr, InDeathTestChild() ?
"Inside" :
"Outside");
1360 TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
1364 fprintf(stderr, InDeathTestChild() ?
"Inside" :
"Outside");
1370 void DieWithMessage(
const char* message) {
1371 fputs(message, stderr);
1376 TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) {
1379 EXPECT_DEATH(DieWithMessage(
"O, I die, Horatio."),
"I d[aeiou]e");
1382 TEST(MatcherDeathTest, MonomorphicMatcherMatches) {
1383 EXPECT_DEATH(DieWithMessage(
"Behind O, I am slain!"),
1384 Matcher<const std::string&>(ContainsRegex(
"I am slain")));
1387 TEST(MatcherDeathTest, MonomorphicMatcherDoesNotMatch) {
1390 DieWithMessage(
"Behind O, I am slain!"),
1391 Matcher<const std::string&>(ContainsRegex(
"Ow, I am slain"))),
1392 "Expected: contains regular expression \"Ow, I am slain\"");
1395 TEST(MatcherDeathTest, PolymorphicMatcherMatches) {
1396 EXPECT_DEATH(DieWithMessage(
"The rest is silence."),
1397 ContainsRegex(
"rest is silence"));
1400 TEST(MatcherDeathTest, PolymorphicMatcherDoesNotMatch) {
1402 EXPECT_DEATH(DieWithMessage(
"The rest is silence."),
1403 ContainsRegex(
"rest is science")),
1404 "Expected: contains regular expression \"rest is science\"");
1409 #else // !GTEST_HAS_DEATH_TEST follows
1419 TEST(ConditionalDeathMacrosTest, WarnsWhenDeathTestsNotAvailable) {
1426 "Death tests are not supported on this platform"));
1433 ASSERT_TRUE(NULL == strstr(output.c_str(),
"streamed message"));
1439 "Death tests are not supported on this platform"));
1445 ASSERT_TRUE(NULL == strstr(output.c_str(),
"streamed message"));
1448 void FuncWithAssert(
int* n) {
1455 TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
1463 #endif // !GTEST_HAS_DEATH_TEST
1472 TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
1495 TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
1503 << "exit in default
switch handler";
1514 TEST(NotADeathTest, Test) {
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
GTEST_API_ std::string GetCapturedStderr()
#define EXPECT_STRNE(s1, s2)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
#define ASSERT_NE(val1, val2)
#define GTEST_LOG_(severity)
#define TEST_F(test_fixture, test_name)
#define TEST(test_suite_name, test_name)
#define ASSERT_EQ(val1, val2)
int ChDir(const char *dir)
#define EXPECT_FATAL_FAILURE(statement, substr)
#define EXPECT_PRED1(pred, v1)
#define ASSERT_TRUE(condition)
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
static void TearDownTestSuite()
GTEST_API_ bool AlwaysTrue()
#define EXPECT_STREQ(s1, s2)
#define EXPECT_EQ(val1, val2)
GTEST_API_ void CaptureStderr()
#define EXPECT_TRUE(condition)
static void SetUpTestSuite()
#define EXPECT_FALSE(condition)
#define ASSERT_FALSE(condition)