OTest2
A C++ testing framework
cmdteardownobject.cpp
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 #include <cmdteardownobject.h>
21 
22 #include <assert.h>
23 #include <memory>
24 
25 #include <commandstack.h>
26 #include <context.h>
27 #include <objectscenario.h>
28 
29 namespace OTest2 {
30 
32  ObjectScenarioPtr object_,
33  ScenarioPtr scenario_,
34  int index_) :
35  object(object_),
36  scenario(scenario_),
37  index(index_) {
38  assert(object != nullptr && scenario != nullptr && index >= 0);
39 
40 }
41 
43 
44 }
45 
47  const Context& context_) {
48  /* -- run the tear-down function */
49  object->tearDownObject(context_, index);
50 
51  /* -- schedule next tear-down function or finish the suite */
52  if(index > 0)
53  context_.command_stack->pushCommand(
54  std::make_shared<CmdTearDownObject>(object, scenario, index - 1));
55 }
56 
57 } /* -- namespace OTest2 */
objectscenario.h
OTest2::CmdTearDownObject::~CmdTearDownObject
virtual ~CmdTearDownObject()
Dtor.
Definition: cmdteardownobject.cpp:42
OTest2::ObjectScenarioPtr
std::shared_ptr< ObjectScenario > ObjectScenarioPtr
Shared pointer of a testing object scheduled by the scenario.
Definition: objectscenarioptr.h:27
OTest2::CmdTearDownObject::CmdTearDownObject
CmdTearDownObject(ObjectScenarioPtr object_, ScenarioPtr scenario_, int index_)
Ctor.
Definition: cmdteardownobject.cpp:31
OTest2::CommandStack::pushCommand
void pushCommand(CommandPtr command_)
Push a command into the stack.
Definition: commandstack.cpp:67
cmdteardownobject.h
commandstack.h
OTest2::Context::command_stack
CommandStack *const command_stack
Definition: context.h:40
OTest2
Definition: assertbean.h:25
OTest2::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Shared pointer of the scenario object.
Definition: scenarioptr.h:27
OTest2::CmdTearDownObject::run
virtual void run(const Context &context_) override
Run the command.
Definition: cmdteardownobject.cpp:46
context.h
OTest2::Context
OTest2 runtime context.
Definition: context.h:38