... | ... |
@@ -0,0 +1,109 @@ |
1 |
+/// Guards |
|
2 |
+ |
|
3 |
+#ifndef GLTEST_HPP_ |
|
4 |
+#define GLTEST_HPP_ |
|
5 |
+ |
|
6 |
+ |
|
7 |
+/// Includes |
|
8 |
+ |
|
9 |
+#include <string> |
|
10 |
+#include <vector> |
|
11 |
+ |
|
12 |
+// #include <glbackend.hpp> |
|
13 |
+class GLBackend; |
|
14 |
+ |
|
15 |
+ |
|
16 |
+/// Struct definition |
|
17 |
+ |
|
18 |
+struct GLTest_ |
|
19 |
+{ |
|
20 |
+ std::string title; |
|
21 |
+ int width; |
|
22 |
+ int height; |
|
23 |
+ int version_major; |
|
24 |
+ int version_minor; |
|
25 |
+ void (*func)(GLBackend & backend); |
|
26 |
+}; |
|
27 |
+ |
|
28 |
+ |
|
29 |
+/// Function forward declarations |
|
30 |
+ |
|
31 |
+std::vector<GLTest_> & gltests_(); |
|
32 |
+ |
|
33 |
+ |
|
34 |
+/// Macros |
|
35 |
+ |
|
36 |
+#define GLTEST(TITLE, WIDTH, HEIGHT, VERSION_MAJOR, VERSION_MINOR) \ |
|
37 |
+ void static gltest_func_##TITLE(GLBackend & backend); \ |
|
38 |
+ auto static gltest_init_##TITLE = ( \ |
|
39 |
+ gltests_().push_back({ \ |
|
40 |
+ #TITLE, \ |
|
41 |
+ WIDTH, \ |
|
42 |
+ HEIGHT, \ |
|
43 |
+ VERSION_MAJOR, \ |
|
44 |
+ VERSION_MINOR, \ |
|
45 |
+ gltest_func_##TITLE \ |
|
46 |
+ }), \ |
|
47 |
+ 0 \ |
|
48 |
+ ); \ |
|
49 |
+ void static gltest_func_##TITLE(GLBackend & backend) |
|
50 |
+ |
|
51 |
+ |
|
52 |
+#define GLTEST_EXPECT_VALUE(VALUE, ...) \ |
|
53 |
+ { \ |
|
54 |
+ auto gltest_value_ = VALUE; \ |
|
55 |
+ auto gltest_expr_value_ = __VA_ARGS__; \ |
|
56 |
+ auto gltest_error_ = std::string{} + \ |
|
57 |
+ ">>> Expression:\n" + \ |
|
58 |
+ #__VA_ARGS__ + "\n" + \ |
|
59 |
+ ">>> Expected value:\n" + \ |
|
60 |
+ #VALUE + " = " + std::to_string(gltest_value_) + "\n" + \ |
|
61 |
+ ">>> Got:"; \ |
|
62 |
+ if (gltest_expr_value_ != gltest_value_) \ |
|
63 |
+ throw std::runtime_error{std::string{} + \ |
|
64 |
+ gltest_error_ + "\n" + \ |
|
65 |
+ std::to_string(gltest_expr_value_) \ |
|
66 |
+ }; \ |
|
67 |
+ } |
|
68 |
+ |
|
69 |
+ |
|
70 |
+#define GLTEST_EXPECT_EXCEPTION(PREFIX, WHAT, ...) \ |
|
71 |
+ { \ |
|
72 |
+ auto gltest_prefix_ = PREFIX; \ |
|
73 |
+ auto gltest_expr_what_ = std::string{}; \ |
|
74 |
+ auto gltest_what_ = WHAT; \ |
|
75 |
+ try \ |
|
76 |
+ { \ |
|
77 |
+ __VA_ARGS__; \ |
|
78 |
+ } \ |
|
79 |
+ catch (std::exception const & gltest_exception_) \ |
|
80 |
+ { \ |
|
81 |
+ gltest_expr_what_ = gltest_exception_.what(); \ |
|
82 |
+ } \ |
|
83 |
+ auto gltest_error_ = std::string{} + \ |
|
84 |
+ ">>> Expression:\n" + \ |
|
85 |
+ #__VA_ARGS__ + "\n" + \ |
|
86 |
+ ">>> Expected exception" + \ |
|
87 |
+ (gltest_prefix_ ? " prefix" : "") + ":\n" + \ |
|
88 |
+ gltest_what_ + "\n" + \ |
|
89 |
+ ">>> Got:"; \ |
|
90 |
+ if (gltest_expr_what_.empty()) \ |
|
91 |
+ throw std::runtime_error{std::string{} + \ |
|
92 |
+ gltest_error_ + " none." \ |
|
93 |
+ }; \ |
|
94 |
+ if (gltest_prefix_ \ |
|
95 |
+ ? (gltest_expr_what_.rfind(gltest_what_, 0) \ |
|
96 |
+ == gltest_expr_what_.npos \ |
|
97 |
+ ) \ |
|
98 |
+ : (gltest_expr_what_ != gltest_what_) \ |
|
99 |
+ ) \ |
|
100 |
+ throw std::runtime_error{std::string{} + \ |
|
101 |
+ gltest_error_ + "\n" + \ |
|
102 |
+ gltest_expr_what_ \ |
|
103 |
+ }; \ |
|
104 |
+ } |
|
105 |
+ |
|
106 |
+ |
|
107 |
+/// Guards |
|
108 |
+ |
|
109 |
+#endif |