tesseract v5.3.3.20231005
googletest-output-test_.cc File Reference
#include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
#include "src/gtest-internal-inl.h"
#include <stdlib.h>

Go to the source code of this file.

Classes

class  FailingParamTest
 
class  EmptyBasenameParamInst
 
class  NonFatalFailureInFixtureConstructorTest
 
class  FatalFailureInFixtureConstructorTest
 
class  NonFatalFailureInSetUpTest
 
class  FatalFailureInSetUpTest
 
class  foo::MixedUpTestSuiteTest
 
class  foo::MixedUpTestSuiteWithSameTestNameTest
 
class  bar::MixedUpTestSuiteTest
 
class  bar::MixedUpTestSuiteWithSameTestNameTest
 
class  TEST_F_before_TEST_in_same_test_case
 
class  TEST_before_TEST_F_in_same_test_case
 
class  ParamTest
 
class  DetectNotInstantiatedTest
 
class  TypedTest< T >
 
class  TypedTestWithNames< T >
 
class  TypedTestNames
 
class  TypedTestP< T >
 
class  TypedTestPNames
 
class  DetectNotInstantiatedTypesTest< T >
 
class  ExpectFailureTest
 
class  DynamicFixture
 
class  DynamicTest< Pass >
 
class  FooEnvironment
 
class  BarEnvironment
 

Namespaces

namespace  foo
 
namespace  bar
 

Typedefs

using NoTests = ParamTest
 
typedef testing::Types< char, int > TypesForTestWithNames
 
typedef testing::Types< unsigned char, unsigned int > UnsignedTypes
 

Functions

void TestEq1 (int x)
 
void TryTestSubroutine ()
 
 TEST (PassingTest, PassingTest1)
 
 TEST (PassingTest, PassingTest2)
 
 TEST_P (FailingParamTest, Fails)
 
 INSTANTIATE_TEST_SUITE_P (PrintingFailingParams, FailingParamTest, testing::Values(2))
 
 TEST_P (EmptyBasenameParamInst, Passes)
 
 INSTANTIATE_TEST_SUITE_P (, EmptyBasenameParamInst, testing::Values(1))
 
 TEST (NonfatalFailureTest, EscapesStringOperands)
 
 TEST (NonfatalFailureTest, DiffForLongStrings)
 
 TEST (FatalFailureTest, FatalFailureInSubroutine)
 
 TEST (FatalFailureTest, FatalFailureInNestedSubroutine)
 
 TEST (FatalFailureTest, NonfatalFailureInSubroutine)
 
 TEST (LoggingTest, InterleavingLoggingAndAssertions)
 
void SubWithoutTrace (int n)
 
void SubWithTrace (int n)
 
 TEST (SCOPED_TRACETest, AcceptedValues)
 
 TEST (SCOPED_TRACETest, ObeysScopes)
 
 TEST (SCOPED_TRACETest, WorksInLoop)
 
 TEST (SCOPED_TRACETest, WorksInSubroutine)
 
 TEST (SCOPED_TRACETest, CanBeNested)
 
 TEST (SCOPED_TRACETest, CanBeRepeated)
 
 TEST (ScopedTraceTest, WithExplicitFileAndLine)
 
 TEST (DisabledTestsWarningTest, DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning)
 
void AdHocTest ()
 
