summaryrefslogtreecommitdiff
path: root/tests/test_validate_testing.h
blob: f301047509bf45e17a521b3e200de709834b1e5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*************************************************************************/
/*  test_validate_testing.h                                              */
/*************************************************************************/
/*                       This file is part of:                           */
/*                           GODOT ENGINE                                */
/*                      https://godotengine.org                          */
/*************************************************************************/
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur.                 */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md).   */
/*                                                                       */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the       */
/* "Software"), to deal in the Software without restriction, including   */
/* without limitation the rights to use, copy, modify, merge, publish,   */
/* distribute, sublicense, and/or sell copies of the Software, and to    */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions:                                             */
/*                                                                       */
/* The above copyright notice and this permission notice shall be        */
/* included in all copies or substantial portions of the Software.       */
/*                                                                       */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */
/*************************************************************************/

#ifndef TEST_VALIDATE_TESTING_H
#define TEST_VALIDATE_TESTING_H

#include "core/os/os.h"

#include "tests/test_macros.h"

TEST_SUITE("Validate tests") {
	TEST_CASE("Always pass") {
		CHECK(true);
	}
	TEST_CASE_PENDING("Pending tests are skipped") {
		if (!doctest::getContextOptions()->no_skip) { // Normal run.
			FAIL("This should be skipped if `--no-skip` is NOT set (missing `doctest::skip()` decorator?)");
		} else {
			CHECK_MESSAGE(true, "Pending test is run with `--no-skip`");
		}
	}
	TEST_CASE("Muting Godot error messages") {
		ERR_PRINT_OFF;
		CHECK_MESSAGE(!_print_error_enabled, "Error printing should be disabled.");
		ERR_PRINT("Still waiting for Godot!"); // This should never get printed!
		ERR_PRINT_ON;
		CHECK_MESSAGE(_print_error_enabled, "Error printing should be re-enabled.");
	}
	TEST_CASE("Stringify Variant types") {
		Variant var;
		INFO(var);

		String string("Godot is finally here!");
		INFO(string);

		Vector2 vec2(0.5, 1.0);
		INFO(vec2);

		Vector2i vec2i(1, 2);
		INFO(vec2i);

		Rect2 rect2(0.5, 0.5, 100.5, 100.5);
		INFO(rect2);

		Rect2i rect2i(0, 0, 100, 100);
		INFO(rect2i);

		Vector3 vec3(0.5, 1.0, 2.0);
		INFO(vec3);

		Vector3i vec3i(1, 2, 3);
		INFO(vec3i);

		Transform2D trans2d(0.5, Vector2(100, 100));
		INFO(trans2d);

		Plane plane(Vector3(1, 1, 1), 1.0);
		INFO(plane);

		Quaternion quat(Vector3(0.5, 1.0, 2.0));
		INFO(quat);

		AABB aabb(Vector3(), Vector3(100, 100, 100));
		INFO(aabb);

		Basis basis(quat);
		INFO(basis);

		Transform3D trans(basis);
		INFO(trans);

		Color color(1, 0.5, 0.2, 0.3);
		INFO(color);

		StringName string_name("has_method");
		INFO(string_name);

		NodePath node_path("godot/sprite");
		INFO(node_path);

		INFO(RID());

		Object *obj = memnew(Object);
		INFO(obj);

		Callable callable(obj, "has_method");
		INFO(callable);

		Signal signal(obj, "script_changed");
		INFO(signal);

		memdelete(obj);

		Dictionary dict;
		dict["string"] = string;
		dict["color"] = color;
		INFO(dict);

		Array arr;
		arr.push_back(string);
		arr.push_back(color);
		INFO(arr);

		PackedByteArray byte_arr;
		byte_arr.push_back(0);
		byte_arr.push_back(1);
		byte_arr.push_back(2);
		INFO(byte_arr);

		PackedInt32Array int32_arr;
		int32_arr.push_back(0);
		int32_arr.push_back(1);
		int32_arr.push_back(2);
		INFO(int32_arr);

		PackedInt64Array int64_arr;
		int64_arr.push_back(0);
		int64_arr.push_back(1);
		int64_arr.push_back(2);
		INFO(int64_arr);

		PackedFloat32Array float32_arr;
		float32_arr.push_back(0.5);
		float32_arr.push_back(1.5);
		float32_arr.push_back(2.5);
		INFO(float32_arr);

		PackedFloat64Array float64_arr;
		float64_arr.push_back(0.5);
		float64_arr.push_back(1.5);
		float64_arr.push_back(2.5);
		INFO(float64_arr);

		PackedStringArray str_arr = string.split(" ");
		INFO(str_arr);

		PackedVector2Array vec2_arr;
		vec2_arr.push_back(Vector2(0, 0));
		vec2_arr.push_back(Vector2(1, 1));
		vec2_arr.push_back(Vector2(2, 2));
		INFO(vec2_arr);

		PackedVector3Array vec3_arr;
		vec3_arr.push_back(Vector3(0, 0, 0));
		vec3_arr.push_back(Vector3(1, 1, 1));
		vec3_arr.push_back(Vector3(2, 2, 2));
		INFO(vec3_arr);

		PackedColorArray color_arr;
		color_arr.push_back(Color(0, 0, 0));
		color_arr.push_back(Color(1, 1, 1));
		color_arr.push_back(Color(2, 2, 2));
		INFO(color_arr);

		// doctest string concatenation.
		CHECK_MESSAGE(true, var, " ", vec2, " ", rect2, " ", color);
	}
}

#endif // TEST_VALIDATE_TESTING_H