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>
47 int a_number; // step number used for xml (informational)
48 anna::Millisecond a_beginTimestamp; // unix time
49 anna::Millisecond a_endTimestamp; // unix time
51 void setBeginTimestamp(const anna::Millisecond &t) throw() { a_beginTimestamp = t; }
52 const anna::Millisecond &getBeginTimestamp() const throw() { return a_beginTimestamp; }
53 void setEndTimestamp(const anna::Millisecond &t) throw() { a_endTimestamp = t; }
54 const anna::Millisecond &getEndTimestamp() const throw() { return a_endTimestamp; }
56 void initialize(TestCase *testCase);
59 struct Type { enum _v { Unconfigured, Timeout, Sendxml2e, Sendxml2c, Delay, Wait, Cmd }; };
60 static const char* asText(const Type::_v type) throw();
62 TestStep(TestCase *testCase) { initialize(testCase); }
63 virtual ~TestStep() {;}
66 const Type::_v &getType() const throw() { return a_type; }
67 const int &getNumber() const throw() { return a_number; }
68 bool isCompleted() const throw() { return a_completed; }
70 bool execute() throw();
71 void complete() throw();
74 virtual anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
75 std::string asXMLString() const throw();
82 virtual bool do_execute() throw() = 0; // returns true if next step must be executed
83 virtual void do_complete() throw() = 0; // end of transaction (delay/timeout expired, wait condition fulfilled, sending done)
84 // In all cases, the next step will be executed except 'timeout' which is asynchronous
85 // and will move to the next step just after timer creation (no complete waited)
86 virtual void do_reset() throw() = 0;
90 class TestStepTimeout : public TestStep {
92 anna::Millisecond a_timeout;
93 TestTimer *a_timer; // just in case i would need to cancel
96 TestStepTimeout(TestCase *testCase) : TestStep(testCase), a_timeout(0), a_timer(NULL) { a_type = Type::Timeout; }
99 void setTimeout(const anna::Millisecond &t) throw() { a_timeout = t; }
100 const anna::Millisecond &getTimeout() const throw() { return a_timeout; }
103 bool do_execute() throw();
104 void do_complete() throw(); // timeout reached, test case failed
105 void do_reset() throw();
106 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
110 class TestStepSendxml : public TestStep {
113 // possible end points:
114 RealmNode *a_realmNode;
116 // Step number reference ('wait for request' step)
117 int a_waitForRequestStepNumber;
120 anna::DataBlock a_message;
123 bool a_expired; // a_endTimestamp will be the expiration reception timestamp
126 TestStepSendxml(TestCase *testCase) : TestStep(testCase), a_message(true), a_expired(false), a_realmNode(NULL), a_waitForRequestStepNumber(-1) {;}
129 void setRealmNode(RealmNode *realm) throw() { a_realmNode = realm; }
130 RealmNode *getRealmNode() const throw() { return a_realmNode; }
131 void setWaitForRequestStepNumber(int stepNumber) throw() { a_waitForRequestStepNumber = stepNumber; }
132 int getWaitForRequestStepNumber() const throw() { return a_waitForRequestStepNumber; }
133 void setMsgDataBlock(const anna::DataBlock &db) throw() { a_message = db; }
134 const anna::DataBlock &getMsgDataBlock() const throw() { return a_message; }
137 bool do_execute() throw();
138 void do_complete() throw() {;}
139 void do_reset() throw();
140 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
143 class TestStepSendxml2e : public TestStepSendxml {
145 TestStepSendxml2e(TestCase *testCase) : TestStepSendxml(testCase) { a_type = Type::Sendxml2e; }
148 class TestStepSendxml2c : public TestStepSendxml {
150 TestStepSendxml2c(TestCase *testCase) : TestStepSendxml(testCase) { a_type = Type::Sendxml2c; }
154 class TestStepDelay : public TestStep {
155 anna::Millisecond a_delay;
156 TestTimer *a_timer; // just in case i would need to cancel
159 TestStepDelay(TestCase *testCase) : TestStep(testCase), a_delay(0), a_timer(NULL) { a_type = Type::Delay; }
162 void setDelay(const anna::Millisecond &d) throw() { a_delay = d; }
163 const anna::Millisecond &getDelay() const throw() { return a_delay; }
166 bool do_execute() throw();
167 void do_complete() throw(); // delay reached
168 void do_reset() throw();
169 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
173 class TestStepWait : public TestStep {
175 TestCondition a_condition;
176 anna::DataBlock a_message; // message which complies with condition
177 anna::diameter::comm::ClientSession *a_clientSession;
178 anna::diameter::comm::ServerSession *a_serverSession;
181 TestStepWait(TestCase *testCase) : TestStep(testCase), a_message(true) { a_type = Type::Wait; a_clientSession = NULL; a_serverSession = NULL; }
185 void setCondition(bool fromEntity,
186 const std::string &code, const std::string &bitR, const std::string &resultCode, const std::string &sessionId,
187 const std::string &hopByHop, const std::string &msisdn, const std::string &imsi, const std::string &serviceContextId) throw();
188 void setCondition(bool fromEntity, const std::string ®exp) throw();
190 void setClientSession(anna::diameter::comm::ClientSession *cs) throw() { a_clientSession = cs; }
191 void setServerSession(anna::diameter::comm::ServerSession *ss) throw() { a_serverSession = ss; }
193 const TestCondition &getCondition() const throw() { return a_condition; }
194 //void setMsgDataBlock(const anna::DataBlock &db) throw() { a_message = db; }
195 bool fulfilled(const anna::DataBlock &db/*, bool matchSessionId = true*/) throw();
196 const anna::DataBlock &getMsgDataBlock() const throw() { return a_message; }
200 bool do_execute() throw(); // this will be executed when test case starts (at least we could measure the time until condition is fulfilled)
201 void do_complete() throw(); // condition fulfilled
202 void do_reset() throw();
203 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
207 class TestStepCmd : public TestStep {
209 std::string a_script;
210 std::string a_parameters;
211 std::thread a_thread;
212 bool a_threadRunning;
213 bool a_threadDeprecated;
215 std::string a_errorMsg;
216 //std::string a_output; // for POPEN
219 TestStepCmd(TestCase *testCase) : TestStep(testCase), a_threadRunning(false), a_threadDeprecated(false), a_resultCode(-2)/*, a_output("")*/, a_errorMsg("") { a_type = Type::Cmd; }
222 void setThreadRunning(bool running) throw() { a_threadRunning = running; }
223 //bool getThreadRunning() const throw() { return a_threadRunning; }
224 //void setThreadDeprecated(bool deprecated) throw() { a_threadDeprecated = deprecated; }
225 //bool getThreadDeprecated() const throw() { return a_threadDeprecated; }
227 void setResultCode(int rc) throw() { a_resultCode = rc; }
228 int getResultCode() const throw() { return a_resultCode; }
229 void setErrorMsg(const std::string &em) throw() { a_errorMsg = em; }
230 const std::string &getErrorMsg() const throw() { return a_errorMsg; }
231 //void appendOutput(const std::string &output) throw() { a_output += output; }
232 //const std::string &getOutput() const throw() { return a_output; }
234 void setScript(const std::string &script) throw() { a_script = script; }
235 const std::string &getScript() const throw() { return a_script; }
236 void setParameters(const std::string ¶ms) throw() { a_parameters = params; }
237 const std::string &getParameters() const throw() { return a_parameters; }
240 bool do_execute() throw();
241 void do_complete() throw();
242 void do_reset() throw();
243 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();