int RunAllTests ()
 
 TEST_F (NonFatalFailureInFixtureConstructorTest, FailureInConstructor)
 
 TEST_F (FatalFailureInFixtureConstructorTest, FailureInConstructor)
 
 TEST_F (NonFatalFailureInSetUpTest, FailureInSetUp)
 
 TEST_F (FatalFailureInSetUpTest, FailureInSetUp)
 
 TEST (AddFailureAtTest, MessageContainsSpecifiedFileAndLineNumber)
 
 TEST (GtestFailAtTest, MessageContainsSpecifiedFileAndLineNumber)
 
 foo::TEST_F (MixedUpTestSuiteTest, FirstTestFromNamespaceFoo)
 
 foo::TEST_F (MixedUpTestSuiteTest, SecondTestFromNamespaceFoo)
 
 foo::TEST_F (MixedUpTestSuiteWithSameTestNameTest, TheSecondTestWithThisNameShouldFail)
 
 bar::TEST_F (MixedUpTestSuiteTest, ThisShouldFail)
 
 bar::TEST_F (MixedUpTestSuiteTest, ThisShouldFailToo)
 
 bar::TEST_F (MixedUpTestSuiteWithSameTestNameTest, TheSecondTestWithThisNameShouldFail)
 
 TEST_F (TEST_F_before_TEST_in_same_test_case, DefinedUsingTEST_F)
 
 TEST (TEST_F_before_TEST_in_same_test_case, DefinedUsingTESTAndShouldFail)
 
 TEST (TEST_before_TEST_F_in_same_test_case, DefinedUsingTEST)
 
 TEST_F (TEST_before_TEST_F_in_same_test_case, DefinedUsingTEST_FAndShouldFail)
 
 TEST (ExpectNonfatalFailureTest, CanReferenceGlobalVariables)
 
 TEST (ExpectNonfatalFailureTest, CanReferenceLocalVariables)
 
 TEST (ExpectNonfatalFailureTest, SucceedsWhenThereIsOneNonfatalFailure)
 
 TEST (ExpectNonfatalFailureTest, FailsWhenThereIsNoNonfatalFailure)
 
 TEST (ExpectNonfatalFailureTest, FailsWhenThereAreTwoNonfatalFailures)
 
 TEST (ExpectNonfatalFailureTest, FailsWhenThereIsOneFatalFailure)
 
 TEST (ExpectNonfatalFailureTest, FailsWhenStatementReturns)
 
 TEST (ExpectFatalFailureTest, CanReferenceGlobalVariables)
 
 TEST (ExpectFatalFailureTest, CanReferenceLocalStaticVariables)
 
 TEST (ExpectFatalFailureTest, SucceedsWhenThereIsOneFatalFailure)
 
 TEST (ExpectFatalFailureTest, FailsWhenThereIsNoFatalFailure)
 
void FatalFailure ()
 
 TEST (ExpectFatalFailureTest, FailsWhenThereAreTwoFatalFailures)
 
 TEST (ExpectFatalFailureTest, FailsWhenThereIsOneNonfatalFailure)
 
 TEST (ExpectFatalFailureTest, FailsWhenStatementReturns)
 
std::string ParamNameFunc (const testing::TestParamInfo< std::string > &info)
 
 TEST_P (ParamTest, Success)
 
 TEST_P (ParamTest, Failure)
 
 INSTANTIATE_TEST_SUITE_P (PrintingStrings, ParamTest, testing::Values(std::string("a")), ParamNameFunc)
 
 INSTANTIATE_TEST_SUITE_P (ThisIsOdd, NoTests, ::testing::Values("Hello"))
 
 TEST_P (DetectNotInstantiatedTest, Used)
 
 TYPED_TEST_SUITE (TypedTest, testing::Types< int >)
 
 TYPED_TEST (TypedTest, Success)
 
 TYPED_TEST (TypedTest, Failure)
 
 TYPED_TEST_SUITE (TypedTestWithNames, TypesForTestWithNames, TypedTestNames)
 
 TYPED_TEST (TypedTestWithNames, Success)
 
 TYPED_TEST (TypedTestWithNames, Failure)
 
 TYPED_TEST_SUITE_P (TypedTestP)
 
 TYPED_TEST_P (TypedTestP, Success)
 
 TYPED_TEST_P (TypedTestP, Failure)
 
 REGISTER_TYPED_TEST_SUITE_P (TypedTestP, Success, Failure)
 
 INSTANTIATE_TYPED_TEST_SUITE_P (Unsigned, TypedTestP, UnsignedTypes)
 
 INSTANTIATE_TYPED_TEST_SUITE_P (UnsignedCustomName, TypedTestP, UnsignedTypes, TypedTestPNames)
 
 TYPED_TEST_SUITE_P (DetectNotInstantiatedTypesTest)
 
 TYPED_TEST_P (DetectNotInstantiatedTypesTest, Used)
 
 REGISTER_TYPED_TEST_SUITE_P (DetectNotInstantiatedTypesTest, Used)
 
 TEST_F (ExpectFailureTest, ExpectFatalFailure)
 
 TEST_F (ExpectFailureTest, ExpectNonFatalFailure)
 
 TEST_F (ExpectFailureTest, ExpectFatalFailureOnAllThreads)
 
 TEST_F (ExpectFailureTest, ExpectNonFatalFailureOnAllThreads)
 
int main (int argc, char **argv)
 

Variables

int global_integer = 0
 
auto dynamic_test
 

Typedef Documentation

◆ NoTests

using NoTests = ParamTest

Definition at line 737 of file googletest-output-test_.cc.

◆ TypesForTestWithNames

Definition at line 761 of file googletest-output-test_.cc.

◆ UnsignedTypes

typedef testing::Types<unsigned char, unsigned int> UnsignedTypes

Definition at line 799 of file googletest-output-test_.cc.

Function Documentation

◆ AdHocTest()

void AdHocTest ( )

Definition at line 355 of file googletest-output-test_.cc.

