Sync with 5.3.0
[deliverable/titan.core.git] / loggerplugins / JUnitLogger2 / JUnitLogger2.hh
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
8 #ifndef JUnitLogger_HH2
9 #define JUnitLogger_HH2
10
11 namespace TitanLoggerApi { class TitanLogEvent; }
12
13 #ifndef TITAN_RUNTIME_2
14 #include "RT1/TitanLoggerApi.hh"
15 #else
16 #include "RT2/TitanLoggerApi.hh"
17 #endif
18
19 #include "ILoggerPlugin.hh"
20 #include <stdio.h>
21 #include <string>
22 #include <vector>
23
24 struct TestCase{
25 typedef enum {
26 Pass,
27 Inconc,
28 Fail,
29 Error,
30 None,
31 Unbound
32 } Verdict;
33
34 Verdict verdict;
35 std::string tc_name;
36 std::string module_name;
37 std::string reason;
38 std::string dte_reason;
39 std::string stack_trace;
40 long long tc_start;
41 double time;
42
43 TestCase():tc_name(""), module_name(""), reason(""), dte_reason(""), stack_trace(""), tc_start(0), time(0.0){}
44
45 void writeTestCase(FILE* file_stream_) const;
46 void setTCVerdict(const TitanLoggerApi::TitanLogEvent& event);
47 void addStackTrace(const TitanLoggerApi::TitanLogEvent& event);
48 void reset() {
49 tc_name = "";
50 module_name = "";
51 reason = "";
52 dte_reason = "";
53 stack_trace = "";
54 tc_start = 0;
55 time = 0.0;
56 }
57 };
58
59
60 struct TestSuite {
61 typedef std::vector<TestCase*> TestCases;
62
63 // TitanLoggerApi::TimestampType timestamp; TODO
64 std::string ts_name;
65 int all;
66 int skipped;
67 int failed;
68 int error;
69 int inconc;
70 TestCases testcases;
71 time_t start_ts;
72 time_t end_ts;
73
74 TestSuite():ts_name(""), all(0), skipped(0), failed(0), error(0), inconc(0) {}
75 ~TestSuite();
76
77 void addTestCase(const TestCase& element);
78 void write(FILE* file_stream_);
79
80 };
81
82 class JUnitLogger2: public ILoggerPlugin
83 {
84 public:
85 JUnitLogger2();
86 virtual ~JUnitLogger2();
87 inline bool is_static() { return false; }
88 void init(const char *options = 0);
89 void fini();
90
91 void log(const TitanLoggerApi::TitanLogEvent& event, bool log_buffered,
92 bool separate_file, bool use_emergency_mask);
93 void set_parameter(const char *parameter_name, const char *parameter_value);
94 // do not implement ILoggerPlugin::set_file_name();
95 // it gets a filename skeleton and can't expand it.
96
97 virtual void open_file(bool /*is_first*/);
98 virtual void close_file();
99
100 enum xml_escape_char_t { LT=0x01, GT=0x02, QUOT=0x04, APOS=0x08, AMP=0x10 };
101 CHARSTRING escape_xml(const CHARSTRING& xml_str, int escape_chars);
102 CHARSTRING escape_xml_attribute(const CHARSTRING& attr_str) { return escape_xml(attr_str, QUOT|AMP); }
103 CHARSTRING escape_xml_element(const CHARSTRING& elem_str) { return escape_xml(elem_str, LT|AMP); }
104 CHARSTRING escape_xml_comment(const CHARSTRING& comm_str) { return escape_xml(comm_str, AMP); /* FIXME: --> should be escaped too */ }
105
106 private:
107 // parameters
108 char *filename_stem_;
109 char *testsuite_name_;
110 // working values
111 char *filename_;
112 TestSuite testsuite;
113 TestCase testcase;
114 std::string dte_reason;
115
116 FILE *file_stream_;
117 };
118
119 #endif // JUnitLogger_HH2
This page took 0.03796 seconds and 5 git commands to generate.