X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Ftesting%2FTestCase.cpp;h=c357e9326f915473695d2c64b9fc8d5255a3ba66;hb=f34b8069233e9e09208339bb79d8576c1ff962e1;hp=8c38d06886bddbb21894996f31d64d2db977a08d;hpb=21054b5919e21b14627fac09e718262ae2812af4;p=anna.git diff --git a/source/testing/TestCase.cpp b/source/testing/TestCase.cpp index 8c38d06..c357e93 100644 --- a/source/testing/TestCase.cpp +++ b/source/testing/TestCase.cpp @@ -33,18 +33,18 @@ using namespace anna::testing; /////////////////////////////////////////////////////////////////////////////////////////////////// -void TestCase::DebugSummary::addHint(const std::string &hint) throw() { +void TestCase::DebugSummary::addHint(const std::string &hint) { event_t event; event.Timestamp = anna::functions::millisecond(); event.Hint = hint; a_events.push_back(event); } -void TestCase::DebugSummary::clear() throw() { +void TestCase::DebugSummary::clear() { a_events.clear(); } -anna::xml::Node* TestCase::DebugSummary::asXML(anna::xml::Node* parent) const throw() { +anna::xml::Node* TestCase::DebugSummary::asXML(anna::xml::Node* parent) const { anna::xml::Node* result = parent->createChild("DebugSummary"); std::vector::const_iterator it; @@ -57,7 +57,7 @@ anna::xml::Node* TestCase::DebugSummary::asXML(anna::xml::Node* parent) const th return result; }; -std::string TestCase::DebugSummary::asString() const throw() { +std::string TestCase::DebugSummary::asString() const { std::string result = ""; std::vector::const_iterator it; @@ -73,6 +73,7 @@ std::string TestCase::DebugSummary::asString() const throw() { TestCase::TestCase(unsigned int id, const std::string &description) : a_id(id), + a_key(""), a_description((description != "") ? description : (anna::functions::asString("Testcase_%d", id))), a_state(State::Initialized), a_startTimestamp(0), @@ -93,20 +94,21 @@ TestCase::~TestCase() { const char* TestCase::asText(const State::_v state) -throw() { +{ static const char* text [] = { "Initialized", "InProgress", "Failed", "Success" }; return text [state]; } -anna::Millisecond TestCase::getLapseMs() const throw() { +anna::Millisecond TestCase::getLapseMs() const { return ((a_finishTimestamp >= a_startTimestamp) ? (a_finishTimestamp - a_startTimestamp) : (anna::Millisecond)0); } anna::xml::Node* TestCase::asXML(anna::xml::Node* parent) const -throw() { +{ anna::xml::Node* result = parent->createChild("TestCase"); result->createAttribute("Id", a_id); + if (a_key != "") result->createAttribute("Key", a_key); result->createAttribute("Description", a_description); result->createAttribute("State", asText(a_state)); result->createAttribute("StartTimestamp", a_startTimestamp.asString()); @@ -134,12 +136,12 @@ throw() { return result; } -std::string TestCase::asXMLString() const throw() { +std::string TestCase::asXMLString() const { anna::xml::Node root("root"); return anna::xml::Compiler().apply(asXML(&root)); } -bool TestCase::hasSameCondition(const TestDiameterCondition &condition) const throw() { +bool TestCase::hasSameCondition(const TestDiameterCondition &condition) const { std::vector::const_iterator it; TestStepWaitDiameter *step; for (it = a_steps.begin(); it != a_steps.end(); it++) { @@ -151,7 +153,7 @@ bool TestCase::hasSameCondition(const TestDiameterCondition &condition) const th } -void TestCase::setState(const State::_v &state) throw() { +void TestCase::setState(const State::_v &state) { State::_v previousState = a_state; if (state == previousState) return; @@ -215,7 +217,7 @@ void TestCase::setState(const State::_v &state) throw() { } } -bool TestCase::done() throw() { +bool TestCase::done() { if (a_stepsIt == a_steps.end()) { setState(State::Success); return true; @@ -224,7 +226,7 @@ bool TestCase::done() throw() { return false; } -bool TestCase::process() throw() { +bool TestCase::process() { if (steps() == 0) { LOGWARNING(anna::Logger::warning(anna::functions::asString("Test case %llu (%s) is empty, nothing to execute", a_id, a_description.c_str()), ANNA_FILE_LOCATION)); return false; @@ -264,7 +266,7 @@ bool TestCase::process() throw() { return somethingDone; } -bool TestCase::reset(bool hard) throw() { +bool TestCase::reset(bool hard) { // Soft reset if finished: if (!hard /* is soft reset */ && !isFinished()) return false; @@ -306,12 +308,14 @@ bool TestCase::safeToClear() { return true; } -void TestCase::assertInitialized() const throw(anna::RuntimeException) { +void TestCase::assertInitialized() const noexcept(false) { 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); } -void TestCase::assertMessage(const anna::DataBlock &db, bool toEntity) throw(anna::RuntimeException) { +std::string TestCase::assertMessage(const anna::DataBlock &db, bool toEntity) noexcept(false) { + + std::string key; bool isRequest = anna::diameter::codec::functions::isRequest(db); bool registerKeys = ((isRequest && toEntity) || (!isRequest && !toEntity) /* (*) */); @@ -330,28 +334,31 @@ void TestCase::assertMessage(const anna::DataBlock &db, bool toEntity) throw(ann if (registerKeys) { TestManager &testManager = TestManager::instantiate(); - testManager.registerKey1(anna::diameter::helpers::base::functions::getSessionId(db), this); + key = anna::diameter::helpers::base::functions::getSessionId(db); + testManager.registerKey1(key, this); - std::string subscriberId = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(db, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164); - if (subscriberId == "") // try with IMSI - subscriberId = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(db, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_IMSI); + key = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(db, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_E164); + if (key == "") // try with IMSI + key = anna::diameter::helpers::dcca::functions::getSubscriptionIdData(db, anna::diameter::helpers::dcca::AVPVALUES__Subscription_Id_Type::END_USER_IMSI); - if (subscriberId != "") - testManager.registerKey2(subscriberId, this); + if (key != "") + testManager.registerKey2(key, this); } + + return key; } -void TestCase::addTimeout(const anna::Millisecond &timeout) throw(anna::RuntimeException) { +void TestCase::addTimeout(const anna::Millisecond &timeout) noexcept(false) { assertInitialized(); TestStepTimeout *step = new TestStepTimeout(this); step->setTimeout(timeout); addStep(step); } -void TestCase::addSendDiameterXml2e(const anna::DataBlock &db, anna::diameter::comm::OriginHost *host, int stepNumber) throw(anna::RuntimeException) { +void TestCase::addSendDiameterXml2e(const anna::DataBlock &db, anna::diameter::comm::OriginHost *host, int stepNumber) noexcept(false) { assertInitialized(); - assertMessage(db, true /* to entity */); + a_key = assertMessage(db, true /* to entity */); if (stepNumber != -1) { const TestStep *stepReferred = getStep(stepNumber); @@ -374,9 +381,9 @@ void TestCase::addSendDiameterXml2e(const anna::DataBlock &db, anna::diameter::c addStep(step); } -void TestCase::addSendDiameterXml2c(const anna::DataBlock &db, anna::diameter::comm::OriginHost *host, int stepNumber) throw(anna::RuntimeException) { +void TestCase::addSendDiameterXml2c(const anna::DataBlock &db, anna::diameter::comm::OriginHost *host, int stepNumber) noexcept(false) { assertInitialized(); - assertMessage(db, false /* to client */); + a_key = assertMessage(db, false /* to client */); if (stepNumber != -1) { const TestStep *stepReferred = getStep(stepNumber); @@ -399,7 +406,7 @@ void TestCase::addSendDiameterXml2c(const anna::DataBlock &db, anna::diameter::c addStep(step); } -void TestCase::addDelay(const anna::Millisecond &delay) throw(anna::RuntimeException) { +void TestCase::addDelay(const anna::Millisecond &delay) noexcept(false) { assertInitialized(); TestStepDelay *step = new TestStepDelay(this); step->setDelay(delay); @@ -409,7 +416,7 @@ void TestCase::addDelay(const anna::Millisecond &delay) throw(anna::RuntimeExcep void TestCase::addWaitDiameter(bool fromEntity, const std::string &code, const std::string &bitR, const std::string &hopByHop, const std::string &applicationId, const std::string &sessionId, const std::string &resultCode, - const std::string &msisdn, const std::string &imsi, const std::string &serviceContextId) throw(anna::RuntimeException) { + const std::string &msisdn, const std::string &imsi, const std::string &serviceContextId) noexcept(false) { assertInitialized(); std::string usedHopByHop = hopByHop; TestStepWaitDiameter *step = NULL; @@ -461,7 +468,7 @@ void TestCase::addWaitDiameter(bool fromEntity, addStep(step); } -void TestCase::addWaitDiameterRegexpHex(bool fromEntity, const std::string ®exp) throw(anna::RuntimeException) { +void TestCase::addWaitDiameterRegexpHex(bool fromEntity, const std::string ®exp) noexcept(false) { assertInitialized(); TestStepWaitDiameter *step = new TestStepWaitDiameter(this); @@ -475,7 +482,7 @@ void TestCase::addWaitDiameterRegexpHex(bool fromEntity, const std::string ®e addStep(step); } -void TestCase::addWaitDiameterRegexpXml(bool fromEntity, const std::string ®exp) throw(anna::RuntimeException) { +void TestCase::addWaitDiameterRegexpXml(bool fromEntity, const std::string ®exp) noexcept(false) { assertInitialized(); TestStepWaitDiameter *step = new TestStepWaitDiameter(this); @@ -489,7 +496,7 @@ void TestCase::addWaitDiameterRegexpXml(bool fromEntity, const std::string ®e addStep(step); } -void TestCase::addCommand(const std::string &cmd) throw(anna::RuntimeException) { +void TestCase::addCommand(const std::string &cmd) noexcept(false) { assertInitialized(); TestStepCmd *step = new TestStepCmd(this); @@ -498,7 +505,7 @@ void TestCase::addCommand(const std::string &cmd) throw(anna::RuntimeException) addStep(step); } -void TestCase::addIpLimit(unsigned int ipLimit) throw(anna::RuntimeException) { +void TestCase::addIpLimit(unsigned int ipLimit) noexcept(false) { assertInitialized(); TestStepIpLimit *step = new TestStepIpLimit(this); @@ -507,7 +514,7 @@ void TestCase::addIpLimit(unsigned int ipLimit) throw(anna::RuntimeException) { addStep(step); } -TestStepWaitDiameter *TestCase::searchNextWaitConditionFulfilled(const anna::DataBlock &message, bool waitFromEntity) throw() { +TestStepWaitDiameter *TestCase::searchNextWaitConditionFulfilled(const anna::DataBlock &message, bool waitFromEntity) { TestStepWaitDiameter *result; for (std::vector::const_iterator it = a_stepsIt /* current */; it != a_steps.end(); it++) { @@ -521,7 +528,7 @@ TestStepWaitDiameter *TestCase::searchNextWaitConditionFulfilled(const anna::Dat return NULL; } -const TestStep *TestCase::getStep(int stepNumber) const throw() { +const TestStep *TestCase::getStep(int stepNumber) const { 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];