OTest2
A C++ testing framework
cmdstate.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 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 <cmdstate.h>
21 
22 #include <assert.h>
23 #include <sstream>
24 
25 #include <caseordinary.h>
26 #include <context.h>
27 #include <internalerror.h>
28 #include <reporter.h>
29 #include <state.h>
30 
31 namespace OTest2 {
32 
34  CaseOrdinaryPtr testcase_,
35  const std::string& name_,
36  int delay_) :
37  testcase(testcase_),
38  name(name_),
39  delay(delay_) {
40  assert(testcase != nullptr && !name_.empty() && delay_ >= 0);
41 
42 }
43 
45 
46 }
47 
49  const Context& context_) {
50  StatePtr state_(testcase->getState(name));
51  if(state_ != nullptr) {
52  state_->scheduleRun(context_, testcase, state_, true, delay);
53  }
54  else {
55  std::ostringstream os_;
56  os_ << "invalid state name '" << name << "'";
57  internalError(context_, os_.str());
58  }
59 }
60 
61 } /* namespace OTest2 */
OTest2::CmdState::~CmdState
virtual ~CmdState()
Dtor.
Definition: cmdstate.cpp:44
reporter.h
caseordinary.h
OTest2::CmdState::run
virtual void run(const Context &context_)
Run the command.
Definition: cmdstate.cpp:48
cmdstate.h
OTest2::CaseOrdinaryPtr
std::shared_ptr< CaseOrdinary > CaseOrdinaryPtr
Shared pointer of the ordinary cases.
Definition: caseordinaryptr.h:27
internalerror.h
OTest2::internalError
void internalError(const Context &context_, const std::string &message_) noexcept
Fail the running test because of an internal error.
Definition: internalerror.cpp:28
OTest2
Definition: assertbean.h:25
OTest2::StatePtr
std::shared_ptr< State > StatePtr
Pointer to test state objects.
Definition: stateptr.h:27
context.h
OTest2::Context
OTest2 runtime context.
Definition: context.h:38
OTest2::CmdState::CmdState
CmdState(const CmdState &)=delete
state.h