OTest2
A C++ testing framework
lib
cmdrepeatobject.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
#include <
cmdrepeatobject.h
>
20
21
#include <assert.h>
22
23
#include <
cmdleaveobject.h
>
24
#include <
cmdstartupobject.h
>
25
#include <
commandstack.h
>
26
#include <
context.h
>
27
#include <
objectscenario.h
>
28
#include <
objectpath.h
>
29
#include <
objectrepeater.h
>
30
#include "
runcode.h
"
31
#include <
scenario.h
>
32
#include <
semanticstack.h
>
33
34
namespace
OTest2
{
35
36
CmdRepeatObject::CmdRepeatObject
(
37
ScenarioPtr
scenario_,
38
ObjectRepeaterPtr
repeater_,
39
const
std::string& name_,
40
ObjectPtr
parent_) :
41
scenario(scenario_),
42
repeater(repeater_),
43
name(name_),
44
parent(parent_) {
45
assert(scenario !=
nullptr
&& repeater !=
nullptr
&& !name.empty());
46
47
}
48
49
CmdRepeatObject::~CmdRepeatObject
() {
50
51
}
52
53
void
CmdRepeatObject::run
(
54
const
Context
& context_) {
55
if
(repeater->hasNextRun(context_)) {
56
/* -- schedule myself for next run */
57
context_.
command_stack
->
pushCommand
(
58
std::make_shared<CmdRepeatObject>(scenario, repeater, name, parent));
59
60
/* -- prepare stack-frame of the object - object's result and path. */
61
context_.
object_path
->
pushName
(name);
62
context_.
semantic_stack
->
push
(
true
);
63
64
/* -- let the repeater to distinguish the run */
65
repeater->modifyObjectPath(context_, *context_.
object_path
);
66
67
/* -- let the scenario modify the object path and report the object */
68
scenario->enterObject(context_);
69
70
/* -- schedule finishing of the suite */
71
context_.
command_stack
->
pushCommand
(std::make_shared<CmdLeaveObject>(scenario));
72
73
/* -- The constructor method of the suite may throw and exception.
74
* So I do the creation in a protected environment. */
75
runUserCode
(context_, [
this
](
const
Context
& context_) {
76
ObjectScenarioPtr
object_(
77
repeater->createObject(context_, name, parent));
78
context_.
command_stack
->
pushCommand
(
79
std::make_shared<CmdStartUpObject>(object_, scenario, parent, 0));
80
});
81
}
82
}
83
84
}
/* -- namespace OTest2 */
objectscenario.h
OTest2::ObjectScenarioPtr
std::shared_ptr< ObjectScenario > ObjectScenarioPtr
Shared pointer of a testing object scheduled by the scenario.
Definition:
objectscenarioptr.h:27
objectrepeater.h
OTest2::CmdRepeatObject::~CmdRepeatObject
virtual ~CmdRepeatObject()
Dtor.
Definition:
cmdrepeatobject.cpp:49
OTest2::ObjectPath::pushName
void pushName(const std::string &name_)
Push name of currently entering testing object.
Definition:
objectpath.cpp:86
OTest2::CmdRepeatObject::CmdRepeatObject
CmdRepeatObject(ScenarioPtr scenarion_, ObjectRepeaterPtr repeater_, const std::string &name_, ObjectPtr parent_)
Ctor.
Definition:
cmdrepeatobject.cpp:36
OTest2::CommandStack::pushCommand
void pushCommand(CommandPtr command_)
Push a command into the stack.
Definition:
commandstack.cpp:67
commandstack.h
OTest2::SemanticStack::push
void push(bool value_)
Push a value.
Definition:
semanticstack.cpp:65
cmdrepeatobject.h
objectpath.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::runUserCode
bool runUserCode(const Context &context_, std::function< void(const Context &)> ftor_) noexcept
Definition:
runcode.cpp:33
cmdleaveobject.h
OTest2::ScenarioPtr
std::shared_ptr< Scenario > ScenarioPtr
Shared pointer of the scenario object.
Definition:
scenarioptr.h:27
OTest2::ObjectRepeaterPtr
std::shared_ptr< ObjectRepeater > ObjectRepeaterPtr
Shared pointer of the object repeater objects.
Definition:
objectrepeaterptr.h:27
OTest2::Context::object_path
ObjectPath *const object_path
Definition:
context.h:42
OTest2::Context::semantic_stack
SemanticStack *const semantic_stack
Definition:
context.h:41
runcode.h
scenario.h
context.h
OTest2::Context
OTest2 runtime context.
Definition:
context.h:38
OTest2::CmdRepeatObject::run
virtual void run(const Context &context_) override
Run the command.
Definition:
cmdrepeatobject.cpp:53
Generated by
1.8.17