// Standard
+#include <algorithm>
// Project
-#include <anna/testing/TestCondition.hpp>
+#include <anna/testing/TestDiameterCondition.hpp>
#include <anna/xml/Node.hpp>
#include <anna/xml/Compiler.hpp>
#include <anna/diameter/helpers/dcca/defines.hpp>
#include <anna/diameter/helpers/dcca/functions.hpp>
#include <anna/core/util/defines.hpp>
+#include <anna/core/util/RegularExpression.hpp>
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
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()));