#include "TestCaseRunner.h" #include "FileLogger.h" #include "ConsoleLogger.h" //#include "TestUiApplication.h" bool TestCaseRunner::sLastTestFailed = false; String TestCaseRunner::sFailureLine = {}; TestCaseRunner::TestCaseRunner() { } TestCaseRunner::~TestCaseRunner() { } /* TestUiApplication* TestCaseRunner::getTestApplication() { return mTestApplication; } void TestCaseRunner::setTestApplication(TestUiApplication* app) { mTestApplication = app; } */ TestCaseRunner& TestCaseRunner::getInstance() { static TestCaseRunner instance; return instance; } void TestCaseRunner::addTestCase(const String& label, const String& tag, TestCase::TestCaseFunction func) { auto test_case = new TestCase(label, tag, func); mCases.push_back(test_case); } void TestCaseRunner::markTestFailure(const String& line) { sLastTestFailed = true; sFailureLine = line; } bool TestCaseRunner::run(const Vector& args) { String test_to_run; if (args.size() > 0 ) { test_to_run = args[0]; } //FileLogger::GetInstance().disable(); for (auto test_case : mCases) { if (!test_to_run.empty()) { if (test_case->getName() != test_to_run) { continue; } } sLastTestFailed = false; ConsoleLogger::logLine("TestFramework: Running Test - %s", test_case->getName().raw()); test_case->run(); if (sLastTestFailed) { ConsoleLogger::logLine("Failed at line %s", sFailureLine.raw()); mFailingTests.push_back(test_case->getName()); } } if (mFailingTests.size() > 0) { ConsoleLogger::logLine("%d failing tests", mFailingTests.size()); for(const auto& name : mFailingTests) { ConsoleLogger::logLine(name); } } return true; }