X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Ftesting%2FTestCase.cpp;h=0b26170aebedbef8dfab069a1415a3360e8af8ff;hb=38f67dae313f5b4b988a11804cfee52f74e16e33;hp=e95a67088b951d03776c61c2587e79d0262e3ece;hpb=a06169181968130467d2e54ac91676aecd14bcea;p=anna.git diff --git a/example/diameter/launcher/testing/TestCase.cpp b/example/diameter/launcher/testing/TestCase.cpp index e95a670..0b26170 100644 --- a/example/diameter/launcher/testing/TestCase.cpp +++ b/example/diameter/launcher/testing/TestCase.cpp @@ -11,8 +11,6 @@ #include #include #include -#include -#include #include // Project @@ -30,6 +28,7 @@ #include +/////////////////////////////////////////////////////////////////////////////////////////////////// void TestCase::DebugSummary::addHint(const std::string &hint) throw() { event_t event; event.Timestamp = anna::functions::millisecond(); @@ -53,12 +52,24 @@ anna::xml::Node* TestCase::DebugSummary::asXML(anna::xml::Node* parent) const th return result; }; +/////////////////////////////////////////////////////////////////////////////////////////////////// +TestCase::TestCase(unsigned int id) : + a_id(id), + a_state(State::Initialized), + a_startTime(0), + a_interactiveAmount(-1) { + + /*a_stepsIt = a_steps.end()*/; + TestManager &testManager = TestManager::instantiate(); + testManager.tcsStateStats(State::Initialized, State::Initialized); +} + TestCase::~TestCase() { reset(true); // hard reset - std::map::const_iterator it; - for (it = a_steps.begin(); it != a_steps.end(); it++) delete (it->second); + 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) @@ -77,9 +88,9 @@ throw() { int steps = a_steps.size(); if (steps != 0) { result->createAttribute("NumberOfTestSteps", steps); - std::map::const_iterator it; + std::vector::const_iterator it; for (it = a_steps.begin(); it != a_steps.end(); it++) { - it->second->asXML(result); + (*it)->asXML(result); } } @@ -98,11 +109,11 @@ std::string TestCase::asXMLString() const throw() { } bool TestCase::hasSameCondition(const TestCondition &condition) const throw() { - std::map::const_iterator it; + std::vector::const_iterator it; TestStepWait *step; for (it = a_steps.begin(); it != a_steps.end(); it++) { - if (it->second->getType() != TestStep::Type::Wait) continue; - step = (TestStepWait *)(it->second); + if ((*it)->getType() != TestStep::Type::Wait) continue; + step = (TestStepWait *)(*it); if (step->getCondition() == condition) return true; } return false; @@ -115,6 +126,11 @@ void TestCase::setState(const State::_v &state) throw() { if (state == previousState) return; a_state = state; TestManager &testManager = TestManager::instantiate(); + + // stats: + testManager.tcsStateStats(previousState, state); + + if (isFinished()) { if (!testManager.getDumpReports()) return; // report file name: cycle-.testcase-.xml @@ -142,14 +158,6 @@ void TestCase::setState(const State::_v &state) throw() { out.close(); } } - - // Count in-progress test cases: - if (inProgress()) { - testManager.setInProgressCountDelta(1); - } - else if (previousState == State::InProgress){ - testManager.setInProgressCountDelta(-1); - } } bool TestCase::done() throw() { @@ -162,7 +170,7 @@ bool TestCase::done() throw() { } bool TestCase::process() throw() { - if (a_steps.size() == 0) { + if (steps() == 0) { LOGWARNING(anna::Logger::warning(anna::functions::asString("Test case %llu is empty, nothing to execute", a_id), ANNA_FILE_LOCATION)); return false; } @@ -183,7 +191,7 @@ bool TestCase::process() throw() { if (done()) return false; bool somethingDone = false; - while (a_stepsIt->second->execute()) { // executes returns 'true' if the next step must be also executed (execute until can't stand no more) + while ((*a_stepsIt)->execute()) { // executes returns 'true' if the next step must be also executed (execute until can't stand no more) nextStep(); // Check end of the test case: if (done()) return false; @@ -200,9 +208,9 @@ bool TestCase::reset(bool hard) throw() { // Clean stage //////////////////////////// // id is kept - std::map::iterator it; + std::vector::iterator it; for (it = a_steps.begin(); it != a_steps.end(); it++) - it->second->reset(); + (*it)->reset(); a_debugSummary.clear(); a_startTime = 0; @@ -233,8 +241,16 @@ void TestCase::assertMessage(const anna::DataBlock &db, bool toEntity) throw(ann a_hopByHops[hbh] = NULL; // may be assigned to a wait condition } - if (registerSessionId) - TestManager::instantiate().registerSessionId(anna::diameter::helpers::base::functions::getSessionId(db), this); + if (registerSessionId) { + try { + std::string sid = anna::diameter::helpers::base::functions::getSessionId(db); + TestManager::instantiate().registerSessionId(sid, this); + } + catch (anna::RuntimeException &ex) { + //ex.trace(); + // if we don't have session-id ... don't worry + } + } } void TestCase::addTimeout(const anna::Millisecond &timeout) throw(anna::RuntimeException) { @@ -367,10 +383,10 @@ void TestCase::addCommand(const std::string &cmd) throw(anna::RuntimeException) TestStepWait *TestCase::searchNextWaitConditionFulfilled(const anna::DataBlock &message, bool waitFromEntity) throw() { TestStepWait *result; - for (std::map::const_iterator it = a_stepsIt /* current */; it != a_steps.end(); it++) { - if (it->second->getType() != TestStep::Type::Wait) continue; - if (it->second->isCompleted()) continue; - result = (TestStepWait*)(it->second); + for (std::vector::const_iterator it = a_stepsIt /* current */; it != a_steps.end(); it++) { + if ((*it)->getType() != TestStep::Type::Wait) continue; + if ((*it)->isCompleted()) continue; + result = (TestStepWait*)(*it); if ((result->getCondition().receivedFromEntity() == waitFromEntity) && (result->fulfilled(message))) return result; } @@ -379,7 +395,7 @@ TestStepWait *TestCase::searchNextWaitConditionFulfilled(const anna::DataBlock & } const TestStep *TestCase::getStep(int stepNumber) const throw() { - std::map::const_iterator it = a_steps.find(stepNumber); - if (it != a_steps.end()) return it->second; - return NULL; + if (stepNumber < 1 || stepNumber > steps()) return NULL; +// return a_steps.at(stepNumber-1); // http://stackoverflow.com/questions/3269809/stdvectorat-vs-operator-surprising-results-5-to-10-times-slower-f + return a_steps[stepNumber-1]; }