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

Go to the source code of this file.

Classes

class  testing::internal::EventRecordingListener
 
class  testing::internal::EnvironmentInvocationCatcher
 
class  testing::internal::ListenerTest
 

Namespaces

namespace  testing
 
namespace  testing::internal
 

Functions

 testing::internal::TEST_F (ListenerTest, DoesFoo)
 
 testing::internal::TEST_F (ListenerTest, DoesBar)
 
void VerifyResults (const std::vector< std::string > &data, const char *const *expected_data, size_t expected_data_size)
 
int main (int argc, char **argv)
 

Variables

std::vector< std::string > * g_events = NULL
 

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 201 of file gtest-listener_test.cc.

201 {
202 std::vector<std::string> events;
203 g_events = &events;
204 InitGoogleTest(&argc, argv);
205
206 UnitTest::GetInstance()->listeners().Append(
207 new EventRecordingListener("1st"));
208 UnitTest::GetInstance()->listeners().Append(
209 new EventRecordingListener("2nd"));
210
211 AddGlobalTestEnvironment(new EnvironmentInvocationCatcher);
212
213 GTEST_CHECK_(events.size() == 0)
214 << "AddGlobalTestEnvironment should not generate any events itself.";
215
216 ::testing::GTEST_FLAG(repeat) = 2;
217 int ret_val = RUN_ALL_TESTS();
218
219 const char* const expected_events[] = {
220 "1st.OnTestProgramStart",
221 "2nd.OnTestProgramStart",
222 "1st.OnTestIterationStart(0)",
223 "2nd.OnTestIterationStart(0)",
224 "1st.OnEnvironmentsSetUpStart",
225 "2nd.OnEnvironmentsSetUpStart",
226 "Environment::SetUp",
227 "2nd.OnEnvironmentsSetUpEnd",
228 "1st.OnEnvironmentsSetUpEnd",
229 "1st.OnTestCaseStart",
230 "2nd.OnTestCaseStart",
231 "ListenerTest::SetUpTestCase",
232 "1st.OnTestStart",
233 "2nd.OnTestStart",
234 "ListenerTest::SetUp",
235 "ListenerTest::* Test Body",
236 "1st.OnTestPartResult",
237 "2nd.OnTestPartResult",
238 "ListenerTest::TearDown",
239 "2nd.OnTestEnd",
240 "1st.OnTestEnd",
241 "1st.OnTestStart",
242 "2nd.OnTestStart",
243 "ListenerTest::SetUp",
244 "ListenerTest::* Test Body",
245 "1st.OnTestPartResult",
246 "2nd.OnTestPartResult",
247 "ListenerTest::TearDown",
248 "2nd.OnTestEnd",
249 "1st.OnTestEnd",
250 "ListenerTest::TearDownTestCase",
251 "2nd.OnTestCaseEnd",
252 "1st.OnTestCaseEnd",
253 "1st.OnEnvironmentsTearDownStart",
254 "2nd.OnEnvironmentsTearDownStart",
255 "Environment::TearDown",
256 "2nd.OnEnvironmentsTearDownEnd",
257 "1st.OnEnvironmentsTearDownEnd",
258 "2nd.OnTestIterationEnd(0)",
259 "1st.OnTestIterationEnd(0)",
260 "1st.OnTestIterationStart(1)",
261 "2nd.OnTestIterationStart(1)",
262 "1st.OnEnvironmentsSetUpStart",
263 "2nd.OnEnvironmentsSetUpStart",
264 "Environment::SetUp",
265 "2nd.OnEnvironmentsSetUpEnd",
266 "1st.OnEnvironmentsSetUpEnd",
267 "1st.OnTestCaseStart",
268 "2nd.OnTestCaseStart",
269 "ListenerTest::SetUpTestCase",
270 "1st.OnTestStart",
271 "2nd.OnTestStart",
272 "ListenerTest::SetUp",
273 "ListenerTest::* Test Body",
274 "1st.OnTestPartResult",
275 "2nd.OnTestPartResult",
276 "ListenerTest::TearDown",
277 "2nd.OnTestEnd",
278 "1st.OnTestEnd",
279 "1st.OnTestStart",
280 "2nd.OnTestStart",
281 "ListenerTest::SetUp",
282 "ListenerTest::* Test Body",
283 "1st.OnTestPartResult",
284 "2nd.OnTestPartResult",
285 "ListenerTest::TearDown",
286 "2nd.OnTestEnd",
287 "1st.OnTestEnd",
288 "ListenerTest::TearDownTestCase",
289 "2nd.OnTestCaseEnd",
290 "1st.OnTestCaseEnd",
291 "1st.OnEnvironmentsTearDownStart",
292 "2nd.OnEnvironmentsTearDownStart",
293 "Environment::TearDown",
294 "2nd.OnEnvironmentsTearDownEnd",
295 "1st.OnEnvironmentsTearDownEnd",
296 "2nd.OnTestIterationEnd(1)",
297 "1st.OnTestIterationEnd(1)",
298 "2nd.OnTestProgramEnd",
299 "1st.OnTestProgramEnd"
300 };
301 VerifyResults(events,
302 expected_events,
303 sizeof(expected_events)/sizeof(expected_events[0]));
304
305 // We need to check manually for ad hoc test failures that happen after
306 // RUN_ALL_TESTS finishes.
307 if (UnitTest::GetInstance()->Failed())
308 ret_val = 1;
309
310 return ret_val;
311}
std::vector< std::string > * g_events
void VerifyResults(const std::vector< std::string > &data, const char *const *expected_data, size_t expected_data_size)
#define GTEST_CHECK_(condition)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition gtest.h:2328
char ** argv
Environment * AddGlobalTestEnvironment(Environment *env)
Definition gtest.h:1391
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition gtest.cc:5787
Here is the call graph for this function:

◆ VerifyResults()

void VerifyResults ( const std::vector< std::string > & data,
const char *const * expected_data,
size_t expected_data_size )

Definition at line 177 of file gtest-listener_test.cc.

179 {
180 const size_t actual_size = data.size();
181 // If the following assertion fails, a new entry will be appended to
182 // data. Hence we save data.size() first.
183 EXPECT_EQ(expected_data_size, actual_size);
184
185 // Compares the common prefix.
186 const size_t shorter_size = expected_data_size <= actual_size ?
187 expected_data_size : actual_size;
188 size_t i = 0;
189 for (; i < shorter_size; ++i) {
190 ASSERT_STREQ(expected_data[i], data[i].c_str())
191 << "at position " << i;
192 }
193
194 // Prints extra elements in the actual data.
195 for (; i < actual_size; ++i) {
196 printf(" Actual event #%lu: %s\n",
197 static_cast<unsigned long>(i), data[i].c_str());
198 }
199}
#define EXPECT_EQ(val1, val2)
Definition gtest.h:1954
#define ASSERT_STREQ(s1, s2)
Definition gtest.h:2036
LOGGING_API void printf(Category category, const char *format,...)
Definition Logging.cpp:30
Here is the caller graph for this function:

Variable Documentation

◆ g_events

std::vector<std::string>* g_events = NULL

Definition at line 50 of file gtest-listener_test.cc.