Fix answer condition from message
[anna.git] / source / testing / TestStep.cpp
index 7e96926..07ed6b3 100644 (file)
@@ -101,6 +101,7 @@ namespace {
     // TODO: mutex the step while setting data here !!
   }
 
+/*
   void cmdRunOnThreadWithFork (TestStepCmd *step, const std::string &cmd) {
 
     // Thread running:
@@ -148,6 +149,7 @@ namespace {
       step->complete();
     }
   }
+*/
 
   bool decodeMessage(const anna::DataBlock &message, anna::diameter::codec::Message &messageCodec) throw() {
 
@@ -343,7 +345,7 @@ throw() {
     xmlmsg += "\n";
   }
   else {
-    xmlmsg = "<unable to decode, check traces>"; 
+    xmlmsg = "<unable to decode, check traces>";
   }
 
   if (msg != "") result->createAttribute("Message", msg);
@@ -357,7 +359,7 @@ throw() {
 
 bool TestStepSendxml::do_execute() throw() {
   bool success = false;
-  std::string failReason;
+  std::string failReason = "Error sending diameter message";
   anna::diameter::comm::Entity *entity = a_originHost->getEntity(); // by default
   anna::diameter::comm::LocalServer *localServer = a_originHost->getDiameterServer(); // by default
   const TestStepWait *tsw = NULL;
@@ -366,12 +368,16 @@ bool TestStepSendxml::do_execute() throw() {
   try {
 
     if (a_waitForRequestStepNumber != -1) {
+      bool thisIsAnswer = anna::diameter::codec::functions::isAnswer(getMsgDataBlock());
+      LOGDEBUG(
+         std::string trace = anna::functions::asString("'Wait For Request' step number for this %s: %d", (thisIsAnswer ? "answer":"request"), a_waitForRequestStepNumber);
+         anna::Logger::debug(trace, ANNA_FILE_LOCATION);
+      );
 
       // Referenced request in the 'wait for request step':
       tsw = static_cast<const TestStepWait*>(a_testCase->getStep(a_waitForRequestStepNumber));
       const anna::DataBlock &referenceRequest = tsw->getMsgDataBlock();
       std::string sessionIdReferenceRequest = anna::diameter::helpers::base::functions::getSessionId(referenceRequest);
-      bool thisIsAnswer = anna::diameter::codec::functions::isRequest(getMsgDataBlock());
 
       if (thisIsAnswer) { // is an answer: try to copy sequence information; alert about Session-Id discrepance
         anna::diameter::HopByHop hbh = anna::diameter::codec::functions::getHopByHop(referenceRequest);
@@ -559,10 +565,14 @@ void TestStepWait::setCondition(bool fromEntity,
   a_condition.setServiceContextId(serviceContextId);
 }
 
-void TestStepWait::setCondition(bool fromEntity, const std::string &regexp) throw() {
+void TestStepWait::setConditionRegexpHex(bool fromEntity, const std::string &regexp) throw() {
+  a_condition.setReceivedFromEntity(fromEntity);
+  a_condition.setRegexpHex(regexp);
+}
 
+void TestStepWait::setConditionRegexpXml(bool fromEntity, const std::string &regexp) throw() {
   a_condition.setReceivedFromEntity(fromEntity);
-  a_condition.setRegexp(regexp);
+  a_condition.setRegexpXml(regexp);
 }
 
 anna::xml::Node* TestStepWait::asXML(anna::xml::Node* parent)
@@ -584,13 +594,18 @@ throw() {
     }
   }
 
-  if (decodeMessage()) {
-    xmlmsg = "\n";
-    xmlmsg += a_messageCodec->asXMLString();
-    xmlmsg += "\n";
+  if (a_message.isEmpty()) {
+      xmlmsg = "<empty>";
   }
   else {
-    xmlmsg = "<unable to decode, check traces>"; 
+    if (decodeMessage()) {
+      xmlmsg = "\n";
+      xmlmsg += a_messageCodec->asXMLString();
+      xmlmsg += "\n";
+    }
+    else {
+      xmlmsg = "<unable to decode, check traces>";
+    }
   }
 
   if (msg != "") result->createAttribute("MatchedMessage", msg);