OTest2
A C++ testing framework
parameters.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Ondrej Starek
3  *
4  * This file is part of OTest2
5  *
6  * OTest2 is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License,
9  * or (at your option) any later version.
10  *
11  * OTest2 is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14  * License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with OTest2. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <parameters.h>
21 
22 #include <assert.h>
23 #include <map>
24 #include <sstream>
25 
26 #include <utils.h>
27 
28 namespace OTest2 {
29 
30 struct Parameters::Impl {
31  typedef std::multimap<std::string, std::string> Params;
32  Params params;
33 
34  /* -- avoid copying */
35  Impl(
36  const Impl&) = delete;
37  Impl& operator = (
38  const Impl&) = delete;
39 
40  Impl() = default;
41  ~Impl() = default;
42 };
43 
45  pimpl(new Impl) {
46 
47 }
48 
50  Parameters&& other_) noexcept :
51  pimpl(other_.pimpl) {
52  other_.pimpl = nullptr;
53 }
54 
56  odelete(pimpl);
57 }
58 
60  Parameters& other_) noexcept {
61  std::swap(pimpl, other_.pimpl);
62 }
63 
65  Parameters&& other_) noexcept {
66  if(this != &other_) {
67  swap(other_);
68  odelete(other_.pimpl);
69  }
70  return *this;
71 }
72 
74  const std::string& name_,
75  const std::string& value_) {
76  assert(!name_.empty());
77  pimpl->params.insert(Impl::Params::value_type(name_, value_));
78 }
79 
81  const std::string& name_) const {
82  std::ostringstream oss_;
83 
84  oss_ << name_;
85 
86  if(!pimpl->params.empty()) {
87  oss_ << " (";
88 
89  bool first_(true);
90  for(const auto& param : pimpl->params) {
91  if(first_)
92  first_ = false;
93  else
94  oss_ << ", ";
95  oss_ << param.first << ": " << param.second;
96  }
97 
98  oss_ << ")";
99  }
100 
101  return oss_.str();
102 }
103 
104 } /* -- namespace OTest2 */
OTest2::Parameters::operator=
Parameters & operator=(const Parameters &)=delete
OTest2::Parameters::~Parameters
~Parameters()
Dtor.
Definition: parameters.cpp:55
utils.h
OTest2::Parameters::mixWithName
std::string mixWithName(const std::string &name_) const
Create one string mixed with a name of a testing object.
Definition: parameters.cpp:80
OTest2::Parameters
Generic parameters of a run of an testing object.
Definition: parameters.h:30
OTest2::Parameters::appendParameter
void appendParameter(const std::string &name_, const std::string &value_)
Append new parameter.
Definition: parameters.cpp:73
OTest2
Definition: assertbean.h:25
parameters.h
OTest2::Parameters::Parameters
Parameters()
Ctor - empty parameters.
Definition: parameters.cpp:44
OTest2::Parameters::swap
void swap(Parameters &other_) noexcept
Swap contents.
Definition: parameters.cpp:59
OTest2::odelete
void odelete(T_ *&object_)
Delete a pointer and set it invalid.
Definition: utils.h:34