OTest2
A C++ testing framework
dfltloop.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 #include <dfltloop.h>
20 
21 #include <chrono>
22 #include <thread>
23 
24 #include <runner.h>
25 
26 namespace OTest2 {
27 
29  Runner& runner_) {
30  ::OTest2::RunnerResult result_;
31  while(true) {
32  /* -- do the test step */
33  result_ = runner_.runNext();
34  if(result_.isFinished())
35  break;
36 
37  /* -- wait for next step */
38  const std::chrono::milliseconds delay_(result_.getDelayMS());
39  if(delay_ > std::chrono::milliseconds(0))
40  std::this_thread::sleep_for(delay_);
41  }
42 
43  if(result_.getResult())
44  return 0;
45  else
46  return 1;
47 }
48 
49 } /* -- namespace OTest2 */
OTest2::Runner::runNext
virtual RunnerResult runNext()=0
Run next pack of work.
dfltloop.h
OTest2::Runner
Generic test runner.
Definition: runner.h:112
OTest2
Definition: assertbean.h:25
OTest2::RunnerResult::getDelayMS
int getDelayMS() const
Get delay between two steps in milliseconds.
Definition: runner.cpp:75
runner.h
OTest2::RunnerResult::isFinished
bool isFinished() const
Check whether the test has already finished.
Definition: runner.cpp:71
OTest2::RunnerResult
Result of test run.
Definition: runner.h:40
OTest2::RunnerResult::getResult
bool getResult() const
Get result of the test - true if the test has passed.
Definition: runner.cpp:80
OTest2::defaultMainLoop
int defaultMainLoop(Runner &runner_)
Default main loop.
Definition: dfltloop.cpp:28