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_TestCase_hpp
10 #define anna_testing_TestCase_hpp
18 #include <anna/core/DataBlock.hpp>
19 #include <anna/core/util/Millisecond.hpp>
22 #include <anna/diameter/defines.hpp>
23 #include <anna/testing/TestDiameterCondition.hpp>
41 class TestStepWaitDiameter;
44 void assertInitialized() const noexcept(false);
45 std::string assertMessage(const anna::DataBlock &db, bool toEntity) noexcept(false);
53 anna::Millisecond Timestamp;
57 std::vector<event_t> a_events;
59 void addHint(const std::string &hint) ;
61 int events() const { return a_events.size(); }
62 anna::xml::Node* asXML(anna::xml::Node* parent) const ;
63 std::string asString() const ;
66 TestCase(unsigned int id, const std::string &description = "");
69 struct State { enum _v { Initialized, InProgress, Failed, Success }; };
70 static const char* asText(const State::_v state) ;
71 const State::_v &getState() const { return a_state; }
72 const anna::Millisecond &getStartTimestamp() const { return a_startTimestamp; }
73 const anna::Millisecond &getFinishTimestamp() const { return a_finishTimestamp; }
74 anna::Millisecond getLapseMs() const ;
75 anna::Millisecond getProcessingTimeMs() const ;
76 void addDebugSummaryHint(const std::string &hint) { a_debugSummary.addHint(hint); }
77 void setState(const State::_v &state) ;
78 bool isFinished() const { return (getState() == State::Failed || getState() == State::Success); }
79 bool inProgress() const { return (getState() == State::InProgress); }
80 bool isFailed() const { return (getState() == State::Failed); }
81 bool isSuccess() const { return (getState() == State::Success); }
82 bool hasSameCondition(const TestDiameterCondition &condition) const ;
83 const DebugSummary & getDebugSummary() const { return a_debugSummary; }
86 void makeInteractive(bool yes = true) { a_interactiveAmount = (yes ? 0:-1); }
87 void addInteractiveAmount(unsigned int amount) {
88 if (a_interactiveAmount == -1) makeInteractive();
89 if (amount == 0) return;
90 a_interactiveAmount += amount;
93 int interactiveAmount() const { return a_interactiveAmount; }
94 void interactiveExecution() { a_interactiveAmount --; }
96 // Step type & information
97 void addTimeout(const anna::Millisecond &timeout) noexcept(false);
98 void addDelay(const anna::Millisecond &delay) noexcept(false);
99 void addWaitDiameter(bool fromEntity,
100 const std::string &code, const std::string &bitR, const std::string &hopByHop, const std::string &applicationId,
101 const std::string &sessionId, const std::string &resultCode,
102 const std::string &msisdn, const std::string &imsi, const std::string &serviceContextId) noexcept(false);
103 void addCommand(const std::string &cmd) noexcept(false);
104 void addIpLimit(unsigned int ipLimit) noexcept(false);
107 void addSendDiameterXml2e(const anna::DataBlock &db, anna::diameter::comm::OriginHost *host, int stepNumber) noexcept(false);
108 void addSendDiameterXml2c(const anna::DataBlock &db, anna::diameter::comm::OriginHost *host, int stepNumber) noexcept(false);
109 void addWaitDiameterAnswer(bool fromEntity, int stepNumber) noexcept(false);
110 void addWaitDiameterRegexpHex(bool fromEntity, const std::string ®exp) noexcept(false);
111 void addWaitDiameterRegexpXml(bool fromEntity, const std::string ®exp) noexcept(false);
115 void nextStep() { a_stepsIt++; }
117 bool process() ; // false to stop
119 // Reset test case and underlaying information (steps context)
120 bool reset(bool hard /* hard reset includes in-progress test cases */) ;
122 // Check for clear (destroy steps)
123 bool safeToClear(); // false if something pending (running threads steps)
126 const unsigned int &getId() const { return a_id; }
127 const std::string &getKey() const { return a_key; }
128 const std::string &getDescription() const { return a_description; }
131 void setDescription(const std::string &description) { a_description = description; }
134 int steps() const { return a_steps.size(); }
135 void addStep(TestStep *step) { a_steps.push_back(step); }
137 TestStepWaitDiameter *searchNextWaitConditionFulfilled(const anna::DataBlock &message, bool waitFromEntity) ;
138 // When a message arrives, we identify the test case by mean the Session-Id. Then, from the current step iterator (included),
139 // we search for a fulfilling condition for that message. The first found, is 'completed' and then breaks the search.
140 const TestStep *getStep(int stepNumber) const ;
142 anna::xml::Node* asXML(anna::xml::Node* parent) const ;
143 std::string asXMLString() const ;
150 std::string a_description;
151 std::vector<TestStep*> a_steps;
152 std::vector<TestStep*>::const_iterator a_stepsIt;
153 std::map<anna::diameter::HopByHop, TestStep*> a_hopByHops; // for wait-answer
155 anna::Millisecond a_startTimestamp;
156 anna::Millisecond a_finishTimestamp;
157 DebugSummary a_debugSummary; // used when a test case has failed, uncovered message conditions, and any other hint.
158 int a_interactiveAmount;
160 friend class TestStep;