355 {
356 printf("The non-test part of the code is expected to have 2 failures.\n\n");
357 EXPECT_TRUE(false);
358 EXPECT_EQ(2, 3);
359}
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:2043
#define EXPECT_TRUE(condition)
Definition: gtest.h:1982

◆ FatalFailure()

void FatalFailure ( )

Definition at line 666 of file googletest-output-test_.cc.

666 {
667 FAIL() << "Expected fatal failure.";
668}
#define FAIL()
Definition: gtest.h:1928

◆ INSTANTIATE_TEST_SUITE_P() [1/4]

INSTANTIATE_TEST_SUITE_P ( EmptyBasenameParamInst  ,
testing::Values(1)   
)

◆ INSTANTIATE_TEST_SUITE_P() [2/4]

INSTANTIATE_TEST_SUITE_P ( PrintingFailingParams  ,
FailingParamTest  ,
testing::Values(2)   
)

◆ INSTANTIATE_TEST_SUITE_P() [3/4]

INSTANTIATE_TEST_SUITE_P ( PrintingStrings  ,
ParamTest  ,
testing::Values(std::string("a"))  ,
ParamNameFunc   
)

◆ INSTANTIATE_TEST_SUITE_P() [4/4]

INSTANTIATE_TEST_SUITE_P ( ThisIsOdd  ,
NoTests  ,
::testing::Values("Hello")   
)

◆ INSTANTIATE_TYPED_TEST_SUITE_P() [1/2]

INSTANTIATE_TYPED_TEST_SUITE_P ( Unsigned  ,
TypedTestP  ,
UnsignedTypes   
)

◆ INSTANTIATE_TYPED_TEST_SUITE_P() [2/2]

INSTANTIATE_TYPED_TEST_SUITE_P ( UnsignedCustomName  ,
TypedTestP  ,
UnsignedTypes  ,
TypedTestPNames   
)

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 1068 of file googletest-output-test_.cc.

1068 {
1069 testing::GTEST_FLAG(print_time) = false;
1070
1071 // We just run the tests, knowing some of them are intended to fail.
1072 // We will use a separate Python script to compare the output of
1073 // this program with the golden file.
1074
1075 // It's hard to test InitGoogleTest() directly, as it has many
1076 // global side effects. The following line serves as a sanity test
1077 // for it.
1078 testing::InitGoogleTest(&argc, argv);
1079 bool internal_skip_environment_and_ad_hoc_tests =
1080 std::count(argv, argv + argc,
1081 std::string("internal_skip_environment_and_ad_hoc_tests")) > 0;
1082
1083#if GTEST_HAS_DEATH_TEST
1084 if (testing::internal::GTEST_FLAG(internal_run_death_test) != "") {
1085 // Skip the usual output capturing if we're running as the child
1086 // process of an threadsafe-style death test.
1087# if GTEST_OS_WINDOWS
1088 posix::FReopen("nul:", "w", stdout);
1089# else
1090 posix::FReopen("/dev/null", "w", stdout);
1091# endif // GTEST_OS_WINDOWS
1092 return RUN_ALL_TESTS();
1093 }
1094#endif // GTEST_HAS_DEATH_TEST
1095
1096 if (internal_skip_environment_and_ad_hoc_tests)
1097 return RUN_ALL_TESTS();
1098
1099 // Registers two global test environments.
1100 // The golden file verifies that they are set up in the order they
1101 // are registered, and torn down in the reverse order.
1104#if _MSC_VER
1106#endif // _MSC_VER
1107 return RunAllTests();
1108}
int * count
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2489
#define GTEST_FLAG(name)
Definition: gtest-port.h:2205
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
Definition: gtest-port.h:324
int RunAllTests()
Environment * AddGlobalTestEnvironment(Environment *env)
Definition: gtest.h:1493
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:6660
FILE * FReopen(const char *path, const char *mode, FILE *stream)
Definition: gtest-port.h:2087

◆ ParamNameFunc()

std::string ParamNameFunc ( const testing::TestParamInfo< std::string > &  info)

Definition at line 716 of file googletest-output-test_.cc.

716 {
717 return info.param;
718}

◆ REGISTER_TYPED_TEST_SUITE_P() [1/2]

REGISTER_TYPED_TEST_SUITE_P ( DetectNotInstantiatedTypesTest  ,
Used   
)

◆ REGISTER_TYPED_TEST_SUITE_P() [2/2]

REGISTER_TYPED_TEST_SUITE_P ( TypedTestP  ,
Success  ,
Failure   
)

◆ RunAllTests()

int RunAllTests ( )

Definition at line 362 of file googletest-output-test_.cc.

