46 #if GTEST_IS_THREADSAFE
47 using testing::ScopedFakeTestPartResultReporter;
48 using testing::TestPartResultArray;
50 using testing::internal::Notification;
51 using testing::internal::ThreadWithParam;
54 namespace posix = ::testing::internal::posix;
76 FAIL() <<
"This should never be reached.";
79 TEST(PassingTest, PassingTest1) {
82 TEST(PassingTest, PassingTest2) {
109 TEST(NonfatalFailureTest, EscapesStringOperands) {
110 std::string actual =
"actual \"string\"";
117 TEST(NonfatalFailureTest, DiffForLongStrings) {
118 std::string golden_str(kGoldenString,
sizeof(kGoldenString) - 1);
123 TEST(FatalFailureTest, FatalFailureInSubroutine) {
124 printf(
"(expecting a failure that x should be 1)\n");
130 TEST(FatalFailureTest, FatalFailureInNestedSubroutine) {
131 printf(
"(expecting a failure that x should be 1)\n");
140 if (HasFatalFailure())
return;
143 FAIL() <<
"This should never be reached.";
147 TEST(FatalFailureTest, NonfatalFailureInSubroutine) {
148 printf(
"(expecting a failure on false)\n");
154 TEST(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);
181 TEST(SCOPED_TRACETest, AcceptedValues) {
185 const char* null_value =
nullptr;
188 ADD_FAILURE() <<
"Just checking that all these values work fine.";
192 TEST(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.";
211 TEST(SCOPED_TRACETest, WorksInLoop) {
212 printf(
"(expected to fail)\n");
214 for (
int i = 1;
i <= 2;
i++) {
222 TEST(SCOPED_TRACETest, WorksInSubroutine) {
223 printf(
"(expected to fail)\n");
230 TEST(SCOPED_TRACETest, CanBeNested) {
231 printf(
"(expected to fail)\n");
239 TEST(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
297 static 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();
313 TEST(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).";
335 #endif // GTEST_IS_THREADSAFE
339 TEST(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.";
471 TEST(AddFailureAtTest, MessageContainsSpecifiedFileAndLineNumber) {
472 ADD_FAILURE_AT(
"foo.cc", 42) <<
"Expected nonfatal failure in foo.cc";
475 TEST(GtestFailAtTest, MessageContainsSpecifiedFileAndLineNumber) {
476 GTEST_FAIL_AT(
"foo.cc", 42) <<
"Expected fatal failure in foo.cc";
501 TheSecondTestWithThisNameShouldFail) {}
521 TheSecondTestWithThisNameShouldFail) {}
553 TEST(ExpectNonfatalFailureTest, CanReferenceGlobalVariables) {
556 EXPECT_EQ(1, global_integer) <<
"Expected non-fatal failure.";
557 },
"Expected non-fatal failure.");
562 TEST(ExpectNonfatalFailureTest, CanReferenceLocalVariables) {
567 EXPECT_EQ(m, n) <<
"Expected non-fatal failure.";
568 },
"Expected non-fatal failure.");
573 TEST(ExpectNonfatalFailureTest, SucceedsWhenThereIsOneNonfatalFailure) {
576 },
"Expected non-fatal failure.");
581 TEST(ExpectNonfatalFailureTest, FailsWhenThereIsNoNonfatalFailure) {
582 printf(
"(expecting a failure)\n");
589 TEST(ExpectNonfatalFailureTest, FailsWhenThereAreTwoNonfatalFailures) {
590 printf(
"(expecting a failure)\n");
599 TEST(ExpectNonfatalFailureTest, FailsWhenThereIsOneFatalFailure) {
600 printf(
"(expecting a failure)\n");
602 FAIL() <<
"Expected fatal failure.";
608 TEST(ExpectNonfatalFailureTest, FailsWhenStatementReturns) {
609 printf(
"(expecting a failure)\n");
615 #if GTEST_HAS_EXCEPTIONS
619 TEST(ExpectNonfatalFailureTest, FailsWhenStatementThrows) {
620 printf(
"(expecting a failure)\n");
629 #endif // GTEST_HAS_EXCEPTIONS
632 TEST(ExpectFatalFailureTest, CanReferenceGlobalVariables) {
635 ASSERT_EQ(1, global_integer) <<
"Expected fatal failure.";
636 },
"Expected fatal failure.");
641 TEST(ExpectFatalFailureTest, CanReferenceLocalStaticVariables) {
645 ASSERT_EQ(0, n) <<
"Expected fatal failure.";
646 },
"Expected fatal failure.");
651 TEST(ExpectFatalFailureTest, SucceedsWhenThereIsOneFatalFailure) {
653 FAIL() <<
"Expected fatal failure.";
654 },
"Expected fatal failure.");
659 TEST(ExpectFatalFailureTest, FailsWhenThereIsNoFatalFailure) {
660 printf(
"(expecting a failure)\n");
667 FAIL() <<
"Expected fatal failure.";
672 TEST(ExpectFatalFailureTest, FailsWhenThereAreTwoFatalFailures) {
673 printf(
"(expecting a failure)\n");
682 TEST(ExpectFatalFailureTest, FailsWhenThereIsOneNonfatalFailure) {
683 printf(
"(expecting a failure)\n");
691 TEST(ExpectFatalFailureTest, FailsWhenStatementReturns) {
692 printf(
"(expecting a failure)\n");
698 #if GTEST_HAS_EXCEPTIONS
702 TEST(ExpectFatalFailureTest, FailsWhenStatementThrows) {
703 printf(
"(expecting a failure)\n");
712 #endif // GTEST_HAS_EXCEPTIONS
728 EXPECT_EQ(
"b", GetParam()) <<
"Expected failure";
748 #if GTEST_HAS_TYPED_TEST
750 template <
typename T>
761 EXPECT_EQ(1, TypeParam()) <<
"Expected failure";
766 template <
typename T>
769 class TypedTestNames {
771 template <
typename T>
772 static std::string GetName(
int i) {
780 TYPED_TEST_SUITE(TypedTestWithNames, TypesForTestWithNames, TypedTestNames);
786 #endif // GTEST_HAS_TYPED_TEST
789 #if GTEST_HAS_TYPED_TEST_P
791 template <
typename T>
802 EXPECT_EQ(1U, TypeParam()) <<
"Expected failure";
810 class TypedTestPNames {
812 template <
typename T>
813 static std::string GetName(
int i) {
826 template <
typename T>
827 class DetectNotInstantiatedTypesTest :
public testing::Test {};
830 TypeParam instantiate;
841 #endif // GTEST_HAS_TYPED_TEST_P
843 #if GTEST_HAS_DEATH_TEST
848 TEST(ADeathTest, ShouldRunFirst) {
851 # if GTEST_HAS_TYPED_TEST
856 template <
typename T>
866 # endif // GTEST_HAS_TYPED_TEST
868 # if GTEST_HAS_TYPED_TEST_P
874 template <
typename T>
887 # endif // GTEST_HAS_TYPED_TEST_P
889 #endif // GTEST_HAS_DEATH_TEST
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);
945 TEST_F(ExpectFailureWithThreadsTest, ExpectFatalFailure) {
947 printf(
"(expecting 2 failures)\n");
949 "Expected fatal failure.");
952 TEST_F(ExpectFailureWithThreadsTest, ExpectNonFatalFailure) {
954 printf(
"(expecting 2 failures)\n");
956 "Expected non-fatal failure.");
959 typedef ExpectFailureWithThreadsTest ScopedFakeTestPartResultReporterTest;
963 TEST_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.";
977 #endif // GTEST_IS_THREADSAFE
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");
1021 template <
bool Pass>
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");
1097 bool internal_skip_environment_and_ad_hoc_tests =
1099 std::string(
"internal_skip_environment_and_ad_hoc_tests")) > 0;
1101 #if GTEST_HAS_DEATH_TEST
1105 # if GTEST_OS_WINDOWS
1109 # endif // GTEST_OS_WINDOWS
1112 #endif // GTEST_HAS_DEATH_TEST
1114 if (internal_skip_environment_and_ad_hoc_tests)
FILE * FReopen(const char *path, const char *mode, FILE *stream)
internal::ValueArray< T...> Values(T...v)
Environment * AddGlobalTestEnvironment(Environment *env)
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 bool HasFatalFailure()
#define EXPECT_NONFATAL_FAILURE(statement, substr)
TYPED_TEST_P(FadBLASUnitTests, testSCAL1)
~FatalFailureInSetUpTest() override
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
::std::string PrintToString(const T &value)
NonFatalFailureInFixtureConstructorTest()
static void SetUpTestSuite()
#define TEST_F(test_fixture, test_name)
#define EXPECT_GE(val1, val2)
#define ADD_FAILURE_AT(file, line)
#define TEST(test_suite_name, test_name)
#define ASSERT_EQ(val1, val2)
~NonFatalFailureInSetUpTest() override
internal::ProxyTypeList< Ts...> Types
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr)
#define EXPECT_FATAL_FAILURE(statement, substr)
#define GTEST_FAIL_AT(file, line)
~NonFatalFailureInFixtureConstructorTest() override
void SubWithoutTrace(int n)
TEST_F(MixedUpTestSuiteTest, FirstTestFromNamespaceFoo)
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
TYPED_TEST_SUITE(TypedTest, MyTypes)
ADVar foo(double d, ADVar x, ADVar y)
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)
TEST_F(MixedUpTestSuiteTest, ThisShouldFail)
static void AddFailure(FailureMode failure)
static const char kGoldenString[]
~FatalFailureInFixtureConstructorTest() override
#define SCOPED_TRACE(message)
TYPED_TEST(FunctionMockerTest, MocksVoidFunction)
FatalFailureInFixtureConstructorTest()
TYPED_TEST_SUITE_P(FadBLASUnitTests)
#define EXPECT_EQ(val1, val2)
#define TEST_P(test_suite_name, test_name)
static void TearDownTestSuite()
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr)
INSTANTIATE_TYPED_TEST_SUITE_P(CacheFad, FadOpsUnitTest, FadTypes)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
#define EXPECT_TRUE(condition)
std::string ParamNameFunc(const testing::TestParamInfo< std::string > &info)
#define INSTANTIATE_TEST_SUITE_P(prefix, test_suite_name,...)
#define ASSERT_FALSE(condition)
~DynamicFixture() override