OTest2
A C++ testing framework
objectrepeateronceimpl.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_OBJECTREPEATERONCEIMPL_H_
21 #define OTest2_INCLUDE_OTEST2_OBJECTREPEATERONCEIMPL_H_
22 
23 #include <assert.h>
24 #include <memory>
25 #include <string>
26 
29 
30 namespace OTest2 {
31 
32 template<typename Object_>
34  private:
35  std::string section_path;
36 
37  virtual ObjectScenarioPtr doCreateObject(
38  const Context& context_,
39  const std::string& decorated_name_,
40  ObjectPtr parent_) override {
41  return std::make_shared<Object_>(context_, section_path);
42  }
43 
44  public:
46  const std::string& section_path_) :
47  section_path(section_path_) {
48 
49  }
50  virtual ~ObjectRepeaterOnceRoot() = default;
51 
52  /* -- avoid copying */
54  const ObjectRepeaterOnceRoot&) = delete;
56  const ObjectRepeaterOnceRoot&) = delete;
57 };
58 
59 template<typename Object_>
61  public:
62  explicit ObjectRepeaterFactoryOnceRoot() = default;
63  virtual ~ObjectRepeaterFactoryOnceRoot() = default;
64 
65  /* -- avoid copying */
67  const ObjectRepeaterFactoryOnceRoot&) = delete;
69  const ObjectRepeaterFactoryOnceRoot&) = delete;
70 
72  const Context& context_,
73  const std::string& section_path_) const {
74  return std::make_shared<ObjectRepeaterOnceRoot<Object_> >(section_path_);
75  }
76 };
77 
78 template<typename Parent_, typename Object_>
80  public:
81  typedef ObjectScenarioPtr (Parent_::* FactoryMethod)(const Context&, const std::string&);
82 
83  private:
84  FactoryMethod factory_method;
85  std::string section_path;
86 
87  virtual ObjectScenarioPtr doCreateObject(
88  const Context& context_,
89  const std::string& decorated_name_,
90  ObjectPtr parent_) override {
91  auto parent_typed_(std::dynamic_pointer_cast<Parent_>(parent_));
92  assert(parent_typed_ != nullptr);
93  return (parent_typed_.get()->*factory_method)(context_, section_path);
94  }
95 
96  public:
98  FactoryMethod factory_method_,
99  const std::string& section_path_) :
100  factory_method(factory_method_),
101  section_path(section_path_) {
102 
103  }
104 
105  virtual ~ObjectRepeaterOnceNested() = default;
106 
107  /* -- avoid copying */
109  const ObjectRepeaterOnceNested&) = delete;
111  const ObjectRepeaterOnceNested&) = delete;
112 };
113 
114 template<typename Parent_, typename Object_>
116  public:
118 
119  private:
120  FactoryMethod factory_method;
121 
122  public:
124  FactoryMethod factory_method_) :
125  factory_method(factory_method_) {
126 
127  }
128 
129  virtual ~ObjectRepeaterFactoryOnceNested() = default;
130 
131  /* -- avoid copying */
133  const ObjectRepeaterFactoryOnceNested&) = delete;
135  const ObjectRepeaterFactoryOnceNested&) = delete;
136 
138  const Context& context_,
139  const std::string& section_path_) const {
140  return std::make_shared<ObjectRepeaterOnceNested<Parent_, Object_> >(factory_method, section_path_);
141  }
142 };
143 
144 } /* -- namespace OTest2 */
145 
146 #endif /* -- OTest2_INCLUDE_OTEST2_OBJECTREPEATERONCEIMPL_H_ */
OTest2::ObjectRepeaterFactoryOnceRoot::operator=
ObjectRepeaterFactoryOnceRoot & operator=(const ObjectRepeaterFactoryOnceRoot &)=delete
OTest2::ObjectScenarioPtr
std::shared_ptr< ObjectScenario > ObjectScenarioPtr
Shared pointer of a testing object scheduled by the scenario.
Definition: objectscenarioptr.h:27
OTest2::ObjectRepeaterFactoryOnceRoot
Definition: objectrepeateronceimpl.h:60
OTest2::ObjectRepeaterFactoryOnceNested::FactoryMethod
ObjectRepeaterOnceNested< Parent_, Object_ >::FactoryMethod FactoryMethod
Definition: objectrepeateronceimpl.h:117
OTest2::ObjectRepeaterOnceNested::~ObjectRepeaterOnceNested
virtual ~ObjectRepeaterOnceNested()=default
OTest2::ObjectRepeaterOnceRoot::~ObjectRepeaterOnceRoot
virtual ~ObjectRepeaterOnceRoot()=default
OTest2::ObjectRepeaterOnceNested::FactoryMethod
ObjectScenarioPtr(Parent_::* FactoryMethod)(const Context &, const std::string &)
Definition: objectrepeateronceimpl.h:81
OTest2::ObjectRepeaterFactoryOnceNested::createRepeater
virtual ObjectRepeaterPtr createRepeater(const Context &context_, const std::string &section_path_) const
Create repeater object.
Definition: objectrepeateronceimpl.h:137
OTest2::ObjectRepeaterOnce
Object repeater which runs the test just once.
Definition: objectrepeateronce.h:33
OTest2::ObjectRepeaterOnceNested::ObjectRepeaterOnceNested
ObjectRepeaterOnceNested(FactoryMethod factory_method_, const std::string &section_path_)
Definition: objectrepeateronceimpl.h:97
OTest2::ObjectRepeaterFactoryOnceNested::~ObjectRepeaterFactoryOnceNested
virtual ~ObjectRepeaterFactoryOnceNested()=default
OTest2::ObjectRepeaterFactoryOnceRoot::~ObjectRepeaterFactoryOnceRoot
virtual ~ObjectRepeaterFactoryOnceRoot()=default
OTest2::ObjectRepeaterOnceNested
Definition: objectrepeateronceimpl.h:79
OTest2::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Shared pointer to a testing object.
Definition: objectptr.h:27
OTest2
Definition: assertbean.h:25
objectrepeateronce.h
OTest2::ObjectRepeaterFactoryOnceRoot::ObjectRepeaterFactoryOnceRoot
ObjectRepeaterFactoryOnceRoot()=default
OTest2::ObjectRepeaterOnceRoot
Definition: objectrepeateronceimpl.h:33
OTest2::ObjectRepeaterPtr
std::shared_ptr< ObjectRepeater > ObjectRepeaterPtr
Shared pointer of the object repeater objects.
Definition: objectrepeaterptr.h:27
OTest2::ObjectRepeaterOnceRoot::ObjectRepeaterOnceRoot
ObjectRepeaterOnceRoot(const std::string &section_path_)
Definition: objectrepeateronceimpl.h:45
OTest2::ObjectRepeaterOnceRoot::operator=
ObjectRepeaterOnceRoot & operator=(const ObjectRepeaterOnceRoot &)=delete
OTest2::ObjectRepeaterFactory
Factory of object repeater objects.
Definition: objectrepeaterfactory.h:35
OTest2::ObjectRepeaterFactoryOnceNested::ObjectRepeaterFactoryOnceNested
ObjectRepeaterFactoryOnceNested(FactoryMethod factory_method_)
Definition: objectrepeateronceimpl.h:123
OTest2::Context
OTest2 runtime context.
Definition: context.h:38
OTest2::ObjectRepeaterFactoryOnceRoot::createRepeater
virtual ObjectRepeaterPtr createRepeater(const Context &context_, const std::string &section_path_) const
Create repeater object.
Definition: objectrepeateronceimpl.h:71
objectrepeaterfactory.h
OTest2::ObjectRepeaterOnceNested::operator=
ObjectRepeaterOnceNested & operator=(const ObjectRepeaterOnceNested &)=delete
OTest2::ObjectRepeaterFactoryOnceNested::operator=
ObjectRepeaterFactoryOnceNested & operator=(const ObjectRepeaterFactoryOnceNested &)=delete
OTest2::ObjectRepeaterFactoryOnceNested
Definition: objectrepeateronceimpl.h:115