41#if GTEST_HAS_DEATH_TEST
61namespace posix = ::testing::internal::posix;
64using testing::internal::DeathTest;
65using testing::internal::DeathTestFactory;
67using testing::internal::GetLastErrnoDescription;
69using testing::internal::InDeathTestChild;
70using testing::internal::ParseNaturalNumber;
77class ReplaceDeathTestFactory {
79 explicit ReplaceDeathTestFactory(DeathTestFactory* new_factory)
80 : unit_test_impl_(GetUnitTestImpl()) {
81 old_factory_ = unit_test_impl_->death_test_factory_.release();
82 unit_test_impl_->death_test_factory_.reset(new_factory);
85 ~ReplaceDeathTestFactory() {
86 unit_test_impl_->death_test_factory_.release();
87 unit_test_impl_->death_test_factory_.reset(old_factory_);
91 ReplaceDeathTestFactory(
const ReplaceDeathTestFactory&);
92 void operator=(
const ReplaceDeathTestFactory&);
94 UnitTestImpl* unit_test_impl_;
95 DeathTestFactory* old_factory_;
101void DieWithMessage(const ::std::string& message) {
102 fprintf(stderr,
"%s", message.c_str());
117void DieInside(const ::std::string& function) {
118 DieWithMessage(
"death inside " + function +
"().");
125 TestForDeathTest() : original_dir_(FilePath::GetCurrentDir()) {}
127 virtual ~TestForDeathTest() {
132 static void StaticMemberFunction() { DieInside(
"StaticMemberFunction"); }
135 void MemberFunction() {
137 DieInside(
"MemberFunction");
142 const FilePath original_dir_;
148 explicit MayDie(
bool should_die) : should_die_(should_die) {}
151 void MemberFunction()
const {
153 DieInside(
"MayDie::MemberFunction");
162void GlobalFunction() { DieInside(
"GlobalFunction"); }
165int NonVoidFunction() {
166 DieInside(
"NonVoidFunction");
171void DieIf(
bool should_die) {
177bool DieIfLessThan(
int x,
int y) {
179 DieInside(
"DieIfLessThan");
185void DeathTestSubroutine() {
186 EXPECT_DEATH(GlobalFunction(),
"death.*GlobalFunction");
187 ASSERT_DEATH(GlobalFunction(),
"death.*GlobalFunction");
191int DieInDebugElse12(
int* sideeffect) {
192 if (sideeffect) *sideeffect = 12;
196 DieInside(
"DieInDebugElse12");
203# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
206TEST(ExitStatusPredicateTest, ExitedWithCode) {
221static int NormalExitStatus(
int exit_code) {
222 pid_t child_pid = fork();
223 if (child_pid == 0) {
227 waitpid(child_pid, &status, 0);
236static int KilledExitStatus(
int signum) {
237 pid_t child_pid = fork();
238 if (child_pid == 0) {
243 waitpid(child_pid, &status, 0);
248TEST(ExitStatusPredicateTest, ExitedWithCode) {
249 const int status0 = NormalExitStatus(0);
250 const int status1 = NormalExitStatus(1);
251 const int status42 = NormalExitStatus(42);
252 const testing::ExitedWithCode pred0(0);
253 const testing::ExitedWithCode pred1(1);
254 const testing::ExitedWithCode pred42(42);
264TEST(ExitStatusPredicateTest, KilledBySignal) {
265 const int status_segv = KilledExitStatus(SIGSEGV);
266 const int status_kill = KilledExitStatus(SIGKILL);
267 const testing::KilledBySignal pred_segv(SIGSEGV);
268 const testing::KilledBySignal pred_kill(SIGKILL);
280TEST_F(TestForDeathTest, SingleStatement) {
283 ASSERT_DEATH(
return,
"");
286 EXPECT_DEATH(_exit(1),
"");
293 ASSERT_DEATH(
return,
"") <<
"did not die";
298 EXPECT_DEATH(_exit(1),
"") << 1 << 2 << 3;
301void DieWithEmbeddedNul() {
302 fprintf(stderr,
"Hello%cmy null world.\n",
'\0');
311TEST_F(TestForDeathTest, EmbeddedNulInMessage) {
312 EXPECT_DEATH(DieWithEmbeddedNul(),
"my null world");
313 ASSERT_DEATH(DieWithEmbeddedNul(),
"my null world");
320TEST_F(TestForDeathTest, SwitchStatement) {
327 ASSERT_DEATH(_exit(1), "") << "exit in default
switch handler";
331 EXPECT_DEATH(_exit(1), "") << "exit in
switch case";
338TEST_F(TestForDeathTest, StaticMemberFunctionFastStyle) {
339 testing::GTEST_FLAG(death_test_style) =
"fast";
340 ASSERT_DEATH(StaticMemberFunction(),
"death.*StaticMember");
345TEST_F(TestForDeathTest, MemberFunctionFastStyle) {
346 testing::GTEST_FLAG(death_test_style) =
"fast";
348 EXPECT_DEATH(MemberFunction(),
"inside.*MemberFunction");
355TEST_F(TestForDeathTest, FastDeathTestInChangedDir) {
356 testing::GTEST_FLAG(death_test_style) =
"fast";
359 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
362 ASSERT_DEATH(_exit(1),
"");
366void SigprofAction(
int, siginfo_t*,
void*) { }
369void SetSigprofActionAndTimer() {
370 struct itimerval timer;
371 timer.it_interval.tv_sec = 0;
372 timer.it_interval.tv_usec = 1;
373 timer.it_value = timer.it_interval;
374 ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, NULL));
375 struct sigaction signal_action;
376 memset(&signal_action, 0,
sizeof(signal_action));
377 sigemptyset(&signal_action.sa_mask);
378 signal_action.sa_sigaction = SigprofAction;
379 signal_action.sa_flags = SA_RESTART | SA_SIGINFO;
380 ASSERT_EQ(0, sigaction(SIGPROF, &signal_action, NULL));
384void DisableSigprofActionAndTimer(
struct sigaction* old_signal_action) {
385 struct itimerval timer;
386 timer.it_interval.tv_sec = 0;
387 timer.it_interval.tv_usec = 0;
388 timer.it_value = timer.it_interval;
389 ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, NULL));
390 struct sigaction signal_action;
391 memset(&signal_action, 0,
sizeof(signal_action));
392 sigemptyset(&signal_action.sa_mask);
393 signal_action.sa_handler = SIG_IGN;
394 ASSERT_EQ(0, sigaction(SIGPROF, &signal_action, old_signal_action));
398TEST_F(TestForDeathTest, FastSigprofActionSet) {
399 testing::GTEST_FLAG(death_test_style) =
"fast";
400 SetSigprofActionAndTimer();
401 EXPECT_DEATH(_exit(1),
"");
402 struct sigaction old_signal_action;
403 DisableSigprofActionAndTimer(&old_signal_action);
404 EXPECT_TRUE(old_signal_action.sa_sigaction == SigprofAction);
407TEST_F(TestForDeathTest, ThreadSafeSigprofActionSet) {
408 testing::GTEST_FLAG(death_test_style) =
"threadsafe";
409 SetSigprofActionAndTimer();
410 EXPECT_DEATH(_exit(1),
"");
411 struct sigaction old_signal_action;
412 DisableSigprofActionAndTimer(&old_signal_action);
413 EXPECT_TRUE(old_signal_action.sa_sigaction == SigprofAction);
419TEST_F(TestForDeathTest, StaticMemberFunctionThreadsafeStyle) {
420 testing::GTEST_FLAG(death_test_style) =
"threadsafe";
421 ASSERT_DEATH(StaticMemberFunction(),
"death.*StaticMember");
424TEST_F(TestForDeathTest, MemberFunctionThreadsafeStyle) {
425 testing::GTEST_FLAG(death_test_style) =
"threadsafe";
427 EXPECT_DEATH(MemberFunction(),
"inside.*MemberFunction");
430TEST_F(TestForDeathTest, ThreadsafeDeathTestInLoop) {
431 testing::GTEST_FLAG(death_test_style) =
"threadsafe";
433 for (
int i = 0; i < 3; ++i)
434 EXPECT_EXIT(_exit(i), testing::ExitedWithCode(i),
"") <<
": i = " << i;
437TEST_F(TestForDeathTest, ThreadsafeDeathTestInChangedDir) {
438 testing::GTEST_FLAG(death_test_style) =
"threadsafe";
441 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
444 ASSERT_DEATH(_exit(1),
"");
447TEST_F(TestForDeathTest, MixedStyles) {
448 testing::GTEST_FLAG(death_test_style) =
"threadsafe";
449 EXPECT_DEATH(_exit(1),
"");
450 testing::GTEST_FLAG(death_test_style) =
"fast";
451 EXPECT_DEATH(_exit(1),
"");
454# if GTEST_HAS_CLONE && GTEST_HAS_PTHREAD
460void SetPthreadFlag() {
466TEST_F(TestForDeathTest, DoesNotExecuteAtforkHooks) {
467 if (!testing::GTEST_FLAG(death_test_use_fork)) {
468 testing::GTEST_FLAG(death_test_style) =
"threadsafe";
469 pthread_flag =
false;
470 ASSERT_EQ(0, pthread_atfork(&SetPthreadFlag, NULL, NULL));
471 ASSERT_DEATH(_exit(1),
"");
479TEST_F(TestForDeathTest, MethodOfAnotherClass) {
480 const MayDie x(
true);
481 ASSERT_DEATH(x.MemberFunction(),
"MayDie\\:\\:MemberFunction");
485TEST_F(TestForDeathTest, GlobalFunction) {
486 EXPECT_DEATH(GlobalFunction(),
"GlobalFunction");
491TEST_F(TestForDeathTest, AcceptsAnythingConvertibleToRE) {
492 static const char regex_c_str[] =
"GlobalFunction";
493 EXPECT_DEATH(GlobalFunction(), regex_c_str);
496 EXPECT_DEATH(GlobalFunction(), regex);
498# if GTEST_HAS_GLOBAL_STRING
500 const ::string regex_str(regex_c_str);
501 EXPECT_DEATH(GlobalFunction(), regex_str);
507 const ::std::string regex_std_str(regex_c_str);
508 EXPECT_DEATH(GlobalFunction(), regex_std_str);
514TEST_F(TestForDeathTest, NonVoidFunction) {
515 ASSERT_DEATH(NonVoidFunction(),
"NonVoidFunction");
519TEST_F(TestForDeathTest, FunctionWithParameter) {
520 EXPECT_DEATH(DieIf(
true),
"DieIf\\(\\)");
521 EXPECT_DEATH(DieIfLessThan(2, 3),
"DieIfLessThan");
525TEST_F(TestForDeathTest, OutsideFixture) {
526 DeathTestSubroutine();
530TEST_F(TestForDeathTest, InsideLoop) {
531 for (
int i = 0; i < 5; i++) {
532 EXPECT_DEATH(DieIfLessThan(-1, i),
"DieIfLessThan") <<
"where i == " << i;
537TEST_F(TestForDeathTest, CompoundStatement) {
547TEST_F(TestForDeathTest, DoesNotDie) {
553TEST_F(TestForDeathTest, ErrorMessageMismatch) {
555 EXPECT_DEATH(DieIf(
true),
"DieIfLessThan") <<
"End of death test message.";
556 },
"died but not with expected error");
561void ExpectDeathTestHelper(
bool* aborted) {
563 EXPECT_DEATH(DieIf(
false),
"DieIf");
568TEST_F(TestForDeathTest, EXPECT_DEATH) {
576TEST_F(TestForDeathTest, ASSERT_DEATH) {
580 ASSERT_DEATH(DieIf(
false),
"DieIf");
587TEST_F(TestForDeathTest, SingleEvaluation) {
589 EXPECT_DEATH(DieIf((++x) == 4),
"DieIf");
591 const char* regex =
"DieIf";
592 const char* regex_save = regex;
593 EXPECT_DEATH(DieIfLessThan(3, 4), regex++);
598TEST_F(TestForDeathTest, RunawayIsFailure) {
605TEST_F(TestForDeathTest, ReturnIsFailure) {
607 "illegal return in test statement.");
617TEST_F(TestForDeathTest, TestExpectDebugDeath) {
622 const char* regex =
"death.*DieInDebugElse12";
624 EXPECT_DEBUG_DEATH(DieInDebugElse12(&sideeffect), regex)
625 <<
"Must accept a streamed message";
647TEST_F(TestForDeathTest, TestAssertDebugDeath) {
650 ASSERT_DEBUG_DEATH(DieInDebugElse12(&sideeffect),
"death.*DieInDebugElse12")
651 <<
"Must accept a streamed message";
668void ExpectDebugDeathHelper(
bool* aborted) {
670 EXPECT_DEBUG_DEATH(
return,
"") <<
"This is expected to fail.";
675TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) {
676 printf(
"This test should be considered failing if it shows "
677 "any pop-up dialogs.\n");
681 testing::GTEST_FLAG(catch_exceptions) =
false;
689TEST_F(TestForDeathTest, ExpectDebugDeathDoesNotAbort) {
695void AssertDebugDeathHelper(
bool* aborted) {
698 ASSERT_DEBUG_DEATH(
GTEST_LOG_(
INFO) <<
"In ASSERT_DEBUG_DEATH";
return,
"")
699 <<
"This is expected to fail.";
706TEST_F(TestForDeathTest, AssertDebugDeathAborts) {
713TEST_F(TestForDeathTest, AssertDebugDeathAborts2) {
720TEST_F(TestForDeathTest, AssertDebugDeathAborts3) {
727TEST_F(TestForDeathTest, AssertDebugDeathAborts4) {
734TEST_F(TestForDeathTest, AssertDebugDeathAborts5) {
741TEST_F(TestForDeathTest, AssertDebugDeathAborts6) {
748TEST_F(TestForDeathTest, AssertDebugDeathAborts7) {
755TEST_F(TestForDeathTest, AssertDebugDeathAborts8) {
762TEST_F(TestForDeathTest, AssertDebugDeathAborts9) {
769TEST_F(TestForDeathTest, AssertDebugDeathAborts10) {
779static void TestExitMacros() {
780 EXPECT_EXIT(_exit(1), testing::ExitedWithCode(1),
"");
781 ASSERT_EXIT(_exit(42), testing::ExitedWithCode(42),
"");
788 EXPECT_EXIT(raise(SIGABRT), testing::ExitedWithCode(3),
"") <<
"b_ar";
790# elif !GTEST_OS_FUCHSIA
793 EXPECT_EXIT(raise(SIGKILL), testing::KilledBySignal(SIGKILL),
"") <<
"foo";
794 ASSERT_EXIT(raise(SIGUSR2), testing::KilledBySignal(SIGUSR2),
"") <<
"bar";
797 ASSERT_EXIT(_exit(0), testing::KilledBySignal(SIGSEGV),
"")
798 <<
"This failure is expected, too.";
799 },
"This failure is expected, too.");
804 EXPECT_EXIT(raise(SIGSEGV), testing::ExitedWithCode(0),
"")
805 <<
"This failure is expected.";
806 },
"This failure is expected.");
809TEST_F(TestForDeathTest, ExitMacros) {
813TEST_F(TestForDeathTest, ExitMacrosUsingFork) {
814 testing::GTEST_FLAG(death_test_use_fork) =
true;
818TEST_F(TestForDeathTest, InvalidStyle) {
819 testing::GTEST_FLAG(death_test_style) =
"rococo";
821 EXPECT_DEATH(_exit(0),
"") <<
"This failure is expected.";
822 },
"This failure is expected.");
825TEST_F(TestForDeathTest, DeathTestFailedOutput) {
826 testing::GTEST_FLAG(death_test_style) =
"fast";
828 EXPECT_DEATH(DieWithMessage(
"death\n"),
831 "[ DEATH ] death\n");
834TEST_F(TestForDeathTest, DeathTestUnexpectedReturnOutput) {
835 testing::GTEST_FLAG(death_test_style) =
"fast";
838 fprintf(stderr,
"returning\n");
842 " Result: illegal return in test statement.\n"
844 "[ DEATH ] returning\n");
847TEST_F(TestForDeathTest, DeathTestBadExitCodeOutput) {
848 testing::GTEST_FLAG(death_test_style) =
"fast";
850 EXPECT_EXIT(DieWithMessage(
"exiting with rc 1\n"),
851 testing::ExitedWithCode(3),
853 " Result: died but not with expected exit code:\n"
854 " Exited with exit status 1\n"
856 "[ DEATH ] exiting with rc 1\n");
859TEST_F(TestForDeathTest, DeathTestMultiLineMatchFail) {
860 testing::GTEST_FLAG(death_test_style) =
"fast";
862 EXPECT_DEATH(DieWithMessage(
"line 1\nline 2\nline 3\n"),
863 "line 1\nxyz\nline 3\n"),
867 "[ DEATH ] line 3\n");
870TEST_F(TestForDeathTest, DeathTestMultiLineMatchPass) {
871 testing::GTEST_FLAG(death_test_style) =
"fast";
872 EXPECT_DEATH(DieWithMessage(
"line 1\nline 2\nline 3\n"),
873 "line 1\nline 2\nline 3\n");
877class MockDeathTestFactory :
public DeathTestFactory {
879 MockDeathTestFactory();
880 virtual bool Create(
const char* statement,
881 const ::testing::internal::RE* regex,
882 const char* file,
int line, DeathTest** test);
885 void SetParameters(
bool create, DeathTest::TestRole role,
886 int status,
bool passed);
889 int AssumeRoleCalls()
const {
return assume_role_calls_; }
890 int WaitCalls()
const {
return wait_calls_; }
891 size_t PassedCalls()
const {
return passed_args_.size(); }
892 bool PassedArgument(
int n)
const {
return passed_args_[n]; }
893 size_t AbortCalls()
const {
return abort_args_.size(); }
894 DeathTest::AbortReason AbortArgument(
int n)
const {
895 return abort_args_[n];
897 bool TestDeleted()
const {
return test_deleted_; }
900 friend class MockDeathTest;
905 DeathTest::TestRole role_;
912 int assume_role_calls_;
917 std::vector<bool> passed_args_;
920 std::vector<DeathTest::AbortReason> abort_args_;
931class MockDeathTest :
public DeathTest {
933 MockDeathTest(MockDeathTestFactory *parent,
934 TestRole role,
int status,
bool passed) :
935 parent_(parent), role_(role), status_(status), passed_(passed) {
937 virtual ~MockDeathTest() {
938 parent_->test_deleted_ =
true;
940 virtual TestRole AssumeRole() {
941 ++parent_->assume_role_calls_;
945 ++parent_->wait_calls_;
948 virtual bool Passed(
bool exit_status_ok) {
949 parent_->passed_args_.push_back(exit_status_ok);
952 virtual void Abort(AbortReason reason) {
953 parent_->abort_args_.push_back(reason);
957 MockDeathTestFactory*
const parent_;
958 const TestRole role_;
965MockDeathTestFactory::MockDeathTestFactory()
967 role_(DeathTest::OVERSEE_TEST),
970 assume_role_calls_(0),
978void MockDeathTestFactory::SetParameters(
bool create,
979 DeathTest::TestRole role,
980 int status,
bool passed) {
986 assume_role_calls_ = 0;
988 passed_args_.clear();
996bool MockDeathTestFactory::Create(
const char* ,
997 const ::testing::internal::RE* ,
1001 test_deleted_ =
false;
1003 *
test =
new MockDeathTest(
this, role_, status_, passed_);
1015 static testing::internal::ReplaceDeathTestFactory* replacer_;
1016 static MockDeathTestFactory* factory_;
1019 factory_ =
new MockDeathTestFactory;
1020 replacer_ =
new testing::internal::ReplaceDeathTestFactory(factory_);
1033 static void RunReturningDeathTest(
bool* flag) {
1041testing::internal::ReplaceDeathTestFactory* MacroLogicDeathTest::replacer_
1043MockDeathTestFactory* MacroLogicDeathTest::factory_ = NULL;
1047TEST_F(MacroLogicDeathTest, NothingHappens) {
1049 factory_->SetParameters(
false, DeathTest::OVERSEE_TEST, 0,
true);
1050 EXPECT_DEATH(flag =
true,
"");
1052 EXPECT_EQ(0, factory_->AssumeRoleCalls());
1062TEST_F(MacroLogicDeathTest, ChildExitsSuccessfully) {
1064 factory_->SetParameters(
true, DeathTest::OVERSEE_TEST, 0,
true);
1065 EXPECT_DEATH(flag =
true,
"");
1067 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1077TEST_F(MacroLogicDeathTest, ChildExitsUnsuccessfully) {
1079 factory_->SetParameters(
true, DeathTest::OVERSEE_TEST, 1,
true);
1080 EXPECT_DEATH(flag =
true,
"");
1082 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1093TEST_F(MacroLogicDeathTest, ChildPerformsReturn) {
1095 factory_->SetParameters(
true, DeathTest::EXECUTE_TEST, 0,
true);
1096 RunReturningDeathTest(&flag);
1098 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1102 EXPECT_EQ(DeathTest::TEST_ENCOUNTERED_RETURN_STATEMENT,
1103 factory_->AbortArgument(0));
1109TEST_F(MacroLogicDeathTest, ChildDoesNotDie) {
1111 factory_->SetParameters(
true, DeathTest::EXECUTE_TEST, 0,
true);
1112 EXPECT_DEATH(flag =
true,
"");
1114 EXPECT_EQ(1, factory_->AssumeRoleCalls());
1124 factory_->AbortArgument(0));
1125 EXPECT_EQ(DeathTest::TEST_ENCOUNTERED_RETURN_STATEMENT,
1126 factory_->AbortArgument(1));
1132TEST(SuccessRegistrationDeathTest, NoSuccessPart) {
1133 EXPECT_DEATH(_exit(1),
"");
1134 EXPECT_EQ(0, GetUnitTestImpl()->current_test_result()->total_part_count());
1137TEST(StreamingAssertionsDeathTest, DeathTest) {
1138 EXPECT_DEATH(_exit(1),
"") <<
"unexpected failure";
1139 ASSERT_DEATH(_exit(1),
"") <<
"unexpected failure";
1141 EXPECT_DEATH(_exit(0),
"") <<
"expected failure";
1142 },
"expected failure");
1144 ASSERT_DEATH(_exit(0),
"") <<
"expected failure";
1145 },
"expected failure");
1150TEST(GetLastErrnoDescription, GetLastErrnoDescriptionWorks) {
1157# if GTEST_OS_WINDOWS
1158TEST(AutoHandleTest, AutoHandleWorks) {
1159 HANDLE handle = ::CreateEvent(NULL,
FALSE,
FALSE, NULL);
1160 ASSERT_NE(INVALID_HANDLE_VALUE, handle);
1163 testing::internal::AutoHandle auto_handle(handle);
1168 auto_handle.Reset();
1169 EXPECT_EQ(INVALID_HANDLE_VALUE, auto_handle.Get());
1173 handle = ::CreateEvent(NULL,
FALSE,
FALSE, NULL);
1174 ASSERT_NE(INVALID_HANDLE_VALUE, handle);
1175 auto_handle.Reset(handle);
1179 testing::internal::AutoHandle auto_handle2;
1180 EXPECT_EQ(INVALID_HANDLE_VALUE, auto_handle2.Get());
1184# if GTEST_OS_WINDOWS
1185typedef unsigned __int64 BiggestParsable;
1186typedef signed __int64 BiggestSignedParsable;
1188typedef unsigned long long BiggestParsable;
1189typedef signed long long BiggestSignedParsable;
1194const BiggestParsable kBiggestParsableMax = ULLONG_MAX;
1195const BiggestSignedParsable kBiggestSignedParsableMax = LLONG_MAX;
1197TEST(ParseNaturalNumberTest, RejectsInvalidFormat) {
1198 BiggestParsable result = 0;
1201 EXPECT_FALSE(ParseNaturalNumber(
"non-number string", &result));
1214TEST(ParseNaturalNumberTest, RejectsOverflownNumbers) {
1215 BiggestParsable result = 0;
1217 EXPECT_FALSE(ParseNaturalNumber(
"99999999999999999999999", &result));
1219 signed char char_result = 0;
1224TEST(ParseNaturalNumberTest, AcceptsValidNumbers) {
1225 BiggestParsable result = 0;
1237 ASSERT_TRUE(ParseNaturalNumber(
"00000", &result));
1241TEST(ParseNaturalNumberTest, AcceptsTypeLimits) {
1243 msg << kBiggestParsableMax;
1245 BiggestParsable result = 0;
1246 EXPECT_TRUE(ParseNaturalNumber(msg.GetString(), &result));
1250 msg2 << kBiggestSignedParsableMax;
1252 BiggestSignedParsable signed_result = 0;
1253 EXPECT_TRUE(ParseNaturalNumber(msg2.GetString(), &signed_result));
1254 EXPECT_EQ(kBiggestSignedParsableMax, signed_result);
1260 EXPECT_TRUE(ParseNaturalNumber(msg3.GetString(), &int_result));
1266 unsigned int uint_result = 0;
1267 EXPECT_TRUE(ParseNaturalNumber(msg4.GetString(), &uint_result));
1271TEST(ParseNaturalNumberTest, WorksForShorterIntegers) {
1272 short short_result = 0;
1273 ASSERT_TRUE(ParseNaturalNumber(
"123", &short_result));
1276 signed char char_result = 0;
1277 ASSERT_TRUE(ParseNaturalNumber(
"123", &char_result));
1281# if GTEST_OS_WINDOWS
1282TEST(EnvironmentTest, HandleFitsIntoSizeT) {
1292TEST(ConditionalDeathMacrosDeathTest, ExpectsDeathWhenDeathTestsAvailable) {
1294 "death inside CondDeathTestExpectMacro");
1296 "death inside CondDeathTestAssertMacro");
1303TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInFastStyle) {
1304 testing::GTEST_FLAG(death_test_style) =
"fast";
1307 fprintf(stderr, InDeathTestChild() ?
"Inside" :
"Outside");
1313TEST(InDeathTestChildDeathTest, ReportsDeathTestCorrectlyInThreadSafeStyle) {
1314 testing::GTEST_FLAG(death_test_style) =
"threadsafe";
1317 fprintf(stderr, InDeathTestChild() ?
"Inside" :
"Outside");
1331TEST(ConditionalDeathMacrosTest, WarnsWhenDeathTestsNotAvailable) {
1336 std::string output = GetCapturedStderr();
1338 "Death tests are not supported on this platform"));
1344 output = GetCapturedStderr();
1345 ASSERT_TRUE(NULL == strstr(output.c_str(),
"streamed message"));
1349 output = GetCapturedStderr();
1351 "Death tests are not supported on this platform"));
1356 output = GetCapturedStderr();
1357 ASSERT_TRUE(NULL == strstr(output.c_str(),
"streamed message"));
1367TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
1380TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
1403TEST(ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement) {
1411 <<
"exit in default switch handler";
static void SetUpTestCase()
static void TearDownTestCase()
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex)
void FuncWithAssert(int *n)
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
#define GTEST_LOG_(severity)
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
#define EXPECT_FATAL_FAILURE(statement, substr)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define TEST_F(test_fixture, test_name)
#define ASSERT_EQ(val1, val2)
#define EXPECT_EQ(val1, val2)
#define ASSERT_FALSE(condition)
#define ASSERT_NE(val1, val2)
#define EXPECT_TRUE(condition)
#define EXPECT_STREQ(s1, s2)
#define TEST(test_case_name, test_name)
#define ASSERT_TRUE(condition)
#define EXPECT_FALSE(condition)
#define EXPECT_STRNE(s1, s2)
#define EXPECT_PRED1(pred, v1)
LOGGING_API void printf(Category category, const char *format,...)
int ChDir(const char *dir)
GTEST_API_ std::string GetCapturedStderr()
GTEST_API_ void CaptureStderr()
GTEST_API_ bool AlwaysTrue()
class UnitTestImpl * GetUnitTestImpl()
@ test
Unit testing utility error code.
switch(session->session_state)
memset(pInfo->slotDescription, ' ', 64)