38 using ::testing::EmptyTestEventListener;
40 using ::testing::Test;
41 using ::testing::TestCase;
42 using ::testing::TestEventListeners;
43 using ::testing::TestInfo;
44 using ::testing::TestPartResult;
45 using ::testing::UnitTest;
49 class TersePrinter :
public EmptyTestEventListener {
52 void OnTestProgramStart(
const UnitTest& )
override {}
55 void OnTestProgramEnd(
const UnitTest& unit_test)
override {
56 fprintf(stdout,
"TEST %s\n", unit_test.Passed() ?
"PASSED" :
"FAILED");
61 void OnTestStart(
const TestInfo& test_info)
override {
63 "*** Test %s.%s starting.\n",
64 test_info.test_case_name(),
70 void OnTestPartResult(
const TestPartResult& test_part_result)
override {
73 test_part_result.failed() ?
"*** Failure" :
"Success",
74 test_part_result.file_name(),
75 test_part_result.line_number(),
76 test_part_result.summary());
81 void OnTestEnd(
const TestInfo& test_info)
override {
83 "*** Test %s.%s ending.\n",
84 test_info.test_case_name(),
90 TEST(CustomOutputTest, PrintsMessage) {
91 printf(
"Printing something from the test body...\n");
94 TEST(CustomOutputTest, Succeeds) {
95 SUCCEED() <<
"SUCCEED() has been invoked from here";
98 TEST(CustomOutputTest, Fails) {
100 <<
"This test fails in order to demonstrate alternative failure messages";
104 int main(
int argc,
char **argv) {
107 bool terse_output =
false;
108 if (argc > 1 && strcmp(argv[1],
"--terse_output") == 0 )
111 printf(
"%s\n",
"Run this program with --terse_output to change the way "
112 "it prints its output.");
114 UnitTest& unit_test = *UnitTest::GetInstance();
119 TestEventListeners& listeners = unit_test.listeners();
125 delete listeners.Release(listeners.default_result_printer());
131 listeners.Append(
new TersePrinter);
137 int unexpectedly_failed_tests = 0;
138 for (
int i = 0;
i < unit_test.total_test_suite_count(); ++
i) {
141 const TestInfo& test_info = *test_suite.
GetTestInfo(j);
144 if (test_info.result()->Failed() &&
145 strcmp(test_info.name(),
"Fails") != 0) {
146 unexpectedly_failed_tests++;
152 if (unexpectedly_failed_tests == 0)
const TestInfo * GetTestInfo(int i) const
int total_test_count() const
#define TEST(test_suite_name, test_name)
#define EXPECT_EQ(val1, val2)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
GTEST_API_ void InitGoogleTest(int *argc, char **argv)