362 {
363 AdHocTest();
364 return RUN_ALL_TESTS();
365}
void AdHocTest()

◆ SubWithoutTrace()

void SubWithoutTrace ( int  n)

Definition at line 169 of file googletest-output-test_.cc.

169 {
170 EXPECT_EQ(1, n);
171 ASSERT_EQ(2, n);
172}
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:2073

◆ SubWithTrace()

void SubWithTrace ( int  n)

Definition at line 175 of file googletest-output-test_.cc.

175 {
176 SCOPED_TRACE(testing::Message() << "n = " << n);
177
179}
#define SCOPED_TRACE(message)
Definition: gtest.h:2281
void SubWithoutTrace(int n)

◆ TEST() [1/34]

TEST ( AddFailureAtTest  ,
MessageContainsSpecifiedFileAndLineNumber   
)

Definition at line 471 of file googletest-output-test_.cc.

471 {
472 ADD_FAILURE_AT("foo.cc", 42) << "Expected nonfatal failure in foo.cc";
473}
#define ADD_FAILURE_AT(file, line)
Definition: gtest.h:1913

◆ TEST() [2/34]

TEST ( DisabledTestsWarningTest  ,
DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning   
)

Definition at line 344 of file googletest-output-test_.cc.

345 {
346 // This test body is intentionally empty. Its sole purpose is for
347 // verifying that the --gtest_also_run_disabled_tests flag
348 // suppresses the "YOU HAVE 12 DISABLED TESTS" warning at the end of
349 // the test output.
350}

◆ TEST() [3/34]

TEST ( ExpectFatalFailureTest  ,
CanReferenceGlobalVariables   
)

Definition at line 632 of file googletest-output-test_.cc.

632 {
633 global_integer = 0;
635 ASSERT_EQ(1, global_integer) << "Expected fatal failure.";
636 }, "Expected fatal failure.");
637}
#define EXPECT_FATAL_FAILURE(statement, substr)
int global_integer

◆ TEST() [4/34]

TEST ( ExpectFatalFailureTest  ,
CanReferenceLocalStaticVariables   
)

Definition at line 641 of file googletest-output-test_.cc.

641 {
642 static int n;
643 n = 1;
645 ASSERT_EQ(0, n) << "Expected fatal failure.";
646 }, "Expected fatal failure.");
647}

◆ TEST() [5/34]

TEST ( ExpectFatalFailureTest  ,
FailsWhenStatementReturns   
)

Definition at line 691 of file googletest-output-test_.cc.

691 {
692 printf("(expecting a failure)\n");
694 return;
695 }, "");
696}

◆ TEST() [6/34]

TEST ( ExpectFatalFailureTest  ,
FailsWhenThereAreTwoFatalFailures   
)

Definition at line 672 of file googletest-output-test_.cc.

672 {
673 printf("(expecting a failure)\n");
675 FatalFailure();
676 FatalFailure();
677 }, "");
678}
void FatalFailure()

◆ TEST() [7/34]

TEST ( ExpectFatalFailureTest  ,
FailsWhenThereIsNoFatalFailure   
)

Definition at line 659 of file googletest-output-test_.cc.

659 {
660 printf("(expecting a failure)\n");
662 }, "");
663}

◆ TEST() [8/34]

TEST ( ExpectFatalFailureTest  ,
FailsWhenThereIsOneNonfatalFailure   
)

Definition at line 682 of file googletest-output-test_.cc.

682 {
683 printf("(expecting a failure)\n");
685 ADD_FAILURE() << "Expected non-fatal failure.";
686 }, "");
687}
#define ADD_FAILURE()
Definition: gtest.h:1909

◆ TEST() [9/34]

TEST ( ExpectFatalFailureTest  ,
SucceedsWhenThereIsOneFatalFailure   
)

Definition at line 651 of file googletest-output-test_.cc.

651 {
653 FAIL() << "Expected fatal failure.";
654 }, "Expected fatal failure.");
655}

◆ TEST() [10/34]

TEST ( ExpectNonfatalFailureTest  ,
CanReferenceGlobalVariables   
)

Definition at line 553 of file googletest-output-test_.cc.

553 {
554 global_integer = 0;
556 EXPECT_EQ(1, global_integer) << "Expected non-fatal failure.";
557 }, "Expected non-fatal failure.");
558}
#define EXPECT_NONFATAL_FAILURE(statement, substr)

◆ TEST() [11/34]

TEST ( ExpectNonfatalFailureTest  ,
CanReferenceLocalVariables   
)

Definition at line 562 of file googletest-output-test_.cc.

