static void helperDoRunOneTest(void* data) { HelperTestRunInfo* runInfo = (HelperTestRunInfo*) data; UtestShell* shell = runInfo->shell_; TestPlugin* plugin = runInfo->plugin_; TestResult* result = runInfo->result_; shell->runOneTest(plugin, *result); }
UtestShell* TestRegistry::findTestWithName(const SimpleString& name) { UtestShell* current = tests_; while (current) { if (current->getName() == name) return current; current = current->getNext(); } return NULL; }
UtestShell* TestRegistry::findTestWithGroup(const SimpleString& group) { UtestShell* current = tests_; while (current) { if (current->getGroup() == group) return current; current = current->getNext(); } return NULL; }
void TestOutput::printCurrentTestStarted(const UtestShell& test) { if (verbose_) print(test.getFormattedName().asCharString()); if (test.willRun()) { setProgressIndicator("."); } else { setProgressIndicator("!"); } }
void FailableMemoryAllocator::failIfUndoneFailedAllocs() { for (int i = 0; i < toFailCount_; i++) { if (allocsToFail_[i] != FAILED_ALLOC_DONE) { UtestShell* currentTest = UtestShell::getCurrent(); SimpleString failText = StringFromFormat("Expected allocation number %d was never done", allocsToFail_[i]); currentTest->failWith(FailFailure(currentTest, currentTest->getName().asCharString(), currentTest->getLineNumber(), failText), TestTerminatorWithoutExceptions()); } } }
void FailableMemoryAllocator::failIfUndoneFailedLocationAllocs() { for (int i = 0; i < locationToFailCount_; i++) { if (!locationAllocsToFail_[i].done) { UtestShell* currentTest = UtestShell::getCurrent(); SimpleString failText = StringFromFormat("Expected failing alloc at %s:%d was never done", locationAllocsToFail_[i].file, locationAllocsToFail_[i].line); currentTest->failWith(FailFailure(currentTest, currentTest->getName().asCharString(), currentTest->getLineNumber(), failText), TestTerminatorWithoutExceptions()); } } }
TEST(gtest, SimpleGoogleTestGetCalled) { StringBufferTestOutput output; TestResult result(output); TestPlugin plugin("dummy"); TestRegistry* registry = TestRegistry::getCurrentRegistry(); UtestShell * shell = registry->findTestWithName("GTestEqual"); g_GTestEqual_has_been_called = false; shell->runOneTest(&plugin, result); CHECK(g_GTestEqual_has_been_called); }
void FailableMemoryAllocator::checkAllFailedAllocsWereDone() { if (head_) { UtestShell* currentTest = UtestShell::getCurrent(); SimpleString failText; if (head_->file_) failText = StringFromFormat("Expected failing alloc at %s:%d was never done", head_->file_, head_->line_); else failText = StringFromFormat("Expected allocation number %d was never done", head_->allocNumberToFail_); currentTest->failWith(FailFailure(currentTest, currentTest->getName().asCharString(), currentTest->getLineNumber(), failText), TestTerminatorWithoutExceptions()); } }
void JUnitTestOutput::printCurrentTestStarted(const UtestShell& test) { impl_->results_.testCount_++; impl_->results_.group_ = test.getGroup(); impl_->results_.startTime_ = GetPlatformSpecificTimeInMillis(); if (impl_->results_.tail_ == 0) { impl_->results_.head_ = impl_->results_.tail_ = new JUnitTestCaseResultNode; } else { impl_->results_.tail_->next_ = new JUnitTestCaseResultNode; impl_->results_.tail_ = impl_->results_.tail_->next_; } impl_->results_.tail_->name_ = test.getName(); }
JUnitTestOutputTestRunner& onLine(int lineNumber) { if(currentTest_) { currentTest_->setLineNumber(lineNumber); } return *this; }
JUnitTestOutputTestRunner& inFile(const char* fileName) { if(currentTest_) { currentTest_->setFileName(fileName); } return *this; }
void MemoryReporterPlugin::preTestAction(UtestShell& test, TestResult& result) { if (formatter_ == NULL) return; initializeAllocator(&mallocAllocator, result); initializeAllocator(&newAllocator, result); initializeAllocator(&newArrayAllocator, result); setGlobalMemoryReportAllocators(); if (test.getGroup() != currentTestGroup_) { formatter_->report_testgroup_start(&result, test); currentTestGroup_ = test.getGroup(); } formatter_->report_test_start(&result, test); }
void IEEE754ExceptionsPlugin::postTestAction(UtestShell& test, TestResult& result) { if(!test.hasFailed()) { IEEE754_CHECK_CLEAR(test, result, FE_DIVBYZERO); IEEE754_CHECK_CLEAR(test, result, FE_OVERFLOW); IEEE754_CHECK_CLEAR(test, result, FE_UNDERFLOW); IEEE754_CHECK_CLEAR(test, result, FE_INVALID); IEEE754_CHECK_CLEAR(test, result, FE_INEXACT); } }
void IEEE754ExceptionsPlugin::postTestAction(UtestShell& test, TestResult& result) { if(!test.hasFailed()) { IEEE754_CHECK_CLEAR(test, result, FE_DIVBYZERO); IEEE754_CHECK_CLEAR(test, result, FE_OVERFLOW); IEEE754_CHECK_CLEAR(test, result, FE_UNDERFLOW); IEEE754_CHECK_CLEAR(test, result, FE_INVALID); // LCOV_EXCL_LINE (not all platforms support this) IEEE754_CHECK_CLEAR(test, result, FE_INEXACT); } }
void MemoryReporterPlugin::postTestAction(UtestShell& test, TestResult& result) { if (formatter_ == NULL) return; removeGlobalMemoryReportAllocators(); formatter_->report_test_end(&result, test); if (test.getNext()->getGroup() != currentTestGroup_) formatter_->report_testgroup_end(&result, test); }
void JUnitTestOutput::printCurrentTestStarted(const UtestShell& test) { impl_->results_.testCount_++; impl_->results_.group_ = test.getGroup(); impl_->results_.startTime_ = GetPlatformSpecificTimeInMillis(); if (impl_->results_.tail_ == NULLPTR) { impl_->results_.head_ = impl_->results_.tail_ = new JUnitTestCaseResultNode; } else { impl_->results_.tail_->next_ = new JUnitTestCaseResultNode; impl_->results_.tail_ = impl_->results_.tail_->next_; } impl_->results_.tail_->name_ = test.getName(); impl_->results_.tail_->file_ = test.getFile(); impl_->results_.tail_->lineNumber_ = test.getLineNumber(); if (!test.willRun()) { impl_->results_.tail_->ignored_ = true; } }
void TestRegistry::listTestGroupNames(TestResult& result) { SimpleString groupList; for (UtestShell *test = tests_; test != NULL; test = test->getNext()) { SimpleString gname; gname += "#"; gname += test->getGroup(); gname += "#"; if (!groupList.contains(gname)) { groupList += gname; groupList += " "; } } groupList.replace("#", ""); if (groupList.endsWith(" ")) groupList = groupList.subString(0, groupList.size() - 1); result.print(groupList.asCharString()); }
void NormalMemoryReportFormatter::report_testgroup_start(TestResult* result, UtestShell& test) { const size_t line_size = 80; SimpleString groupName = StringFromFormat("TEST GROUP(%s)", test.getGroup().asCharString()); size_t beginPos = (line_size/2) - (groupName.size()/2); SimpleString line("-", beginPos); line += groupName; line += SimpleString("-", line_size - line.size()); line += "\n"; result->print(line.asCharString()); }
// LCOV_EXCL_START - actually covered but not in .gcno due to race condition static void defaultCrashMethod() { UtestShell* ptr = (UtestShell*) 0x0; ptr->countTests(); }
virtual void fail(char* fail_string) { UtestShell* currentTest = UtestShell::getCurrent(); currentTest->getTestResult()->addFailure(FailFailure(currentTest, currentTest->getName().asCharString(), currentTest->getLineNumber(), fail_string)); currentTest->exitCurrentTestWithoutException(); }
void NormalMemoryReportFormatter::report_test_end(TestResult* result, UtestShell& test) { result->print(StringFromFormat("ENDTEST(%s, %s)\n", test.getGroup().asCharString(), test.getName().asCharString()).asCharString()); }
void CodeMemoryReportFormatter::report_testgroup_start(TestResult* result, UtestShell& test) { result->print(StringFromFormat("*/TEST_GROUP(%s_memoryReport)\n{\n};\n/*", test.getGroup().asCharString()).asCharString()); }
void CodeMemoryReportFormatter::report_test_start(TestResult* result, UtestShell& test) { clearReporting(); result->print(StringFromFormat("*/\nTEST(%s_memoryReport, %s)\n{ /* at %s:%d */\n", test.getGroup().asCharString(), test.getName().asCharString(), test.getFile().asCharString(), test.getLineNumber()).asCharString()); }