X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=source%2Ftesting%2FTestCondition.cpp;h=e82e52eea13ee7ceaeeb914a9e8e6224eb74a19d;hb=4275d46f5d3c3a150ced258ae20c985520f6477a;hp=ba1db979bd656188b8bc15ced66d942c70227cd6;hpb=d723d5bf571eb48c641b092058eaa38bb6c4fcc8;p=anna.git diff --git a/source/testing/TestCondition.cpp b/source/testing/TestCondition.cpp index ba1db97..e82e52e 100644 --- a/source/testing/TestCondition.cpp +++ b/source/testing/TestCondition.cpp @@ -7,9 +7,10 @@ // Standard +#include // Project -#include +#include #include #include @@ -21,54 +22,34 @@ #include #include #include +#include using namespace anna::testing; -const char* TestCondition::asText(const Type::_v type) -throw() { - static const char* text [] = { "Generic", "Basic" }; +const char* TestDiameterCondition::asText(const Type::_v type) +{ + static const char* text [] = { "RegexpXml", "RegexpHex", "Fields" }; return text [type]; } -bool TestCondition::exists() const throw() { - if (a_type == Type::Generic) - return (a_regexp != ""); - else - return (a_code != "" || a_bitR != "" || a_hopByHop != "" || a_applicationId != "" || a_sessionId != "" || a_resultCode != "" || a_msisdn != "" || a_imsi != "" || a_serviceContextId != ""); -} - -/* -bool anna::testing::operator==(const TestCondition &c1, const TestCondition &c2) throw() { - - if (c1.getType() != c2.getType()) return false; - - if (c1.getType() == TestCondition::Type::Generic) { - if (c1.getRegexp() != c2.getRegexp()) return false; - } - else { - if (c1.getCode() != c2.getCode()) return false; - if (c1.getBitR() != c2.getBitR()) return false; - if (c1.getHopByHop() != c2.getHopByHop()) return false; - if (c1.getApplicationId() != c2.getApplicationId()) return false; - if (c1.getSessionId() != c2.getSessionId()) return false; - if (c1.getResultCode() != c2.getResultCode()) return false; - if (c1.getMsisdn() != c2.getMsisdn()) return false; - if (c1.getImsi() != c2.getImsi()) return false; - if (c1.getServiceContextId() != c2.getServiceContextId()) return false; - } +bool TestDiameterCondition::exists() const { + if (a_type != Type::Fields) return (getRegexp() != ""); - return true; + return (a_code != "" || a_bitR != "" || a_hopByHop != "" || a_applicationId != "" || a_sessionId != "" || a_resultCode != "" || a_msisdn != "" || a_imsi != "" || a_serviceContextId != ""); } -*/ -bool TestCondition::comply(const anna::DataBlock &message/*, bool matchSessionId*/) const throw() { +bool TestDiameterCondition::comply(const anna::DataBlock &message) const { - if (a_type == Type::Generic) { + if (a_type == Type::RegexpXml) { anna::diameter::codec::Message codecMsg; try { codecMsg.decode(message); } catch (anna::RuntimeException &ex) { ex.trace(); } - return codecMsg.isLike(a_regexp); + return codecMsg.isLike(getRegexp()); + } + else if (a_type == Type::RegexpHex) { + anna::RegularExpression re(getRegexp()); + return re.isLike(anna::functions::asHexString(message)); } // Basic @@ -156,13 +137,16 @@ bool TestCondition::comply(const anna::DataBlock &message/*, bool matchSessionId return true; } -anna::xml::Node* TestCondition::asXML(anna::xml::Node* parent) const -throw() { - anna::xml::Node* result = parent->createChild("TestCondition"); +anna::xml::Node* TestDiameterCondition::asXML(anna::xml::Node* parent) const +{ + anna::xml::Node* result = parent->createChild("TestDiameterCondition"); if (!exists()) return result; - if (a_type == Type::Generic) { - if (a_regexp != "") result->createAttribute("Regexp", a_regexp); + if (a_type == Type::RegexpXml) { + if (getRegexp() != "") result->createAttribute("RegexpXml", getRegexp()); + } + else if (a_type == Type::RegexpHex) { + if (getRegexp() != "") result->createAttribute("RegexpHex", getRegexp()); } else { if (a_code != "") result->createAttribute("Code", atoi(a_code.c_str()));