OTest2
A C++ testing framework
cmdstartupobject.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 <cmdstartupobject.h>
21 
22 #include <assert.h>
23 #include <memory>
24 
25 #include <cmdnextobject.h>
26 #include <cmdteardownobject.h>
27 #include <commandstack.h>
28 #include <context.h>
29 #include <objectscenario.h>
30 #include <semanticstack.h>
31 
32 namespace OTest2 {
33 
35  ObjectScenarioPtr object_,
36  ScenarioPtr scenario_,
37  ObjectPtr parent_,
38  int index_) :
39  object(object_),
40  scenario(scenario_),
41  parent(parent_),
42  index(index_) {
43  assert(object != nullptr && scenario != nullptr && index >= 0);
44 }
45 
47 
48 }
49 
51  const Context& context_) {
52  if(object->startUpObject(context_, index)) {
53  /* -- check result of the start-up function */
54  if(context_.semantic_stack->top()) {
55  /* -- the start-up function passed -> schedule next start-up function */
56  context_.command_stack->pushCommand(
57  std::make_shared<CmdStartUpObject>(object, scenario, parent, index + 1));
58  }
59  else {
60  /* -- the start-up function failed -> schedule clean-up of previously
61  * invoked functions. */
62  if(index > 0)
63  context_.command_stack->pushCommand(
64  std::make_shared<CmdTearDownObject>(object, scenario, index - 1));
65  }
66  }
67  else {
68  /* -- Cll start-up functions has passed. Continue. */
69 
70  /* -- schedule cleaning up */
71  if(index > 0)
72  context_.command_stack->pushCommand(
73  std::make_shared<CmdTearDownObject>(object, scenario, index - 1));
74 
75  /* -- schedule run of the object body */
76  object->scheduleBody(context_, scenario, object);
77  }
78 }
79 
80 } /* -- namespace OTest2 */
objectscenario.h
OTest2::CmdStartUpObject::~CmdStartUpObject
virtual ~CmdStartUpObject()
Dtor.
Definition: cmdstartupobject.cpp:46
OTest2::ObjectScenarioPtr
std::shared_ptr< ObjectScenario > ObjectScenarioPtr
Shared pointer of a testing object scheduled by the scenario.
Definition: objectscenarioptr.h:27
OTest2::CommandStack::pushCommand
void pushCommand(CommandPtr command_)
Push a command into the stack.
Definition: commandstack.cpp:67
cmdteardownobject.h
commandstack.h
semanticstack.h
OTest2::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Shared pointer to a testing object.
Definition: objectptr.h:27
OTest2::Context::command_stack
CommandStack *const command_stack
Definition: context.h:40
OTest2
Definition: assertbean.h:25
cmdstartupobject.h
OTest2::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Shared pointer of the scenario object.
Definition: scenarioptr.h:27
OTest2::Context::semantic_stack
SemanticStack *const semantic_stack
Definition: context.h:41
context.h
OTest2::Context
OTest2 runtime context.
Definition: context.h:38
OTest2::CmdStartUpObject::CmdStartUpObject
CmdStartUpObject(ObjectScenarioPtr object_, ScenarioPtr scenario_, ObjectPtr parent_, int index_)
Ctor.
Definition: cmdstartupobject.cpp:34
OTest2::CmdStartUpObject::run
virtual void run(const Context &context_) override
Run the command.
Definition: cmdstartupobject.cpp:50
cmdnextobject.h
OTest2::SemanticStack::top
bool top() const
Get top value.
Definition: semanticstack.cpp:70