哦?TestInfo也有一个impl?看来我们之前漏掉了点东西,和UnitTest很类似,TestInfo内部也有一个主管各种实现的类,那就是TestInfoImpl,它在TestInfo的构造函数中创建了出来(还记得前面讲的TestInfo的创建过程吗?):
TestInfo::TestInfo(const char* test_case_name, const char* name, const char* test_case_comment, const char* comment, internal::TypeId fixture_class_id, internal::TestFactoryBase* factory) { impl_ = new internal::TestInfoImpl(this, test_case_name, name, test_case_comment, comment, fixture_class_id, factory); } |
void TestInfoImpl::Run() { // ... UnitTestEventListenerInterface* const result_printer =impl->result_printer(); result_printer->OnTestStart(parent_); // 开始计时 const TimeInMillis start = GetTimeInMillis(); Test* test = NULL; __try { // 我们的对象工厂,使用CreateTest()生成Test对象 test = factory_->CreateTest(); } __except(internal::UnitTestOptions::GTestShouldProcessSEH( GetExceptionCode())) { AddExceptionThrownFailure(GetExceptionCode(), "the test fixture's constructor"); return; } // 如果Test对象创建成功if (!Test::HasFatalFailure()) {
// 调用Test对象的Run()方法,执行测试案例 } // 执行完毕,删除Test对象 impl->os_stack_trace_getter()->UponLeavingGTest(); delete test; test = NULL; // 停止计时 result_.set_elapsed_time(GetTimeInMillis() - start); result_printer->OnTestEnd(parent_); } |