Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/tests/test_validate_testing.h
9887 views
1
/**************************************************************************/
2
/* test_validate_testing.h */
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
#pragma once
32
33
#include "core/core_globals.h"
34
#include "core/os/os.h"
35
36
#include "tests/test_macros.h"
37
#include "tests/test_tools.h"
38
39
TEST_SUITE("Validate tests") {
40
TEST_CASE("Always pass") {
41
CHECK(true);
42
}
43
TEST_CASE_PENDING("Pending tests are skipped") {
44
if (!doctest::getContextOptions()->no_skip) { // Normal run.
45
FAIL("This should be skipped if `--no-skip` is NOT set (missing `doctest::skip()` decorator?)");
46
} else {
47
CHECK_MESSAGE(true, "Pending test is run with `--no-skip`");
48
}
49
}
50
TEST_CASE("Muting Godot error messages") {
51
ERR_PRINT_OFF;
52
CHECK_MESSAGE(!CoreGlobals::print_error_enabled, "Error printing should be disabled.");
53
ERR_PRINT("Still waiting for Godot!"); // This should never get printed!
54
ERR_PRINT_ON;
55
CHECK_MESSAGE(CoreGlobals::print_error_enabled, "Error printing should be re-enabled.");
56
}
57
TEST_CASE("Stringify Variant types") {
58
Variant var;
59
INFO(var);
60
61
String string("Godot is finally here!");
62
INFO(string);
63
64
Vector2 vec2(0.5, 1.0);
65
INFO(vec2);
66
67
Vector2i vec2i(1, 2);
68
INFO(vec2i);
69
70
Rect2 rect2(0.5, 0.5, 100.5, 100.5);
71
INFO(rect2);
72
73
Rect2i rect2i(0, 0, 100, 100);
74
INFO(rect2i);
75
76
Vector3 vec3(0.5, 1.0, 2.0);
77
INFO(vec3);
78
79
Vector3i vec3i(1, 2, 3);
80
INFO(vec3i);
81
82
Transform2D trans2d(0.5, Vector2(100, 100));
83
INFO(trans2d);
84
85
Plane plane(Vector3(1, 1, 1), 1.0);
86
INFO(plane);
87
88
Quaternion quat = Quaternion::from_euler(Vector3(0.5, 1.0, 2.0));
89
INFO(quat);
90
91
AABB aabb(Vector3(), Vector3(100, 100, 100));
92
INFO(aabb);
93
94
Basis basis(quat);
95
INFO(basis);
96
97
Transform3D trans(basis);
98
INFO(trans);
99
100
Color color(1, 0.5, 0.2, 0.3);
101
INFO(color);
102
103
StringName string_name("has_method");
104
INFO(string_name);
105
106
NodePath node_path("godot/sprite");
107
INFO(node_path);
108
109
INFO(RID());
110
111
Object *obj = memnew(Object);
112
INFO(obj);
113
114
Callable callable(obj, "has_method");
115
INFO(callable);
116
117
Signal signal(obj, "script_changed");
118
INFO(signal);
119
120
memdelete(obj);
121
122
Dictionary dict;
123
dict["string"] = string;
124
dict["color"] = color;
125
INFO(dict);
126
127
Array arr = { string, color };
128
INFO(arr);
129
130
PackedByteArray byte_arr;
131
byte_arr.push_back(0);
132
byte_arr.push_back(1);
133
byte_arr.push_back(2);
134
INFO(byte_arr);
135
136
PackedInt32Array int32_arr;
137
int32_arr.push_back(0);
138
int32_arr.push_back(1);
139
int32_arr.push_back(2);
140
INFO(int32_arr);
141
142
PackedInt64Array int64_arr;
143
int64_arr.push_back(0);
144
int64_arr.push_back(1);
145
int64_arr.push_back(2);
146
INFO(int64_arr);
147
148
PackedFloat32Array float32_arr;
149
float32_arr.push_back(0.5);
150
float32_arr.push_back(1.5);
151
float32_arr.push_back(2.5);
152
INFO(float32_arr);
153
154
PackedFloat64Array float64_arr;
155
float64_arr.push_back(0.5);
156
float64_arr.push_back(1.5);
157
float64_arr.push_back(2.5);
158
INFO(float64_arr);
159
160
PackedStringArray str_arr = string.split(" ");
161
INFO(str_arr);
162
163
PackedVector2Array vec2_arr;
164
vec2_arr.push_back(Vector2(0, 0));
165
vec2_arr.push_back(Vector2(1, 1));
166
vec2_arr.push_back(Vector2(2, 2));
167
INFO(vec2_arr);
168
169
PackedVector3Array vec3_arr;
170
vec3_arr.push_back(Vector3(0, 0, 0));
171
vec3_arr.push_back(Vector3(1, 1, 1));
172
vec3_arr.push_back(Vector3(2, 2, 2));
173
INFO(vec3_arr);
174
175
PackedColorArray color_arr;
176
color_arr.push_back(Color(0, 0, 0));
177
color_arr.push_back(Color(1, 1, 1));
178
color_arr.push_back(Color(2, 2, 2));
179
INFO(color_arr);
180
181
PackedVector4Array vec4_arr;
182
vec4_arr.push_back(Vector4(0, 0, 0, 0));
183
vec4_arr.push_back(Vector4(1, 1, 1, 1));
184
vec4_arr.push_back(Vector4(2, 2, 2, 2));
185
vec4_arr.push_back(Vector4(3, 3, 3, 3));
186
INFO(vec4_arr);
187
188
// doctest string concatenation.
189
CHECK_MESSAGE(true, var, " ", vec2, " ", rect2, " ", color);
190
}
191
TEST_CASE("Detect error messages") {
192
ErrorDetector ed;
193
194
REQUIRE_FALSE(ed.has_error);
195
196
ERR_PRINT_OFF;
197
ERR_PRINT("Still waiting for Godot!");
198
ERR_PRINT_ON;
199
200
REQUIRE(ed.has_error);
201
}
202
}
203
204