Fork variant for TestStep command
[anna.git] / example / diameter / launcher / testing / TestCase.cpp
index b3d2f2f..63851f7 100644 (file)
@@ -9,6 +9,10 @@
 // Standard
 #include <string>
 #include <fstream>
+#include <sstream>
+#include <cmath>
+
+#include <iostream>
 
 // Project
 #include <anna/xml/Compiler.hpp>
@@ -82,6 +86,8 @@ throw() {
     a_debugSummary.asXML(result);
   }
 
+  result->createAttribute("Interactive", (a_interactiveAmount != -1) ? "yes":"no");
+
   return result;
 }
 
@@ -111,7 +117,17 @@ void TestCase::setState(const State::_v &state) throw() {
   if (isFinished()) {
     if (!testManager.getDumpReports()) return;
     // report file name: cycle-<cycle id>.testcase-<test case id>.xml
-    std::string file = testManager.getReportsDirectory() + anna::functions::asString("/cycle-%d.testcase-%llu.xml", testManager.getPoolCycle(), a_id);
+
+    // FORMAT: We tabulate the cycle and test case in order to ease ordering of files by mean ls:
+    int cycles = testManager.getPoolRepeats();
+    int tests = testManager.tests();
+    int cyclesWidth = (cycles<=0) ? 3 /* 1000 cycles !! */: ((int) log10 ((double) cycles) + 1);
+    int testsWidth = (tests<=0) ? 9 /* subscribers */: ((int) log10 ((double) tests) + 1);
+    std::stringstream format;
+    format << "/cycle-%0" << cyclesWidth << "d.testcase-%0" << testsWidth << "llu.xml";
+
+    // FILE NAME:
+    std::string file = testManager.getReportsDirectory() + anna::functions::asString(format.str().c_str(), testManager.getPoolCycle(), a_id);
     std::ofstream out;
     out.open(file.c_str(), std::ofstream::out | std::ofstream::app);
     if(out.is_open() == false) {
@@ -189,6 +205,7 @@ bool TestCase::reset(bool hard) throw() {
 
   a_debugSummary.clear();
   a_startTime = 0;
+  a_interactiveAmount = -1;
 
   setState(State::Initialized);
 
@@ -234,15 +251,15 @@ void TestCase::addSendxml2e(const anna::DataBlock &db, RealmNode *realm, int ste
     int steps = a_steps.size();
     int stepIndx = stepNumber - 1;
     if ((stepIndx < 0) || (stepIndx > (a_steps.size()-1)))
-      throw anna::RuntimeException(anna::functions::asString("Step number out of range (test case %llu)", a_id), ANNA_FILE_LOCATION);
+      throw anna::RuntimeException(anna::functions::asString("Step number (%d) out of range (test case %llu)", stepNumber, a_id), ANNA_FILE_LOCATION);
 
     TestStep *stepReferred = a_steps[stepIndx];
     if (stepReferred->getType() != TestStep::Type::Wait)
-      throw anna::RuntimeException(anna::functions::asString("Step number must refer to a 'wait' step (test case %llu)", a_id), ANNA_FILE_LOCATION);
+      throw anna::RuntimeException(anna::functions::asString("Step number (%d) must refer to a 'wait' step (test case %llu)", stepNumber, a_id), ANNA_FILE_LOCATION);
 
     const TestCondition &tc = (static_cast<TestStepWait*>(stepReferred))->getCondition();
     if (tc.getCode() == "0") { // if regexp used, is not possible to detect this kind of errors
-      throw anna::RuntimeException(anna::functions::asString("Step number must refer to a 'wait for request' step (test case %llu)", a_id), ANNA_FILE_LOCATION);
+      throw anna::RuntimeException(anna::functions::asString("Step number (%d) must refer to a 'wait for request' step (test case %llu)", stepNumber, a_id), ANNA_FILE_LOCATION);
     }
   }
 
@@ -271,8 +288,9 @@ void TestCase::addDelay(const anna::Millisecond &delay) throw(anna::RuntimeExcep
 }
 
 void TestCase::addWait(bool fromEntity,
-                        const std::string &code, const std::string &bitR, const std::string &resultCode, const std::string &sessionId,
-                        const std::string &hopByHop, const std::string &msisdn, const std::string &imsi, const std::string &serviceContextId) throw(anna::RuntimeException) {
+              const std::string &code, const std::string &bitR, const std::string &hopByHop, const std::string &applicationId,
+              const std::string &sessionId, const std::string &resultCode,
+              const std::string &msisdn, const std::string &imsi, const std::string &serviceContextId) throw(anna::RuntimeException) {
   assertInitialized();
   std::string usedHopByHop = hopByHop;
   TestStepWait *step = NULL;
@@ -315,7 +333,7 @@ void TestCase::addWait(bool fromEntity,
   }
 
   if (!step) step = new TestStepWait(this);
-  step->setCondition(fromEntity, code, bitR, resultCode, sessionId, usedHopByHop, msisdn, imsi, serviceContextId);
+  step->setCondition(fromEntity, code, bitR, usedHopByHop, applicationId, sessionId, resultCode, msisdn, imsi, serviceContextId);
 
   LOGWARNING(
     if (hasSameCondition(step->getCondition()))
@@ -339,12 +357,11 @@ void TestCase::addWaitRegexp(bool fromEntity, const std::string &regexp) throw(a
   a_steps.push_back(step);
 }
 
-void TestCase::addCmd(const std::string &script, const std::string &parameters) throw(anna::RuntimeException) {
+void TestCase::addCommand(const std::string &cmd) throw(anna::RuntimeException) {
   assertInitialized();
 
   TestStepCmd *step = new TestStepCmd(this);
-  step->setScript(script);
-  step->setParameters(parameters);
+  step->setScript(cmd);
 
   a_steps.push_back(step);
 }