Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sample9_unittest.cc File Reference
#include <stdio.h>
#include "gtest/gtest.h"
Include dependency graph for sample9_unittest.cc:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 105 of file sample9_unittest.cc.

105 {
106 InitGoogleTest(&argc, argv);
107
108 bool terse_output = false;
109 if (argc > 1 && strcmp(argv[1], "--terse_output") == 0 )
110 terse_output = true;
111 else
112 printf("%s\n", "Run this program with --terse_output to change the way "
113 "it prints its output.");
114
115 UnitTest& unit_test = *UnitTest::GetInstance();
116
117 // If we are given the --terse_output command line flag, suppresses the
118 // standard output and attaches own result printer.
119 if (terse_output) {
120 TestEventListeners& listeners = unit_test.listeners();
121
122 // Removes the default console output listener from the list so it will
123 // not receive events from Google Test and won't print any output. Since
124 // this operation transfers ownership of the listener to the caller we
125 // have to delete it as well.
126 delete listeners.Release(listeners.default_result_printer());
127
128 // Adds the custom output listener to the list. It will now receive
129 // events from Google Test and print the alternative output. We don't
130 // have to worry about deleting it since Google Test assumes ownership
131 // over it after adding it to the list.
132 listeners.Append(new TersePrinter);
133 }
134 int ret_val = RUN_ALL_TESTS();
135
136 // This is an example of using the UnitTest reflection API to inspect test
137 // results. Here we discount failures from the tests we expected to fail.
138 int unexpectedly_failed_tests = 0;
139 for (int i = 0; i < unit_test.total_test_case_count(); ++i) {
140 const TestCase& test_case = *unit_test.GetTestCase(i);
141 for (int j = 0; j < test_case.total_test_count(); ++j) {
142 const TestInfo& test_info = *test_case.GetTestInfo(j);
143 // Counts failed tests that were not meant to fail (those without
144 // 'Fails' in the name).
145 if (test_info.result()->Failed() &&
146 strcmp(test_info.name(), "Fails") != 0) {
147 unexpectedly_failed_tests++;
148 }
149 }
150 }
151
152 // Test that were meant to fail should not affect the test program outcome.
153 if (unexpectedly_failed_tests == 0)
154 ret_val = 0;
155
156 return ret_val;
157}
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition gtest.h:2328
char ** argv
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition gtest.cc:5787
uint16_t j
Here is the call graph for this function: