FreeNOS
XMLReporter.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Niek Linnenbank
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <libgen.h>
22#include <ListIterator.h>
23#include <TerminalCodes.h>
24#include "TestCase.h"
25#include "XMLReporter.h"
26
27XMLReporter::XMLReporter(int argc, char **argv)
28 : TestReporter(argc, argv)
29{
30}
31
33{
34 if (m_multiline)
35 {
36 printf("<!-- Init %s -->\r\n",
37 m_argv[0]);
38 }
39 else
40 {
41 printf("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n"
42 "<testsuites id=\"%s\" name=\"%s\">\r\n"
43 "<testsuite id=\"%s\" name=\"%s\" tests=\"%d\">\r\n",
44 m_argv[0], m_argv[0],
45 m_argv[0], m_argv[0], tests.count());
46 }
47
48#ifdef __HOST__
49 fflush(stdout);
50#endif /* __HOST__ */
51}
52
54{
55 if (m_multiline)
56 {
57 printf("<!-- Start %s -->\r\n", *test.m_name);
58 }
59 else
60 {
61 printf(" <testcase id=\"%s.%s\" name=\"%s.%s\">\r\n",
62 m_argv[0], *test.m_name,
63 m_argv[0], *test.m_name);
64 }
65
66#ifdef __HOST__
67 fflush(stdout);
68#endif /* __HOST__ */
69}
70
72{
73 if (m_multiline)
74 {
75 switch (result.getResult())
76 {
77 case TestResult::Success: printf("<!-- Finish %s OK -->\r\n", *test.m_name); break;
78 case TestResult::Failure: printf("<!-- Finish %s FAIL -->\r\n", *test.m_name); break;
79 case TestResult::Skipped: printf("<!-- Finish %s SKIP -->\r\n", *test.m_name); break;
80 }
81 }
82 else
83 {
84 switch (result.getResult())
85 {
87 printf(" <!-- OK -->\r\n");
88 break;
89
91 printf(" <failure message=\"%s\" type=\"error\" />\r\n",
92 *result.getDescription());
93 break;
94
96 printf(" <skipped message=\"Skipped: %s\" type=\"unittest.case.SkipTest\">Skipped: %s</skipped>\r\n",
97 *test.m_name, *test.m_name);
98 break;
99 }
100 printf(" </testcase>\r\n");
101 }
102
103#ifdef __HOST__
104 fflush(stdout);
105#endif /* __HOST__ */
106}
107
109{
110 if (m_multiline)
111 printf("</testsuites>\r\n"
112 "<!-- Completed ");
113 else
114 printf("</testsuite>\r\n"
115 "</testsuites>\r\n"
116 "<!-- Result ");
117
118 printf("%s (%d passed %d failed %d skipped %d total) -->\r\n",
119 m_fail == 0 ? "OK" : "FAIL", m_ok, m_fail, m_skip, (m_ok + m_fail + m_skip));
120
121#ifdef __HOST__
122 fflush(stdout);
123#endif /* __HOST__ */
124}
Simple linked list template class.
Definition List.h:37
Size count() const
Get the number of items on the list.
Definition List.h:402
Represents a test instance.
String m_name
Name of the test instance.
Responsible for outputting test results.
uint m_ok
Test statistics.
char ** m_argv
Argument values.
bool m_multiline
Multi line output.
Represents a Test result created by a TestInstance.
Definition TestResult.h:48
String & getDescription()
Get result description.
const Result getResult() const
Get result code.
virtual void reportBefore(TestInstance &test)
Report start of a test.
virtual void reportBegin(List< TestInstance * > &tests)
Report start of testing.
virtual void reportAfter(TestInstance &test, TestResult &result)
Report finish of a test.
XMLReporter(int argc, char **argv)
Constructor.
virtual void reportFinish(List< TestInstance * > &tests)
Report completion of all tests.
C int printf(const char *format,...)
Output a formatted string to standard output.
Definition printf.cpp:22