X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Ftesting%2FTestManager.cpp;h=beb0d9398895ee05844e96723ed5285a77671717;hb=4275d46f5d3c3a150ced258ae20c985520f6477a;hp=87278f14ce768aa66fccaf82daf59c81f38e5897;hpb=5a6cba5fde2b2f538a7515f8293cc0a8d9589dfa;p=anna.git diff --git a/source/testing/TestManager.cpp b/source/testing/TestManager.cpp index 87278f1..beb0d93 100644 --- a/source/testing/TestManager.cpp +++ b/source/testing/TestManager.cpp @@ -287,6 +287,10 @@ TestCase *TestManager::findTestCase(unsigned int id) const { // id = -1 provides TestCase *TestManager::getTestCase(unsigned int id, const std::string &description) { + if (id == 0) { // 0 is used to sequence automatically and get the value of 'tests() + 1' + id = tests() + 1; + } + test_pool_nc_it it = a_testPool.find(id); if (it != a_testPool.end()) return it->second; @@ -295,6 +299,56 @@ TestCase *TestManager::getTestCase(unsigned int id, const std::string &descripti return result; } +bool TestManager::clearTestCase(std::string &result, unsigned int id) { + result = ""; + + if (!tests()) { + result = "There are not programmed test cases to be removed"; + return false; + } + + test_pool_it it = ((id != -1) ? a_testPool.find(id) : a_currentTestIt); + if (it == a_testPool.end()) { + result = "Test case id provided not found"; + return false; + } + + if (!it->second->safeToClear()) { + result = "Test case id provided has running-thread steps. Check for stuck external procedures or try later."; + return false; + } + + a_testPool.erase(it); + + result = "Provided test case has been dropped"; + bool something_removed = false; + + auto key1_it = a_key1TestCaseMap.find(it->second->getKey1()); + if (key1_it != a_key1TestCaseMap.end()) { + a_key1TestCaseMap.erase(key1_it); + result += " | Removed key1 = "; + result += it->second->getKey1(); + something_removed = true; + } + auto key2_it = a_key2TestCaseMap.find(it->second->getKey2()); + if (key2_it != a_key2TestCaseMap.end()) { + a_key2TestCaseMap.erase(key2_it); + result += " | Removed key2 = "; + result += it->second->getKey2(); + something_removed = true; + } + + if (something_removed) return true; + + result = "Provided test case has been dropped, but key1 = '"; + result += it->second->getKey1(); + result += "' was not found, and also key2 = '"; + result += it->second->getKey2(); + result += "' was not found"; + + return false; +} + bool TestManager::clearPool(std::string &result) { result = "";