X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Ftesting%2FTestCase.cpp;h=e95a67088b951d03776c61c2587e79d0262e3ece;hb=a06169181968130467d2e54ac91676aecd14bcea;hp=32ecba158334c15d84683adcc657c2dae5989661;hpb=e80e62a5cf9aacad1a9551c68c432147ef98cd29;p=anna.git diff --git a/example/diameter/launcher/testing/TestCase.cpp b/example/diameter/launcher/testing/TestCase.cpp index 32ecba1..e95a670 100644 --- a/example/diameter/launcher/testing/TestCase.cpp +++ b/example/diameter/launcher/testing/TestCase.cpp @@ -11,7 +11,8 @@ #include #include #include - +#include +#include #include // Project @@ -56,8 +57,8 @@ anna::xml::Node* TestCase::DebugSummary::asXML(anna::xml::Node* parent) const th TestCase::~TestCase() { reset(true); // hard reset - std::vector::const_iterator it; - for (it = a_steps.begin(); it != a_steps.end(); it++) delete (*it); + std::map::const_iterator it; + for (it = a_steps.begin(); it != a_steps.end(); it++) delete (it->second); } const char* TestCase::asText(const State::_v state) @@ -76,9 +77,9 @@ throw() { int steps = a_steps.size(); if (steps != 0) { result->createAttribute("NumberOfTestSteps", steps); - std::vector::const_iterator it; + std::map::const_iterator it; for (it = a_steps.begin(); it != a_steps.end(); it++) { - (*it)->asXML(result); + it->second->asXML(result); } } @@ -86,6 +87,8 @@ throw() { a_debugSummary.asXML(result); } + result->createAttribute("Interactive", (a_interactiveAmount != -1) ? "yes":"no"); + return result; } @@ -95,11 +98,11 @@ std::string TestCase::asXMLString() const throw() { } bool TestCase::hasSameCondition(const TestCondition &condition) const throw() { - std::vector::const_iterator it; + std::map::const_iterator it; TestStepWait *step; for (it = a_steps.begin(); it != a_steps.end(); it++) { - if ((*it)->getType() != TestStep::Type::Wait) continue; - step = (TestStepWait *)(*it); + if (it->second->getType() != TestStep::Type::Wait) continue; + step = (TestStepWait *)(it->second); if (step->getCondition() == condition) return true; } return false; @@ -180,7 +183,7 @@ bool TestCase::process() throw() { if (done()) return false; bool somethingDone = false; - while ((*a_stepsIt)->execute()) { // executes returns 'true' if the next step must be also executed (execute until can't stand no more) + while (a_stepsIt->second->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; @@ -197,12 +200,13 @@ bool TestCase::reset(bool hard) throw() { // Clean stage //////////////////////////// // id is kept - std::vector::iterator it; + std::map::iterator it; for (it = a_steps.begin(); it != a_steps.end(); it++) - (*it)->reset(); + it->second->reset(); a_debugSummary.clear(); a_startTime = 0; + a_interactiveAmount = -1; setState(State::Initialized); @@ -237,7 +241,7 @@ void TestCase::addTimeout(const anna::Millisecond &timeout) throw(anna::RuntimeE assertInitialized(); TestStepTimeout *step = new TestStepTimeout(this); step->setTimeout(timeout); - a_steps.push_back(step); + addStep(step); } void TestCase::addSendxml2e(const anna::DataBlock &db, RealmNode *realm, int stepNumber) throw(anna::RuntimeException) { @@ -245,16 +249,14 @@ void TestCase::addSendxml2e(const anna::DataBlock &db, RealmNode *realm, int ste assertMessage(db, true /* to entity */); if (stepNumber != -1) { - int steps = a_steps.size(); - int stepIndx = stepNumber - 1; - if ((stepIndx < 0) || (stepIndx > (a_steps.size()-1))) - throw anna::RuntimeException(anna::functions::asString("Step number (%d) out of range (test case %llu)", stepNumber, a_id), ANNA_FILE_LOCATION); + const TestStep *stepReferred = getStep(stepNumber); + if (!stepReferred) + throw anna::RuntimeException(anna::functions::asString("Step number (%d) do not exists (test case %llu)", stepNumber, a_id), ANNA_FILE_LOCATION); - TestStep *stepReferred = a_steps[stepIndx]; if (stepReferred->getType() != TestStep::Type::Wait) throw anna::RuntimeException(anna::functions::asString("Step number (%d) must refer to a 'wait' step (test case %llu)", stepNumber, a_id), ANNA_FILE_LOCATION); - const TestCondition &tc = (static_cast(stepReferred))->getCondition(); + const TestCondition &tc = (static_cast(stepReferred))->getCondition(); if (tc.getCode() == "0") { // if regexp used, is not possible to detect this kind of errors throw anna::RuntimeException(anna::functions::asString("Step number (%d) must refer to a 'wait for request' step (test case %llu)", stepNumber, a_id), ANNA_FILE_LOCATION); } @@ -264,7 +266,7 @@ void TestCase::addSendxml2e(const anna::DataBlock &db, RealmNode *realm, int ste step->setMsgDataBlock(db); step->setRealmNode(realm); step->setWaitForRequestStepNumber(stepNumber); // -1 means, no reference - a_steps.push_back(step); + addStep(step); } void TestCase::addSendxml2c(const anna::DataBlock &db, RealmNode *realm, int stepNumber) throw(anna::RuntimeException) { @@ -274,14 +276,14 @@ void TestCase::addSendxml2c(const anna::DataBlock &db, RealmNode *realm, int ste TestStepSendxml2c *step = new TestStepSendxml2c(this); step->setMsgDataBlock(db); step->setRealmNode(realm); - a_steps.push_back(step); + addStep(step); } void TestCase::addDelay(const anna::Millisecond &delay) throw(anna::RuntimeException) { assertInitialized(); TestStepDelay *step = new TestStepDelay(this); step->setDelay(delay); - a_steps.push_back(step); + addStep(step); } void TestCase::addWait(bool fromEntity, @@ -302,20 +304,19 @@ void TestCase::addWait(bool fromEntity, else { if (hopByHop != "") { if (hopByHop[0] == '#') { - int steps = a_steps.size(); - if (steps == 0) + if (steps() == 0) throw anna::RuntimeException(anna::functions::asString("No steps has been programmed, step reference is nonsense (test case %llu)", a_id), ANNA_FILE_LOCATION); int stepNumber = atoi(hopByHop.substr(1).c_str()); - int stepIndx = stepNumber - 1; - if ((stepIndx < 0) || (stepIndx > (steps-1))) - throw anna::RuntimeException(anna::functions::asString("Step reference number %d out of range [1-%d]", stepNumber, steps), ANNA_FILE_LOCATION); - TestStep *stepReferred = a_steps[stepIndx]; + const TestStep *stepReferred = getStep(stepNumber); + if (!stepReferred) + throw anna::RuntimeException(anna::functions::asString("Step reference number (%d) do not exists (test case %llu)", stepNumber, a_id), ANNA_FILE_LOCATION); + if (stepReferred->getType() != TestStep::Type::Sendxml2e && stepReferred->getType() != TestStep::Type::Sendxml2c) throw anna::RuntimeException(anna::functions::asString("Step number must refer to a 'sendxml2e' or 'sendxml2c' step (test case %llu)", a_id), ANNA_FILE_LOCATION); - const anna::DataBlock &db = (static_cast(stepReferred))->getMsgDataBlock(); + const anna::DataBlock &db = (static_cast(stepReferred))->getMsgDataBlock(); bool isAnswer = anna::diameter::codec::functions::isAnswer(db); if (isAnswer) throw anna::RuntimeException(anna::functions::asString("Step number must refer to a request message (test case %llu)", a_id), ANNA_FILE_LOCATION); @@ -337,7 +338,7 @@ void TestCase::addWait(bool fromEntity, anna::Logger::warning(anna::functions::asString("The same wait condition has already been programmed in this test case (%llu). Are you sure ?", a_id), ANNA_FILE_LOCATION); ); - a_steps.push_back(step); + addStep(step); } void TestCase::addWaitRegexp(bool fromEntity, const std::string ®exp) throw(anna::RuntimeException) { @@ -351,26 +352,25 @@ void TestCase::addWaitRegexp(bool fromEntity, const std::string ®exp) throw(a anna::Logger::warning(anna::functions::asString("The same wait condition has already been programmed in this test case (%llu). Are you sure ?", a_id), ANNA_FILE_LOCATION); ); - a_steps.push_back(step); + addStep(step); } -void TestCase::addCmd(const std::string &script, const std::string ¶meters) throw(anna::RuntimeException) { +void TestCase::addCommand(const std::string &cmd) throw(anna::RuntimeException) { assertInitialized(); TestStepCmd *step = new TestStepCmd(this); - step->setScript(script); - step->setParameters(parameters); + step->setScript(cmd); - a_steps.push_back(step); + addStep(step); } TestStepWait *TestCase::searchNextWaitConditionFulfilled(const anna::DataBlock &message, bool waitFromEntity) throw() { TestStepWait *result; - 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); + 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); if ((result->getCondition().receivedFromEntity() == waitFromEntity) && (result->fulfilled(message))) return result; } @@ -379,8 +379,7 @@ TestStepWait *TestCase::searchNextWaitConditionFulfilled(const anna::DataBlock & } const TestStep *TestCase::getStep(int stepNumber) const throw() { - int stepIndx = stepNumber - 1; - if ((stepIndx < 0) || (stepIndx > (a_steps.size()-1))) return NULL; - std::vector::const_iterator it = (a_steps.begin() + stepNumber); - return (*it); + std::map::const_iterator it = a_steps.find(stepNumber); + if (it != a_steps.end()) return it->second; + return NULL; }