X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2Flauncher%2Ftesting%2FTestStep.cpp;h=d02d9b6aa98ebcb8568b8aad149c0775aae0eec0;hb=786b2fe6e2363dc5af619526208583c61f18f70b;hp=75ede747387ee3c0d6d67aa624534c1d5c922b06;hpb=603b76b5dc02acdfd87c58c51b6d48ae1858f58d;p=anna.git diff --git a/example/diameter/launcher/testing/TestStep.cpp b/example/diameter/launcher/testing/TestStep.cpp index 75ede74..d02d9b6 100644 --- a/example/diameter/launcher/testing/TestStep.cpp +++ b/example/diameter/launcher/testing/TestStep.cpp @@ -33,7 +33,7 @@ #include // Process -#include +#include #include #include #include @@ -152,7 +152,7 @@ namespace { bool result = true; try { - messageCodec.setEngine(NULL); // perhaps we will need another codec engine ... + messageCodec.clear(); messageCodec.decode(message); } catch (anna::RuntimeException &ex) { @@ -231,21 +231,21 @@ bool TestStep::execute() throw() { if (a_executed) return false; // avoid repeating (this implies amount consumption) } - LOGDEBUG(anna::Logger::debug(anna::functions::asString("EXECUTING %s (step number %d) for Test Case %llu (%p) (%p)", asText(a_type), a_number, a_testCase->getId(), (TestCaseStep*)this, this), ANNA_FILE_LOCATION)); + LOGDEBUG(anna::Logger::debug(anna::functions::asString("EXECUTING %s (step number %d) for Test Case %llu (%p)", asText(a_type), a_number, a_testCase->getId(), this), ANNA_FILE_LOCATION)); setBeginTimestamp(anna::functions::millisecond()); a_executed = true; return do_execute(); } void TestStep::complete() throw() { - LOGDEBUG(anna::Logger::debug(anna::functions::asString("COMPLETE %s (step number %d) for Test Case %llu (%p) (%p)", asText(a_type), a_number, a_testCase->getId(), (TestCaseStep*)this, this), ANNA_FILE_LOCATION)); + LOGDEBUG(anna::Logger::debug(anna::functions::asString("COMPLETE %s (step number %d) for Test Case %llu (%p)", asText(a_type), a_number, a_testCase->getId(), this), ANNA_FILE_LOCATION)); a_completed = true; setEndTimestamp(anna::functions::millisecond()); do_complete(); } void TestStep::reset() throw() { - LOGDEBUG(anna::Logger::debug(anna::functions::asString("RESET %s (step number %d) for Test Case %llu (%p) (%p)", asText(a_type), a_number, a_testCase->getId(), (TestCaseStep*)this, this), ANNA_FILE_LOCATION)); + LOGDEBUG(anna::Logger::debug(anna::functions::asString("RESET %s (step number %d) for Test Case %llu (%p)", asText(a_type), a_number, a_testCase->getId(), this), ANNA_FILE_LOCATION)); // type and testCase kept a_completed = false; a_executed = false; @@ -300,8 +300,6 @@ void TestStepTimeout::do_complete() throw() { } void TestStepTimeout::do_reset() throw() { - LOGDEBUG(anna::Logger::debug(anna::functions::asString("REXXXXXET %s for Test Case %llu (%p) (%p) (a_timer %p)", asText(a_type), a_testCase->getId(), (TestCaseStep*)this, this, a_timer), ANNA_FILE_LOCATION)); - try { TestManager::instantiate().cancelTimer(a_timer); } @@ -336,6 +334,9 @@ throw() { xmlmsg += a_messageCodec->asXMLString(); xmlmsg += "\n"; } + else { + xmlmsg = ""; + } if (msg != "") result->createAttribute("Message", msg); if (xmlmsg != "") result->createAttribute("XMLMessage", xmlmsg); @@ -349,12 +350,12 @@ throw() { bool TestStepSendxml::do_execute() throw() { bool success = false; std::string failReason, s_warn; - MyDiameterEntity *entity = a_realmNode->getEntity(); // by default - MyLocalServer *localServer = a_realmNode->getDiameterServer(); // by default + MyDiameterEntity *entity = a_originHost->getEntity(); // by default + MyLocalServer *localServer = a_originHost->getDiameterServer(); // by default const TestStepWait *tsw = NULL; // Create comm message: - anna::diameter::comm::Message *msg = a_realmNode->createCommMessage(); + anna::diameter::comm::Message *msg = a_originHost->createCommMessage(); //msg->clearBody(); msg->setBody(a_message); @@ -362,10 +363,12 @@ bool TestStepSendxml::do_execute() throw() { // Update sequence for answers: if (a_waitForRequestStepNumber != -1) { // is an answer: try to copy sequence information; alert about Session-Id discrepance // Request which was received: - tsw = (const TestStepWait*)(a_testCase->getStep(a_waitForRequestStepNumber)); + tsw = static_cast(a_testCase->getStep(a_waitForRequestStepNumber)); + const anna::DataBlock &request = tsw->getMsgDataBlock(); anna::diameter::HopByHop hbh = anna::diameter::codec::functions::getHopByHop(request); anna::diameter::EndToEnd ete = anna::diameter::codec::functions::getEndToEnd(request); + // Update sequence: anna::diameter::codec::functions::setHopByHop(a_message, hbh); anna::diameter::codec::functions::setEndToEnd(a_message, ete); @@ -373,6 +376,7 @@ bool TestStepSendxml::do_execute() throw() { // Check Session-Id for warning ... std::string sessionIdAnswer = anna::diameter::helpers::base::functions::getSessionId(a_message); std::string sessionIdRequest = anna::diameter::helpers::base::functions::getSessionId(request); + if (sessionIdRequest != sessionIdAnswer) { s_warn = anna::functions::asString("Sending an answer which Session-Id (%s) is different than supposed corresponding request (%s)", sessionIdAnswer.c_str(), sessionIdRequest.c_str()); LOGWARNING(anna::Logger::warning(s_warn, ANNA_FILE_LOCATION)); @@ -408,11 +412,13 @@ bool TestStepSendxml::do_execute() throw() { } // else (normal sending) // Detailed log: - if(a_realmNode->logEnabled()) { - if (decodeMessage()) { + if(a_originHost->logEnabled()) { + //if (decodeMessage()) { + // here we decode what we encoded on programming, then we could have a validation problem but not a decoding one: + decodeMessage(); std::string detail = usedClientSession ? usedClientSession->asString() : ""; // shouldn't happen - a_realmNode->writeLogFile(*a_messageCodec, (success ? "sent2e" : "send2eError"), detail); - } + a_originHost->writeLogFile(*a_messageCodec, (success ? "sent2e" : "send2eError"), detail); + //} } } else if (getType() == Type::Sendxml2c) { @@ -442,11 +448,13 @@ bool TestStepSendxml::do_execute() throw() { } // else (normal sending) // Detailed log: - if(a_realmNode->logEnabled()) { - if (decodeMessage()) { + if(a_originHost->logEnabled()) { + //if (decodeMessage()) { + // here we decode what we encoded on programming, then we could have a validation problem but not a decoding one: + decodeMessage(); std::string detail = usedServerSession ? usedServerSession->asString() : ""; // shouldn't happen - a_realmNode->writeLogFile(*a_messageCodec, (success ? "sent2c" : "send2cError"), detail); - } + a_originHost->writeLogFile(*a_messageCodec, (success ? "sent2c" : "send2cError"), detail); + //} } } @@ -455,7 +463,7 @@ bool TestStepSendxml::do_execute() throw() { } // release msg - a_realmNode->releaseCommMessage(msg); + a_originHost->releaseCommMessage(msg); if (!success) { a_testCase->addDebugSummaryHint(failReason); // before report (when set Failed state); @@ -482,12 +490,13 @@ throw() { anna::xml::Node* result = TestStep::asXML(parent); //parent->createChild("TestStepDelay"); - result->createAttribute("Delay", a_delay.asString()); + result->createAttribute("Delay", ((a_delay == 0) ? "dummy step, no delay" : a_delay.asString())); return result; } bool TestStepDelay::do_execute() throw() { + if (a_delay == 0) { complete(); return true; } // special case try { a_timer = TestManager::instantiate().createTimer((TestCaseStep*)this, a_delay, TestTimer::Type::Delay); } @@ -501,12 +510,14 @@ bool TestStepDelay::do_execute() throw() { } void TestStepDelay::do_complete() throw() { + if (a_delay == 0) return; // special case a_timer = NULL; next(); // next() invoked here because execute() is always false for delay and never advance the iterator // TODO, avoid this recursion } void TestStepDelay::do_reset() throw() { + if (a_delay == 0) return; // special case try { TestManager::instantiate().cancelTimer(a_timer); } @@ -566,9 +577,14 @@ throw() { xmlmsg += a_messageCodec->asXMLString(); xmlmsg += "\n"; } + else { + xmlmsg = ""; + } if (msg != "") result->createAttribute("MatchedMessage", msg); if (xmlmsg != "") result->createAttribute("MatchedXMLMessage", xmlmsg); + if (a_clientSession) result->createAttribute("ClientSessionOrigin", anna::functions::asString("%p", a_clientSession)); + if (a_serverSession) result->createAttribute("ServerSessionOrigin", anna::functions::asString("%p", a_serverSession)); return result; }