+anna::xml::Node* TestManager::junitAsXML(anna::xml::Node* parent) const
+{
+ // if only a single testsuite element is present, the testsuites element can be omitted
+ //anna::xml::Node* result = parent->createChild("testsuites");
+ anna::xml::Node* result = parent->createChild("testsuite");
+
+/*
+https://stackoverflow.com/questions/4922867/what-is-the-junit-xml-format-specification-that-hudson-supports
+
+JUnit XSD file
+==============
+https://windyroad.com.au/dl/Open%20Source/JUnit.xsd
+
+EXAMPLES
+========
+<?xml version="1.0" encoding="UTF-8"?>
+<testsuites disabled="" errors="" failures="" name="" tests="" time="">
+ <testsuite disabled="" errors="" failures="" hostname="" id=""
+ name="" package="" skipped="" tests="" time="" timestamp="">
+ <properties>
+ <property name="" value=""/>
+ </properties>
+ <testcase assertions="" classname="" name="" status="" time="">
+ <skipped/>
+ <error message="" type=""/>
+ <failure message="" type=""/>
+ <system-out/>
+ <system-err/>
+ </testcase>
+ <system-out/>
+ <system-err/>
+ </testsuite>
+</testsuites>
+
+Some of these items can occur multiple times:
+
+There can only be one testsuites element, since that's how XML works, but there can be multiple testsuite elements within the testsuites element.
+Each properties element can have multiple property children.
+Each testsuite element can have multiple testcase children.
+Each testcase element can have multiple error, failure, system-out, or system-err children:
+
+<testsuite tests="3">
+ <testcase classname="foo1" name="ASuccessfulTest"/>
+ <testcase classname="foo2" name="AnotherSuccessfulTest"/>
+ <testcase classname="foo3" name="AFailingTest">
+ <failure type="NotEnoughFoo"> details about failure </failure>
+ </testcase>
+</testsuite>
+
+*/
+
+/*
+ <testsuite name="" <!-- Full (class) name of the test for non-aggregated testsuite documents.
+ Class name without the package for aggregated testsuites documents. Required -->
+ tests="" <!-- The total number of tests in the suite, required. -->
+
+ disabled="" <!-- the total number of disabled tests in the suite. optional -->
+ errors="" <!-- The total number of tests in the suite that errored. An errored test is one that had an unanticipated problem,
+ for example an unchecked throwable; or a problem with the implementation of the test. optional -->
+ failures="" <!-- The total number of tests in the suite that failed. A failure is a test which the code has explicitly failed
+ by using the mechanisms for that purpose. e.g., via an assertEquals. optional -->
+ hostname="" <!-- Host on which the tests were executed. 'localhost' should be used if the hostname cannot be determined. optional -->
+ id="" <!-- Starts at 0 for the first testsuite and is incremented by 1 for each following testsuite -->
+ package="" <!-- Derived from testsuite/@name in the non-aggregated documents. optional -->
+ skipped="" <!-- The total number of skipped tests. optional -->
+ time="" <!-- Time taken (in seconds) to execute the tests in the suite. optional -->
+ timestamp="" <!-- when the test was executed in ISO 8601 format (2014-01-21T16:17:18). Timezone may not be specified. optional -->
+ >
+*/
+ result->createAttribute("name", "ADML Testing Main Testsuite");
+ int poolSize = a_testPool.size();
+ result->createAttribute("tests", poolSize);
+
+ result->createAttribute("errors", 0);
+ result->createAttribute("failures", a_statSummary.getFailedCount());
+ result->createAttribute("hostname", anna::functions::getHostname());
+ result->createAttribute("skipped", a_statSummary.getInitializedCount());
+
+ // Testcases:
+
+/*
+ <!-- testcase can appear multiple times, see /testsuites/testsuite@tests -->
+ <testcase name="" <!-- Name of the test method, required. -->
+ assertions="" <!-- number of assertions in the test case. optional -->
+ classname="" <!-- Full class name for the class the test method is in. required -->
+ status=""
+ time="" <!-- Time taken (in seconds) to execute the test. optional -->
+ >
+
+*/
+ int testcasesLapseMs = 0;
+ int startTimestampMs = 0;
+ double secs;
+ if (poolSize != 0) {
+ test_pool_it it_min = a_testPool.begin();
+ test_pool_it it_max = a_testPool.end();
+ startTimestampMs = (int)((*it_min).second->getStartTimestamp());
+ std::string debugSummary;
+
+ for (test_pool_it it = it_min; it != it_max; it++) {
+ anna::xml::Node* testcase = result->createChild("testcase");
+ auto tc = (*it).second;
+
+ testcasesLapseMs = (int)(tc->getLapseMs());
+ testcase->createAttribute("classname", "adml_testcase");
+ testcase->createAttribute("description", tc->getDescription());
+ testcase->createAttribute("status", TestCase::asText(tc->getState()));
+
+ secs = testcasesLapseMs / 1000.0;
+ testcase->createAttribute("time", anna::functions::asString(secs, "%.2f"));
+
+ if (tc->isFailed()) {
+ anna::xml::Node* failure = testcase->createChild("failure");
+ std::string text = "";
+ debugSummary = tc->getDebugSummary().asString();
+ if (debugSummary != "") {
+ text += "[Testcase debug summary]";
+ text += "<!--";
+ text += debugSummary;
+ text += "-->";
+ }
+ text += "[Testcase information (xml dump)]";
+ text += "<!--";
+ text += tc->asXMLString();
+ text += "-->";
+ failure->createText(text);
+ }
+ }
+ }
+
+ time_t startTimestamp = startTimestampMs/1000;
+ time(&startTimestamp);
+ char buf[sizeof "2011-10-08T07:07:09Z"];
+ strftime(buf, sizeof buf, "%FT%TZ", gmtime(&startTimestamp));
+ // this will work too, if your compiler doesn't support %F or %T:
+ // //strftime(buf, sizeof buf, "%Y-%m-%dT%H:%M:%SZ", gmtime(&now));
+ // std::cout << buf << "\n";
+ result->createAttribute("timestamp", buf);
+
+
+ return result;
+}
+
+std::string TestManager::asXMLString() const {