scenario_simulator_v2 C++ API
test_suites.hpp
Go to the documentation of this file.
1 // Copyright 2015 TIER IV, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef JUNIT_EXPORTER__JUNIT_EXPORTER_HPP_
16 #define JUNIT_EXPORTER__JUNIT_EXPORTER_HPP_
17 
18 #include <boost/filesystem/path.hpp>
19 #include <numeric>
20 #include <pugixml.hpp>
22 #include <string>
23 
24 namespace junit
25 {
27 {
28  const std::string timestamp_;
29 
30  std::unordered_map<std::string, TestSuite> test_suites_;
31 
32 public:
33  explicit TestSuites();
34 
35  void write(const boost::filesystem::path & path);
36 
37  auto contains(const std::string & suite_name, const std::string & case_name) const
38  {
39  const auto iter = test_suites_.find(suite_name);
40 
41  if (iter != std::end(test_suites_)) {
42  return std::any_of(
43  std::begin(iter->second), std::end(iter->second),
44  [&](const auto & each_case) { return each_case.name == case_name; });
45  } else {
46  return false;
47  }
48  }
49 
50  auto getTotalTime() const
51  {
52  return std::accumulate(
53  std::cbegin(test_suites_), std::cend(test_suites_), 0,
54  [](const auto sum, const auto & each_suite) {
55  const auto & each_cases = std::get<1>(each_suite);
56 
57  return sum + std::accumulate(
58  std::cbegin(each_cases), std::cend(each_cases), 0.0,
59  [](const auto sum, const auto & each_case) { return sum + each_case.time; });
60  });
61  }
62 
63  template <typename... Ts>
65  const std::string & suite_name, //
66  const std::string & case_name, //
67  Ts &&... xs)
68  {
69  if (not contains(suite_name, case_name)) {
70  test_suites_[suite_name].emplace_back(
71  case_name, suite_name, std::forward<decltype(xs)>(xs)...);
72  }
73  }
74 };
75 } // namespace junit
76 
77 #endif // JUNIT_EXPORTER__JUNIT_EXPORTER_HPP_
Definition: test_suites.hpp:27
TestSuites()
Definition: test_suites.cpp:24
auto getTotalTime() const
Definition: test_suites.hpp:50
void write(const boost::filesystem::path &path)
Definition: test_suites.cpp:29
auto contains(const std::string &suite_name, const std::string &case_name) const
Definition: test_suites.hpp:37
void addTestCase(const std::string &suite_name, const std::string &case_name, Ts &&... xs)
Definition: test_suites.hpp:64
Definition: test_case.hpp:23
Definition: junit5.hpp:25
std::string string
Definition: junit5.hpp:26