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 example_diameter_launcher_TestStep_hpp
10 #define example_diameter_launcher_TestStep_hpp
18 #include <anna/core/DataBlock.hpp>
19 #include <anna/xml/Node.hpp>
22 #include <TestCondition.hpp>
50 int a_number; // step number used for xml (informational)
51 anna::Millisecond a_beginTimestamp; // unix time
52 anna::Millisecond a_endTimestamp; // unix time
54 void setBeginTimestamp(const anna::Millisecond &t) throw() { a_beginTimestamp = t; }
55 const anna::Millisecond &getBeginTimestamp() const throw() { return a_beginTimestamp; }
56 void setEndTimestamp(const anna::Millisecond &t) throw() { a_endTimestamp = t; }
57 const anna::Millisecond &getEndTimestamp() const throw() { return a_endTimestamp; }
59 void initialize(TestCase *testCase);
62 struct Type { enum _v { Unconfigured, Timeout, Sendxml2e, Sendxml2c, Delay, Wait, Cmd }; };
63 static const char* asText(const Type::_v type) throw();
65 TestStep(TestCase *testCase) { initialize(testCase); }
66 virtual ~TestStep() {;}
69 const Type::_v &getType() const throw() { return a_type; }
70 const int &getNumber() const throw() { return a_number; }
71 bool isCompleted() const throw() { return a_completed; }
73 bool execute() throw();
74 void complete() throw();
77 virtual anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
78 std::string asXMLString() const throw();
85 virtual bool do_execute() throw() = 0; // returns true if next step must be executed
86 virtual void do_complete() throw() = 0; // end of transaction (delay/timeout expired, wait condition fulfilled, sending done)
87 // In all cases, the next step will be executed except 'timeout' which is asynchronous
88 // and will move to the next step just after timer creation (no complete waited)
89 virtual void do_reset() throw() = 0;
93 class TestStepTimeout : public TestStep {
95 anna::Millisecond a_timeout;
96 TestTimer *a_timer; // just in case i would need to cancel
99 TestStepTimeout(TestCase *testCase) : TestStep(testCase), a_timeout(0), a_timer(NULL) { a_type = Type::Timeout; }
102 void setTimeout(const anna::Millisecond &t) throw() { a_timeout = t; }
103 const anna::Millisecond &getTimeout() const throw() { return a_timeout; }
106 bool do_execute() throw();
107 void do_complete() throw(); // timeout reached, test case failed
108 void do_reset() throw();
109 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
113 class TestStepSendxml : public TestStep {
116 // possible end points:
117 RealmNode *a_realmNode;
119 // Step number reference ('wait for request' step)
120 int a_waitForRequestStepNumber;
123 anna::DataBlock a_message;
124 anna::diameter::codec::Message *a_messageCodec; // used as helper and for traffic logs
127 bool a_expired; // a_endTimestamp will be the expiration reception timestamp
130 TestStepSendxml(TestCase *testCase) : TestStep(testCase), a_message(true), a_messageCodec(NULL), a_expired(false), a_realmNode(NULL), a_waitForRequestStepNumber(-1) {;}
134 void setRealmNode(RealmNode *realm) throw() { a_realmNode = realm; }
135 RealmNode *getRealmNode() const throw() { return a_realmNode; }
136 void setWaitForRequestStepNumber(int stepNumber) throw() { a_waitForRequestStepNumber = stepNumber; }
137 int getWaitForRequestStepNumber() const throw() { return a_waitForRequestStepNumber; }
138 void setMsgDataBlock(const anna::DataBlock &db) throw() { a_message = db; }
139 const anna::DataBlock &getMsgDataBlock() const throw() { return a_message; }
142 bool do_execute() throw();
143 void do_complete() throw() {;}
144 void do_reset() throw();
145 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
148 class TestStepSendxml2e : public TestStepSendxml {
150 TestStepSendxml2e(TestCase *testCase) : TestStepSendxml(testCase) { a_type = Type::Sendxml2e; }
153 class TestStepSendxml2c : public TestStepSendxml {
155 TestStepSendxml2c(TestCase *testCase) : TestStepSendxml(testCase) { a_type = Type::Sendxml2c; }
159 class TestStepDelay : public TestStep {
160 anna::Millisecond a_delay;
161 TestTimer *a_timer; // just in case i would need to cancel
164 TestStepDelay(TestCase *testCase) : TestStep(testCase), a_delay(0), a_timer(NULL) { a_type = Type::Delay; }
167 void setDelay(const anna::Millisecond &d) throw() { a_delay = d; }
168 const anna::Millisecond &getDelay() const throw() { return a_delay; }
171 bool do_execute() throw();
172 void do_complete() throw(); // delay reached
173 void do_reset() throw();
174 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
178 class TestStepWait : public TestStep {
180 TestCondition a_condition;
181 anna::DataBlock a_message; // message which complies with condition
182 anna::diameter::codec::Message *a_messageCodec; // used as helper and for traffic logs
183 anna::diameter::comm::ClientSession *a_clientSession;
184 anna::diameter::comm::ServerSession *a_serverSession;
187 TestStepWait(TestCase *testCase) : TestStep(testCase), a_message(true), a_messageCodec(NULL) { a_type = Type::Wait; a_clientSession = NULL; a_serverSession = NULL; }
191 void setCondition(bool fromEntity,
192 const std::string &code, const std::string &bitR, const std::string &resultCode, const std::string &sessionId,
193 const std::string &hopByHop, const std::string &msisdn, const std::string &imsi, const std::string &serviceContextId) throw();
194 void setCondition(bool fromEntity, const std::string ®exp) throw();
196 void setClientSession(anna::diameter::comm::ClientSession *cs) throw() { a_clientSession = cs; }
197 void setServerSession(anna::diameter::comm::ServerSession *ss) throw() { a_serverSession = ss; }
198 anna::diameter::comm::ClientSession *getClientSession() const throw() { return a_clientSession; }
199 anna::diameter::comm::ServerSession *getServerSession() const throw() { return a_serverSession; }
201 const TestCondition &getCondition() const throw() { return a_condition; }
202 //void setMsgDataBlock(const anna::DataBlock &db) throw() { a_message = db; }
203 bool fulfilled(const anna::DataBlock &db/*, bool matchSessionId = true*/) throw();
204 const anna::DataBlock &getMsgDataBlock() const throw() { return a_message; }
208 bool do_execute() throw(); // this will be executed when test case starts (at least we could measure the time until condition is fulfilled)
209 void do_complete() throw(); // condition fulfilled
210 void do_reset() throw();
211 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
215 class TestStepCmd : public TestStep {
217 std::string a_script;
218 std::string a_parameters;
219 std::thread a_thread;
220 bool a_threadRunning;
221 bool a_threadDeprecated;
223 std::string a_errorMsg;
224 //std::string a_output; // for POPEN
227 TestStepCmd(TestCase *testCase) : TestStep(testCase), a_threadRunning(false), a_threadDeprecated(false), a_resultCode(-2)/*, a_output("")*/, a_errorMsg("") { a_type = Type::Cmd; }
230 void setThreadRunning(bool running) throw() { a_threadRunning = running; }
231 //bool getThreadRunning() const throw() { return a_threadRunning; }
232 //void setThreadDeprecated(bool deprecated) throw() { a_threadDeprecated = deprecated; }
233 //bool getThreadDeprecated() const throw() { return a_threadDeprecated; }
235 void setResultCode(int rc) throw() { a_resultCode = rc; }
236 int getResultCode() const throw() { return a_resultCode; }
237 void setErrorMsg(const std::string &em) throw() { a_errorMsg = em; }
238 const std::string &getErrorMsg() const throw() { return a_errorMsg; }
239 //void appendOutput(const std::string &output) throw() { a_output += output; }
240 //const std::string &getOutput() const throw() { return a_output; }
242 void setScript(const std::string &script) throw() { a_script = script; }
243 const std::string &getScript() const throw() { return a_script; }
244 void setParameters(const std::string ¶ms) throw() { a_parameters = params; }
245 const std::string &getParameters() const throw() { return a_parameters; }
248 bool do_execute() throw();
249 void do_complete() throw();
250 void do_reset() throw();
251 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();