X-Git-Url: https://git.teslayout.com/public/public/public/?p=anna.git;a=blobdiff_plain;f=source%2Ftesting%2FTestCase.cpp;h=8c38d06886bddbb21894996f31d64d2db977a08d;hp=fd4ed421760b2f8a689f9a66bce3b27cc849c4d9;hb=21054b5919e21b14627fac09e718262ae2812af4;hpb=882e3764e48fdf93aeb078c1832b10a956288da3 diff --git a/source/testing/TestCase.cpp b/source/testing/TestCase.cpp index fd4ed42..8c38d06 100644 --- a/source/testing/TestCase.cpp +++ b/source/testing/TestCase.cpp @@ -85,11 +85,13 @@ TestCase::TestCase(unsigned int id, const std::string &description) : } TestCase::~TestCase() { + // TestCase should not be deleted until is safeToClear() reset(true); // hard reset std::vector::const_iterator it; for (it = a_steps.begin(); it != a_steps.end(); it++) delete (*it); } + const char* TestCase::asText(const State::_v state) throw() { static const char* text [] = { "Initialized", "InProgress", "Failed", "Success" }; @@ -289,6 +291,21 @@ bool TestCase::reset(bool hard) throw() { return true; } +bool TestCase::safeToClear() { + + // Check if any step is running (command steps): + std::vector::const_iterator it; + for (it = a_steps.begin(); it != a_steps.end(); it++) { + if ((*it)->getType() == TestStep::Type::Cmd) { + const TestStepCmd *tscmd = static_cast(*it); + if(tscmd->threadRunning()) + return false; + } + } + + return true; +} + void TestCase::assertInitialized() const throw(anna::RuntimeException) { if (isFinished()) throw anna::RuntimeException(anna::functions::asString("Cannot program anymore. The test case %llu (%s) has finished. You must reset it to append new steps (or do it during execution, which is also allowed).", a_id, a_description.c_str()), ANNA_FILE_LOCATION);