562 {
563 int m = 0;
564 static int n;
565 n = 1;
567 EXPECT_EQ(m, n) << "Expected non-fatal failure.";
568 }, "Expected non-fatal failure.");
569}

◆ TEST() [12/34]

TEST ( ExpectNonfatalFailureTest  ,
FailsWhenStatementReturns   
)

Definition at line 608 of file googletest-output-test_.cc.

608 {
609 printf("(expecting a failure)\n");
611 return;
612 }, "");
613}

◆ TEST() [13/34]

TEST ( ExpectNonfatalFailureTest  ,
FailsWhenThereAreTwoNonfatalFailures   
)

Definition at line 589 of file googletest-output-test_.cc.

589 {
590 printf("(expecting a failure)\n");
592 ADD_FAILURE() << "Expected non-fatal failure 1.";
593 ADD_FAILURE() << "Expected non-fatal failure 2.";
594 }, "");
595}

◆ TEST() [14/34]

TEST ( ExpectNonfatalFailureTest  ,
FailsWhenThereIsNoNonfatalFailure   
)

Definition at line 581 of file googletest-output-test_.cc.

581 {
582 printf("(expecting a failure)\n");
584 }, "");
585}

◆ TEST() [15/34]

TEST ( ExpectNonfatalFailureTest  ,
FailsWhenThereIsOneFatalFailure   
)

Definition at line 599 of file googletest-output-test_.cc.

599 {
600 printf("(expecting a failure)\n");
602 FAIL() << "Expected fatal failure.";
603 }, "");
604}

◆ TEST() [16/34]

TEST ( ExpectNonfatalFailureTest  ,
SucceedsWhenThereIsOneNonfatalFailure   
)

Definition at line 573 of file googletest-output-test_.cc.

573 {
575 ADD_FAILURE() << "Expected non-fatal failure.";
576 }, "Expected non-fatal failure.");
577}

◆ TEST() [17/34]

TEST ( FatalFailureTest  ,
FatalFailureInNestedSubroutine   
)

Definition at line 130 of file googletest-output-test_.cc.

130 {
131 printf("(expecting a failure that x should be 1)\n");
132
133 // Calls a subrountine that yields a fatal failure.
135
136 // Catches the fatal failure and aborts the test.
137 //
138 // When calling HasFatalFailure() inside a TEST, TEST_F, or test
139 // fixture, the testing::Test:: prefix is not needed.
140 if (HasFatalFailure()) return;
141
142 // If we get here, something is wrong.
143 FAIL() << "This should never be reached.";
144}
void TryTestSubroutine()

◆ TEST() [18/34]

TEST ( FatalFailureTest  ,
FatalFailureInSubroutine   
)

Definition at line 123 of file googletest-output-test_.cc.

123 {
124 printf("(expecting a failure that x should be 1)\n");
125
127}

◆ TEST() [19/34]

TEST ( FatalFailureTest  ,
NonfatalFailureInSubroutine   
)

Definition at line 147 of file googletest-output-test_.cc.

147 {
148 printf("(expecting a failure on false)\n");
149 EXPECT_TRUE(false); // Generates a nonfatal failure
150 ASSERT_FALSE(HasFatalFailure()); // This should succeed.
151}
#define ASSERT_FALSE(condition)
Definition: gtest.h:1994

◆ TEST() [20/34]

TEST ( GtestFailAtTest  ,
MessageContainsSpecifiedFileAndLineNumber   
)

Definition at line 475 of file googletest-output-test_.cc.

475 {
476 GTEST_FAIL_AT("foo.cc", 42) << "Expected fatal failure in foo.cc";
477}
#define GTEST_FAIL_AT(file, line)
Definition: gtest.h:1921

◆ TEST() [21/34]

TEST ( LoggingTest  ,
InterleavingLoggingAndAssertions   
)

Definition at line 154 of file googletest-output-test_.cc.

154 {
155 static const int a[4] = {
156 3, 9, 2, 6
157 };
158
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);
162 EXPECT_GE(3, a[i]);
163 }
164}
#define EXPECT_GE(val1, val2)
Definition: gtest.h:2051

◆ TEST() [22/34]

TEST ( NonfatalFailureTest  ,
DiffForLongStrings   
)

Definition at line 117 of file googletest-output-test_.cc.

117 {
118 std::string golden_str(kGoldenString, sizeof(kGoldenString) - 1);
119 EXPECT_EQ(golden_str, "Line 2");
120}

◆ TEST() [23/34]

TEST ( NonfatalFailureTest  ,
EscapesStringOperands   
)

Definition at line 109 of file googletest-output-test_.cc.

