OTest2
A C++ testing framework
repeatervalues.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2020 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 #ifndef OTest2_INCLUDE_OTEST2_REPEATERVALUES_H_
21 #define OTest2_INCLUDE_OTEST2_REPEATERVALUES_H_
22 
23 #include <initializer_list>
24 #include <memory>
25 #include <otest2/repeater.h>
26 #include <vector>
27 
28 namespace OTest2 {
29 
35 template<typename Value_>
36 class RepeaterValue : public Repeater {
37  private:
38  std::vector<Value_> values;
39  int index;
40 
41  public:
42  /* -- avoid copying */
44  const RepeaterValue&) = delete;
46  const RepeaterValue&) = delete;
47 
51  explicit RepeaterValue(
52  std::vector<Value_>&& values_);
53 
59  explicit RepeaterValue(
60  std::initializer_list<Value_> values_);
61 
65  template<typename Container_>
66  explicit RepeaterValue(
67  Container_&& values_);
68 
72  template<typename Iter_>
74  Iter_ begin_,
75  Iter_ end_);
76 
80  virtual ~RepeaterValue();
81 
85  Value_ getValue() const;
86 
90  int getIndex() const;
91 
92  /* -- repeater interface */
93  virtual bool hasNextRun(
94  const Context& context_) const noexcept;
95 
104  static std::shared_ptr<RepeaterValue> createNext(
105  const Context& context_,
106  std::shared_ptr<RepeaterValue>& current_,
107  std::vector<Value_>&& values_);
108 
118  template<typename Container_>
119  static std::shared_ptr<RepeaterValue> createNext(
120  const Context& context_,
121  std::shared_ptr<RepeaterValue>& current_,
122  Container_&& values_) {
123  return createNext(
124  context_,
125  current_,
126  std::vector<Value_>(std::forward<Container_>(values_)));
127  }
128 
138  template<typename Iter_>
139  static std::shared_ptr<RepeaterValue> createNext(
140  const Context& context_,
141  std::shared_ptr<RepeaterValue>& current_,
142  Iter_ begin_,
143  Iter_ end_) {
144  return createNext(context_, current_, std::vector<Value_>(begin_, end_));
145  }
146 };
147 
148 } /* -- namespace OTest2 */
149 
150 #endif /* -- OTest2_INCLUDE_OTEST2_REPEATERVALUES_H_ */
OTest2::RepeaterValue
Generic repeater for a list of values.
Definition: repeatervalues.h:36
OTest2::RepeaterValue::createNext
static std::shared_ptr< RepeaterValue > createNext(const Context &context_, std::shared_ptr< RepeaterValue > &current_, Container_ &&values_)
Factory function of particular runs.
Definition: repeatervalues.h:119
OTest2::RepeaterValue::getIndex
int getIndex() const
Get current value index.
Definition: repeatervaluesimpl.h:49
repeater.h
OTest2::RepeaterValue::~RepeaterValue
virtual ~RepeaterValue()
Dtor.
Definition: repeatervaluesimpl.h:38
OTest2::RepeaterValue::getValue
Value_ getValue() const
Get current value.
Definition: repeatervaluesimpl.h:43
OTest2::RepeaterValue::RepeaterValue
RepeaterValue(const RepeaterValue &)=delete
OTest2
Definition: assertbean.h:25
OTest2::RepeaterValue::createNext
static std::shared_ptr< RepeaterValue > createNext(const Context &context_, std::shared_ptr< RepeaterValue > &current_, Iter_ begin_, Iter_ end_)
Factory function of particular runs.
Definition: repeatervalues.h:139
OTest2::Repeater
Generic repeater interface.
Definition: repeater.h:48
OTest2::RepeaterValue::hasNextRun
virtual bool hasNextRun(const Context &context_) const noexcept
Check whether there is a next run prepared.
Definition: repeatervaluesimpl.h:54
OTest2::RepeaterValue::createNext
static std::shared_ptr< RepeaterValue > createNext(const Context &context_, std::shared_ptr< RepeaterValue > &current_, std::vector< Value_ > &&values_)
Factory function of particular runs.
OTest2::Context
OTest2 runtime context.
Definition: context.h:38
OTest2::RepeaterValue::operator=
RepeaterValue & operator=(const RepeaterValue &)=delete