1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_testing_TestCondition_hpp
10 #define anna_testing_TestCondition_hpp
16 #include <anna/core/DataBlock.hpp>
26 // TODO: fix types (code to int, etc.)
31 // RegexpXml = Regexp against XML representation for incoming messages
32 // RegexpHex = Regexp against HEX representation for incoming messages
33 // Fields = Compare specific message fields
34 struct Type { enum _v { RegexpXml, RegexpHex, Fields }; };
35 static const char* asText(const Type::_v type) throw();
37 TestCondition() : a_rcvFromEntity(true),
41 a_code(""), a_bitR(""), a_hopByHop(""), a_applicationId(""),
42 a_sessionId(""), a_resultCode(""),
43 a_msisdn(""), a_imsi(""), a_serviceContextId("") { a_type = Type::Fields; }
46 // Source of the received message
47 void setReceivedFromEntity(bool rfe) throw() { a_rcvFromEntity = rfe; }
48 bool receivedFromEntity() const throw() { return a_rcvFromEntity; }
51 void setRegexpXml(const std::string ®exp) throw() { a_regexp = regexp; a_type = Type::RegexpXml; }
52 void setRegexpHex(const std::string ®exp) throw() { a_regexp = regexp; a_type = Type::RegexpHex; }
55 void setCode(const std::string &value) throw() { a_code = value; a_type = Type::Fields; }
56 void setBitR(const std::string &value) throw() { a_bitR = value; a_type = Type::Fields; }
57 void setHopByHop(const std::string &value) throw() { a_hopByHop = value; a_type = Type::Fields; }
58 void setApplicationId(const std::string &value) throw() { a_applicationId = value; a_type = Type::Fields; }
59 void setSessionId(const std::string &value) throw() { a_sessionId = value; a_type = Type::Fields; }
60 void setResultCode(const std::string &value) throw() { a_resultCode = value; a_type = Type::Fields; }
61 void setMsisdn(const std::string &value) throw() { a_msisdn = value; a_type = Type::Fields; }
62 void setImsi(const std::string &value) throw() { a_imsi = value; a_type = Type::Fields; }
63 void setServiceContextId(const std::string &value) throw() { a_serviceContextId = value; a_type = Type::Fields; }
65 bool exists() const throw();
66 friend bool operator==(const TestCondition &c1, const TestCondition &c2) throw() {
68 if (c1.getType() != c2.getType()) return false;
70 if (c1.getType() == TestCondition::Type::RegexpXml || c1.getType() == TestCondition::Type::RegexpHex) {
71 if (c1.getRegexp() != c2.getRegexp()) return false;
74 if (c1.getCode() != c2.getCode()) return false;
75 if (c1.getBitR() != c2.getBitR()) return false;
76 if (c1.getHopByHop() != c2.getHopByHop()) return false;
77 if (c1.getApplicationId() != c2.getApplicationId()) return false;
78 if (c1.getSessionId() != c2.getSessionId()) return false;
79 if (c1.getResultCode() != c2.getResultCode()) return false;
80 if (c1.getMsisdn() != c2.getMsisdn()) return false;
81 if (c1.getImsi() != c2.getImsi()) return false;
82 if (c1.getServiceContextId() != c2.getServiceContextId()) return false;
89 const Type::_v &getType() const throw() { return a_type; }
92 const std::string & getRegexp() const throw() { return a_regexp; }
94 const std::string & getCode() const throw() { return a_code; }
95 const std::string & getBitR() const throw() { return a_bitR; }
96 const std::string & getHopByHop() const throw() { return a_hopByHop; }
97 const std::string & getApplicationId() const throw() { return a_applicationId; }
98 const std::string & getSessionId() const throw() { return a_sessionId; }
99 const std::string & getResultCode() const throw() { return a_resultCode; }
100 const std::string & getMsisdn() const throw() { return a_msisdn; }
101 const std::string & getImsi() const throw() { return a_imsi; }
102 const std::string & getServiceContextId() const throw() { return a_serviceContextId; }
105 bool comply (const anna::DataBlock &message) const throw();
107 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
112 // Source of the received message
113 bool a_rcvFromEntity;
119 std::string a_regexp;
124 std::string a_hopByHop;
125 std::string a_applicationId;
126 std::string a_sessionId;
127 std::string a_resultCode;
128 std::string a_msisdn;
130 std::string a_serviceContextId;