109 {
110 std::string actual = "actual \"string\"";
111 EXPECT_EQ(kGoldenString, actual);
112
113 const char* golden = kGoldenString;
114 EXPECT_EQ(golden, actual);
115}

◆ TEST() [24/34]

TEST ( PassingTest  ,
PassingTest1   
)

Definition at line 79 of file googletest-output-test_.cc.

79 {
80}

◆ TEST() [25/34]

TEST ( PassingTest  ,
PassingTest2   
)

Definition at line 82 of file googletest-output-test_.cc.

82 {
83}

◆ TEST() [26/34]

TEST ( SCOPED_TRACETest  ,
AcceptedValues   
)

Definition at line 181 of file googletest-output-test_.cc.

181 {
182 SCOPED_TRACE("literal string");
183 SCOPED_TRACE(std::string("std::string"));
184 SCOPED_TRACE(1337); // streamable type
185 const char* null_value = nullptr;
186 SCOPED_TRACE(null_value);
187
188 ADD_FAILURE() << "Just checking that all these values work fine.";
189}

◆ TEST() [27/34]

TEST ( SCOPED_TRACETest  ,
CanBeNested   
)

Definition at line 230 of file googletest-output-test_.cc.

230 {
231 printf("(expected to fail)\n");
232
233 SCOPED_TRACE(""); // A trace without a message.
234
235 SubWithTrace(2);
236}
void SubWithTrace(int n)

◆ TEST() [28/34]

TEST ( SCOPED_TRACETest  ,
CanBeRepeated   
)

Definition at line 239 of file googletest-output-test_.cc.

239 {
240 printf("(expected to fail)\n");
241
242 SCOPED_TRACE("A");
244 << "This failure is expected, and should contain trace point A.";
245
246 SCOPED_TRACE("B");
248 << "This failure is expected, and should contain trace point A and B.";
249
250 {
251 SCOPED_TRACE("C");
252 ADD_FAILURE() << "This failure is expected, and should "
253 << "contain trace point A, B, and C.";
254 }
255
256 SCOPED_TRACE("D");
257 ADD_FAILURE() << "This failure is expected, and should "
258 << "contain trace point A, B, and D.";
259}

◆ TEST() [29/34]

TEST ( SCOPED_TRACETest  ,
ObeysScopes   
)

Definition at line 192 of file googletest-output-test_.cc.

192 {
193 printf("(expected to fail)\n");
194
195 // There should be no trace before SCOPED_TRACE() is invoked.
196 ADD_FAILURE() << "This failure is expected, and shouldn't have a trace.";
197
198 {
199 SCOPED_TRACE("Expected trace");
200 // After SCOPED_TRACE(), a failure in the current scope should contain
201 // the trace.
202 ADD_FAILURE() << "This failure is expected, and should have a trace.";
203 }
204
205 // Once the control leaves the scope of the SCOPED_TRACE(), there
206 // should be no trace again.
207 ADD_FAILURE() << "This failure is expected, and shouldn't have a trace.";
208}

◆ TEST() [30/34]

TEST ( SCOPED_TRACETest  ,
WorksInLoop   
)

Definition at line 211 of file googletest-output-test_.cc.

211 {
212 printf("(expected to fail)\n");
213
214 for (int i = 1; i <= 2; i++) {
215 SCOPED_TRACE(testing::Message() << "i = " << i);
216
218 }
219}

◆ TEST() [31/34]

TEST ( SCOPED_TRACETest  ,
WorksInSubroutine   
)

Definition at line 222 of file googletest-output-test_.cc.

222 {
223 printf("(expected to fail)\n");
224
225 SubWithTrace(1);
226 SubWithTrace(2);
227}

◆ TEST() [32/34]

TEST ( ScopedTraceTest  ,
WithExplicitFileAndLine   
)

Definition at line 339 of file googletest-output-test_.cc.

339 {
340 testing::ScopedTrace trace("explicit_file.cc", 123, "expected trace message");
341 ADD_FAILURE() << "Check that the trace is attached to a particular location.";
342}

◆ TEST() [33/34]

TEST ( TEST_before_TEST_F_in_same_test_case  ,
DefinedUsingTEST   
)

Definition at line 542 of file googletest-output-test_.cc.

542{}

◆ TEST() [34/34]

TEST ( TEST_F_before_TEST_in_same_test_case  ,
DefinedUsingTESTAndShouldFail   
)

Definition at line 537 of file googletest-output-test_.cc.

537{}

◆ TEST_F() [1/10]

TEST_F ( ExpectFailureTest  ,
ExpectFatalFailure   
)

Definition at line 890 of file googletest-output-test_.cc.

