SmingTest.h
Go to the documentation of this file.
1 /****
2  * SmingTest.h - Extensible test framework for Sming
3  *
4  * Copyright 2019 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the SmingTest Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  * @author: 2018 - Mikee47 <mike@sillyhouse.net>
19  *
20  ****/
21 
22 #pragma once
23 
24 #include <SmingCore.h>
25 #include "SmingTest/TestGroup.h"
26 #include <WVector.h>
27 #include <Timer.h>
28 
48 #define REGISTER_TEST(name) register_test_##name()
49 
50 namespace SmingTest
51 {
55 typedef TestGroup* (*Factory)();
56 
57 using Callback = Delegate<void()>;
58 
59 class Runner
60 {
61 public:
62  Runner();
63 
64  void setGroupIntervalMs(unsigned ms)
65  {
66  groupIntervalMs = ms;
67  }
68 
70  {
71  groupFactories.add(factory);
72  }
73 
74  void execute(Callback onComplete, unsigned initialDelayMs = 0);
75 
76  void groupComplete(TestGroup* group);
77 
78 protected:
79  void runNextGroup();
80 
81 private:
82  Vector<Factory> groupFactories;
83  Timer taskTimer;
84  unsigned taskIndex{0};
85  enum class State {
86  stopped,
87  waiting,
88  running,
89  };
90  State state{State::stopped};
91  NanoTime::Time<uint32_t> totalTestTime;
92  unsigned testCount{0};
93  unsigned failureCount{0};
94  unsigned groupIntervalMs{500};
95  Callback onComplete;
96 };
97 
98 extern Runner runner;
99 
100 } // namespace SmingTest
101 
106 template <class GroupClass> void registerGroup()
107 {
108  SmingTest::runner.addFactory([]() -> TestGroup* { return new GroupClass; });
109 }
bool add(const Element &obj)
Definition: WVector.h:160
Class to simplify generation of begin/end messages for a test group.
Definition: TestGroup.h:34
void registerGroup()
Register a factory function (a lambda) to create a given TestGroup class.
Definition: SmingTest.h:106
void addFactory(Factory factory)
Definition: SmingTest.h:69
Definition: SmingTest.h:50
Callback timer class.
Definition: Timer.h:262
void execute(Callback onComplete, unsigned initialDelayMs=0)
Definition: SmingTest.h:59
Runner runner
Factory * factory
Provided by ssl adapter, NULL if SSL is disabled.
void setGroupIntervalMs(unsigned ms)
Definition: SmingTest.h:64
Delegate< void()> Callback
Definition: SmingTest.h:57
void groupComplete(TestGroup *group)