Path: blob/master/tests/core/test_validate_testing.cpp
23449 views
/**************************************************************************/1/* test_validate_testing.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "tests/test_macros.h"3132TEST_FORCE_LINK(test_validate_testing)3334#include "core/core_globals.h"35#include "core/object/object.h"36#include "tests/test_tools.h"3738namespace TestValidateTesting {3940TEST_SUITE("Validate tests") {41TEST_CASE("Always pass") {42CHECK(true);43}44TEST_CASE_PENDING("Pending tests are skipped") {45if (!doctest::getContextOptions()->no_skip) { // Normal run.46FAIL("This should be skipped if `--no-skip` is NOT set (missing `doctest::skip()` decorator?)");47} else {48CHECK_MESSAGE(true, "Pending test is run with `--no-skip`");49}50}51TEST_CASE("Muting Godot error messages") {52ERR_PRINT_OFF;53CHECK_MESSAGE(!CoreGlobals::print_error_enabled, "Error printing should be disabled.");54ERR_PRINT("Still waiting for Godot!"); // This should never get printed!55ERR_PRINT_ON;56CHECK_MESSAGE(CoreGlobals::print_error_enabled, "Error printing should be re-enabled.");57}58TEST_CASE("Stringify Variant types") {59Variant var;60INFO(var);6162String string("Godot is finally here!");63INFO(string);6465Vector2 vec2(0.5, 1.0);66INFO(vec2);6768Vector2i vec2i(1, 2);69INFO(vec2i);7071Rect2 rect2(0.5, 0.5, 100.5, 100.5);72INFO(rect2);7374Rect2i rect2i(0, 0, 100, 100);75INFO(rect2i);7677Vector3 vec3(0.5, 1.0, 2.0);78INFO(vec3);7980Vector3i vec3i(1, 2, 3);81INFO(vec3i);8283Transform2D trans2d(0.5, Vector2(100, 100));84INFO(trans2d);8586Plane plane(Vector3(1, 1, 1), 1.0);87INFO(plane);8889Quaternion quat = Quaternion::from_euler(Vector3(0.5, 1.0, 2.0));90INFO(quat);9192AABB aabb(Vector3(), Vector3(100, 100, 100));93INFO(aabb);9495Basis basis(quat);96INFO(basis);9798Transform3D trans(basis);99INFO(trans);100101Color color(1, 0.5, 0.2, 0.3);102INFO(color);103104StringName string_name("has_method");105INFO(string_name);106107NodePath node_path("godot/sprite");108INFO(node_path);109110INFO(RID());111112Object *obj = memnew(Object);113INFO(obj);114115Callable callable(obj, "has_method");116INFO(callable);117118Signal signal(obj, "script_changed");119INFO(signal);120121memdelete(obj);122123Dictionary dict;124dict["string"] = string;125dict["color"] = color;126INFO(dict);127128Array arr = { string, color };129INFO(arr);130131PackedByteArray byte_arr;132byte_arr.push_back(0);133byte_arr.push_back(1);134byte_arr.push_back(2);135INFO(byte_arr);136137PackedInt32Array int32_arr;138int32_arr.push_back(0);139int32_arr.push_back(1);140int32_arr.push_back(2);141INFO(int32_arr);142143PackedInt64Array int64_arr;144int64_arr.push_back(0);145int64_arr.push_back(1);146int64_arr.push_back(2);147INFO(int64_arr);148149PackedFloat32Array float32_arr;150float32_arr.push_back(0.5);151float32_arr.push_back(1.5);152float32_arr.push_back(2.5);153INFO(float32_arr);154155PackedFloat64Array float64_arr;156float64_arr.push_back(0.5);157float64_arr.push_back(1.5);158float64_arr.push_back(2.5);159INFO(float64_arr);160161PackedStringArray str_arr = string.split(" ");162INFO(str_arr);163164PackedVector2Array vec2_arr;165vec2_arr.push_back(Vector2(0, 0));166vec2_arr.push_back(Vector2(1, 1));167vec2_arr.push_back(Vector2(2, 2));168INFO(vec2_arr);169170PackedVector3Array vec3_arr;171vec3_arr.push_back(Vector3(0, 0, 0));172vec3_arr.push_back(Vector3(1, 1, 1));173vec3_arr.push_back(Vector3(2, 2, 2));174INFO(vec3_arr);175176PackedColorArray color_arr;177color_arr.push_back(Color(0, 0, 0));178color_arr.push_back(Color(1, 1, 1));179color_arr.push_back(Color(2, 2, 2));180INFO(color_arr);181182PackedVector4Array vec4_arr;183vec4_arr.push_back(Vector4(0, 0, 0, 0));184vec4_arr.push_back(Vector4(1, 1, 1, 1));185vec4_arr.push_back(Vector4(2, 2, 2, 2));186vec4_arr.push_back(Vector4(3, 3, 3, 3));187INFO(vec4_arr);188189// doctest string concatenation.190CHECK_MESSAGE(true, var, " ", vec2, " ", rect2, " ", color);191}192TEST_CASE("Detect error messages") {193ErrorDetector ed;194195REQUIRE_FALSE(ed.has_error);196197ERR_PRINT_OFF;198ERR_PRINT("Still waiting for Godot!");199ERR_PRINT_ON;200201REQUIRE(ed.has_error);202}203}204205} // namespace TestValidateTesting206207208