890 {
891 // Expected fatal failure, but succeeds.
892 printf("(expecting 1 failure)\n");
893 EXPECT_FATAL_FAILURE(SUCCEED(), "Expected fatal failure.");
894 // Expected fatal failure, but got a non-fatal failure.
895 printf("(expecting 1 failure)\n");
896 EXPECT_FATAL_FAILURE(AddFailure(NONFATAL_FAILURE), "Expected non-fatal "
897 "failure.");
898 // Wrong message.
899 printf("(expecting 1 failure)\n");
900 EXPECT_FATAL_FAILURE(AddFailure(FATAL_FAILURE), "Some other fatal failure "
901 "expected.");
902}
#define SUCCEED()
Definition: gtest.h:1937

◆ TEST_F() [2/10]

TEST_F ( ExpectFailureTest  ,
ExpectFatalFailureOnAllThreads   
)

Definition at line 961 of file googletest-output-test_.cc.

961 {
962 // Expected fatal failure, but succeeds.
963 printf("(expecting 1 failure)\n");
964 EXPECT_FATAL_FAILURE_ON_ALL_THREADS(SUCCEED(), "Expected fatal failure.");
965 // Expected fatal failure, but got a non-fatal failure.
966 printf("(expecting 1 failure)\n");
967 EXPECT_FATAL_FAILURE_ON_ALL_THREADS(AddFailure(NONFATAL_FAILURE),
968 "Expected non-fatal failure.");
969 // Wrong message.
970 printf("(expecting 1 failure)\n");
971 EXPECT_FATAL_FAILURE_ON_ALL_THREADS(AddFailure(FATAL_FAILURE),
972 "Some other fatal failure expected.");
973}
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr)

◆ TEST_F() [3/10]

TEST_F ( ExpectFailureTest  ,
ExpectNonFatalFailure   
)

Definition at line 904 of file googletest-output-test_.cc.

904 {
905 // Expected non-fatal failure, but succeeds.
906 printf("(expecting 1 failure)\n");
907 EXPECT_NONFATAL_FAILURE(SUCCEED(), "Expected non-fatal failure.");
908 // Expected non-fatal failure, but got a fatal failure.
909 printf("(expecting 1 failure)\n");
910 EXPECT_NONFATAL_FAILURE(AddFailure(FATAL_FAILURE), "Expected fatal failure.");
911 // Wrong message.
912 printf("(expecting 1 failure)\n");
913 EXPECT_NONFATAL_FAILURE(AddFailure(NONFATAL_FAILURE), "Some other non-fatal "
914 "failure.");
915}

◆ TEST_F() [4/10]

TEST_F ( ExpectFailureTest  ,
ExpectNonFatalFailureOnAllThreads   
)

Definition at line 975 of file googletest-output-test_.cc.

975 {
976 // Expected non-fatal failure, but succeeds.
977 printf("(expecting 1 failure)\n");
978 EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(SUCCEED(), "Expected non-fatal "
979 "failure.");
980 // Expected non-fatal failure, but got a fatal failure.
981 printf("(expecting 1 failure)\n");
982 EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(AddFailure(FATAL_FAILURE),
983 "Expected fatal failure.");
984 // Wrong message.
985 printf("(expecting 1 failure)\n");
986 EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(AddFailure(NONFATAL_FAILURE),
987 "Some other non-fatal failure.");
988}
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr)

◆ TEST_F() [5/10]

TEST_F ( FatalFailureInFixtureConstructorTest  ,
FailureInConstructor   
)

Definition at line 420 of file googletest-output-test_.cc.

420 {
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.";
424}

◆ TEST_F() [6/10]

TEST_F ( FatalFailureInSetUpTest  ,
FailureInSetUp   
)

Definition at line 466 of file googletest-output-test_.cc.

466 {
467 FAIL() << "UNEXPECTED failure in the test function. "
468 << "We should never get here, as SetUp() failed.";
469}

◆ TEST_F() [7/10]

TEST_F ( NonFatalFailureInFixtureConstructorTest  ,
FailureInConstructor   
)

Definition at line 386 of file googletest-output-test_.cc.

386 {
387 ADD_FAILURE() << "Expected failure #3, in the test body.";
388}

◆ TEST_F() [8/10]

TEST_F ( NonFatalFailureInSetUpTest  ,
FailureInSetUp   
)

Definition at line 444 of file googletest-output-test_.cc.

444 {
445 FAIL() << "Expected failure #2, in the test function.";
446}

◆ TEST_F() [9/10]

TEST_F ( TEST_before_TEST_F_in_same_test_case  ,
DefinedUsingTEST_FAndShouldFail   
)

Definition at line 546 of file googletest-output-test_.cc.

546 {
547}

◆ TEST_F() [10/10]

