Allow to automatically reserve an FSM test id
[anna.git] / example / diameter / launcher / EventOperation.cpp
index a3ee7ba..2b42486 100644 (file)
@@ -357,7 +357,7 @@ bool EventOperation::sendmsg_hex_2e(std::string &response, const std::string & d
   if(my_app.getOperatedHost()->logEnabled()) {
     anna::diameter::comm::Server *usedServer = my_app.getOperatedEntity()->getLastUsedResource();
     anna::diameter::comm::ClientSession *usedClientSession = usedServer ? usedServer->getLastUsedResource() : NULL;
-    std::string detail = usedClientSession ? usedClientSession->asString() : "<null client session>"; // shouldn't happen
+    std::string detail = usedClientSession ? usedClientSession->asString() : "[null client session]"; // shouldn't happen
     my_app.getOperatedHost()->writeLogFile(codecMsg, (success ? "sent2e" : "send2eError"), detail);
   }
 
@@ -422,7 +422,7 @@ bool EventOperation::sendmsg_hex_2c(std::string &response, const std::string & d
   // Detailed log:
   if(my_app.getOperatedHost()->logEnabled()) {
     anna::diameter::comm::ServerSession *usedServerSession = my_app.getOperatedServer()->getLastUsedResource();
-    std::string detail = usedServerSession ? usedServerSession->asString() : "<null server session>"; // shouldn't happen
+    std::string detail = usedServerSession ? usedServerSession->asString() : "[null server session]"; // shouldn't happen
     my_app.getOperatedHost()->writeLogFile(codecMsg, (success ? "sent2c" : "send2cError"), detail);
   }
 
@@ -558,8 +558,9 @@ bool EventOperation::test_id__description(std::string &response, unsigned int id
   anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
 
   try {
-    testManager.getTestCase(id)->setDescription(description); // creates / reuses
-    response = "Done";
+    anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+    tc->setDescription(description);
+    response = std::to_string(tc->getId());
   }
   catch(anna::RuntimeException &ex) {
     ex.trace();
@@ -576,8 +577,9 @@ bool EventOperation::test_id__ip_limit(std::string &response, unsigned int id, i
   anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
 
   try {
-    testManager.getTestCase(id)->addIpLimit(amount); // creates / reuses
-    response = "Done";
+    anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+    tc->addIpLimit(amount);
+    response = std::to_string(tc->getId());
   }
   catch(anna::RuntimeException &ex) {
     ex.trace();
@@ -595,8 +597,9 @@ bool EventOperation::test_id__timeout(std::string &response, unsigned int id, in
 
   try {
     anna::Millisecond timeout = my_app.checkTimeMeasure("Test case timeout", anna::functions::asString(msecs));
-    testManager.getTestCase(id)->addTimeout(timeout); // creates / reuses
-    response = "Done";
+    anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+    tc->addTimeout(timeout);
+    response = std::to_string(tc->getId());
   }
   catch(anna::RuntimeException &ex) {
     ex.trace();
@@ -627,13 +630,14 @@ bool EventOperation::test_id__sendmsg2e_2c(std::string &response, unsigned int i
   );
 
   try {
+    anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
     my_app.updateOperatedOriginHostWithMessage(codecMsg);
     if (_2e_or_2c)
-      testManager.getTestCase(id)->addSendDiameterXml2e(codecMsg.code(), my_app.getOperatedHost(), stepNumber); // creates / reuses
+      tc->addSendDiameterXml2e(codecMsg.code(), my_app.getOperatedHost(), stepNumber);
     else
-      testManager.getTestCase(id)->addSendDiameterXml2c(codecMsg.code(), my_app.getOperatedHost(), stepNumber); // creates / reuses
+      tc->addSendDiameterXml2c(codecMsg.code(), my_app.getOperatedHost(), stepNumber);
 
-    response = "Done";
+    response = std::to_string(tc->getId());
   }
   catch(anna::RuntimeException &ex) {
     ex.trace();
@@ -650,9 +654,10 @@ bool EventOperation::test_id__delay(std::string &response, unsigned int id, int
   anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
 
   try {
+    anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
     anna::Millisecond delay = ((msecs == 0 /* special case */) ? (anna::Millisecond)0 : my_app.checkTimeMeasure("Test case delay step", anna::functions::asString(msecs)));
-    testManager.getTestCase(id)->addDelay(delay); // creates / reuses
-    response = "Done";
+    tc->addDelay(delay); // creates / reuses
+    response = std::to_string(tc->getId());
   }
   catch(anna::RuntimeException &ex) {
     ex.trace();
@@ -669,8 +674,9 @@ bool EventOperation::test_id__sh_command(std::string &response, unsigned int id,
   anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
 
   try {
-    testManager.getTestCase(id)->addCommand(script); // creates / reuses
-    response = "Done";
+    anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+    tc->addCommand(script); // creates / reuses
+    response = std::to_string(tc->getId());
   }
   catch(anna::RuntimeException &ex) {
     ex.trace();
@@ -718,8 +724,9 @@ bool EventOperation::test_id__waitfefc_hex(std::string &response, unsigned int i
   }
 
   try {
-    testManager.getTestCase(id)->addWaitDiameterRegexpHex(fe_or_fc, regexp);
-    response = "Done";
+    anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+    tc->addWaitDiameterRegexpHex(fe_or_fc, regexp);
+    response = std::to_string(tc->getId());
   }
   catch(anna::RuntimeException &ex) {
     ex.trace();
@@ -754,18 +761,22 @@ bool EventOperation::test_id__waitfefc_msg(std::string &response, unsigned int i
       std::string::size_type pos, pos_1, pos_2;
 
       pos = regexp.find("end-to-end-id=", 0u);
-      pos = regexp.find("\"", pos);
-      pos_1 = pos;
-      pos = regexp.find("\"", pos+1);
-      pos_2 = pos;
-      regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+      if (pos != std::string::npos) {
+        pos = regexp.find("\"", pos);
+        pos_1 = pos;
+        pos = regexp.find("\"", pos+1);
+        pos_2 = pos;
+        regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+      }
 
       pos = regexp.find("hop-by-hop-id=", 0u);
-      pos = regexp.find("\"", pos);
-      pos_1 = pos;
-      pos = regexp.find("\"", pos+1);
-      pos_2 = pos;
-      regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+      if (pos != std::string::npos) {
+        pos = regexp.find("\"", pos);
+        pos_1 = pos;
+        pos = regexp.find("\"", pos+1);
+        pos_2 = pos;
+        regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+      }
 
       // For this representation: <avp name="Origin-State-Id" data="1428633668"/>
       //pos = regexp.find("Origin-State-Id", 0u);
@@ -777,20 +788,23 @@ bool EventOperation::test_id__waitfefc_msg(std::string &response, unsigned int i
       //regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
       // But we have this one: <avp data="1428633668" name="Origin-State-Id"/>
       pos = regexp.find("Origin-State-Id", 0u);
-      pos = regexp.rfind("\"", pos);
-      pos = regexp.rfind("\"", pos-1);
-      pos = regexp.rfind("\"", pos-1);
-      pos_1 = pos;
-      pos = regexp.find("\"", pos+1);
-      pos_2 = pos;
-      regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+      if (pos != std::string::npos) {
+        pos = regexp.rfind("\"", pos);
+        pos = regexp.rfind("\"", pos-1);
+        pos = regexp.rfind("\"", pos-1);
+        pos_1 = pos;
+        pos = regexp.find("\"", pos+1);
+        pos_2 = pos;
+        regexp.replace(pos_1 + 1, pos_2 - pos_1 - 1, "[0-9]+");
+      }
 
       //regexp.insert(0, "^");
       //regexp += "$";
     }
 
-    testManager.getTestCase(id)->addWaitDiameterRegexpXml(fe_or_fc, regexp);
-    response = "Done";
+    anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+    tc->addWaitDiameterRegexpXml(fe_or_fc, regexp);
+    response = std::to_string(tc->getId());
   }
   catch(anna::RuntimeException &ex) {
     ex.trace();
@@ -816,8 +830,9 @@ bool EventOperation::test_id__waitfefc(std::string &response, unsigned int id, b
   anna::testing::TestManager &testManager = anna::testing::TestManager::instantiate();
 
   try { // [code]|[bitR]|[hopByHop]|[applicationId]|[sessionId]|[resultCode]|[msisdn]|[imsi]|[serviceContextId]
-    testManager.getTestCase(id)->addWaitDiameter(fe_or_fc, code, bitR, hopByHop, applicationId, sessionId, resultCode, msisdn, imsi, serviceContextId);
-    response = "Done";
+    anna::testing::TestCase *tc = testManager.getTestCase(id); // creates / reuses
+    tc->addWaitDiameter(fe_or_fc, code, bitR, hopByHop, applicationId, sessionId, resultCode, msisdn, imsi, serviceContextId);
+    response = std::to_string(tc->getId());
   }
   catch(anna::RuntimeException &ex) {
     ex.trace();
@@ -877,12 +892,12 @@ bool EventOperation::test__ip_limit(std::string &response, int amount) {
   if (amount > -2) {
     testManager.setInProgressLimit(amount);
     response = "New in-progress limit: ";
-    response += (amount != -1) ? anna::functions::asString(amount) : "<no limit>";
+    response += (amount != -1) ? anna::functions::asString(amount) : "[no limit]";
   }
   else {
     response = "In-progress limit amount: ";
     int limit = testManager.getInProgressLimit();
-    response += (limit != -1) ? anna::functions::asString(limit) : "<no limit>";
+    response += (limit != -1) ? anna::functions::asString(limit) : "[no limit]";
     response += "; currently there are ";
     response += anna::functions::asString(testManager.getInProgressCount());
     response += " test cases running";