44#if GTEST_IS_THREADSAFE
48using testing::internal::Notification;
49using testing::internal::ThreadWithParam;
52namespace posix = ::testing::internal::posix;
74 FAIL() <<
"This should never be reached.";
77TEST(PassingTest, PassingTest1) {
80TEST(PassingTest, PassingTest2) {
97static const char kGoldenString[] =
"\"Line\0 1\"\nLine 2";
99TEST(NonfatalFailureTest, EscapesStringOperands) {
100 std::string actual =
"actual \"string\"";
103 const char* golden = kGoldenString;
107TEST(NonfatalFailureTest, DiffForLongStrings) {
108 std::string golden_str(kGoldenString,
sizeof(kGoldenString) - 1);
113TEST(FatalFailureTest, FatalFailureInSubroutine) {
114 printf(
"(expecting a failure that x should be 1)\n");
120TEST(FatalFailureTest, FatalFailureInNestedSubroutine) {
121 printf(
"(expecting a failure that x should be 1)\n");
130 if (HasFatalFailure())
return;
133 FAIL() <<
"This should never be reached.";
137TEST(FatalFailureTest, NonfatalFailureInSubroutine) {
138 printf(
"(expecting a failure on false)\n");
144TEST(LoggingTest, InterleavingLoggingAndAssertions) {
145 static const int a[4] = {
149 printf(
"(expecting 2 failures on (3) >= (a[i]))\n");
150 for (
int i = 0; i < static_cast<int>(
sizeof(
a)/
sizeof(*
a)); i++) {
151 printf(
"i == %d\n", i);
171TEST(SCOPED_TRACETest, AcceptedValues) {
175 const char* null_value = NULL;
178 ADD_FAILURE() <<
"Just checking that all these values work fine.";
182TEST(SCOPED_TRACETest, ObeysScopes) {
183 printf(
"(expected to fail)\n");
186 ADD_FAILURE() <<
"This failure is expected, and shouldn't have a trace.";
192 ADD_FAILURE() <<
"This failure is expected, and should have a trace.";
197 ADD_FAILURE() <<
"This failure is expected, and shouldn't have a trace.";
201TEST(SCOPED_TRACETest, WorksInLoop) {
202 printf(
"(expected to fail)\n");
204 for (
int i = 1; i <= 2; i++) {
212TEST(SCOPED_TRACETest, WorksInSubroutine) {
213 printf(
"(expected to fail)\n");
220TEST(SCOPED_TRACETest, CanBeNested) {
221 printf(
"(expected to fail)\n");
229TEST(SCOPED_TRACETest, CanBeRepeated) {
230 printf(
"(expected to fail)\n");
234 <<
"This failure is expected, and should contain trace point A.";
238 <<
"This failure is expected, and should contain trace point A and B.";
242 ADD_FAILURE() <<
"This failure is expected, and should "
243 <<
"contain trace point A, B, and C.";
247 ADD_FAILURE() <<
"This failure is expected, and should "
248 <<
"contain trace point A, B, and D.";
251#if GTEST_IS_THREADSAFE
287static void ThreadWithScopedTrace(CheckPoints* check_points) {
291 <<
"Expected failure #1 (in thread B, only trace B alive).";
292 check_points->n1.Notify();
293 check_points->n2.WaitForNotification();
296 <<
"Expected failure #3 (in thread B, trace A & B both alive).";
299 <<
"Expected failure #4 (in thread B, only trace A alive).";
300 check_points->n3.Notify();
303TEST(SCOPED_TRACETest, WorksConcurrently) {
304 printf(
"(expecting 6 failures)\n");
306 CheckPoints check_points;
307 ThreadWithParam<CheckPoints*> thread(&ThreadWithScopedTrace,
310 check_points.n1.WaitForNotification();
315 <<
"Expected failure #2 (in thread A, trace A & B both alive).";
316 check_points.n2.Notify();
317 check_points.n3.WaitForNotification();
320 <<
"Expected failure #5 (in thread A, only trace A alive).";
323 <<
"Expected failure #6 (in thread A, no trace alive).";
330TEST(ScopedTraceTest, WithExplicitFileAndLine) {
332 ADD_FAILURE() <<
"Check that the trace is attached to a particular location.";
336 DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning) {
347 printf(
"The non-test part of the code is expected to have 2 failures.\n\n");
362 printf(
"(expecting 5 failures)\n");
363 ADD_FAILURE() <<
"Expected failure #1, in the test fixture c'tor.";
367 ADD_FAILURE() <<
"Expected failure #5, in the test fixture d'tor.";
371 ADD_FAILURE() <<
"Expected failure #2, in SetUp().";
375 ADD_FAILURE() <<
"Expected failure #4, in TearDown.";
380 ADD_FAILURE() <<
"Expected failure #3, in the test body.";
387 printf(
"(expecting 2 failures)\n");
392 ADD_FAILURE() <<
"Expected failure #2, in the test fixture d'tor.";
397 <<
"We should never get here, as the test fixture c'tor "
398 <<
"had a fatal failure.";
402 ADD_FAILURE() <<
"UNEXPECTED failure in TearDown(). "
403 <<
"We should never get here, as the test fixture c'tor "
404 <<
"had a fatal failure.";
409 FAIL() <<
"Expected failure #1, in the test fixture c'tor.";
414 ADD_FAILURE() <<
"UNEXPECTED failure in the test body. "
415 <<
"We should never get here, as the test fixture c'tor "
416 <<
"had a fatal failure.";
427 printf(
"(expecting 4 failures)\n");
428 ADD_FAILURE() <<
"Expected failure #1, in SetUp().";
432 FAIL() <<
"Expected failure #3, in TearDown().";
436 FAIL() <<
"Expected failure #4, in the test fixture d'tor.";
441 FAIL() <<
"Expected failure #2, in the test function.";
452 printf(
"(expecting 3 failures)\n");
453 FAIL() <<
"Expected failure #1, in SetUp().";
457 FAIL() <<
"Expected failure #2, in TearDown().";
461 FAIL() <<
"Expected failure #3, in the test fixture d'tor.";
466 FAIL() <<
"UNEXPECTED failure in the test function. "
467 <<
"We should never get here, as SetUp() failed.";
470TEST(AddFailureAtTest, MessageContainsSpecifiedFileAndLineNumber) {
474#if GTEST_IS_THREADSAFE
477void DieIf(
bool should_die) {
478 GTEST_CHECK_(!should_die) <<
" - death inside DieIf().";
484struct SpawnThreadNotifications {
485 SpawnThreadNotifications() {}
487 Notification spawn_thread_started;
488 Notification spawn_thread_ok_to_terminate;
496static void ThreadRoutine(SpawnThreadNotifications* notifications) {
498 notifications->spawn_thread_started.Notify();
501 notifications->spawn_thread_ok_to_terminate.WaitForNotification();
510 virtual void SetUp() {
511 thread_.reset(
new ThreadWithParam<SpawnThreadNotifications*>(
512 &ThreadRoutine, ¬ifications_, NULL));
513 notifications_.spawn_thread_started.WaitForNotification();
521 notifications_.spawn_thread_ok_to_terminate.Notify();
525 SpawnThreadNotifications notifications_;
554 TheSecondTestWithThisNameShouldFail) {}
574 TheSecondTestWithThisNameShouldFail) {}
606TEST(ExpectNonfatalFailureTest, CanReferenceGlobalVariables) {
610 },
"Expected non-fatal failure.");
615TEST(ExpectNonfatalFailureTest, CanReferenceLocalVariables) {
620 EXPECT_EQ(m, n) <<
"Expected non-fatal failure.";
621 },
"Expected non-fatal failure.");
626TEST(ExpectNonfatalFailureTest, SucceedsWhenThereIsOneNonfatalFailure) {
629 },
"Expected non-fatal failure.");
634TEST(ExpectNonfatalFailureTest, FailsWhenThereIsNoNonfatalFailure) {
635 printf(
"(expecting a failure)\n");
642TEST(ExpectNonfatalFailureTest, FailsWhenThereAreTwoNonfatalFailures) {
643 printf(
"(expecting a failure)\n");
652TEST(ExpectNonfatalFailureTest, FailsWhenThereIsOneFatalFailure) {
653 printf(
"(expecting a failure)\n");
655 FAIL() <<
"Expected fatal failure.";
661TEST(ExpectNonfatalFailureTest, FailsWhenStatementReturns) {
662 printf(
"(expecting a failure)\n");
668#if GTEST_HAS_EXCEPTIONS
672TEST(ExpectNonfatalFailureTest, FailsWhenStatementThrows) {
673 printf(
"(expecting a failure)\n");
685TEST(ExpectFatalFailureTest, CanReferenceGlobalVariables) {
689 },
"Expected fatal failure.");
694TEST(ExpectFatalFailureTest, CanReferenceLocalStaticVariables) {
698 ASSERT_EQ(0, n) <<
"Expected fatal failure.";
699 },
"Expected fatal failure.");
704TEST(ExpectFatalFailureTest, SucceedsWhenThereIsOneFatalFailure) {
706 FAIL() <<
"Expected fatal failure.";
707 },
"Expected fatal failure.");
712TEST(ExpectFatalFailureTest, FailsWhenThereIsNoFatalFailure) {
713 printf(
"(expecting a failure)\n");
720 FAIL() <<
"Expected fatal failure.";
725TEST(ExpectFatalFailureTest, FailsWhenThereAreTwoFatalFailures) {
726 printf(
"(expecting a failure)\n");
735TEST(ExpectFatalFailureTest, FailsWhenThereIsOneNonfatalFailure) {
736 printf(
"(expecting a failure)\n");
744TEST(ExpectFatalFailureTest, FailsWhenStatementReturns) {
745 printf(
"(expecting a failure)\n");
751#if GTEST_HAS_EXCEPTIONS
755TEST(ExpectFatalFailureTest, FailsWhenStatementThrows) {
756 printf(
"(expecting a failure)\n");
781 EXPECT_EQ(
"b", GetParam()) <<
"Expected failure";
790#if GTEST_HAS_TYPED_TEST
803 EXPECT_EQ(1, TypeParam()) <<
"Expected failure";
809#if GTEST_HAS_TYPED_TEST_P
822 EXPECT_EQ(1U, TypeParam()) <<
"Expected failure";
827typedef testing::Types<unsigned char, unsigned int> UnsignedTypes;
832#if GTEST_HAS_DEATH_TEST
837TEST(ADeathTest, ShouldRunFirst) {
840# if GTEST_HAS_TYPED_TEST
849typedef testing::Types<int, double> NumericTypes;
857# if GTEST_HAS_TYPED_TEST_P
890 FAIL() <<
"Expected fatal failure.";
899 printf(
"(expecting 1 failure)\n");
902 printf(
"(expecting 1 failure)\n");
906 printf(
"(expecting 1 failure)\n");
913 printf(
"(expecting 1 failure)\n");
916 printf(
"(expecting 1 failure)\n");
919 printf(
"(expecting 1 failure)\n");
924#if GTEST_IS_THREADSAFE
928 static void AddFailureInOtherThread(FailureMode failure) {
929 ThreadWithParam<FailureMode> thread(&AddFailure, failure, NULL);
934TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailure) {
936 printf(
"(expecting 2 failures)\n");
938 "Expected fatal failure.");
941TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailure) {
943 printf(
"(expecting 2 failures)\n");
945 "Expected non-fatal failure.");
948typedef ExpectFailureWithThreadsTest ScopedFakeTestPartResultReporterTest;
952TEST_F(ScopedFakeTestPartResultReporterTest, InterceptOnlyCurrentThread) {
953 printf(
"(expecting 2 failures)\n");
956 ScopedFakeTestPartResultReporter reporter(
957 ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
959 AddFailureInOtherThread(FATAL_FAILURE);
960 AddFailureInOtherThread(NONFATAL_FAILURE);
970 printf(
"(expecting 1 failure)\n");
973 printf(
"(expecting 1 failure)\n");
975 "Expected non-fatal failure.");
977 printf(
"(expecting 1 failure)\n");
979 "Some other fatal failure expected.");
984 printf(
"(expecting 1 failure)\n");
988 printf(
"(expecting 1 failure)\n");
990 "Expected fatal failure.");
992 printf(
"(expecting 1 failure)\n");
994 "Some other non-fatal failure.");
1003 printf(
"%s",
"FooEnvironment::SetUp() called.\n");
1007 printf(
"%s",
"FooEnvironment::TearDown() called.\n");
1008 FAIL() <<
"Expected fatal failure.";
1015 printf(
"%s",
"BarEnvironment::SetUp() called.\n");
1019 printf(
"%s",
"BarEnvironment::TearDown() called.\n");
1030 testing::GTEST_FLAG(print_time) =
false;
1040 bool internal_skip_environment_and_ad_hoc_tests =
1042 std::string(
"internal_skip_environment_and_ad_hoc_tests")) > 0;
1044#if GTEST_HAS_DEATH_TEST
1045 if (testing::internal::GTEST_FLAG(internal_run_death_test) !=
"") {
1048# if GTEST_OS_WINDOWS
1057 if (internal_skip_environment_and_ad_hoc_tests)
static void AddFailure(FailureMode failure)
FatalFailureInFixtureConstructorTest()
~FatalFailureInFixtureConstructorTest()
virtual ~FatalFailureInSetUpTest()
~NonFatalFailureInFixtureConstructorTest()
NonFatalFailureInFixtureConstructorTest()
virtual ~NonFatalFailureInSetUpTest()
static bool HasFatalFailure()
#define INSTANTIATE_TEST_CASE_P(prefix, test_case_name, generator,...)
#define TEST_P(test_case_name, test_name)
#define GTEST_CHECK_(condition)
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
#define EXPECT_FATAL_FAILURE(statement, substr)
#define EXPECT_NONFATAL_FAILURE(statement, substr)
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr)
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr)
#define TEST_F(test_fixture, test_name)
#define ASSERT_EQ(val1, val2)
#define EXPECT_EQ(val1, val2)
#define ADD_FAILURE_AT(file, line)
#define SCOPED_TRACE(message)
#define ASSERT_FALSE(condition)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
#define EXPECT_GE(val1, val2)
#define EXPECT_TRUE(condition)
#define TEST(test_case_name, test_name)
REGISTER_TYPED_TEST_CASE_P(TypeParamTest, TestA, TestB)
TYPED_TEST(TypedTest, TestA)
TYPED_TEST_CASE(TypedTest, MyTypes)
TYPED_TEST_CASE_P(TypeParamTest)
TYPED_TEST_P(TypeParamTest, TestA)
INSTANTIATE_TYPED_TEST_CASE_P(My, TypeParamTest, MyTypes)
std::string ParamNameFunc(const testing::TestParamInfo< std::string > &info)
void SubWithoutTrace(int n)
LOGGING_API void printf(Category category, const char *format,...)
FILE * FReopen(const char *path, const char *mode, FILE *stream)
internal::ValueArray1< T1 > Values(T1 v1)
Environment * AddGlobalTestEnvironment(Environment *env)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
account_query_db::get_accounts_by_authorizers_result results