diff options
Diffstat (limited to 'tests')
56 files changed, 1843 insertions, 194 deletions
diff --git a/tests/data/images/icon.bmp b/tests/data/images/icon.bmp Binary files differnew file mode 100644 index 0000000000..e006f7ebdd --- /dev/null +++ b/tests/data/images/icon.bmp diff --git a/tests/data/images/icon.jpg b/tests/data/images/icon.jpg Binary files differnew file mode 100644 index 0000000000..b45bfa8d9b --- /dev/null +++ b/tests/data/images/icon.jpg diff --git a/tests/data/images/icon.png b/tests/data/images/icon.png Binary files differnew file mode 100644 index 0000000000..45aaaf584f --- /dev/null +++ b/tests/data/images/icon.png diff --git a/tests/data/images/icon.tga b/tests/data/images/icon.tga Binary files differnew file mode 100644 index 0000000000..dcacdc5c67 --- /dev/null +++ b/tests/data/images/icon.tga diff --git a/tests/data/images/icon.webp b/tests/data/images/icon.webp Binary files differnew file mode 100644 index 0000000000..6c4707e858 --- /dev/null +++ b/tests/data/images/icon.webp diff --git a/tests/test_aabb.h b/tests/test_aabb.h index 404a73a95f..517c4dcefd 100644 --- a/tests/test_aabb.h +++ b/tests/test_aabb.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_astar.h b/tests/test_astar.h index cd1bd84c15..12664a5ff1 100644 --- a/tests/test_astar.h +++ b/tests/test_astar.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_basis.h b/tests/test_basis.h index 00a00b4a5b..11c68f9eb7 100644 --- a/tests/test_basis.h +++ b/tests/test_basis.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_class_db.h b/tests/test_class_db.h index f95b98be15..9ef4569c14 100644 --- a/tests/test_class_db.h +++ b/tests/test_class_db.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -28,8 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef GODOT_TEST_CLASS_DB_H -#define GODOT_TEST_CLASS_DB_H +#ifndef TEST_CLASS_DB_H +#define TEST_CLASS_DB_H #include "core/register_core_types.h" @@ -42,11 +42,6 @@ #include "tests/test_macros.h" -#define TEST_COND DOCTEST_CHECK_FALSE_MESSAGE -#define TEST_FAIL DOCTEST_FAIL -#define TEST_FAIL_COND DOCTEST_REQUIRE_FALSE_MESSAGE -#define TEST_FAIL_COND_WARN DOCTEST_WARN_FALSE_MESSAGE - namespace TestClassDB { struct TypeReference { @@ -298,7 +293,7 @@ void validate_property(const Context &p_context, const ExposedClass &p_class, co const ExposedClass *top = &p_class; while (!setter && top->base != StringName()) { top = p_context.find_exposed_class(top->base); - TEST_FAIL_COND(!top, "Class not found '" + top->base + "'. Inherited by '" + top->name + "'."); + TEST_FAIL_COND(!top, "Class not found '", top->base, "'. Inherited by '", top->name, "'."); setter = top->find_method_by_name(p_prop.setter); } @@ -308,23 +303,23 @@ void validate_property(const Context &p_context, const ExposedClass &p_class, co top = &p_class; while (!getter && top->base != StringName()) { top = p_context.find_exposed_class(top->base); - TEST_FAIL_COND(!top, "Class not found '" + top->base + "'. Inherited by '" + top->name + "'."); + TEST_FAIL_COND(!top, "Class not found '", top->base, "'. Inherited by '", top->name, "'."); getter = top->find_method_by_name(p_prop.getter); } TEST_FAIL_COND((!setter && !getter), - "Couldn't find neither the setter nor the getter for property: '" + p_class.name + "." + String(p_prop.name) + "'."); + "Couldn't find neither the setter nor the getter for property: '", p_class.name, ".", String(p_prop.name), "'."); if (setter) { int setter_argc = p_prop.index != -1 ? 2 : 1; TEST_FAIL_COND(setter->arguments.size() != setter_argc, - "Invalid property setter argument count: '" + p_class.name + "." + String(p_prop.name) + "'."); + "Invalid property setter argument count: '", p_class.name, ".", String(p_prop.name), "'."); } if (getter) { int getter_argc = p_prop.index != -1 ? 1 : 0; TEST_FAIL_COND(getter->arguments.size() != getter_argc, - "Invalid property setter argument count: '" + p_class.name + "." + String(p_prop.name) + "'."); + "Invalid property setter argument count: '", p_class.name, ".", String(p_prop.name), "'."); } if (getter && setter) { @@ -335,7 +330,7 @@ void validate_property(const Context &p_context, const ExposedClass &p_class, co setter_first_arg.type.name == p_context.names_cache.string_type; TEST_FAIL_COND(!whitelisted, - "Return type from getter doesn't match first argument of setter, for property: '" + p_class.name + "." + String(p_prop.name) + "'."); + "Return type from getter doesn't match first argument of setter, for property: '", p_class.name, ".", String(p_prop.name), "'."); } } @@ -344,10 +339,17 @@ void validate_property(const Context &p_context, const ExposedClass &p_class, co const ExposedClass *prop_class = p_context.find_exposed_class(prop_type_ref); if (prop_class) { TEST_COND(prop_class->is_singleton, - "Property type is a singleton: '" + p_class.name + "." + String(p_prop.name) + "'."); + "Property type is a singleton: '", p_class.name, ".", String(p_prop.name), "'."); + + if (p_class.api_type == ClassDB::API_CORE) { + TEST_COND(prop_class->api_type == ClassDB::API_EDITOR, + "Property '", p_class.name, ".", p_prop.name, "' has type '", prop_class->name, + "' from the editor API. Core API cannot have dependencies on the editor API."); + } } else { + // Look for types that don't inherit Object TEST_FAIL_COND(!p_context.has_type(prop_type_ref), - "Property type '" + prop_type_ref.name + "' not found: '" + p_class.name + "." + String(p_prop.name) + "'."); + "Property type '", prop_type_ref.name, "' not found: '", p_class.name, ".", String(p_prop.name), "'."); } if (getter) { @@ -356,7 +358,7 @@ void validate_property(const Context &p_context, const ExposedClass &p_class, co if (idx_arg.type.name != p_context.names_cache.int_type) { // If not an int, it can be an enum TEST_COND(p_context.enum_types.find(idx_arg.type.name) < 0, - "Invalid type '" + idx_arg.type.name + "' for index argument of property getter: '" + p_class.name + "." + String(p_prop.name) + "'."); + "Invalid type '", idx_arg.type.name, "' for index argument of property getter: '", p_class.name, ".", String(p_prop.name), "'."); } } } @@ -368,17 +370,29 @@ void validate_property(const Context &p_context, const ExposedClass &p_class, co // Assume the index parameter is an enum // If not an int, it can be an enum TEST_COND(p_context.enum_types.find(idx_arg.type.name) < 0, - "Invalid type '" + idx_arg.type.name + "' for index argument of property setter: '" + p_class.name + "." + String(p_prop.name) + "'."); + "Invalid type '", idx_arg.type.name, "' for index argument of property setter: '", p_class.name, ".", String(p_prop.name), "'."); } } } } void validate_method(const Context &p_context, const ExposedClass &p_class, const MethodData &p_method) { - const ExposedClass *return_class = p_context.find_exposed_class(p_method.return_type); - if (return_class) { - TEST_COND(return_class->is_singleton, - "Method return type is a singleton: '" + p_class.name + "." + p_method.name + "'."); + if (p_method.return_type.name != StringName()) { + const ExposedClass *return_class = p_context.find_exposed_class(p_method.return_type); + if (return_class) { + TEST_COND(return_class->is_singleton, + "Method return type is a singleton: '", p_class.name, ".", p_method.name, "'."); + + if (p_class.api_type == ClassDB::API_CORE) { + TEST_COND(return_class->api_type == ClassDB::API_EDITOR, + "Method '", p_class.name, ".", p_method.name, "' has return type '", return_class->name, + "' from the editor API. Core API cannot have dependencies on the editor API."); + } + } else { + // Look for types that don't inherit Object + TEST_FAIL_COND(!p_context.has_type(p_method.return_type), + "Method return type '", p_method.return_type.name, "' not found: '", p_class.name, ".", p_method.name, "'."); + } } for (const List<ArgumentData>::Element *F = p_method.arguments.front(); F; F = F->next()) { @@ -387,10 +401,17 @@ void validate_method(const Context &p_context, const ExposedClass &p_class, cons const ExposedClass *arg_class = p_context.find_exposed_class(arg.type); if (arg_class) { TEST_COND(arg_class->is_singleton, - "Argument type is a singleton: '" + arg.name + "' of method '" + p_class.name + "." + p_method.name + "'."); + "Argument type is a singleton: '", arg.name, "' of method '", p_class.name, ".", p_method.name, "'."); + + if (p_class.api_type == ClassDB::API_CORE) { + TEST_COND(arg_class->api_type == ClassDB::API_EDITOR, + "Argument '", arg.name, "' of method '", p_class.name, ".", p_method.name, "' has type '", + arg_class->name, "' from the editor API. Core API cannot have dependencies on the editor API."); + } } else { + // Look for types that don't inherit Object TEST_FAIL_COND(!p_context.has_type(arg.type), - "Argument type '" + arg.type.name + "' not found: '" + arg.name + "' of method" + p_class.name + "." + p_method.name + "'."); + "Argument type '", arg.type.name, "' not found: '", arg.name, "' of method", p_class.name, ".", p_method.name, "'."); } if (arg.has_defval) { @@ -412,10 +433,17 @@ void validate_signal(const Context &p_context, const ExposedClass &p_class, cons const ExposedClass *arg_class = p_context.find_exposed_class(arg.type); if (arg_class) { TEST_COND(arg_class->is_singleton, - "Argument class is a singleton: '" + arg.name + "' of signal" + p_class.name + "." + p_signal.name + "'."); + "Argument class is a singleton: '", arg.name, "' of signal '", p_class.name, ".", p_signal.name, "'."); + + if (p_class.api_type == ClassDB::API_CORE) { + TEST_COND(arg_class->api_type == ClassDB::API_EDITOR, + "Argument '", arg.name, "' of signal '", p_class.name, ".", p_signal.name, "' has type '", + arg_class->name, "' from the editor API. Core API cannot have dependencies on the editor API."); + } } else { + // Look for types that don't inherit Object TEST_FAIL_COND(!p_context.has_type(arg.type), - "Argument type '" + arg.type.name + "' not found: '" + arg.name + "' of signal" + p_class.name + "." + p_signal.name + "'."); + "Argument type '", arg.type.name, "' not found: '", arg.name, "' of signal", p_class.name, ".", p_signal.name, "'."); } } } @@ -426,7 +454,7 @@ void validate_class(const Context &p_context, const ExposedClass &p_exposed_clas if (!is_derived_type) { // Asserts about the base Object class TEST_FAIL_COND(p_exposed_class.name != p_context.names_cache.object_class, - "Class '" + p_exposed_class.name + "' has no base class."); + "Class '", p_exposed_class.name, "' has no base class."); TEST_FAIL_COND(!p_exposed_class.is_instantiable, "Object class is not instantiable."); TEST_FAIL_COND(p_exposed_class.api_type != ClassDB::API_CORE, @@ -436,10 +464,10 @@ void validate_class(const Context &p_context, const ExposedClass &p_exposed_clas } TEST_FAIL_COND((p_exposed_class.is_singleton && p_exposed_class.base != p_context.names_cache.object_class), - "Singleton base class '" + String(p_exposed_class.base) + "' is not Object, for class '" + p_exposed_class.name + "'."); + "Singleton base class '", String(p_exposed_class.base), "' is not Object, for class '", p_exposed_class.name, "'."); TEST_FAIL_COND((is_derived_type && !p_context.exposed_classes.has(p_exposed_class.base)), - "Base type '" + p_exposed_class.base.operator String() + "' does not exist, for class '" + p_exposed_class.name + "'."); + "Base type '", p_exposed_class.base.operator String(), "' does not exist, for class '", p_exposed_class.name, "'."); for (const List<PropertyData>::Element *F = p_exposed_class.properties.front(); F; F = F->next()) { validate_property(p_context, p_exposed_class, F->get()); @@ -519,7 +547,7 @@ void add_exposed_classes(Context &r_context) { bool valid = false; prop.index = ClassDB::get_property_index(class_name, prop.name, &valid); - TEST_FAIL_COND(!valid, "Invalid property: '" + exposed_class.name + "." + String(prop.name) + "'."); + TEST_FAIL_COND(!valid, "Invalid property: '", exposed_class.name, ".", String(prop.name), "'."); exposed_class.properties.push_back(prop); } @@ -557,7 +585,7 @@ void add_exposed_classes(Context &r_context) { if (!m && !method.is_virtual) { TEST_FAIL_COND(!virtual_method_list.find(method_info), - "Missing MethodBind for non-virtual method: '" + exposed_class.name + "." + method.name + "'."); + "Missing MethodBind for non-virtual method: '", exposed_class.name, ".", method.name, "'."); // A virtual method without the virtual flag. This is a special case. @@ -584,9 +612,8 @@ void add_exposed_classes(Context &r_context) { bool bad_reference_hint = !method.is_virtual && return_info.hint != PROPERTY_HINT_RESOURCE_TYPE && ClassDB::is_parent_class(return_info.class_name, r_context.names_cache.reference_class); - TEST_COND(bad_reference_hint, String() + "Return type is reference but hint is not '" _STR(PROPERTY_HINT_RESOURCE_TYPE) "'." + - " Are you returning a reference type by pointer? Method: '" + - exposed_class.name + "." + method.name + "'."); + TEST_COND(bad_reference_hint, "Return type is reference but hint is not '" _STR(PROPERTY_HINT_RESOURCE_TYPE) "'.", " Are you returning a reference type by pointer? Method: '", + exposed_class.name, ".", method.name, "'."); } else if (return_info.hint == PROPERTY_HINT_RESOURCE_TYPE) { method.return_type.name = return_info.hint_string; } else if (return_info.type == Variant::NIL && return_info.usage & PROPERTY_USAGE_NIL_IS_VARIANT) { @@ -636,7 +663,7 @@ void add_exposed_classes(Context &r_context) { } TEST_COND(exposed_class.find_property_by_name(method.name), - "Method name conflicts with property: '" + String(class_name) + "." + String(method.name) + "'."); + "Method name conflicts with property: '", String(class_name), ".", String(method.name), "'."); // Classes starting with an underscore are ignored unless they're used as a property setter or getter if (!method.is_virtual && String(method.name)[0] == '_') { @@ -724,8 +751,8 @@ void add_exposed_classes(Context &r_context) { for (const List<StringName>::Element *E = enum_constants.front(); E; E = E->next()) { const StringName &constant_name = E->get(); int *value = class_info->constant_map.getptr(constant_name); - TEST_FAIL_COND(!value, "Missing enum constant value: '" + - String(class_name) + "." + String(enum_.name) + "." + String(constant_name) + "'."); + TEST_FAIL_COND(!value, "Missing enum constant value: '", + String(class_name), ".", String(enum_.name), ".", String(constant_name), "'."); constants.erase(constant_name); ConstantData constant; @@ -743,7 +770,7 @@ void add_exposed_classes(Context &r_context) { for (const List<String>::Element *E = constants.front(); E; E = E->next()) { const String &constant_name = E->get(); int *value = class_info->constant_map.getptr(StringName(E->get())); - TEST_FAIL_COND(!value, "Missing enum constant value: '" + String(class_name) + "." + String(constant_name) + "'."); + TEST_FAIL_COND(!value, "Missing enum constant value: '", String(class_name), ".", String(constant_name), "'."); ConstantData constant; constant.name = constant_name; @@ -822,7 +849,7 @@ TEST_SUITE("[ClassDB]") { const ExposedClass *object_class = context.find_exposed_class(context.names_cache.object_class); TEST_FAIL_COND(!object_class, "Object class not found."); TEST_FAIL_COND(object_class->base != StringName(), - "Object class derives from another class: '" + object_class->base + "'."); + "Object class derives from another class: '", object_class->base, "'."); for (ExposedClasses::Element E = context.exposed_classes.front(); E; E = E.next()) { validate_class(context, E.value()); @@ -832,4 +859,4 @@ TEST_SUITE("[ClassDB]") { } } // namespace TestClassDB -#endif //GODOT_TEST_CLASS_DB_H +#endif // TEST_CLASS_DB_H diff --git a/tests/test_color.h b/tests/test_color.h index c2bb63b7d0..eb8d7dcbd4 100644 --- a/tests/test_color.h +++ b/tests/test_color.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_command_queue.h b/tests/test_command_queue.h index ce42d94475..b4fa63ad2b 100644 --- a/tests/test_command_queue.h +++ b/tests/test_command_queue.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -122,8 +122,8 @@ public: int message_count_to_read = 0; bool exit_threads = false; - Thread *reader_thread = nullptr; - Thread *writer_thread = nullptr; + Thread reader_thread; + Thread writer_thread; int func1_count = 0; @@ -221,20 +221,16 @@ public: } void init_threads() { - reader_thread = Thread::create(&SharedThreadState::static_reader_thread_loop, this); - writer_thread = Thread::create(&SharedThreadState::static_writer_thread_loop, this); + reader_thread.start(&SharedThreadState::static_reader_thread_loop, this); + writer_thread.start(&SharedThreadState::static_writer_thread_loop, this); } void destroy_threads() { exit_threads = true; reader_threadwork.main_start_work(); writer_threadwork.main_start_work(); - Thread::wait_to_finish(reader_thread); - memdelete(reader_thread); - reader_thread = nullptr; - Thread::wait_to_finish(writer_thread); - memdelete(writer_thread); - writer_thread = nullptr; + reader_thread.wait_to_finish(); + writer_thread.wait_to_finish(); } }; diff --git a/tests/test_config_file.h b/tests/test_config_file.h index f910ca4b1f..958341018b 100644 --- a/tests/test_config_file.h +++ b/tests/test_config_file.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_crypto.h b/tests/test_crypto.h index 9e219ceec9..8da8c75544 100644 --- a/tests/test_crypto.h +++ b/tests/test_crypto.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_curve.h b/tests/test_curve.h index b123ef6325..019941a7ce 100644 --- a/tests/test_curve.h +++ b/tests/test_curve.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_expression.h b/tests/test_expression.h index 2b89de4327..0ef60d1a19 100644 --- a/tests/test_expression.h +++ b/tests/test_expression.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_file_access.h b/tests/test_file_access.h index a55d846360..00a314644c 100644 --- a/tests/test_file_access.h +++ b/tests/test_file_access.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_geometry_2d.h b/tests/test_geometry_2d.h index ed26611803..ea02d1114f 100644 --- a/tests/test_geometry_2d.h +++ b/tests/test_geometry_2d.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_gradient.h b/tests/test_gradient.h index 0c018c33e5..8eaa6b2b64 100644 --- a/tests/test_gradient.h +++ b/tests/test_gradient.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_gui.cpp b/tests/test_gui.cpp index a1a5ca0d4e..b83bd10af4 100644 --- a/tests/test_gui.cpp +++ b/tests/test_gui.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_gui.h b/tests/test_gui.h index 5a23179eee..e5c40de7e8 100644 --- a/tests/test_gui.h +++ b/tests/test_gui.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_image.h b/tests/test_image.h new file mode 100644 index 0000000000..d73717f5b7 --- /dev/null +++ b/tests/test_image.h @@ -0,0 +1,259 @@ +/*************************************************************************/ +/* test_image.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_IMAGE_H +#define TEST_IMAGE_H + +#include "core/io/file_access_pack.h" +#include "core/io/image.h" +#include "test_utils.h" + +#include "thirdparty/doctest/doctest.h" + +namespace TestImage { + +TEST_CASE("[Image] Instantiation") { + Ref<Image> image = memnew(Image(8, 4, false, Image::FORMAT_RGBA8)); + CHECK_MESSAGE( + !image->is_empty(), + "An image created with specified size and format should not be empty at first."); + CHECK_MESSAGE( + image->is_invisible(), + "A newly created image should be invisible."); + CHECK_MESSAGE( + !image->is_compressed(), + "A newly created image should not be compressed."); + CHECK(!image->has_mipmaps()); + + Ref<Image> image_copy = memnew(Image()); + CHECK_MESSAGE( + image_copy->is_empty(), + "An image created without any specified size and format be empty at first."); + image_copy->copy_internals_from(image); + + CHECK_MESSAGE( + image->get_data() == image_copy->get_data(), + "Duplicated images should have the same data."); + + PackedByteArray image_data = image->get_data(); + Ref<Image> image_from_data = memnew(Image(8, 4, false, Image::FORMAT_RGBA8, image_data)); + CHECK_MESSAGE( + image->get_data() == image_from_data->get_data(), + "An image created from data of another image should have the same data of the original image."); +} + +TEST_CASE("[Image] Saving and loading") { + Ref<Image> image = memnew(Image(4, 4, false, Image::FORMAT_RGBA8)); + const String save_path_png = OS::get_singleton()->get_cache_path().plus_file("image.png"); + const String save_path_exr = OS::get_singleton()->get_cache_path().plus_file("image.exr"); + + // Save PNG + Error err; + err = image->save_png(save_path_png); + CHECK_MESSAGE( + err == OK, + "The image should be saved successfully as a .png file."); + + // Save EXR + err = image->save_exr(save_path_exr, false); + CHECK_MESSAGE( + err == OK, + "The image should be saved successfully as an .exr file."); + + // Load using load() + Ref<Image> image_load = memnew(Image()); + err = image_load->load(save_path_png); + CHECK_MESSAGE( + err == OK, + "The image should load successfully using load()."); + CHECK_MESSAGE( + image->get_data() == image_load->get_data(), + "The loaded image should have the same data as the one that got saved."); + + // Load BMP + Ref<Image> image_bmp = memnew(Image()); + FileAccessRef f_bmp = FileAccess::open(TestUtils::get_data_path("images/icon.bmp"), FileAccess::READ, &err); + PackedByteArray data_bmp; + data_bmp.resize(f_bmp->get_len() + 1); + f_bmp->get_buffer(data_bmp.ptrw(), f_bmp->get_len()); + CHECK_MESSAGE( + image_bmp->load_bmp_from_buffer(data_bmp) == OK, + "The BMP image should load successfully."); + + // Load JPG + Ref<Image> image_jpg = memnew(Image()); + FileAccessRef f_jpg = FileAccess::open(TestUtils::get_data_path("images/icon.jpg"), FileAccess::READ, &err); + PackedByteArray data_jpg; + data_jpg.resize(f_jpg->get_len() + 1); + f_jpg->get_buffer(data_jpg.ptrw(), f_jpg->get_len()); + CHECK_MESSAGE( + image_jpg->load_jpg_from_buffer(data_jpg) == OK, + "The JPG image should load successfully."); + + // Load WEBP + Ref<Image> image_webp = memnew(Image()); + FileAccessRef f_webp = FileAccess::open(TestUtils::get_data_path("images/icon.webp"), FileAccess::READ, &err); + PackedByteArray data_webp; + data_webp.resize(f_webp->get_len() + 1); + f_webp->get_buffer(data_webp.ptrw(), f_webp->get_len()); + CHECK_MESSAGE( + image_webp->load_webp_from_buffer(data_webp) == OK, + "The WEBP image should load successfully."); + + // Load PNG + Ref<Image> image_png = memnew(Image()); + FileAccessRef f_png = FileAccess::open(TestUtils::get_data_path("images/icon.png"), FileAccess::READ, &err); + PackedByteArray data_png; + data_png.resize(f_png->get_len() + 1); + f_png->get_buffer(data_png.ptrw(), f_png->get_len()); + CHECK_MESSAGE( + image_png->load_png_from_buffer(data_png) == OK, + "The PNG image should load successfully."); + + // Load TGA + Ref<Image> image_tga = memnew(Image()); + FileAccessRef f_tga = FileAccess::open(TestUtils::get_data_path("images/icon.tga"), FileAccess::READ, &err); + PackedByteArray data_tga; + data_tga.resize(f_tga->get_len() + 1); + f_tga->get_buffer(data_tga.ptrw(), f_tga->get_len()); + CHECK_MESSAGE( + image_tga->load_tga_from_buffer(data_tga) == OK, + "The TGA image should load successfully."); +} + +TEST_CASE("[Image] Basic getters") { + Ref<Image> image = memnew(Image(8, 4, false, Image::FORMAT_LA8)); + CHECK(image->get_width() == 8); + CHECK(image->get_height() == 4); + CHECK(image->get_size() == Vector2(8, 4)); + CHECK(image->get_format() == Image::FORMAT_LA8); + CHECK(image->get_used_rect() == Rect2(0, 0, 0, 0)); + Ref<Image> image_get_rect = image->get_rect(Rect2(0, 0, 2, 1)); + CHECK(image_get_rect->get_size() == Vector2(2, 1)); +} + +TEST_CASE("[Image] Resizing") { + Ref<Image> image = memnew(Image(8, 8, false, Image::FORMAT_RGBA8)); + // Crop + image->crop(4, 4); + CHECK_MESSAGE( + image->get_size() == Vector2(4, 4), + "get_size() should return the correct size after cropping."); + image->set_pixel(0, 0, Color(1, 1, 1, 1)); + + // Resize + for (int i = 0; i < 5; i++) { + Ref<Image> image_resized = memnew(Image()); + image_resized->copy_internals_from(image); + Image::Interpolation interpolation = static_cast<Image::Interpolation>(i); + image_resized->resize(8, 8, interpolation); + CHECK_MESSAGE( + image_resized->get_size() == Vector2(8, 8), + "get_size() should return the correct size after resizing."); + CHECK_MESSAGE( + image_resized->get_pixel(1, 1).a > 0, + "Resizing an image should also affect its content."); + } + + // shrink_x2() + image->shrink_x2(); + CHECK_MESSAGE( + image->get_size() == Vector2(2, 2), + "get_size() should return the correct size after shrink_x2()."); + + // resize_to_po2() + Ref<Image> image_po_2 = memnew(Image(14, 28, false, Image::FORMAT_RGBA8)); + image_po_2->resize_to_po2(); + CHECK_MESSAGE( + image_po_2->get_size() == Vector2(16, 32), + "get_size() should return the correct size after resize_to_po2()."); +} + +TEST_CASE("[Image] Modifying pixels of an image") { + Ref<Image> image = memnew(Image(3, 3, false, Image::FORMAT_RGBA8)); + image->set_pixel(0, 0, Color(1, 1, 1, 1)); + CHECK_MESSAGE( + !image->is_invisible(), + "Image should not be invisible after drawing on it."); + CHECK_MESSAGE( + image->get_pixelv(Vector2(0, 0)).is_equal_approx(Color(1, 1, 1, 1)), + "Image's get_pixel() should return the same color value as the one being set with set_pixel() in the same position."); + CHECK_MESSAGE( + image->get_used_rect() == Rect2(0, 0, 1, 1), + "Image's get_used_rect should return the expected value, larger than Rect2(0, 0, 0, 0) if it's visible."); + + image->set_pixelv(Vector2(0, 0), Color(0.5, 0.5, 0.5, 0.5)); + Ref<Image> image2 = memnew(Image(3, 3, false, Image::FORMAT_RGBA8)); + + // Fill image with color + image2->fill(Color(0.5, 0.5, 0.5, 0.5)); + for (int x = 0; x < image2->get_width(); x++) { + for (int y = 0; y < image2->get_height(); y++) { + CHECK_MESSAGE( + image2->get_pixel(x, y).r > 0.49, + "fill() should colorize all pixels of the image."); + } + } + + // Blend two images together + image->blend_rect(image2, Rect2(Vector2(0, 0), image2->get_size()), Vector2(0, 0)); + CHECK_MESSAGE( + image->get_pixel(0, 0).a > 0.7, + "blend_rect() should blend the alpha values of the two images."); + CHECK_MESSAGE( + image->get_used_rect().size == image->get_size(), + "get_used_rect() should return the expected value, its Rect size should be the same as get_size() if there are no transparent pixels."); + + Ref<Image> image3 = memnew(Image(2, 2, false, Image::FORMAT_RGBA8)); + image3->set_pixel(0, 0, Color(0, 1, 0, 1)); + + //blit_rect() two images together + image->blit_rect(image3, Rect2(Vector2(0, 0), image3->get_size()), Vector2(0, 0)); + CHECK_MESSAGE( + image->get_pixel(0, 0).is_equal_approx(Color(0, 1, 0, 1)), + "blit_rect() should replace old colors and not blend them."); + CHECK_MESSAGE( + !image->get_pixel(2, 2).is_equal_approx(Color(0, 1, 0, 1)), + "blit_rect() should not affect the area of the image that is outside src_rect."); + + // Flip image + image3->flip_x(); + CHECK(image3->get_pixel(1, 0).is_equal_approx(Color(0, 1, 0, 1))); + CHECK_MESSAGE( + image3->get_pixel(0, 0).is_equal_approx(Color(0, 0, 0, 0)), + "flip_x() should not leave old pixels behind."); + image3->flip_y(); + CHECK(image3->get_pixel(1, 1).is_equal_approx(Color(0, 1, 0, 1))); + CHECK_MESSAGE( + image3->get_pixel(1, 0).is_equal_approx(Color(0, 0, 0, 0)), + "flip_y() should not leave old pixels behind."); +} +} // namespace TestImage +#endif // TEST_IMAGE_H diff --git a/tests/test_json.h b/tests/test_json.h index fe29e89e06..e652a8fced 100644 --- a/tests/test_json.h +++ b/tests/test_json.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_list.h b/tests/test_list.h index 99d52bb9d1..1c70b6e961 100644 --- a/tests/test_list.h +++ b/tests/test_list.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_local_vector.h b/tests/test_local_vector.h new file mode 100644 index 0000000000..eff2a16abc --- /dev/null +++ b/tests/test_local_vector.h @@ -0,0 +1,229 @@ +/*************************************************************************/ +/* test_local_vector.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_LOCAL_VECTOR_H +#define TEST_LOCAL_VECTOR_H + +#include "core/templates/local_vector.h" + +#include "tests/test_macros.h" + +namespace TestLocalVector { + +TEST_CASE("[LocalVector] Push Back.") { + LocalVector<int> vector; + vector.push_back(0); + vector.push_back(1); + vector.push_back(2); + vector.push_back(3); + vector.push_back(4); + + CHECK(vector[0] == 0); + CHECK(vector[1] == 1); + CHECK(vector[2] == 2); + CHECK(vector[3] == 3); + CHECK(vector[4] == 4); +} + +TEST_CASE("[LocalVector] Find.") { + LocalVector<int> vector; + vector.push_back(3); + vector.push_back(1); + vector.push_back(4); + vector.push_back(0); + vector.push_back(2); + + CHECK(vector[0] == 3); + CHECK(vector[1] == 1); + CHECK(vector[2] == 4); + CHECK(vector[3] == 0); + CHECK(vector[4] == 2); + + CHECK(vector.find(0) == 3); + CHECK(vector.find(1) == 1); + CHECK(vector.find(2) == 4); + CHECK(vector.find(3) == 0); + CHECK(vector.find(4) == 2); + + CHECK(vector.find(-1) == -1); + CHECK(vector.find(5) == -1); +} + +TEST_CASE("[LocalVector] Remove.") { + LocalVector<int> vector; + vector.push_back(0); + vector.push_back(1); + vector.push_back(2); + vector.push_back(3); + vector.push_back(4); + + vector.remove(0); + + CHECK(vector[0] == 1); + CHECK(vector[1] == 2); + CHECK(vector[2] == 3); + CHECK(vector[3] == 4); + + vector.remove(2); + + CHECK(vector[0] == 1); + CHECK(vector[1] == 2); + CHECK(vector[2] == 4); + + vector.remove(1); + + CHECK(vector[0] == 1); + CHECK(vector[1] == 4); + + vector.remove(0); + + CHECK(vector[0] == 4); +} + +TEST_CASE("[LocalVector] Remove Unordered.") { + LocalVector<int> vector; + vector.push_back(0); + vector.push_back(1); + vector.push_back(2); + vector.push_back(3); + vector.push_back(4); + + CHECK(vector.size() == 5); + + vector.remove_unordered(0); + + CHECK(vector.size() == 4); + + CHECK(vector.find(0) == -1); + CHECK(vector.find(1) != -1); + CHECK(vector.find(2) != -1); + CHECK(vector.find(3) != -1); + CHECK(vector.find(4) != -1); + + // Now the vector is no more ordered. + vector.remove_unordered(vector.find(3)); + + CHECK(vector.size() == 3); + + CHECK(vector.find(3) == -1); + CHECK(vector.find(1) != -1); + CHECK(vector.find(2) != -1); + CHECK(vector.find(4) != -1); + + vector.remove_unordered(vector.find(2)); + + CHECK(vector.size() == 2); + + CHECK(vector.find(2) == -1); + CHECK(vector.find(1) != -1); + CHECK(vector.find(4) != -1); + + vector.remove_unordered(vector.find(4)); + + CHECK(vector.size() == 1); + + CHECK(vector.find(4) == -1); + CHECK(vector.find(1) != -1); + + // Remove the last one. + vector.remove_unordered(0); + + CHECK(vector.is_empty()); + CHECK(vector.size() == 0); +} + +TEST_CASE("[LocalVector] Erase.") { + LocalVector<int> vector; + vector.push_back(1); + vector.push_back(3); + vector.push_back(0); + vector.push_back(2); + vector.push_back(4); + + CHECK(vector.find(2) == 3); + + vector.erase(2); + + CHECK(vector.find(2) == -1); + CHECK(vector.size() == 4); +} + +TEST_CASE("[LocalVector] Size / Resize / Reserve.") { + LocalVector<int> vector; + + CHECK(vector.is_empty()); + CHECK(vector.size() == 0); + CHECK(vector.get_capacity() == 0); + + vector.resize(10); + + CHECK(vector.size() == 10); + CHECK(vector.get_capacity() >= 10); + + vector.resize(5); + + CHECK(vector.size() == 5); + // Capacity is supposed to change only when the size increase. + CHECK(vector.get_capacity() >= 10); + + vector.remove(0); + vector.remove(0); + vector.remove(0); + + CHECK(vector.size() == 2); + // Capacity is supposed to change only when the size increase. + CHECK(vector.get_capacity() >= 10); + + vector.reset(); + + CHECK(vector.size() == 0); + CHECK(vector.get_capacity() == 0); + + vector.reserve(3); + + CHECK(vector.is_empty()); + CHECK(vector.size() == 0); + CHECK(vector.get_capacity() >= 3); + + vector.push_back(0); + vector.push_back(0); + vector.push_back(0); + + CHECK(vector.size() == 3); + CHECK(vector.get_capacity() >= 3); + + vector.push_back(0); + + CHECK(vector.size() == 4); + CHECK(vector.get_capacity() >= 4); +} +} // namespace TestLocalVector + +#endif // TEST_LOCAL_VECTOR_H diff --git a/tests/test_lru.h b/tests/test_lru.h index 260841f4c4..2802754729 100644 --- a/tests/test_lru.h +++ b/tests/test_lru.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_macros.cpp b/tests/test_macros.cpp index 2317223b23..b0b28ab374 100644 --- a/tests/test_macros.cpp +++ b/tests/test_macros.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_macros.h b/tests/test_macros.h index ae6af93825..a13f3abbe7 100644 --- a/tests/test_macros.h +++ b/tests/test_macros.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -44,6 +44,12 @@ // The test case is marked as failed, but does not fail the entire test run. #define TEST_CASE_MAY_FAIL(name) TEST_CASE(name *doctest::may_fail()) +// Provide aliases to conform with Godot naming conventions (see error macros). +#define TEST_COND(cond, ...) DOCTEST_CHECK_FALSE_MESSAGE(cond, __VA_ARGS__) +#define TEST_FAIL(cond, ...) DOCTEST_FAIL(cond, __VA_ARGS__) +#define TEST_FAIL_COND(cond, ...) DOCTEST_REQUIRE_FALSE_MESSAGE(cond, __VA_ARGS__) +#define TEST_FAIL_COND_WARN(cond, ...) DOCTEST_WARN_FALSE_MESSAGE(cond, __VA_ARGS__) + // Temporarily disable error prints to test failure paths. // This allows to avoid polluting the test summary with error messages. // The `_print_error_enabled` boolean is defined in `core/print_string.cpp` and diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 2042337379..2697eb6399 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -46,9 +46,12 @@ #include "test_geometry_2d.h" #include "test_gradient.h" #include "test_gui.h" +#include "test_image.h" #include "test_json.h" #include "test_list.h" +#include "test_local_vector.h" #include "test_lru.h" +#include "test_marshalls.h" #include "test_math.h" #include "test_method_bind.h" #include "test_node_path.h" diff --git a/tests/test_main.h b/tests/test_main.h index 983bfde402..8c506a776f 100644 --- a/tests/test_main.h +++ b/tests/test_main.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_marshalls.h b/tests/test_marshalls.h new file mode 100644 index 0000000000..6bd916164e --- /dev/null +++ b/tests/test_marshalls.h @@ -0,0 +1,329 @@ +/*************************************************************************/ +/* test_marshalls.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_MARSHALLS_H +#define TEST_MARSHALLS_H + +#include "core/io/marshalls.h" + +#include "tests/test_macros.h" + +namespace TestMarshalls { + +TEST_CASE("[Marshalls] Unsigned 16 bit integer encoding") { + uint8_t arr[2]; + + unsigned int actual_size = encode_uint16(0x1234, arr); + CHECK(actual_size == sizeof(uint16_t)); + CHECK_MESSAGE(arr[0] == 0x34, "First encoded byte value should be equal to low order byte value."); + CHECK_MESSAGE(arr[1] == 0x12, "Last encoded byte value should be equal to high order byte value."); +} + +TEST_CASE("[Marshalls] Unsigned 32 bit integer encoding") { + uint8_t arr[4]; + + unsigned int actual_size = encode_uint32(0x12345678, arr); + CHECK(actual_size == sizeof(uint32_t)); + CHECK_MESSAGE(arr[0] == 0x78, "First encoded byte value should be equal to low order byte value."); + CHECK(arr[1] == 0x56); + CHECK(arr[2] == 0x34); + CHECK_MESSAGE(arr[3] == 0x12, "Last encoded byte value should be equal to high order byte value."); +} + +TEST_CASE("[Marshalls] Unsigned 64 bit integer encoding") { + uint8_t arr[8]; + + unsigned int actual_size = encode_uint64(0x0f123456789abcdef, arr); + CHECK(actual_size == sizeof(uint64_t)); + CHECK_MESSAGE(arr[0] == 0xef, "First encoded byte value should be equal to low order byte value."); + CHECK(arr[1] == 0xcd); + CHECK(arr[2] == 0xab); + CHECK(arr[3] == 0x89); + CHECK(arr[4] == 0x67); + CHECK(arr[5] == 0x45); + CHECK(arr[6] == 0x23); + CHECK_MESSAGE(arr[7] == 0xf1, "Last encoded byte value should be equal to high order byte value."); +} + +TEST_CASE("[Marshalls] Unsigned 16 bit integer decoding") { + uint8_t arr[] = { 0x34, 0x12 }; + + CHECK(decode_uint16(arr) == 0x1234); +} + +TEST_CASE("[Marshalls] Unsigned 32 bit integer decoding") { + uint8_t arr[] = { 0x78, 0x56, 0x34, 0x12 }; + + CHECK(decode_uint32(arr) == 0x12345678); +} + +TEST_CASE("[Marshalls] Unsigned 64 bit integer decoding") { + uint8_t arr[] = { 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0xf1 }; + + CHECK(decode_uint64(arr) == 0x0f123456789abcdef); +} + +TEST_CASE("[Marshalls] Floating point single precision encoding") { + uint8_t arr[4]; + + // Decimal: 0.15625 + // IEEE 754 single-precision binary floating-point format: + // sign exponent (8 bits) fraction (23 bits) + // 0 01111100 01000000000000000000000 + // Hexadecimal: 0x3E200000 + unsigned int actual_size = encode_float(0.15625f, arr); + CHECK(actual_size == sizeof(uint32_t)); + CHECK(arr[0] == 0x00); + CHECK(arr[1] == 0x00); + CHECK(arr[2] == 0x20); + CHECK(arr[3] == 0x3e); +} + +TEST_CASE("[Marshalls] Floating point double precision encoding") { + uint8_t arr[8]; + + // Decimal: 0.333333333333333314829616256247390992939472198486328125 + // IEEE 754 double-precision binary floating-point format: + // sign exponent (11 bits) fraction (52 bits) + // 0 01111111101 0101010101010101010101010101010101010101010101010101 + // Hexadecimal: 0x3FD5555555555555 + unsigned int actual_size = encode_double(0.33333333333333333, arr); + CHECK(actual_size == sizeof(uint64_t)); + CHECK(arr[0] == 0x55); + CHECK(arr[1] == 0x55); + CHECK(arr[2] == 0x55); + CHECK(arr[3] == 0x55); + CHECK(arr[4] == 0x55); + CHECK(arr[5] == 0x55); + CHECK(arr[6] == 0xd5); + CHECK(arr[7] == 0x3f); +} + +TEST_CASE("[Marshalls] Floating point single precision decoding") { + uint8_t arr[] = { 0x00, 0x00, 0x20, 0x3e }; + + // See floating point encoding test case for details behind expected values + CHECK(decode_float(arr) == 0.15625f); +} + +TEST_CASE("[Marshalls] Floating point double precision decoding") { + uint8_t arr[] = { 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xd5, 0x3f }; + + // See floating point encoding test case for details behind expected values + CHECK(decode_double(arr) == 0.33333333333333333); +} + +TEST_CASE("[Marshalls] C string encoding") { + char cstring[] = "Godot"; // 5 characters + uint8_t data[6]; + + int actual_size = encode_cstring(cstring, data); + CHECK(actual_size == 6); + CHECK(data[0] == 'G'); + CHECK(data[1] == 'o'); + CHECK(data[2] == 'd'); + CHECK(data[3] == 'o'); + CHECK(data[4] == 't'); + CHECK(data[5] == '\0'); +} + +TEST_CASE("[Marshalls] NIL Variant encoding") { + int r_len; + Variant variant; + uint8_t buffer[4]; + + CHECK(encode_variant(variant, buffer, r_len) == OK); + CHECK_MESSAGE(r_len == 4, "Length == 4 bytes for Variant::Type"); + CHECK_MESSAGE(buffer[0] == 0x00, "Variant::NIL"); + CHECK(buffer[1] == 0x00); + CHECK(buffer[2] == 0x00); + CHECK(buffer[3] == 0x00); + // No value +} + +TEST_CASE("[Marshalls] INT 32 bit Variant encoding") { + int r_len; + Variant variant(0x12345678); + uint8_t buffer[8]; + + CHECK(encode_variant(variant, buffer, r_len) == OK); + CHECK_MESSAGE(r_len == 8, "Length == 4 bytes for Variant::Type + 4 bytes for int32_t"); + CHECK_MESSAGE(buffer[0] == 0x02, "Variant::INT"); + CHECK(buffer[1] == 0x00); + CHECK(buffer[2] == 0x00); + CHECK(buffer[3] == 0x00); + // Check value + CHECK(buffer[4] == 0x78); + CHECK(buffer[5] == 0x56); + CHECK(buffer[6] == 0x34); + CHECK(buffer[7] == 0x12); +} + +TEST_CASE("[Marshalls] INT 64 bit Variant encoding") { + int r_len; + Variant variant(uint64_t(0x0f123456789abcdef)); + uint8_t buffer[12]; + + CHECK(encode_variant(variant, buffer, r_len) == OK); + CHECK_MESSAGE(r_len == 12, "Length == 4 bytes for Variant::Type + 8 bytes for int64_t"); + CHECK_MESSAGE(buffer[0] == 0x02, "Variant::INT"); + CHECK(buffer[1] == 0x00); + CHECK_MESSAGE(buffer[2] == 0x01, "ENCODE_FLAG_64"); + CHECK(buffer[3] == 0x00); + // Check value + CHECK(buffer[4] == 0xef); + CHECK(buffer[5] == 0xcd); + CHECK(buffer[6] == 0xab); + CHECK(buffer[7] == 0x89); + CHECK(buffer[8] == 0x67); + CHECK(buffer[9] == 0x45); + CHECK(buffer[10] == 0x23); + CHECK(buffer[11] == 0xf1); +} + +TEST_CASE("[Marshalls] FLOAT single precision Variant encoding") { + int r_len; + Variant variant(0.15625f); + uint8_t buffer[8]; + + CHECK(encode_variant(variant, buffer, r_len) == OK); + CHECK_MESSAGE(r_len == 8, "Length == 4 bytes for Variant::Type + 4 bytes for float"); + CHECK_MESSAGE(buffer[0] == 0x03, "Variant::FLOAT"); + CHECK(buffer[1] == 0x00); + CHECK(buffer[2] == 0x00); + CHECK(buffer[3] == 0x00); + // Check value + CHECK(buffer[4] == 0x00); + CHECK(buffer[5] == 0x00); + CHECK(buffer[6] == 0x20); + CHECK(buffer[7] == 0x3e); +} + +TEST_CASE("[Marshalls] FLOAT double precision Variant encoding") { + int r_len; + Variant variant(0.33333333333333333); + uint8_t buffer[12]; + + CHECK(encode_variant(variant, buffer, r_len) == OK); + CHECK_MESSAGE(r_len == 12, "Length == 4 bytes for Variant::Type + 8 bytes for double"); + CHECK_MESSAGE(buffer[0] == 0x03, "Variant::FLOAT"); + CHECK(buffer[1] == 0x00); + CHECK_MESSAGE(buffer[2] == 0x01, "ENCODE_FLAG_64"); + CHECK(buffer[3] == 0x00); + // Check value + CHECK(buffer[4] == 0x55); + CHECK(buffer[5] == 0x55); + CHECK(buffer[6] == 0x55); + CHECK(buffer[7] == 0x55); + CHECK(buffer[8] == 0x55); + CHECK(buffer[9] == 0x55); + CHECK(buffer[10] == 0xd5); + CHECK(buffer[11] == 0x3f); +} + +TEST_CASE("[Marshalls] Invalid data Variant decoding") { + Variant variant; + int r_len = 0; + uint8_t some_buffer[1] = { 0x00 }; + uint8_t out_of_range_type_buffer[4] = { 0xff }; // Greater than Variant::VARIANT_MAX + + CHECK(decode_variant(variant, some_buffer, /* less than 4 */ 1, &r_len) == ERR_INVALID_DATA); + CHECK(r_len == 0); + + CHECK(decode_variant(variant, out_of_range_type_buffer, 4, &r_len) == ERR_INVALID_DATA); + CHECK(r_len == 0); +} + +TEST_CASE("[Marshalls] NIL Variant decoding") { + Variant variant; + int r_len; + uint8_t buffer[] = { + 0x00, 0x00, 0x00, 0x00 // Variant::NIL + }; + + CHECK(decode_variant(variant, buffer, 4, &r_len) == OK); + CHECK(r_len == 4); + CHECK(variant == Variant()); +} + +TEST_CASE("[Marshalls] INT 32 bit Variant decoding") { + Variant variant; + int r_len; + uint8_t buffer[] = { + 0x02, 0x00, 0x00, 0x00, // Variant::INT + 0x78, 0x56, 0x34, 0x12 // value + }; + + CHECK(decode_variant(variant, buffer, 8, &r_len) == OK); + CHECK(r_len == 8); + CHECK(variant == Variant(0x12345678)); +} + +TEST_CASE("[Marshalls] INT 64 bit Variant decoding") { + Variant variant; + int r_len; + uint8_t buffer[] = { + 0x02, 0x00, 0x01, 0x00, // Variant::INT & ENCODE_FLAG_64 + 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x23, 0xf1 // value + }; + + CHECK(decode_variant(variant, buffer, 12, &r_len) == OK); + CHECK(r_len == 12); + CHECK(variant == Variant(uint64_t(0x0f123456789abcdef))); +} + +TEST_CASE("[Marshalls] FLOAT single precision Variant decoding") { + Variant variant; + int r_len; + uint8_t buffer[] = { + 0x03, 0x00, 0x00, 0x00, // Variant::FLOAT + 0x00, 0x00, 0x20, 0x3e // value + }; + + CHECK(decode_variant(variant, buffer, 8, &r_len) == OK); + CHECK(r_len == 8); + CHECK(variant == Variant(0.15625f)); +} + +TEST_CASE("[Marshalls] FLOAT double precision Variant decoding") { + Variant variant; + int r_len; + uint8_t buffer[] = { + 0x03, 0x00, 0x01, 0x00, // Variant::FLOAT & ENCODE_FLAG_64 + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xd5, 0x3f // value + }; + + CHECK(decode_variant(variant, buffer, 12, &r_len) == OK); + CHECK(r_len == 12); + CHECK(variant == Variant(0.33333333333333333)); +} +} // namespace TestMarshalls + +#endif // TEST_MARSHALLS_H diff --git a/tests/test_math.cpp b/tests/test_math.cpp index 3d97c8bc45..26c2aa2088 100644 --- a/tests/test_math.cpp +++ b/tests/test_math.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -617,7 +617,7 @@ MainLoop *test() { List<String> args; args.push_back("-l"); - Error err = OS::get_singleton()->execute("/bin/ls", args, true, nullptr, &ret); + Error err = OS::get_singleton()->execute("/bin/ls", args, &ret); print_line("error: " + itos(err)); print_line(ret); diff --git a/tests/test_math.h b/tests/test_math.h index 77bce8dd66..4375925bd5 100644 --- a/tests/test_math.h +++ b/tests/test_math.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_method_bind.h b/tests/test_method_bind.h index 62d8bd132c..879e7949e2 100644 --- a/tests/test_method_bind.h +++ b/tests/test_method_bind.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_node_path.h b/tests/test_node_path.h index e9e06186f5..f30fe53c5a 100644 --- a/tests/test_node_path.h +++ b/tests/test_node_path.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_oa_hash_map.cpp b/tests/test_oa_hash_map.cpp index b0bb01bc71..904c01642d 100644 --- a/tests/test_oa_hash_map.cpp +++ b/tests/test_oa_hash_map.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_oa_hash_map.h b/tests/test_oa_hash_map.h index eb2b3d1e99..9745802cc0 100644 --- a/tests/test_oa_hash_map.h +++ b/tests/test_oa_hash_map.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_object.h b/tests/test_object.h index 6fef2576e7..142d76553d 100644 --- a/tests/test_object.h +++ b/tests/test_object.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -31,12 +31,103 @@ #ifndef TEST_OBJECT_H #define TEST_OBJECT_H +#include "core/core_string_names.h" #include "core/object/object.h" #include "thirdparty/doctest/doctest.h" +// Declared in global namespace because of GDCLASS macro warning (Windows): +// "Unqualified friend declaration referring to type outside of the nearest enclosing namespace +// is a Microsoft extension; add a nested name specifier". +class _TestDerivedObject : public Object { + GDCLASS(_TestDerivedObject, Object); + + int property_value; + +protected: + static void _bind_methods() { + ClassDB::bind_method(D_METHOD("set_property", "property"), &_TestDerivedObject::set_property); + ClassDB::bind_method(D_METHOD("get_property"), &_TestDerivedObject::get_property); + ADD_PROPERTY(PropertyInfo(Variant::INT, "property"), "set_property", "get_property"); + } + +public: + void set_property(int value) { property_value = value; } + int get_property() const { return property_value; } +}; + namespace TestObject { +class _MockScriptInstance : public ScriptInstance { + StringName property_name = "NO_NAME"; + Variant property_value; + +public: + bool set(const StringName &p_name, const Variant &p_value) override { + property_name = p_name; + property_value = p_value; + return true; + } + bool get(const StringName &p_name, Variant &r_ret) const override { + if (property_name == p_name) { + r_ret = property_value; + return true; + } + return false; + } + void get_property_list(List<PropertyInfo> *p_properties) const override { + } + Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const override { + return Variant::PACKED_FLOAT32_ARRAY; + } + void get_method_list(List<MethodInfo> *p_list) const override { + } + bool has_method(const StringName &p_method) const override { + return false; + } + Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override { + return Variant(); + } + void notification(int p_notification) override { + } + Ref<Script> get_script() const override { + return Ref<Script>(); + } + Vector<ScriptNetData> get_rpc_methods() const override { + return Vector<ScriptNetData>(); + } + uint16_t get_rpc_method_id(const StringName &p_method) const override { + return 0; + } + StringName get_rpc_method(uint16_t p_id) const override { + return StringName(); + } + MultiplayerAPI::RPCMode get_rpc_mode_by_id(uint16_t p_id) const override { + return MultiplayerAPI::RPC_MODE_PUPPET; + } + MultiplayerAPI::RPCMode get_rpc_mode(const StringName &p_method) const override { + return MultiplayerAPI::RPC_MODE_PUPPET; + } + Vector<ScriptNetData> get_rset_properties() const override { + return Vector<ScriptNetData>(); + } + uint16_t get_rset_property_id(const StringName &p_variable) const override { + return 0; + } + StringName get_rset_property(uint16_t p_id) const override { + return StringName(); + } + MultiplayerAPI::RPCMode get_rset_mode_by_id(uint16_t p_id) const override { + return MultiplayerAPI::RPC_MODE_PUPPET; + } + MultiplayerAPI::RPCMode get_rset_mode(const StringName &p_variable) const override { + return MultiplayerAPI::RPC_MODE_PUPPET; + } + ScriptLanguage *get_language() override { + return nullptr; + } +}; + TEST_CASE("[Object] Core getters") { Object object; @@ -55,6 +146,15 @@ TEST_CASE("[Object] Core getters") { CHECK_MESSAGE( object.get_save_class() == "Object", "The returned save class should match the expected value."); + + List<String> inheritance_list; + object.get_inheritance_list_static(&inheritance_list); + CHECK_MESSAGE( + inheritance_list.size() == 1, + "The inheritance list should consist of Object only"); + CHECK_MESSAGE( + inheritance_list[0] == "Object", + "The inheritance list should consist of Object only"); } TEST_CASE("[Object] Metadata") { @@ -87,6 +187,119 @@ TEST_CASE("[Object] Metadata") { meta_list2.size() == 0, "The metadata list should contain 0 items after removing all metadata items."); } + +TEST_CASE("[Object] Construction") { + Object object; + + CHECK_MESSAGE( + !object.is_reference(), + "Object is not a Reference."); + + Object *p_db = ObjectDB::get_instance(object.get_instance_id()); + CHECK_MESSAGE( + p_db == &object, + "The database pointer returned by the object id should reference same object."); +} + +TEST_CASE("[Object] Script instance property setter") { + Object object; + _MockScriptInstance *script_instance = memnew(_MockScriptInstance); + object.set_script_instance(script_instance); + + bool valid = false; + object.set("some_name", 100, &valid); + CHECK(valid); + Variant actual_value; + CHECK_MESSAGE( + script_instance->get("some_name", actual_value), + "The assigned script instance should successfully retrieve value by name."); + CHECK_MESSAGE( + actual_value == Variant(100), + "The returned value should equal the one which was set by the object."); +} + +TEST_CASE("[Object] Script instance property getter") { + Object object; + _MockScriptInstance *script_instance = memnew(_MockScriptInstance); + script_instance->set("some_name", 100); // Make sure script instance has the property + object.set_script_instance(script_instance); + + bool valid = false; + const Variant &actual_value = object.get("some_name", &valid); + CHECK(valid); + CHECK_MESSAGE( + actual_value == Variant(100), + "The returned value should equal the one which was set by the script instance."); +} + +TEST_CASE("[Object] Built-in property setter") { + ClassDB::register_class<_TestDerivedObject>(); + _TestDerivedObject derived_object; + + bool valid = false; + derived_object.set("property", 100, &valid); + CHECK(valid); + CHECK_MESSAGE( + derived_object.get_property() == 100, + "The property value should equal the one which was set with built-in setter."); +} + +TEST_CASE("[Object] Built-in property getter") { + ClassDB::register_class<_TestDerivedObject>(); + _TestDerivedObject derived_object; + derived_object.set_property(100); + + bool valid = false; + const Variant &actual_value = derived_object.get("property", &valid); + CHECK(valid); + CHECK_MESSAGE( + actual_value == Variant(100), + "The returned value should equal the one which was set with built-in setter."); +} + +TEST_CASE("[Object] Script property setter") { + Object object; + Variant script; + + bool valid = false; + object.set(CoreStringNames::get_singleton()->_script, script, &valid); + CHECK(valid); + CHECK_MESSAGE( + object.get_script() == script, + "The object script should be equal to the assigned one."); +} + +TEST_CASE("[Object] Script property getter") { + Object object; + Variant script; + object.set_script(script); + + bool valid = false; + const Variant &actual_value = object.get(CoreStringNames::get_singleton()->_script, &valid); + CHECK(valid); + CHECK_MESSAGE( + actual_value == script, + "The returned value should be equal to the assigned script."); +} + +TEST_CASE("[Object] Absent name setter") { + Object object; + + bool valid = true; + object.set("absent_name", 100, &valid); + CHECK(!valid); +} + +TEST_CASE("[Object] Absent name getter") { + Object object; + + bool valid = true; + const Variant &actual_value = object.get("absent_name", &valid); + CHECK(!valid); + CHECK_MESSAGE( + actual_value == Variant(), + "The returned value should equal nil variant."); +} } // namespace TestObject #endif // TEST_OBJECT_H diff --git a/tests/test_ordered_hash_map.h b/tests/test_ordered_hash_map.h index ef26d2531b..fbaaa224cf 100644 --- a/tests/test_ordered_hash_map.h +++ b/tests/test_ordered_hash_map.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_paged_array.h b/tests/test_paged_array.h index 6b61160229..7efd3799f3 100644 --- a/tests/test_paged_array.h +++ b/tests/test_paged_array.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_pck_packer.h b/tests/test_pck_packer.h index e086d65105..8e4721b821 100644 --- a/tests/test_pck_packer.h +++ b/tests/test_pck_packer.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_physics_2d.cpp b/tests/test_physics_2d.cpp index 47dce78e83..570e1897d6 100644 --- a/tests/test_physics_2d.cpp +++ b/tests/test_physics_2d.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_physics_2d.h b/tests/test_physics_2d.h index 517d324f3b..966d49200a 100644 --- a/tests/test_physics_2d.h +++ b/tests/test_physics_2d.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_physics_3d.cpp b/tests/test_physics_3d.cpp index 2a0c34320a..74afbad9d1 100644 --- a/tests/test_physics_3d.cpp +++ b/tests/test_physics_3d.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -59,7 +59,7 @@ class TestPhysics3DMainLoop : public MainLoop { RID character; - float ofs_x, ofs_y; + real_t ofs_x, ofs_y; Point2 joy_direction; @@ -86,7 +86,9 @@ protected: PhysicsServer3D *ps = PhysicsServer3D::get_singleton(); RID mesh_instance = vs->instance_create2(type_mesh_map[p_shape], scenario); - RID body = ps->body_create(p_body, !p_active_default); + RID body = ps->body_create(); + ps->body_set_mode(body, p_body); + ps->body_set_state(body, PhysicsServer3D::BODY_STATE_SLEEPING, !p_active_default); ps->body_set_space(body, space); ps->body_set_param(body, PhysicsServer3D::BODY_PARAM_BOUNCE, 0.0); //todo set space @@ -108,14 +110,16 @@ protected: RID world_margin_shape = ps->shape_create(PhysicsServer3D::SHAPE_PLANE); ps->shape_set_data(world_margin_shape, p_plane); - RID b = ps->body_create(PhysicsServer3D::BODY_MODE_STATIC); + RID b = ps->body_create(); + ps->body_set_mode(b, PhysicsServer3D::BODY_MODE_STATIC); + ps->body_set_space(b, space); //todo set space ps->body_add_shape(b, world_margin_shape); return b; } - void configure_body(RID p_body, float p_mass, float p_friction, float p_bounce) { + void configure_body(RID p_body, real_t p_mass, real_t p_friction, real_t p_bounce) { PhysicsServer3D *ps = PhysicsServer3D::get_singleton(); ps->body_set_param(p_body, PhysicsServer3D::BODY_PARAM_MASS, p_mass); ps->body_set_param(p_body, PhysicsServer3D::BODY_PARAM_FRICTION, p_friction); @@ -202,7 +206,8 @@ protected: RID triins = vs->instance_create2(trimesh_mesh, scenario); - RID tribody = ps->body_create(PhysicsServer3D::BODY_MODE_STATIC); + RID tribody = ps->body_create(); + ps->body_set_mode(tribody, PhysicsServer3D::BODY_MODE_STATIC); ps->body_set_space(tribody, space); //todo set space ps->body_add_shape(tribody, trimesh_shape); @@ -211,8 +216,8 @@ protected: vs->instance_set_transform(triins, tritrans); } - void make_grid(int p_width, int p_height, float p_cellsize, float p_cellheight, const Transform &p_xform = Transform()) { - Vector<Vector<float>> grid; + void make_grid(int p_width, int p_height, real_t p_cellsize, real_t p_cellheight, const Transform &p_xform = Transform()) { + Vector<Vector<real_t>> grid; grid.resize(p_width); @@ -253,8 +258,8 @@ public: } if (mm.is_valid() && mm->get_button_mask() & 1) { - float y = -mm->get_relative().y / 20.0; - float x = mm->get_relative().x / 20.0; + real_t y = -mm->get_relative().y / 20.0; + real_t x = mm->get_relative().x / 20.0; if (mover.is_valid()) { PhysicsServer3D *ps = PhysicsServer3D::get_singleton(); @@ -312,7 +317,7 @@ public: } virtual bool physics_process(float p_time) override { if (mover.is_valid()) { - static float joy_speed = 10; + static real_t joy_speed = 10; PhysicsServer3D *ps = PhysicsServer3D::get_singleton(); Transform t = ps->body_get_state(mover, PhysicsServer3D::BODY_STATE_TRANSFORM); t.origin += Vector3(joy_speed * joy_direction.x * p_time, -joy_speed * joy_direction.y * p_time, 0); @@ -358,7 +363,8 @@ public: ps->shape_set_data(capsule_shape, capsule_params); RID mesh_instance = vs->instance_create2(capsule_mesh, scenario); - character = ps->body_create(PhysicsServer3D::BODY_MODE_CHARACTER); + character = ps->body_create(); + ps->body_set_mode(character, PhysicsServer3D::BODY_MODE_CHARACTER); ps->body_set_space(character, space); //todo add space ps->body_add_shape(character, capsule_shape); diff --git a/tests/test_physics_3d.h b/tests/test_physics_3d.h index d03f2c6573..b6b66f350e 100644 --- a/tests/test_physics_3d.h +++ b/tests/test_physics_3d.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_random_number_generator.h b/tests/test_random_number_generator.h index 999e6d4862..39c4771c19 100644 --- a/tests/test_random_number_generator.h +++ b/tests/test_random_number_generator.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -73,8 +73,8 @@ TEST_CASE_MAY_FAIL("[RandomNumberGenerator] Integer 32 bit") { break; } } - INFO("Current seed: " << rng->get_seed()); - INFO("Current iteration: " << i); + INFO("Current seed: ", rng->get_seed()); + INFO("Current iteration: ", i); CHECK_MESSAGE(higher, "Given current seed, this should give an integer higher than 0x0fff'ffff at least once."); } @@ -185,13 +185,13 @@ TEST_CASE("[RandomNumberGenerator] Zero for first number immediately after seedi rng->set_seed(0); uint32_t n1 = rng->randi(); uint32_t n2 = rng->randi(); - INFO("Initial random values: " << n1 << " " << n2); + INFO("Initial random values: ", n1, " ", n2); CHECK(n1 != 0); rng->set_seed(1); uint32_t n3 = rng->randi(); uint32_t n4 = rng->randi(); - INFO("Values after changing the seed: " << n3 << " " << n4); + INFO("Values after changing the seed: ", n3, " ", n4); CHECK(n3 != 0); } @@ -199,7 +199,7 @@ TEST_CASE("[RandomNumberGenerator] Restore state") { Ref<RandomNumberGenerator> rng = memnew(RandomNumberGenerator); rng->randomize(); uint64_t last_seed = rng->get_seed(); - INFO("Current seed: " << last_seed); + INFO("Current seed: ", last_seed); rng->randi(); rng->randi(); @@ -208,18 +208,18 @@ TEST_CASE("[RandomNumberGenerator] Restore state") { "The seed should remain the same after generating some numbers"); uint64_t saved_state = rng->get_state(); - INFO("Current state: " << saved_state); + INFO("Current state: ", saved_state); real_t f1_before = rng->randf(); real_t f2_before = rng->randf(); - INFO("This seed produces: " << f1_before << " " << f2_before); + INFO("This seed produces: ", f1_before, " ", f2_before); // Restore now. rng->set_state(saved_state); real_t f1_after = rng->randf(); real_t f2_after = rng->randf(); - INFO("Resetting the state produces: " << f1_after << " " << f2_after); + INFO("Resetting the state produces: ", f1_after, " ", f2_after); String msg = "Should restore the sequence of numbers after resetting the state"; CHECK_MESSAGE(f1_before == f1_after, msg); @@ -229,22 +229,22 @@ TEST_CASE("[RandomNumberGenerator] Restore state") { TEST_CASE("[RandomNumberGenerator] Restore from seed") { Ref<RandomNumberGenerator> rng = memnew(RandomNumberGenerator); rng->set_seed(0); - INFO("Current seed: " << rng->get_seed()); + INFO("Current seed: ", rng->get_seed()); uint32_t s0_1_before = rng->randi(); uint32_t s0_2_before = rng->randi(); - INFO("This seed produces: " << s0_1_before << " " << s0_2_before); + INFO("This seed produces: ", s0_1_before, " ", s0_2_before); rng->set_seed(9000); - INFO("Current seed: " << rng->get_seed()); + INFO("Current seed: ", rng->get_seed()); uint32_t s9000_1 = rng->randi(); uint32_t s9000_2 = rng->randi(); - INFO("This seed produces: " << s9000_1 << " " << s9000_2); + INFO("This seed produces: ", s9000_1, " ", s9000_2); rng->set_seed(0); - INFO("Current seed: " << rng->get_seed()); + INFO("Current seed: ", rng->get_seed()); uint32_t s0_1_after = rng->randi(); uint32_t s0_2_after = rng->randi(); - INFO("This seed produces: " << s0_1_after << " " << s0_2_after); + INFO("This seed produces: ", s0_1_after, " ", s0_2_after); String msg = "Should restore the sequence of numbers after resetting the seed"; CHECK_MESSAGE(s0_1_before == s0_1_after, msg); diff --git a/tests/test_rect2.h b/tests/test_rect2.h index b5b6fa255f..b94a8b7d05 100644 --- a/tests/test_rect2.h +++ b/tests/test_rect2.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_render.cpp b/tests/test_render.cpp index d14251bc6a..72b2840098 100644 --- a/tests/test_render.cpp +++ b/tests/test_render.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -183,8 +183,8 @@ public: //vs->light_set_shadow( lightaux, true ); light = vs->instance_create2(lightaux, scenario); Transform lla; - //lla.set_look_at(Vector3(),Vector3(1,-1,1),Vector3(0,1,0)); - lla.set_look_at(Vector3(), Vector3(-0.000000, -0.836026, -0.548690), Vector3(0, 1, 0)); + //lla.set_look_at(Vector3(),Vector3(1, -1, 1)); + lla.set_look_at(Vector3(), Vector3(0.0, -0.836026, -0.548690)); vs->instance_set_transform(light, lla); diff --git a/tests/test_render.h b/tests/test_render.h index 4a6340c443..35bb383773 100644 --- a/tests/test_render.h +++ b/tests/test_render.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_shader_lang.cpp b/tests/test_shader_lang.cpp index 2233b4464e..a023f35506 100644 --- a/tests/test_shader_lang.cpp +++ b/tests/test_shader_lang.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_shader_lang.h b/tests/test_shader_lang.h index 2811c5f46e..46a2e6af35 100644 --- a/tests/test_shader_lang.h +++ b/tests/test_shader_lang.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_string.h b/tests/test_string.h index 910ff6361e..cc3152203e 100644 --- a/tests/test_string.h +++ b/tests/test_string.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -266,7 +266,7 @@ TEST_CASE("[String] Operator []") { a[6] = 'C'; CHECK(a == "Sugar Cane"); CHECK(a[1] == 'u'); - CHECK(a.ord_at(1) == 'u'); + CHECK(a.unicode_at(1) == 'u'); } TEST_CASE("[String] Case function test") { @@ -370,12 +370,9 @@ TEST_CASE("[String] String to integer") { TEST_CASE("[String] Hex to integer") { static const char *nums[4] = { "0xFFAE", "22", "0", "AADDAD" }; static const int64_t num[4] = { 0xFFAE, 0x22, 0, 0xAADDAD }; - static const bool wo_prefix[4] = { false, true, true, true }; - static const bool w_prefix[4] = { true, false, true, false }; for (int i = 0; i < 4; i++) { - CHECK((String(nums[i]).hex_to_int(true) == num[i]) == w_prefix[i]); - CHECK((String(nums[i]).hex_to_int(false) == num[i]) == wo_prefix[i]); + CHECK(String(nums[i]).hex_to_int() == num[i]); } } @@ -1155,20 +1152,12 @@ TEST_CASE("[String] hash") { CHECK(a.hash64() != c.hash64()); } -TEST_CASE("[String] http_escape/unescape") { +TEST_CASE("[String] uri_encode/unescape") { String s = "Godot Engine:'docs'"; String t = "Godot%20Engine%3A%27docs%27"; - CHECK(s.http_escape() == t); - CHECK(t.http_unescape() == s); -} - -TEST_CASE("[String] percent_encode/decode") { // Note: is it redundant? Seems to be same as http_escape/unescape but in lower case. - String s = "Godot Engine:'docs'"; - String t = "Godot%20Engine%3a%27docs%27"; - - CHECK(s.percent_encode() == t); - CHECK(t.percent_decode() == s); + CHECK(s.uri_encode() == t); + CHECK(t.uri_decode() == s); } TEST_CASE("[String] xml_escape/unescape") { diff --git a/tests/test_text_server.h b/tests/test_text_server.h index a1a97f3211..b0b40447fe 100644 --- a/tests/test_text_server.h +++ b/tests/test_text_server.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -45,7 +45,7 @@ TEST_SUITE("[[TextServer]") { SUBCASE("[TextServer] Init") { for (int i = 0; i < TextServerManager::get_interface_count(); i++) { TextServer *ts = TextServerManager::initialize(i, err); - TEST_FAIL_COND((err != OK || ts == nullptr), "Text server " + TextServerManager::get_interface_name(i) + " init failed."); + TEST_FAIL_COND((err != OK || ts == nullptr), "Text server ", TextServerManager::get_interface_name(i), " init failed."); } } diff --git a/tests/test_utils.cpp b/tests/test_utils.cpp index ad5ba94aea..1666a257a9 100644 --- a/tests/test_utils.cpp +++ b/tests/test_utils.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_utils.h b/tests/test_utils.h index 1f93860b7f..f05ab0bdb1 100644 --- a/tests/test_utils.h +++ b/tests/test_utils.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ diff --git a/tests/test_validate_testing.h b/tests/test_validate_testing.h index b4ea6eb576..6d3eea724c 100644 --- a/tests/test_validate_testing.h +++ b/tests/test_validate_testing.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -179,10 +179,8 @@ TEST_SUITE("Validate tests") { color_arr.push_back(Color(2, 2, 2)); INFO(color_arr); - INFO("doctest insertion operator << " - << var << " " << vec2 << " " << rect2 << " " << color); - - CHECK(true); // So all above prints. + // doctest string concatenation. + CHECK_MESSAGE(true, var, " ", vec2, " ", rect2, " ", color); } } diff --git a/tests/test_variant.h b/tests/test_variant.h index b575f6744d..dfc72b512c 100644 --- a/tests/test_variant.h +++ b/tests/test_variant.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* 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 */ @@ -105,6 +105,600 @@ TEST_CASE("[Variant] Writer and parser float") { CHECK_MESSAGE(b64_float_parsed == 340282001837565597733306976381245063168.0, "Should not overflow."); } + +TEST_CASE("[Variant] Assignment To Bool from Int,Float,String,Vec2,Vec2i,Vec3,Vec3i and Color") { + Variant int_v = 0; + Variant bool_v = true; + int_v = bool_v; // int_v is now a bool + CHECK(int_v == Variant(true)); + bool_v = false; + int_v = bool_v; + CHECK(int_v.get_type() == Variant::BOOL); + + Variant float_v = 0.0f; + bool_v = true; + float_v = bool_v; + CHECK(float_v == Variant(true)); + bool_v = false; + float_v = bool_v; + CHECK(float_v.get_type() == Variant::BOOL); + + Variant string_v = ""; + bool_v = true; + string_v = bool_v; + CHECK(string_v == Variant(true)); + bool_v = false; + string_v = bool_v; + CHECK(string_v.get_type() == Variant::BOOL); + + Variant vec2_v = Vector2(0, 0); + bool_v = true; + vec2_v = bool_v; + CHECK(vec2_v == Variant(true)); + bool_v = false; + vec2_v = bool_v; + CHECK(vec2_v.get_type() == Variant::BOOL); + + Variant vec2i_v = Vector2i(0, 0); + bool_v = true; + vec2i_v = bool_v; + CHECK(vec2i_v == Variant(true)); + bool_v = false; + vec2i_v = bool_v; + CHECK(vec2i_v.get_type() == Variant::BOOL); + + Variant vec3_v = Vector3(0, 0, 0); + bool_v = true; + vec3_v = bool_v; + CHECK(vec3_v == Variant(true)); + bool_v = false; + vec3_v = bool_v; + CHECK(vec3_v.get_type() == Variant::BOOL); + + Variant vec3i_v = Vector3i(0, 0, 0); + bool_v = true; + vec3i_v = bool_v; + CHECK(vec3i_v == Variant(true)); + bool_v = false; + vec3i_v = bool_v; + CHECK(vec3i_v.get_type() == Variant::BOOL); + + Variant col_v = Color(0.5f, 0.2f, 0.75f); + bool_v = true; + col_v = bool_v; + CHECK(col_v == Variant(true)); + bool_v = false; + col_v = bool_v; + CHECK(col_v.get_type() == Variant::BOOL); +} + +TEST_CASE("[Variant] Assignment To Int from Bool,Float,String,Vec2,Vec2i,Vec3,Vec3i and Color") { + Variant bool_v = false; + Variant int_v = 2; + bool_v = int_v; // Now bool_v is int + CHECK(bool_v == Variant(2)); + int_v = -3; + bool_v = int_v; + CHECK(bool_v.get_type() == Variant::INT); + + Variant float_v = 0.0f; + int_v = 2; + float_v = int_v; + CHECK(float_v == Variant(2)); + int_v = -3; + float_v = int_v; + CHECK(float_v.get_type() == Variant::INT); + + Variant string_v = ""; + int_v = 2; + string_v = int_v; + CHECK(string_v == Variant(2)); + int_v = -3; + string_v = int_v; + CHECK(string_v.get_type() == Variant::INT); + + Variant vec2_v = Vector2(0, 0); + int_v = 2; + vec2_v = int_v; + CHECK(vec2_v == Variant(2)); + int_v = -3; + vec2_v = int_v; + CHECK(vec2_v.get_type() == Variant::INT); + + Variant vec2i_v = Vector2i(0, 0); + int_v = 2; + vec2i_v = int_v; + CHECK(vec2i_v == Variant(2)); + int_v = -3; + vec2i_v = int_v; + CHECK(vec2i_v.get_type() == Variant::INT); + + Variant vec3_v = Vector3(0, 0, 0); + int_v = 2; + vec3_v = int_v; + CHECK(vec3_v == Variant(2)); + int_v = -3; + vec3_v = int_v; + CHECK(vec3_v.get_type() == Variant::INT); + + Variant vec3i_v = Vector3i(0, 0, 0); + int_v = 2; + vec3i_v = int_v; + CHECK(vec3i_v == Variant(2)); + int_v = -3; + vec3i_v = int_v; + CHECK(vec3i_v.get_type() == Variant::INT); + + Variant col_v = Color(0.5f, 0.2f, 0.75f); + int_v = 2; + col_v = int_v; + CHECK(col_v == Variant(2)); + int_v = -3; + col_v = int_v; + CHECK(col_v.get_type() == Variant::INT); +} + +TEST_CASE("[Variant] Assignment To Float from Bool,Int,String,Vec2,Vec2i,Vec3,Vec3i and Color") { + Variant bool_v = false; + Variant float_v = 1.5f; + bool_v = float_v; // Now bool_v is float + CHECK(bool_v == Variant(1.5f)); + float_v = -4.6f; + bool_v = float_v; + CHECK(bool_v.get_type() == Variant::FLOAT); + + Variant int_v = 1; + float_v = 1.5f; + int_v = float_v; + CHECK(int_v == Variant(1.5f)); + float_v = -4.6f; + int_v = float_v; + CHECK(int_v.get_type() == Variant::FLOAT); + + Variant string_v = ""; + float_v = 1.5f; + string_v = float_v; + CHECK(string_v == Variant(1.5f)); + float_v = -4.6f; + string_v = float_v; + CHECK(string_v.get_type() == Variant::FLOAT); + + Variant vec2_v = Vector2(0, 0); + float_v = 1.5f; + vec2_v = float_v; + CHECK(vec2_v == Variant(1.5f)); + float_v = -4.6f; + vec2_v = float_v; + CHECK(vec2_v.get_type() == Variant::FLOAT); + + Variant vec2i_v = Vector2i(0, 0); + float_v = 1.5f; + vec2i_v = float_v; + CHECK(vec2i_v == Variant(1.5f)); + float_v = -4.6f; + vec2i_v = float_v; + CHECK(vec2i_v.get_type() == Variant::FLOAT); + + Variant vec3_v = Vector3(0, 0, 0); + float_v = 1.5f; + vec3_v = float_v; + CHECK(vec3_v == Variant(1.5f)); + float_v = -4.6f; + vec3_v = float_v; + CHECK(vec3_v.get_type() == Variant::FLOAT); + + Variant vec3i_v = Vector3i(0, 0, 0); + float_v = 1.5f; + vec3i_v = float_v; + CHECK(vec3i_v == Variant(1.5f)); + float_v = -4.6f; + vec3i_v = float_v; + CHECK(vec3i_v.get_type() == Variant::FLOAT); + + Variant col_v = Color(0.5f, 0.2f, 0.75f); + float_v = 1.5f; + col_v = float_v; + CHECK(col_v == Variant(1.5f)); + float_v = -4.6f; + col_v = float_v; + CHECK(col_v.get_type() == Variant::FLOAT); +} + +TEST_CASE("[Variant] Assignment To String from Bool,Int,Float,Vec2,Vec2i,Vec3,Vec3i and Color") { + Variant bool_v = false; + Variant string_v = "Hello"; + bool_v = string_v; // Now bool_v is string + CHECK(bool_v == Variant("Hello")); + string_v = "Hello there"; + bool_v = string_v; + CHECK(bool_v.get_type() == Variant::STRING); + + Variant int_v = 0; + string_v = "Hello"; + int_v = string_v; + CHECK(int_v == Variant("Hello")); + string_v = "Hello there"; + int_v = string_v; + CHECK(int_v.get_type() == Variant::STRING); + + Variant float_v = 0.0f; + string_v = "Hello"; + float_v = string_v; + CHECK(float_v == Variant("Hello")); + string_v = "Hello there"; + float_v = string_v; + CHECK(float_v.get_type() == Variant::STRING); + + Variant vec2_v = Vector2(0, 0); + string_v = "Hello"; + vec2_v = string_v; + CHECK(vec2_v == Variant("Hello")); + string_v = "Hello there"; + vec2_v = string_v; + CHECK(vec2_v.get_type() == Variant::STRING); + + Variant vec2i_v = Vector2i(0, 0); + string_v = "Hello"; + vec2i_v = string_v; + CHECK(vec2i_v == Variant("Hello")); + string_v = "Hello there"; + vec2i_v = string_v; + CHECK(vec2i_v.get_type() == Variant::STRING); + + Variant vec3_v = Vector3(0, 0, 0); + string_v = "Hello"; + vec3_v = string_v; + CHECK(vec3_v == Variant("Hello")); + string_v = "Hello there"; + vec3_v = string_v; + CHECK(vec3_v.get_type() == Variant::STRING); + + Variant vec3i_v = Vector3i(0, 0, 0); + string_v = "Hello"; + vec3i_v = string_v; + CHECK(vec3i_v == Variant("Hello")); + string_v = "Hello there"; + vec3i_v = string_v; + CHECK(vec3i_v.get_type() == Variant::STRING); + + Variant col_v = Color(0.5f, 0.2f, 0.75f); + string_v = "Hello"; + col_v = string_v; + CHECK(col_v == Variant("Hello")); + string_v = "Hello there"; + col_v = string_v; + CHECK(col_v.get_type() == Variant::STRING); +} + +TEST_CASE("[Variant] Assignment To Vec2 from Bool,Int,Float,String,Vec2i,Vec3,Vec3i and Color") { + Variant bool_v = false; + Variant vec2_v = Vector2(2.2f, 3.5f); + bool_v = vec2_v; // Now bool_v is Vector2 + CHECK(bool_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + bool_v = vec2_v; + CHECK(bool_v.get_type() == Variant::VECTOR2); + + Variant int_v = 0; + vec2_v = Vector2(2.2f, 3.5f); + int_v = vec2_v; + CHECK(int_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + int_v = vec2_v; + CHECK(int_v.get_type() == Variant::VECTOR2); + + Variant float_v = 0.0f; + vec2_v = Vector2(2.2f, 3.5f); + float_v = vec2_v; + CHECK(float_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + float_v = vec2_v; + CHECK(float_v.get_type() == Variant::VECTOR2); + + Variant string_v = ""; + vec2_v = Vector2(2.2f, 3.5f); + string_v = vec2_v; + CHECK(string_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + string_v = vec2_v; + CHECK(string_v.get_type() == Variant::VECTOR2); + + Variant vec2i_v = Vector2i(0, 0); + vec2_v = Vector2(2.2f, 3.5f); + vec2i_v = vec2_v; + CHECK(vec2i_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + vec2i_v = vec2_v; + CHECK(vec2i_v.get_type() == Variant::VECTOR2); + + Variant vec3_v = Vector3(0, 0, 0); + vec2_v = Vector2(2.2f, 3.5f); + vec3_v = vec2_v; + CHECK(vec3_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + vec3_v = vec2_v; + CHECK(vec3_v.get_type() == Variant::VECTOR2); + + Variant vec3i_v = Vector3i(0, 0, 0); + vec2_v = Vector2(2.2f, 3.5f); + vec3i_v = vec2_v; + CHECK(vec3i_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + vec3i_v = vec2_v; + CHECK(vec3i_v.get_type() == Variant::VECTOR2); + + Variant col_v = Color(0.5f, 0.2f, 0.75f); + vec2_v = Vector2(2.2f, 3.5f); + col_v = vec2_v; + CHECK(col_v == Variant(Vector2(2.2f, 3.5f))); + vec2_v = Vector2(-5.4f, -7.9f); + col_v = vec2_v; + CHECK(col_v.get_type() == Variant::VECTOR2); +} + +TEST_CASE("[Variant] Assignment To Vec2i from Bool,Int,Float,String,Vec2,Vec3,Vec3i and Color") { + Variant bool_v = false; + Variant vec2i_v = Vector2i(2, 3); + bool_v = vec2i_v; // Now bool_v is Vector2i + CHECK(bool_v == Variant(Vector2i(2, 3))); + vec2i_v = Vector2i(-5, -7); + bool_v = vec2i_v; + CHECK(bool_v.get_type() == Variant::VECTOR2I); + + Variant int_v = 0; + vec2i_v = Vector2i(2, 3); + int_v = vec2i_v; + CHECK(int_v == Variant(Vector2i(2, 3))); + vec2i_v = Vector2i(-5, -7); + int_v = vec2i_v; + CHECK(int_v.get_type() == Variant::VECTOR2I); + + Variant float_v = 0.0f; + vec2i_v = Vector2i(2, 3); + float_v = vec2i_v; + CHECK(float_v == Variant(Vector2i(2, 3))); + vec2i_v = Vector2i(-5, -7); + float_v = vec2i_v; + CHECK(float_v.get_type() == Variant::VECTOR2I); + + Variant string_v = ""; + vec2i_v = Vector2i(2, 3); + string_v = vec2i_v; + CHECK(string_v == Variant(Vector2i(2, 3))); + vec2i_v = Vector2i(-5, -7); + string_v = vec2i_v; + CHECK(string_v.get_type() == Variant::VECTOR2I); + + Variant vec2_v = Vector2(0, 0); + vec2i_v = Vector2i(2, 3); + vec2_v = vec2i_v; + CHECK(vec2_v == Variant(Vector2i(2, 3))); + vec2i_v = Vector2i(-5, -7); + vec2_v = vec2i_v; + CHECK(vec2i_v.get_type() == Variant::VECTOR2I); + + Variant vec3_v = Vector3(0, 0, 0); + vec2i_v = Vector2i(2, 3); + vec3_v = vec2i_v; + CHECK(vec3_v == Variant(Vector2i(2, 3))); + vec2i_v = Vector2i(-5, -7); + vec3_v = vec2i_v; + CHECK(vec3_v.get_type() == Variant::VECTOR2I); + + Variant vec3i_v = Vector3i(0, 0, 0); + vec2i_v = Vector2i(2, 3); + vec3i_v = vec2i_v; + CHECK(vec3i_v == Variant(Vector2i(2, 3))); + vec2i_v = Vector2i(-5, -7); + vec3i_v = vec2i_v; + CHECK(vec3i_v.get_type() == Variant::VECTOR2I); + + Variant col_v = Color(0.5f, 0.2f, 0.75f); + vec2i_v = Vector2i(2, 3); + col_v = vec2i_v; + CHECK(col_v == Variant(Vector2i(2, 3))); + vec2i_v = Vector2i(-5, -7); + col_v = vec2i_v; + CHECK(col_v.get_type() == Variant::VECTOR2I); +} + +TEST_CASE("[Variant] Assignment To Vec3 from Bool,Int,Float,String,Vec2,Vec2i,Vec3i and Color") { + Variant bool_v = false; + Variant vec3_v = Vector3(2.2f, 3.5f, 5.3f); + bool_v = vec3_v; // Now bool_v is Vector3 + CHECK(bool_v == Variant(Vector3(2.2f, 3.5f, 5.3f))); + vec3_v = Vector3(-5.4f, -7.9f, -2.1f); + bool_v = vec3_v; + CHECK(bool_v.get_type() == Variant::VECTOR3); + + Variant int_v = 0; + vec3_v = Vector3(2.2f, 3.5f, 5.3f); + int_v = vec3_v; + CHECK(int_v == Variant(Vector3(2.2f, 3.5f, 5.3f))); + vec3_v = Vector3(-5.4f, -7.9f, -2.1f); + int_v = vec3_v; + CHECK(int_v.get_type() == Variant::VECTOR3); + + Variant float_v = 0.0f; + vec3_v = Vector3(2.2f, 3.5f, 5.3f); + float_v = vec3_v; + CHECK(float_v == Variant(Vector3(2.2f, 3.5f, 5.3f))); + vec3_v = Vector3(-5.4f, -7.9f, -2.1f); + float_v = vec3_v; + CHECK(float_v.get_type() == Variant::VECTOR3); + + Variant string_v = ""; + vec3_v = Vector3(2.2f, 3.5f, 5.3f); + string_v = vec3_v; + CHECK(string_v == Variant(Vector3(2.2f, 3.5f, 5.3f))); + vec3_v = Vector3(-5.4f, -7.9f, -2.1f); + string_v = vec3_v; + CHECK(string_v.get_type() == Variant::VECTOR3); + + Variant vec2_v = Vector2(0, 0); + vec3_v = Vector3(2.2f, 3.5f, 5.3f); + vec2_v = vec3_v; + CHECK(vec2_v == Variant(Vector3(2.2f, 3.5f, 5.3f))); + vec3_v = Vector3(-5.4f, -7.9f, -2.1f); + vec2_v = vec3_v; + CHECK(vec2_v.get_type() == Variant::VECTOR3); + + Variant vec2i_v = Vector2i(0, 0); + vec3_v = Vector3(2.2f, 3.5f, 5.3f); + vec2i_v = vec3_v; + CHECK(vec2i_v == Variant(Vector3(2.2f, 3.5f, 5.3f))); + vec3_v = Vector3(-5.4f, -7.9f, -2.1f); + vec2i_v = vec3_v; + CHECK(vec2i_v.get_type() == Variant::VECTOR3); + + Variant vec3i_v = Vector3i(0, 0, 0); + vec3_v = Vector3(2.2f, 3.5f, 5.3f); + vec3i_v = vec3_v; + CHECK(vec3i_v == Variant(Vector3(2.2f, 3.5f, 5.3f))); + vec3_v = Vector3(-5.4f, -7.9f, -2.1f); + vec3i_v = vec3_v; + CHECK(vec3i_v.get_type() == Variant::VECTOR3); + + Variant col_v = Color(0.5f, 0.2f, 0.75f); + vec3_v = Vector3(2.2f, 3.5f, 5.3f); + col_v = vec3_v; + CHECK(col_v == Variant(Vector3(2.2f, 3.5f, 5.3f))); + vec3_v = Vector3(-5.4f, -7.9f, -2.1f); + col_v = vec3_v; + CHECK(col_v.get_type() == Variant::VECTOR3); +} + +TEST_CASE("[Variant] Assignment To Vec3i from Bool,Int,Float,String,Vec2,Vec2i,Vec3 and Color") { + Variant bool_v = false; + Variant vec3i_v = Vector3i(2, 3, 5); + bool_v = vec3i_v; // Now bool_v is Vector3i + CHECK(bool_v == Variant(Vector3i(2, 3, 5))); + vec3i_v = Vector3i(-5, -7, -2); + bool_v = vec3i_v; + CHECK(bool_v.get_type() == Variant::VECTOR3I); + + Variant int_v = 0; + vec3i_v = Vector3i(2, 3, 5); + int_v = vec3i_v; + CHECK(int_v == Variant(Vector3i(2, 3, 5))); + vec3i_v = Vector3i(-5, -7, -2); + int_v = vec3i_v; + CHECK(int_v.get_type() == Variant::VECTOR3I); + + Variant float_v = 0.0f; + vec3i_v = Vector3i(2, 3, 5); + float_v = vec3i_v; + CHECK(float_v == Variant(Vector3i(2, 3, 5))); + vec3i_v = Vector3i(-5, -7, -2); + float_v = vec3i_v; + CHECK(float_v.get_type() == Variant::VECTOR3I); + + Variant string_v = ""; + vec3i_v = Vector3i(2, 3, 5); + string_v = vec3i_v; + CHECK(string_v == Variant(Vector3i(2, 3, 5))); + vec3i_v = Vector3i(-5, -7, -2); + string_v = vec3i_v; + CHECK(string_v.get_type() == Variant::VECTOR3I); + + Variant vec2_v = Vector2(0, 0); + vec3i_v = Vector3i(2, 3, 5); + vec2_v = vec3i_v; + CHECK(vec2_v == Variant(Vector3i(2, 3, 5))); + vec3i_v = Vector3i(-5, -7, -2); + vec2_v = vec3i_v; + CHECK(vec2_v.get_type() == Variant::VECTOR3I); + + Variant vec2i_v = Vector2i(0, 0); + vec3i_v = Vector3i(2, 3, 5); + vec2i_v = vec3i_v; + CHECK(vec2i_v == Variant(Vector3i(2, 3, 5))); + vec3i_v = Vector3i(-5, -7, -2); + vec2i_v = vec3i_v; + CHECK(vec2i_v.get_type() == Variant::VECTOR3I); + + Variant vec3_v = Vector3(0, 0, 0); + vec3i_v = Vector3i(2, 3, 5); + vec3_v = vec3i_v; + CHECK(vec3_v == Variant(Vector3i(2, 3, 5))); + vec3i_v = Vector3i(-5, -7, -2); + vec3_v = vec3i_v; + CHECK(vec3_v.get_type() == Variant::VECTOR3I); + + Variant col_v = Color(0.5f, 0.2f, 0.75f); + vec3i_v = Vector3i(2, 3, 5); + col_v = vec3i_v; + CHECK(col_v == Variant(Vector3i(2, 3, 5))); + vec3i_v = Vector3i(-5, -7, -2); + col_v = vec3i_v; + CHECK(col_v.get_type() == Variant::VECTOR3I); +} + +TEST_CASE("[Variant] Assignment To Color from Bool,Int,Float,String,Vec2,Vec2i,Vec3 and Vec3i") { + Variant bool_v = false; + Variant col_v = Color(0.25f, 0.4f, 0.78f); + bool_v = col_v; // Now bool_v is Color + CHECK(bool_v == Variant(Color(0.25f, 0.4f, 0.78f))); + col_v = Color(0.33f, 0.75f, 0.21f); + bool_v = col_v; + CHECK(bool_v.get_type() == Variant::COLOR); + + Variant int_v = 0; + col_v = Color(0.25f, 0.4f, 0.78f); + int_v = col_v; + CHECK(int_v == Variant(Color(0.25f, 0.4f, 0.78f))); + col_v = Color(0.33f, 0.75f, 0.21f); + int_v = col_v; + CHECK(int_v.get_type() == Variant::COLOR); + + Variant float_v = 0.0f; + col_v = Color(0.25f, 0.4f, 0.78f); + float_v = col_v; + CHECK(float_v == Variant(Color(0.25f, 0.4f, 0.78f))); + col_v = Color(0.33f, 0.75f, 0.21f); + float_v = col_v; + CHECK(float_v.get_type() == Variant::COLOR); + + Variant string_v = ""; + col_v = Color(0.25f, 0.4f, 0.78f); + string_v = col_v; + CHECK(string_v == Variant(Color(0.25f, 0.4f, 0.78f))); + col_v = Color(0.33f, 0.75f, 0.21f); + string_v = col_v; + CHECK(string_v.get_type() == Variant::COLOR); + + Variant vec2_v = Vector2(0, 0); + col_v = Color(0.25f, 0.4f, 0.78f); + vec2_v = col_v; + CHECK(vec2_v == Variant(Color(0.25f, 0.4f, 0.78f))); + col_v = Color(0.33f, 0.75f, 0.21f); + vec2_v = col_v; + CHECK(vec2_v.get_type() == Variant::COLOR); + + Variant vec2i_v = Vector2i(0, 0); + col_v = Color(0.25f, 0.4f, 0.78f); + vec2i_v = col_v; + CHECK(vec2i_v == Variant(Color(0.25f, 0.4f, 0.78f))); + col_v = Color(0.33f, 0.75f, 0.21f); + vec2i_v = col_v; + CHECK(vec2i_v.get_type() == Variant::COLOR); + + Variant vec3_v = Vector3(0, 0, 0); + col_v = Color(0.25f, 0.4f, 0.78f); + vec3_v = col_v; + CHECK(vec3_v == Variant(Color(0.25f, 0.4f, 0.78f))); + col_v = Color(0.33f, 0.75f, 0.21f); + vec3_v = col_v; + CHECK(vec3_v.get_type() == Variant::COLOR); + + Variant vec3i_v = Vector3i(0, 0, 0); + col_v = Color(0.25f, 0.4f, 0.78f); + vec3i_v = col_v; + CHECK(vec3i_v == Variant(Color(0.25f, 0.4f, 0.78f))); + col_v = Color(0.33f, 0.75f, 0.21f); + vec3i_v = col_v; + CHECK(vec3i_v.get_type() == Variant::COLOR); +} } // namespace TestVariant #endif // TEST_VARIANT_H |