OTest2
A C++ testing framework
repeatervaluesimpl.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_REPEATERVALUESIMPL_H_
21 #define OTest2_INCLUDE_OTEST2_REPEATERVALUESIMPL_H_
22 
23 #include <assert.h>
24 #include <otest2/repeatervalues.h>
25 #include <utility>
26 
27 namespace OTest2 {
28 
29 template<typename Value_>
31  std::vector<Value_>&& values_) :
32  values(std::move(values_)),
33  index(0) {
34 
35 }
36 
37 template<typename Value_>
39 
40 }
41 
42 template<typename Value_>
44  assert(index < values.size());
45  return values[index];
46 }
47 
48 template<typename Value_>
50  return index;
51 }
52 
53 template<typename Value_>
55  const Context& context_) const noexcept {
56  return index + 1 < values.size();
57 }
58 
59 template<typename Value_>
60 std::shared_ptr<RepeaterValue<Value_>> RepeaterValue<Value_>::createNext(
61  const Context& context_,
62  std::shared_ptr<RepeaterValue<Value_>>& current_,
63  std::vector<Value_>&& values_) {
64  if(current_ == nullptr)
65  /* -- first run */
66  return std::make_shared<RepeaterValue<Value_>>(std::move(values_));
67  else {
68  /* -- following runs */
69  ++current_->index;
70  assert(current_->index < current_->values.size());
71  return current_;
72  }
73 }
74 
75 } /* -- namespace OTest2 */
76 
77 #endif /* -- OTest2_INCLUDE_OTEST2_REPEATERVALUESIMPL_H_ */
repeatervalues.h
OTest2::RepeaterValue
Generic repeater for a list of values.
Definition: repeatervalues.h:36
OTest2::RepeaterValue::getIndex
int getIndex() const
Get current value index.
Definition: repeatervaluesimpl.h:49
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::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