1+ // Licensed to the Apache Software Foundation (ASF) under one or more
2+ // contributor license agreements. See the NOTICE file distributed with
3+ // this work for additional information regarding copyright ownership.
4+ // The ASF licenses this file to You under the Apache License, Version 2.0
5+ // (the "License"); you may not use this file except in compliance with
6+ // the License. You may obtain a copy of the License at
7+ //
8+ // http://www.apache.org/licenses/LICENSE-2.0
9+ //
10+ // Unless required by applicable law or agreed to in writing, software
11+ // distributed under the License is distributed on an "AS IS" BASIS,
12+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ // See the License for the specific language governing permissions and
14+ // limitations under the License.
15+ //
16+
17+ #include " ignite_xml_unit_test_result_printer.h"
18+
19+ namespace ignite ::detail {
20+
21+ ignite_xml_unit_test_result_printer::ignite_xml_unit_test_result_printer (
22+ testing::TestEventListener *delegate, std::string version)
23+ : m_delegate(delegate)
24+ , m_version(std::move(version)){}
25+
26+ void ignite_xml_unit_test_result_printer::OnTestProgramStart (const ::testing::UnitTest &unit_test) {
27+ m_delegate->OnTestProgramStart (unit_test);
28+ }
29+
30+ void ignite_xml_unit_test_result_printer::OnTestIterationStart (const ::testing::UnitTest &unit_test, int iteration) {
31+ m_delegate->OnTestIterationStart (unit_test, iteration);
32+ }
33+
34+ void ignite_xml_unit_test_result_printer::OnEnvironmentsSetUpStart (const ::testing::UnitTest &unit_test) {
35+ m_delegate->OnEnvironmentsSetUpStart (unit_test);
36+ }
37+
38+ void ignite_xml_unit_test_result_printer::OnEnvironmentsSetUpEnd (const ::testing::UnitTest &unit_test) {
39+ m_delegate->OnEnvironmentsSetUpEnd (unit_test);
40+ }
41+
42+ void ignite_xml_unit_test_result_printer::OnTestSuiteStart (const ::testing::TestSuite &test_suite) {
43+ m_delegate->OnTestSuiteStart (test_suite);
44+ }
45+
46+ void ignite_xml_unit_test_result_printer::OnTestSuiteEnd (const ::testing::TestSuite &test_suite) {
47+ m_delegate->OnTestSuiteEnd (test_suite);
48+ }
49+
50+ void ignite_xml_unit_test_result_printer::OnTestCaseStart (const ::testing::TestCase &test_case) {
51+ m_delegate->OnTestCaseStart (test_case);
52+ }
53+
54+ void ignite_xml_unit_test_result_printer::OnTestCaseEnd (const ::testing::TestCase &test_case) {
55+ m_delegate->OnTestCaseEnd (test_case);
56+ }
57+
58+ void ignite_xml_unit_test_result_printer::OnTestStart (const ::testing::TestInfo &test_info) {
59+ m_delegate->OnTestStart (test_info);
60+ }
61+
62+ void ignite_xml_unit_test_result_printer::OnTestDisabled (const testing::TestInfo &test_info) {
63+ m_delegate->OnTestDisabled (test_info);
64+ }
65+
66+ void ignite_xml_unit_test_result_printer::OnTestPartResult (const ::testing::TestPartResult &test_part_result) {
67+ m_delegate->OnTestPartResult (test_part_result);
68+ }
69+
70+ void ignite_xml_unit_test_result_printer::OnTestEnd (const ::testing::TestInfo &test_info) {
71+ m_delegate->OnTestEnd (test_info);
72+ }
73+
74+ void ignite_xml_unit_test_result_printer::OnEnvironmentsTearDownStart (const ::testing::UnitTest &unit_test) {
75+ m_delegate->OnEnvironmentsTearDownStart (unit_test);
76+ }
77+
78+ void ignite_xml_unit_test_result_printer::OnEnvironmentsTearDownEnd (const ::testing::UnitTest &unit_test) {
79+ m_delegate->OnEnvironmentsTearDownEnd (unit_test);
80+ }
81+
82+ void ignite_xml_unit_test_result_printer::OnTestIterationEnd (const ::testing::UnitTest &unit_test, int iteration) {
83+ for (int i = 0 ; i < unit_test.total_test_case_count (); ++i) {
84+ // We are extracting test suite info to add version info
85+ const testing::TestSuite *ts = unit_test.GetTestSuite (i);
86+
87+ // because underlying storage is std::string we able to override it content without changing length.
88+ char *s = const_cast <char *>(ts->name ());
89+
90+ std::string_view sw = s;
91+
92+ std::string_view suffix = " _ign_version" ;
93+
94+ if (sw.rfind (suffix) != sw.size () - suffix.size ()) {
95+ std::stringstream ss;
96+ ss << " Expected test suite name to have suffix '" << suffix <<" ' but got [name = " << sw << " ]" ;
97+ throw std::runtime_error (ss.str ());
98+ }
99+
100+ // it is possible to have more complex version text like 9.1.18-p3, etc.
101+ if (m_version.size () >= suffix.size ()) {
102+ std::stringstream ss;
103+ ss << " Expected version string to be shorter than a suffix but got "
104+ << " [version = " << m_version << " ; suf fix = " << suffix <<" ]" ;
105+ throw std::runtime_error (ss.str ());
106+ }
107+
108+ auto s_it = s + (sw.size () - suffix.size () + 1 /* skip leading '_'*/ );
109+ auto s_end = s + sw.size ();
110+ for (auto it = m_version.begin (); it != m_version.end (); ++it, ++s_it) {
111+ char c = *it;
112+ c = c == ' .' ? ' _' : c;// Teamcity treats '.' specifically.
113+ *s_it = c;
114+ }
115+
116+ while (s_it != s_end) {
117+ *s_it = ' _' ;
118+ ++s_it;
119+ }
120+ }
121+ m_delegate->OnTestIterationEnd (unit_test, iteration);
122+ }
123+
124+ void ignite_xml_unit_test_result_printer::OnTestProgramEnd (const ::testing::UnitTest &unit_test) {
125+ m_delegate->OnTestProgramEnd (unit_test);
126+ }
127+ } // namespace ignite::detail
0 commit comments