46#if GTEST_IS_THREADSAFE
47using testing::ScopedFakeTestPartResultReporter;
48using testing::TestPartResultArray;
50using testing::internal::Notification;
51using testing::internal::ThreadWithParam;
54namespace posix = ::testing::internal::posix;
76 FAIL() <<
"This should never be reached.";
79TEST(PassingTest, PassingTest1) {
82TEST(PassingTest, PassingTest2) {
109TEST(NonfatalFailureTest, EscapesStringOperands) {
110 std::string actual =
"actual \"string\"";
117TEST(NonfatalFailureTest, DiffForLongStrings) {
123TEST(FatalFailureTest, FatalFailureInSubroutine) {
124 printf(
"(expecting a failure that x should be 1)\n");
130TEST(FatalFailureTest, FatalFailureInNestedSubroutine) {
131 printf(
"(expecting a failure that x should be 1)\n");
140 if (HasFatalFailure())
return;
143 FAIL() <<
"This should never be reached.";
147TEST(FatalFailureTest, NonfatalFailureInSubroutine) {
148 printf(
"(expecting a failure on false)\n");
154TEST(LoggingTest, InterleavingLoggingAndAssertions) {
155 static const int a[4] = {
159 printf(
"(expecting 2 failures on (3) >= (a[i]))\n");
160 for (
int i = 0; i < static_cast<int>(
sizeof(
a)/
sizeof(*
a));
i++) {
161 printf(
"i == %d\n",
i);
181TEST(SCOPED_TRACETest, AcceptedValues) {
185 const char* null_value =
nullptr;
188 ADD_FAILURE() <<
"Just checking that all these values work fine.";
192TEST(SCOPED_TRACETest, ObeysScopes) {
193 printf(
"(expected to fail)\n");
196 ADD_FAILURE() <<
"This failure is expected, and shouldn't have a trace.";
202 ADD_FAILURE() <<
"This failure is expected, and should have a trace.";
207 ADD_FAILURE() <<
"This failure is expected, and shouldn't have a trace.";
211TEST(SCOPED_TRACETest, WorksInLoop) {
212 printf(
"(expected to fail)\n");
214 for (
int i = 1;
i <= 2;
i++) {
222TEST(SCOPED_TRACETest, WorksInSubroutine) {
223 printf(
"(expected to fail)\n");
230TEST(SCOPED_TRACETest, CanBeNested) {
231 printf(
"(expected to fail)\n");
239TEST(SCOPED_TRACETest, CanBeRepeated) {
240 printf(
"(expected to fail)\n");
244 <<
"This failure is expected, and should contain trace point A.";
248 <<
"This failure is expected, and should contain trace point A and B.";
252 ADD_FAILURE() <<
"This failure is expected, and should "
253 <<
"contain trace point A, B, and C.";
257 ADD_FAILURE() <<
"This failure is expected, and should "
258 <<
"contain trace point A, B, and D.";
261#if GTEST_IS_THREADSAFE
297static void ThreadWithScopedTrace(CheckPoints* check_points) {
301 <<
"Expected failure #1 (in thread B, only trace B alive).";
302 check_points->n1.Notify();
303 check_points->n2.WaitForNotification();
306 <<
"Expected failure #3 (in thread B, trace A & B both alive).";
309 <<
"Expected failure #4 (in thread B, only trace A alive).";
310 check_points->n3.Notify();
313TEST(SCOPED_TRACETest, WorksConcurrently) {
314 printf(
"(expecting 6 failures)\n");
316 CheckPoints check_points;
317 ThreadWithParam<CheckPoints*> thread(&ThreadWithScopedTrace, &check_points,
319 check_points.n1.WaitForNotification();
324 <<
"Expected failure #2 (in thread A, trace A & B both alive).";
325 check_points.n2.Notify();
326 check_points.n3.WaitForNotification();
329 <<
"Expected failure #5 (in thread A, only trace A alive).";
332 <<
"Expected failure #6 (in thread A, no trace alive).";
339TEST(ScopedTraceTest, WithExplicitFileAndLine) {
341 ADD_FAILURE() <<
"Check that the trace is attached to a particular location.";
345 DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning) {
356 printf(
"The non-test part of the code is expected to have 2 failures.\n\n");
371 printf(
"(expecting 5 failures)\n");
372 ADD_FAILURE() <<
"Expected failure #1, in the test fixture c'tor.";
376 ADD_FAILURE() <<
"Expected failure #5, in the test fixture d'tor.";
382 ADD_FAILURE() <<
"Expected failure #4, in TearDown.";
387 ADD_FAILURE() <<
"Expected failure #3, in the test body.";
394 printf(
"(expecting 2 failures)\n");
399 ADD_FAILURE() <<
"Expected failure #2, in the test fixture d'tor.";
404 <<
"We should never get here, as the test fixture c'tor "
405 <<
"had a fatal failure.";
409 ADD_FAILURE() <<
"UNEXPECTED failure in TearDown(). "
410 <<
"We should never get here, as the test fixture c'tor "
411 <<
"had a fatal failure.";
416 FAIL() <<
"Expected failure #1, in the test fixture c'tor.";
421 ADD_FAILURE() <<
"UNEXPECTED failure in the test body. "
422 <<
"We should never get here, as the test fixture c'tor "
423 <<
"had a fatal failure.";
432 printf(
"(expecting 4 failures)\n");
433 ADD_FAILURE() <<
"Expected failure #1, in SetUp().";
436 void TearDown()
override {
FAIL() <<
"Expected failure #3, in TearDown()."; }
440 FAIL() <<
"Expected failure #4, in the test fixture d'tor.";
445 FAIL() <<
"Expected failure #2, in the test function.";
454 printf(
"(expecting 3 failures)\n");
455 FAIL() <<
"Expected failure #1, in SetUp().";
458 void TearDown()
override {
FAIL() <<
"Expected failure #2, in TearDown()."; }
462 FAIL() <<
"Expected failure #3, in the test fixture d'tor.";
467 FAIL() <<
"UNEXPECTED failure in the test function. "
468 <<
"We should never get here, as SetUp() failed.";
471TEST(AddFailureAtTest, MessageContainsSpecifiedFileAndLineNumber) {
472 ADD_FAILURE_AT(
"foo.cc", 42) <<
"Expected nonfatal failure in foo.cc";
475TEST(GtestFailAtTest, MessageContainsSpecifiedFileAndLineNumber) {
476 GTEST_FAIL_AT(
"foo.cc", 42) <<
"Expected fatal failure in foo.cc";
501 TheSecondTestWithThisNameShouldFail) {}
521 TheSecondTestWithThisNameShouldFail) {}
553TEST(ExpectNonfatalFailureTest, CanReferenceGlobalVariables) {
557 },
"Expected non-fatal failure.");
562TEST(ExpectNonfatalFailureTest, CanReferenceLocalVariables) {
567 EXPECT_EQ(m, n) <<
"Expected non-fatal failure.";
568 },
"Expected non-fatal failure.");
573TEST(ExpectNonfatalFailureTest, SucceedsWhenThereIsOneNonfatalFailure) {
576 },
"Expected non-fatal failure.");
581TEST(ExpectNonfatalFailureTest, FailsWhenThereIsNoNonfatalFailure) {
582 printf(
"(expecting a failure)\n");
589TEST(ExpectNonfatalFailureTest, FailsWhenThereAreTwoNonfatalFailures) {
590 printf(
"(expecting a failure)\n");
599TEST(ExpectNonfatalFailureTest, FailsWhenThereIsOneFatalFailure) {
600 printf(
"(expecting a failure)\n");
602 FAIL() <<
"Expected fatal failure.";
608TEST(ExpectNonfatalFailureTest, FailsWhenStatementReturns) {
609 printf(
"(expecting a failure)\n");
615#if GTEST_HAS_EXCEPTIONS
619TEST(ExpectNonfatalFailureTest, FailsWhenStatementThrows) {
620 printf(
"(expecting a failure)\n");
632TEST(ExpectFatalFailureTest, CanReferenceGlobalVariables) {
636 },
"Expected fatal failure.");
641TEST(ExpectFatalFailureTest, CanReferenceLocalStaticVariables) {
645 ASSERT_EQ(0, n) <<
"Expected fatal failure.";
646 },
"Expected fatal failure.");
651TEST(ExpectFatalFailureTest, SucceedsWhenThereIsOneFatalFailure) {
653 FAIL() <<
"Expected fatal failure.";
654 },
"Expected fatal failure.");
659TEST(ExpectFatalFailureTest, FailsWhenThereIsNoFatalFailure) {
660 printf(
"(expecting a failure)\n");
667 FAIL() <<
"Expected fatal failure.";
672TEST(ExpectFatalFailureTest, FailsWhenThereAreTwoFatalFailures) {
673 printf(
"(expecting a failure)\n");
682TEST(ExpectFatalFailureTest, FailsWhenThereIsOneNonfatalFailure) {
683 printf(
"(expecting a failure)\n");
691TEST(ExpectFatalFailureTest, FailsWhenStatementReturns) {
692 printf(
"(expecting a failure)\n");
698#if GTEST_HAS_EXCEPTIONS
702TEST(ExpectFatalFailureTest, FailsWhenStatementThrows) {
703 printf(
"(expecting a failure)\n");
728 EXPECT_EQ(
"b", GetParam()) <<
"Expected failure";
748#if GTEST_HAS_TYPED_TEST
761 EXPECT_EQ(1, TypeParam()) <<
"Expected failure";
769class TypedTestNames {
771 template <
typename T>
772 static std::string GetName(
int i) {
773 if (std::is_same<T, char>::value)
775 if (std::is_same<T, int>::value)
789#if GTEST_HAS_TYPED_TEST_P
802 EXPECT_EQ(1U, TypeParam()) <<
"Expected failure";
810class TypedTestPNames {
812 template <
typename T>
813 static std::string GetName(
int i) {
814 if (std::is_same<T, unsigned char>::value) {
817 if (std::is_same<T, unsigned int>::value) {
827class DetectNotInstantiatedTypesTest :
public testing::Test {};
830 TypeParam instantiate;
843#if GTEST_HAS_DEATH_TEST
848TEST(ADeathTest, ShouldRunFirst) {
851# if GTEST_HAS_TYPED_TEST
868# if GTEST_HAS_TYPED_TEST_P
901 FAIL() <<
"Expected fatal failure.";
910 printf(
"(expecting 1 failure)\n");
913 printf(
"(expecting 1 failure)\n");
917 printf(
"(expecting 1 failure)\n");
924 printf(
"(expecting 1 failure)\n");
927 printf(
"(expecting 1 failure)\n");
930 printf(
"(expecting 1 failure)\n");
935#if GTEST_IS_THREADSAFE
939 static void AddFailureInOtherThread(FailureMode failure) {
940 ThreadWithParam<FailureMode> thread(&AddFailure, failure,
nullptr);
945TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailure) {
947 printf(
"(expecting 2 failures)\n");
949 "Expected fatal failure.");
952TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailure) {
954 printf(
"(expecting 2 failures)\n");
956 "Expected non-fatal failure.");
959typedef ExpectFailureWithThreadsTest ScopedFakeTestPartResultReporterTest;
963TEST_F(ScopedFakeTestPartResultReporterTest, InterceptOnlyCurrentThread) {
964 printf(
"(expecting 2 failures)\n");
965 TestPartResultArray results;
967 ScopedFakeTestPartResultReporter reporter(
968 ScopedFakeTestPartResultReporter::INTERCEPT_ONLY_CURRENT_THREAD,
970 AddFailureInOtherThread(FATAL_FAILURE);
971 AddFailureInOtherThread(NONFATAL_FAILURE);
974 EXPECT_EQ(0, results.size()) <<
"This shouldn't fail.";
981 printf(
"(expecting 1 failure)\n");
984 printf(
"(expecting 1 failure)\n");
986 "Expected non-fatal failure.");
988 printf(
"(expecting 1 failure)\n");
990 "Some other fatal failure expected.");
995 printf(
"(expecting 1 failure)\n");
999 printf(
"(expecting 1 failure)\n");
1001 "Expected fatal failure.");
1003 printf(
"(expecting 1 failure)\n");
1005 "Some other non-fatal failure.");
1012 void SetUp()
override { printf(
"DynamicFixture::SetUp\n"); }
1013 void TearDown()
override { printf(
"DynamicFixture::TearDown\n"); }
1017 printf(
"DynamicFixture::TearDownTestSuite\n");
1030 "DynamicFixture",
"DynamicTestPass",
nullptr,
nullptr, __FILE__,
1033 "DynamicFixture",
"DynamicTestFail",
nullptr,
nullptr, __FILE__,
1038 "DynamicFixtureAnotherName",
"DynamicTestPass",
nullptr,
nullptr,
1044 "BadDynamicFixture1",
"FixtureBase",
nullptr,
nullptr, __FILE__,
1047 "BadDynamicFixture1",
"TestBase",
nullptr,
nullptr, __FILE__, __LINE__,
1053 "BadDynamicFixture2",
"FixtureBase",
nullptr,
nullptr, __FILE__,
1063 void SetUp()
override { printf(
"%s",
"FooEnvironment::SetUp() called.\n"); }
1066 printf(
"%s",
"FooEnvironment::TearDown() called.\n");
1067 FAIL() <<
"Expected fatal failure.";
1073 void SetUp()
override { printf(
"%s",
"BarEnvironment::SetUp() called.\n"); }
1076 printf(
"%s",
"BarEnvironment::TearDown() called.\n");
1087 testing::GTEST_FLAG(print_time) =
false;
1097 bool internal_skip_environment_and_ad_hoc_tests =
1098 std::count(argv, argv + argc,
1099 std::string(
"internal_skip_environment_and_ad_hoc_tests")) > 0;
1101#if GTEST_HAS_DEATH_TEST
1102 if (testing::internal::GTEST_FLAG(internal_run_death_test) !=
"") {
1105# if GTEST_OS_WINDOWS
1114 if (internal_skip_environment_and_ad_hoc_tests)
INSTANTIATE_TYPED_TEST_SUITE_P(CacheFad, FadOpsUnitTest, FadTypes)
TYPED_TEST_P(FadBLASUnitTests, testSCAL1)
TYPED_TEST_SUITE_P(FadBLASUnitTests)
REGISTER_TYPED_TEST_SUITE_P(FadBLASUnitTests, testSCAL1, testSCAL2, testSCAL3, testSCAL4, testCOPY1, testCOPY2, testCOPY3, testCOPY4, testAXPY1, testAXPY2, testAXPY3, testAXPY4, testDOT1, testDOT2, testDOT3, testDOT4, testNRM21, testNRM22, testGEMV1, testGEMV2, testGEMV3, testGEMV4, testGEMV5, testGEMV6, testGEMV7, testGEMV8, testGEMV9, testTRMV1, testTRMV2, testTRMV3, testTRMV4, testGER1, testGER2, testGER3, testGER4, testGER5, testGER6, testGER7, testGEMM1, testGEMM2, testGEMM3, testGEMM4, testGEMM5, testGEMM6, testGEMM7, testGEMM8, testGEMM9, testGEMM10, testSYMM1, testSYMM2, testSYMM3, testSYMM4, testSYMM5, testSYMM6, testSYMM7, testSYMM8, testSYMM9, testTRMM1, testTRMM2, testTRMM3, testTRMM4, testTRMM5, testTRMM6, testTRMM7, testTRSM1, testTRSM2, testTRSM3, testTRSM4, testTRSM5, testTRSM6, testTRSM7)
static void TearDownTestSuite()
static void SetUpTestSuite()
~DynamicFixture() override
static void AddFailure(FailureMode failure)
FatalFailureInFixtureConstructorTest()
~FatalFailureInFixtureConstructorTest() override
~FatalFailureInSetUpTest() override
~NonFatalFailureInFixtureConstructorTest() override
NonFatalFailureInFixtureConstructorTest()
~NonFatalFailureInSetUpTest() override
static bool HasFatalFailure()
TYPED_TEST_SUITE(TypedTest, MyTypes)
TYPED_TEST(TypedTest, TestA)
std::string ParamNameFunc(const testing::TestParamInfo< std::string > &info)
static const char kGoldenString[]
void SubWithoutTrace(int n)
#define TEST_P(test_suite_name, test_name)
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name,...)
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
#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 TEST(test_suite_name, test_name)
#define EXPECT_GE(val1, val2)
#define EXPECT_TRUE(condition)
#define GTEST_FAIL_AT(file, line)
FILE * FReopen(const char *path, const char *mode, FILE *stream)
Environment * AddGlobalTestEnvironment(Environment *env)
internal::ProxyTypeList< Ts... > Types
TestInfo * RegisterTest(const char *test_suite_name, const char *test_name, const char *type_param, const char *value_param, const char *file, int line, Factory factory)
::std::string PrintToString(const T &value)
internal::ValueArray< T... > Values(T... v)
GTEST_API_ void InitGoogleTest()