X-Git-Url: https://git.teslayout.com/public/public/public/?p=anna.git;a=blobdiff_plain;f=source%2Ftesting%2FTestCondition.cpp;h=fcb3c089651b017ae79af19d0ed2ff3a5229cb98;hp=ba1db979bd656188b8bc15ced66d942c70227cd6;hb=9fa68da11c56250017da9735e4a5dd3fd3b2021b;hpb=d30d9e082885e16f0098a699a3b79f53fb28910b diff --git a/source/testing/TestCondition.cpp b/source/testing/TestCondition.cpp index ba1db97..fcb3c08 100644 --- a/source/testing/TestCondition.cpp +++ b/source/testing/TestCondition.cpp @@ -7,6 +7,7 @@ // Standard +#include // Project #include @@ -21,6 +22,7 @@ #include #include #include +#include using namespace anna::testing; @@ -28,47 +30,36 @@ using namespace anna::testing; const char* TestCondition::asText(const Type::_v type) throw() { - static const char* text [] = { "Generic", "Basic" }; + 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; - } + 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 TestCondition::comply(const anna::DataBlock &message) const throw() { - 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()); + // We will remove LF from both sides to ease regexp management: + std::string regexp = getRegexp(); + regexp.erase(std::remove(regexp.begin(), regexp.end(), '\n'), regexp.end()); + anna::RegularExpression re(regexp); + + std::string msgString = codecMsg.asXMLString(); + msgString.erase(std::remove(msgString.begin(), msgString.end(), '\n'), msgString.end()); + + return re.isLike(msgString); + } + else if (a_type == Type::RegexpHex) { + anna::RegularExpression re(getRegexp()); + return re.isLike(anna::functions::asHexString(message)); } // Basic @@ -161,8 +152,11 @@ throw() { anna::xml::Node* result = parent->createChild("TestCondition"); 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()));