Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/core/test_validate_testing.cpp
23449 views
1
/**************************************************************************/
2
/* test_validate_testing.cpp */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#include "tests/test_macros.h"
32
33
TEST_FORCE_LINK(test_validate_testing)
34
35
#include "core/core_globals.h"
36
#include "core/object/object.h"
37
#include "tests/test_tools.h"
38
39
namespace TestValidateTesting {
40
41
TEST_SUITE("Validate tests") {
42
TEST_CASE("Always pass") {
43
CHECK(true);
44
}
45
TEST_CASE_PENDING("Pending tests are skipped") {
46
if (!doctest::getContextOptions()->no_skip) { // Normal run.
47
FAIL("This should be skipped if `--no-skip` is NOT set (missing `doctest::skip()` decorator?)");
48
} else {
49
CHECK_MESSAGE(true, "Pending test is run with `--no-skip`");
50
}
51
}
52
TEST_CASE("Muting Godot error messages") {
53
ERR_PRINT_OFF;
54
CHECK_MESSAGE(!CoreGlobals::print_error_enabled, "Error printing should be disabled.");
55
ERR_PRINT("Still waiting for Godot!"); // This should never get printed!
56
ERR_PRINT_ON;
57
CHECK_MESSAGE(CoreGlobals::print_error_enabled, "Error printing should be re-enabled.");
58
}
59
TEST_CASE("Stringify Variant types") {
60
Variant var;
61
INFO(var);
62
63
String string("Godot is finally here!");
64
INFO(string);
65
66
Vector2 vec2(0.5, 1.0);
67
INFO(vec2);
68
69
Vector2i vec2i(1, 2);
70
INFO(vec2i);
71
72
Rect2 rect2(0.5, 0.5, 100.5, 100.5);
73
INFO(rect2);
74
75
Rect2i rect2i(0, 0, 100, 100);
76
INFO(rect2i);
77
78
Vector3 vec3(0.5, 1.0, 2.0);
79
INFO(vec3);
80
81
Vector3i vec3i(1, 2, 3);
82
INFO(vec3i);
83
84
Transform2D trans2d(0.5, Vector2(100, 100));
85
INFO(trans2d);
86
87
Plane plane(Vector3(1, 1, 1), 1.0);
88
INFO(plane);
89
90
Quaternion quat = Quaternion::from_euler(Vector3(0.5, 1.0, 2.0));
91
INFO(quat);
92
93
AABB aabb(Vector3(), Vector3(100, 100, 100));
94
INFO(aabb);
95
96
Basis basis(quat);
97
INFO(basis);
98
99
Transform3D trans(basis);
100
INFO(trans);
101
102
Color color(1, 0.5, 0.2, 0.3);
103
INFO(color);
104
105
StringName string_name("has_method");
106
INFO(string_name);
107
108
NodePath node_path("godot/sprite");
109
INFO(node_path);
110
111
INFO(RID());
112
113
Object *obj = memnew(Object);
114
INFO(obj);
115
116
Callable callable(obj, "has_method");
117
INFO(callable);
118
119
Signal signal(obj, "script_changed");
120
INFO(signal);
121
122
memdelete(obj);
123
124
Dictionary dict;
125
dict["string"] = string;
126
dict["color"] = color;
127
INFO(dict);
128
129
Array arr = { string, color };
130
INFO(arr);
131
132
PackedByteArray byte_arr;
133
byte_arr.push_back(0);
134
byte_arr.push_back(1);
135
byte_arr.push_back(2);
136
INFO(byte_arr);
137
138
PackedInt32Array int32_arr;
139
int32_arr.push_back(0);
140
int32_arr.push_back(1);
141
int32_arr.push_back(2);
142
INFO(int32_arr);
143
144
PackedInt64Array int64_arr;
145
int64_arr.push_back(0);
146
int64_arr.push_back(1);
147
int64_arr.push_back(2);
148
INFO(int64_arr);
149
150
PackedFloat32Array float32_arr;
151
float32_arr.push_back(0.5);
152
float32_arr.push_back(1.5);
153
float32_arr.push_back(2.5);
154
INFO(float32_arr);
155
156
PackedFloat64Array float64_arr;
157
float64_arr.push_back(0.5);
158
float64_arr.push_back(1.5);
159
float64_arr.push_back(2.5);
160
INFO(float64_arr);
161
162
PackedStringArray str_arr = string.split(" ");
163
INFO(str_arr);
164
165
PackedVector2Array vec2_arr;
166
vec2_arr.push_back(Vector2(0, 0));
167
vec2_arr.push_back(Vector2(1, 1));
168
vec2_arr.push_back(Vector2(2, 2));
169
INFO(vec2_arr);
170
171
PackedVector3Array vec3_arr;
172
vec3_arr.push_back(Vector3(0, 0, 0));
173
vec3_arr.push_back(Vector3(1, 1, 1));
174
vec3_arr.push_back(Vector3(2, 2, 2));
175
INFO(vec3_arr);
176
177
PackedColorArray color_arr;
178
color_arr.push_back(Color(0, 0, 0));
179
color_arr.push_back(Color(1, 1, 1));
180
color_arr.push_back(Color(2, 2, 2));
181
INFO(color_arr);
182
183
PackedVector4Array vec4_arr;
184
vec4_arr.push_back(Vector4(0, 0, 0, 0));
185
vec4_arr.push_back(Vector4(1, 1, 1, 1));
186
vec4_arr.push_back(Vector4(2, 2, 2, 2));
187
vec4_arr.push_back(Vector4(3, 3, 3, 3));
188
INFO(vec4_arr);
189
190
// doctest string concatenation.
191
CHECK_MESSAGE(true, var, " ", vec2, " ", rect2, " ", color);
192
}
193
TEST_CASE("Detect error messages") {
194
ErrorDetector ed;
195
196
REQUIRE_FALSE(ed.has_error);
197
198
ERR_PRINT_OFF;
199
ERR_PRINT("Still waiting for Godot!");
200
ERR_PRINT_ON;
201
202
REQUIRE(ed.has_error);
203
}
204
}
205
206
} // namespace TestValidateTesting
207
208