Max OS 0.3
Loading...
Searching...
No Matches
test.cpp
Go to the documentation of this file.
1
9#include <tests/test.h>
10#include <tests/common.h>
11
12using namespace MaxOS;
13using namespace MaxOS::tests;
14
21Test::Test(string const& name, TestType type)
22: m_name(name),
23 m_type(type)
24{
26}
27
34
35 // Run the test
36 auto result = execute();
37 StringBuilder msg;
38
39 // Build the message
40 msg << "Test ";
41 switch(result) {
42 case TestStatus::PASS:
43 msg << "PASSED";
44 break;
45 case TestStatus::SKIP:
46 msg << "SKIPPED";
47 break;
48 case TestStatus::FAIL:
49 msg << "FAILED";
50 break;
51 }
52 msg << " - " << m_name << "\n";
53
54 // Print the outcome
55 if (result == TestStatus::FAIL)
56 Logger::ERROR() << msg.out;
57 else
58 Logger::TEST() << msg.out;
59
60 return result;
61}
62
68const string& Test::name() const {
69 return m_name;
70}
71
78 return m_type;
79}
80
81Test::~Test() = default;
82
90ConditionalTest::ConditionalTest(string const& name, TestType type, bool (* condition)())
91: Test(name, type),
92 m_condition(condition)
93{
94}
95
102
103 if (m_condition())
104 return TestStatus::PASS;
105 else
106 return TestStatus::FAIL;
107
108}
109
110
111ConditionalTest::~ConditionalTest() = default;
112
117 Logger::TEST() << "Running all tests... (" << (int )s_tests.size() << " tests found)\n";
118 for (auto& test : s_tests)
119 test->run();
120}
121
128 for (auto& test : s_tests)
129 if (test->type() == type)
130 test->run();
131}
132
139 s_tests.push_back(test);
140}
141
146 register_tests_common();
147}
148
153
154 // Add all tests
155 s_tests = common::Vector<Test*>();
157
158 // Run all system tests
160
161}
static Logger TEST()
Gets active logger set to test level.
Definition logger.cpp:182
static Logger ERROR()
Gets active logger set to ERROR level.
Definition logger.cpp:216
Creates a string using a using a combination of parts with the '<<' operator. Simmilar to the logger.
Definition string.h:97
String out
The output string.
Definition string.h:99
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
TestStatus execute() override
Executes the conditional test based on the provided condition function.
Definition test.cpp:101
ConditionalTest(const string &name, TestType type, bool(*condition)())
Constructs a ConditionalTest with a name, type, and condition function.
Definition test.cpp:90
static void test_kernel()
Setups the TestRunner and runs all kernel tests.
Definition test.cpp:152
static void run_all_types(TestType type)
Runs all tests of a specific type.
Definition test.cpp:127
static void run_all_tests()
Runs all registered tests.
Definition test.cpp:116
static void add_all_tests()
Adds all predefined tests to the test runner.
Definition test.cpp:145
static void add_test(Test *test)
Adds a test to the test runner.
Definition test.cpp:138
A basic test class.
Definition test.h:69
const string & name() const
Gets the name of the test.
Definition test.cpp:68
TestStatus run()
Runs the test and returns the result.
Definition test.cpp:33
virtual TestStatus execute()=0
Executes the test and returns the status of the test.
Test(const string &name, TestType type)
Constructs a Test with a name and type, and registers it with the TestRunner.
Definition test.cpp:21
TestType type() const
Gets the type of the test.
Definition test.cpp:77
Defines a basic test class for MaxOS.
TestType
The different types of tests.
Definition test.h:36
TestStatus
The possible outcomes of a test.
Definition test.h:26