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_TestCase_hpp
10 #define example_diameter_launcher_TestCase_hpp
17 #include <anna/core/DataBlock.hpp>
18 #include <anna/xml/Node.hpp>
19 #include <anna/diameter/defines.hpp>
22 #include <TestStep.hpp>
38 void assertInitialized() const throw(anna::RuntimeException);
39 void assertMessage(const anna::DataBlock &db, bool toEntity) throw(anna::RuntimeException);
47 anna::Millisecond Timestamp;
51 std::vector<event_t> a_events;
53 void addHint(const std::string &hint) throw();
55 int events() const throw() { return a_events.size(); }
56 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
59 TestCase(unsigned int id) : a_id(id), a_state(State::Initialized), a_startTime(0), a_interactiveAmount(-1) { /*a_stepsIt = a_steps.end()*/;}
62 struct State { enum _v { Initialized, InProgress, Failed, Success }; };
63 static const char* asText(const State::_v state) throw();
64 const State::_v &getState() const throw() { return a_state; }
65 const anna::Millisecond &getStartTimestamp() const throw() { return a_startTime; }
66 void addDebugSummaryHint(const std::string &hint) throw() { a_debugSummary.addHint(hint); }
67 void setState(const State::_v &state) throw();
68 bool isFinished() const throw() { return (getState() == State::Failed || getState() == State::Success); }
69 bool inProgress() const throw() { return (getState() == State::InProgress); }
70 bool hasSameCondition(const TestCondition &condition) const throw();
73 void makeInteractive(bool yes = true) throw() { a_interactiveAmount = (yes ? 0:-1); }
74 void addInteractiveAmount(unsigned int amount) throw() {
75 if (a_interactiveAmount == -1) makeInteractive();
76 if (amount == 0) return;
77 a_interactiveAmount += amount;
80 int interactiveAmount() const throw() { return a_interactiveAmount; }
81 void interactiveExecution() throw() { a_interactiveAmount --; }
83 // Step type & information
84 void addTimeout(const anna::Millisecond &timeout) throw(anna::RuntimeException);
85 void addSendxml2e(const anna::DataBlock &db, RealmNode *realm, int stepNumber) throw(anna::RuntimeException);
86 void addSendxml2c(const anna::DataBlock &db, RealmNode *realm, int stepNumber) throw(anna::RuntimeException);
87 void addDelay(const anna::Millisecond &delay) throw(anna::RuntimeException);
88 void addWait(bool fromEntity,
89 const std::string &code, const std::string &bitR, const std::string &hopByHop, const std::string &applicationId,
90 const std::string &sessionId, const std::string &resultCode,
91 const std::string &msisdn, const std::string &imsi, const std::string &serviceContextId) throw(anna::RuntimeException);
92 void addWaitAnswer(bool fromEntity, int stepNumber) throw(anna::RuntimeException);
93 void addWaitRegexp(bool fromEntity, const std::string ®exp) throw(anna::RuntimeException);
94 void addCommand(const std::string &cmd) throw(anna::RuntimeException);
98 void nextStep() throw() { a_stepsIt++; }
100 bool process() throw(); // false to stop
102 // Reset test case and underlaying information (steps context)
103 bool reset(bool hard /* hard reset includes in-progress test cases */) throw();
106 const anna::Millisecond &getStartTime() const throw() { return a_startTime; }
107 const unsigned int &getId() const throw() { return a_id; }
110 int steps() const throw() { return a_steps.size(); }
111 TestStepWait *searchNextWaitConditionFulfilled(const anna::DataBlock &message, bool waitFromEntity) throw();
112 // When a message arrives, we identify the test case by mean the Session-Id. Then, from the current step iterator (included),
113 // we search for a fulfilling condition for that message. The first found, is 'completed' and then breaks the search.
114 const TestStep *getStep(int stepNumber) const throw();
116 anna::xml::Node* asXML(anna::xml::Node* parent) const throw();
117 std::string asXMLString() const throw();
123 std::vector<TestStep*> a_steps;
124 std::vector<TestStep*>::const_iterator a_stepsIt;
125 std::map<anna::diameter::HopByHop, TestStep*> a_hopByHops; // for wait-answer
127 anna::Millisecond a_startTime;
128 DebugSummary a_debugSummary; // used when a test case has failed, uncovered message conditions, and any other hint.
129 int a_interactiveAmount;
131 friend class TestStep;