TEST_F ( TEST_F_before_TEST_in_same_test_case  ,
DefinedUsingTEST_F   
)

Definition at line 533 of file googletest-output-test_.cc.

533{}

◆ TEST_P() [1/5]

TEST_P ( DetectNotInstantiatedTest  ,
Used   
)

Definition at line 742 of file googletest-output-test_.cc.

742{ }

◆ TEST_P() [2/5]

TEST_P ( EmptyBasenameParamInst  ,
Passes   
)

Definition at line 103 of file googletest-output-test_.cc.

103{ EXPECT_EQ(1, GetParam()); }

◆ TEST_P() [3/5]

TEST_P ( FailingParamTest  ,
Fails   
)

Definition at line 89 of file googletest-output-test_.cc.

89 {
90 EXPECT_EQ(1, GetParam());
91}

◆ TEST_P() [4/5]

TEST_P ( ParamTest  ,
Failure   
)

Definition at line 727 of file googletest-output-test_.cc.

727 {
728 EXPECT_EQ("b", GetParam()) << "Expected failure";
729}

◆ TEST_P() [5/5]

TEST_P ( ParamTest  ,
Success   
)

Definition at line 723 of file googletest-output-test_.cc.

723 {
724 EXPECT_EQ("a", GetParam());
725}

◆ TestEq1()

void TestEq1 ( int  x)

Definition at line 59 of file googletest-output-test_.cc.

59 {
60 ASSERT_EQ(1, x);
61}

◆ TryTestSubroutine()

void TryTestSubroutine ( )

Definition at line 65 of file googletest-output-test_.cc.

65 {
66 // Calls a subrountine that yields a fatal failure.
67 TestEq1(2);
68
69 // Catches the fatal failure and aborts the test.
70 //
71 // The testing::Test:: prefix is necessary when calling
72 // HasFatalFailure() outside of a TEST, TEST_F, or test fixture.
74
75 // If we get here, something is wrong.
76 FAIL() << "This should never be reached.";
77}
void TestEq1(int x)
static bool HasFatalFailure()
Definition: gtest.cc:2695

◆ TYPED_TEST() [1/4]

TYPED_TEST ( TypedTest  ,
Failure   
)

Definition at line 757 of file googletest-output-test_.cc.

757 {
758 EXPECT_EQ(1, TypeParam()) << "Expected failure";
759}

◆ TYPED_TEST() [2/4]

TYPED_TEST ( TypedTest  ,
Success   
)

Definition at line 753 of file googletest-output-test_.cc.

753 {
754 EXPECT_EQ(0, TypeParam());
755}

◆ TYPED_TEST() [3/4]

TYPED_TEST ( TypedTestWithNames  ,
Failure   
)

Definition at line 781 of file googletest-output-test_.cc.

781{ FAIL(); }

◆ TYPED_TEST() [4/4]

TYPED_TEST ( TypedTestWithNames  ,
Success   
)

Definition at line 779 of file googletest-output-test_.cc.

779{}

◆ TYPED_TEST_P() [1/3]

TYPED_TEST_P ( DetectNotInstantiatedTypesTest  ,
Used   
)

Definition at line 821 of file googletest-output-test_.cc.

821 {
822 TypeParam instantiate;
823 (void)instantiate;
824}

◆ TYPED_TEST_P() [2/3]

TYPED_TEST_P ( TypedTestP  ,
Failure   
)

Definition at line 793 of file googletest-output-test_.cc.

793 {
794 EXPECT_EQ(1U, TypeParam()) << "Expected failure";
795}

◆ TYPED_TEST_P() [3/3]

TYPED_TEST_P ( TypedTestP  ,
Success   
)

Definition at line 789 of file googletest-output-test_.cc.

789 {
790 EXPECT_EQ(0U, TypeParam());
791}

◆ TYPED_TEST_SUITE() [1/2]

TYPED_TEST_SUITE ( TypedTest  ,
testing::Types< int >   
)

◆ TYPED_TEST_SUITE() [2/2]

TYPED_TEST_SUITE ( TypedTestWithNames  ,
TypesForTestWithNames  ,
TypedTestNames   
)

◆ TYPED_TEST_SUITE_P() [1/2]

TYPED_TEST_SUITE_P ( DetectNotInstantiatedTypesTest  )

◆ TYPED_TEST_SUITE_P() [2/2]

TYPED_TEST_SUITE_P ( TypedTestP  )

Variable Documentation

◆ dynamic_test

auto dynamic_test

Definition at line 1009 of file googletest-output-test_.cc.

◆ global_integer

int global_integer = 0

Definition at line 550 of file googletest-output-test_.cc.