Max OS 0.3
Loading...
Searching...
No Matches
test.h File Reference

Defines a basic test class for MaxOS. More...

#include <common/string.h>
#include <common/logger.h>
#include <common/macros.h>

Go to the source code of this file.

Classes

class  MaxOS::tests::Test
 A basic test class. More...
 
class  MaxOS::tests::ConditionalTest
 A test that only checks a condition to determine pass/fail. More...
 
class  MaxOS::tests::TestRunner
 A class to run all tests. More...
 

Macros

#define MAXOS_CONDITIONAL_TEST(name, type)    auto CONCATENATE(test_, __COUNTER__) = new ConditionalTest(#name, type, []()
 Simplified macro to define a conditional test.
 

Enumerations

enum class  MaxOS::tests::TestStatus { PASS , FAIL , SKIP }
 The possible outcomes of a test. More...
 
enum class  MaxOS::tests::TestType {
  COMMON , DRIVER , FILESYSTEM , GUI ,
  HARDWARE_COMMUNICATION , MEMORY , NETWORK , PROCESSES ,
  RUNTIME , SYSTEM , MAX_TEST_TYPES
}
 The different types of tests. More...
 

Functions

template<typename T1 , typename T2 >
bool MaxOS::tests::compare (T1 const &actual, T2 const &expected)
 Compares two values and logs a warning if they are not equal.
 

Variables

constexpr const char * MaxOS::tests::TEST_TYPE_STRINGS []
 String representations of the TestType enum.
 

Detailed Description

Defines a basic test class for MaxOS.

Date
23rd November 2025
Author
Max Tyson

Definition in file test.h.

Macro Definition Documentation

◆ MAXOS_CONDITIONAL_TEST

#define MAXOS_CONDITIONAL_TEST (   name,
  type 
)     auto CONCATENATE(test_, __COUNTER__) = new ConditionalTest(#name, type, []()

Simplified macro to define a conditional test.

Definition at line 17 of file test.h.

19 {
20
25 enum class TestStatus {
26 PASS,
27 FAIL,
28 SKIP
29 };
30
35 enum class TestType {
36 COMMON,
37 DRIVER,
38 FILESYSTEM,
39 GUI,
40 HARDWARE_COMMUNICATION,
41 MEMORY,
42 NETWORK,
43 PROCESSES,
44 RUNTIME,
45 SYSTEM,
46 MAX_TEST_TYPES
47 };
48
50 constexpr const char* TEST_TYPE_STRINGS[] = {
51 "COMMON",
52 "DRIVER",
53 "FILESYSTEM",
54 "GUI",
55 "HARDWARE_COMMUNICATION",
56 "MEMORY",
57 "NETWORK",
58 "PROCESSES",
59 "RUNTIME",
60 "SYSTEM",
61 "UNKNOWN"
62 };
63
68 class Test {
69
70 private:
71 string m_name;
72 TestType m_type;
73
74 public:
75 Test(const string& name, TestType type);
76 virtual ~Test();
77
78 TestStatus run();
79
85 virtual TestStatus execute() = 0;
86
87 const string& name() const;
88 TestType type() const;
89 };
90
100 template<typename T1, typename T2> bool compare(T1 const& actual, T2 const& expected) {
101
102 // Direct comparison
103 if (actual == expected)
104 return true;
105
106 // Report what failed
107 Logger::WARNING() << "Test failed comparison: expected [" << expected << "], got [" << actual << "]\n";
108 return false;
109 }
110
115 class ConditionalTest : public Test {
116 private:
117 bool (*m_condition)();
118
119 public:
120 ConditionalTest(const string& name, TestType type, bool (*condition)());
121 ~ConditionalTest() override;
122
123 TestStatus execute() override;
124 };
125
132 class TestRunner {
133
134 private:
135 inline static common::Vector<Test*> s_tests = common::Vector<Test*>();
136
137 public:
138
139 static void test_kernel();
140
141 static void run_all_tests();
142 static void run_all_types(TestType type);
143
144 static void add_all_tests();
145 static void add_test(Test* test);
146
147 };
148}
149
150#endif //MAXOS_TESTS_TEST_H
constexpr const char * TEST_TYPE_STRINGS[]
String representations of the TestType enum.
Definition test.h:51
TestType
The different types of tests.
Definition test.h:36
TestStatus
The possible outcomes of a test.
Definition test.h:26
bool compare(T1 const &actual, T2 const &expected)
Compares two values and logs a warning if they are not equal.
Definition test.h:101

Enumeration Type Documentation

◆ TestStatus

enum class MaxOS::tests::TestStatus
strong

The possible outcomes of a test.

Definition at line 26 of file test.h.

26 {
27 PASS,
28 FAIL,
29 SKIP
30 };

◆ TestType

enum class MaxOS::tests::TestType
strong

The different types of tests.

Definition at line 36 of file test.h.

36 {
37 COMMON,
38 DRIVER,
39 FILESYSTEM,
40 GUI,
41 HARDWARE_COMMUNICATION,
42 MEMORY,
43 NETWORK,
44 PROCESSES,
45 RUNTIME,
46 SYSTEM,
47 MAX_TEST_TYPES
48 };

Function Documentation

◆ compare()

template<typename T1 , typename T2 >
bool MaxOS::tests::compare ( T1 const &  actual,
T2 const &  expected 
)

Compares two values and logs a warning if they are not equal.

Template Parameters
T1The type of the actual value
T2The type of the expected value
Parameters
actualThe actual value
expectedThe expected value
Returns
True if the values are equal, false otherwise

Definition at line 101 of file test.h.

101 {
102
103 // Direct comparison
104 if (actual == expected)
105 return true;
106
107 // Report what failed
108 Logger::WARNING() << "Test failed comparison: expected [" << expected << "], got [" << actual << "]\n";
109 return false;
110 }

References MaxOS::tests::compare(), and MaxOS::Logger::WARNING().

Referenced by MaxOS::tests::compare().

Variable Documentation

◆ TEST_TYPE_STRINGS

constexpr const char* MaxOS::tests::TEST_TYPE_STRINGS[]
constexpr
Initial value:
= {
"COMMON",
"DRIVER",
"FILESYSTEM",
"GUI",
"HARDWARE_COMMUNICATION",
"MEMORY",
"NETWORK",
"PROCESSES",
"RUNTIME",
"SYSTEM",
"UNKNOWN"
}

String representations of the TestType enum.

Definition at line 51 of file test.h.

51 {
52 "COMMON",
53 "DRIVER",
54 "FILESYSTEM",
55 "GUI",
56 "HARDWARE_COMMUNICATION",
57 "MEMORY",
58 "NETWORK",
59 "PROCESSES",
60 "RUNTIME",
61 "SYSTEM",
62 "UNKNOWN"
63 };