diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-11-20 14:03:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-20 14:03:12 +0100 |
commit | 34895e7b28c61d181bf304bba4ac0b27f43444e8 (patch) | |
tree | 5504b800523901e3b7d26461d61e06ae5fb4a44f /tests | |
parent | 29f34782f0082ce0ea78e5fc61cc80bbbf23bd9b (diff) | |
parent | e924bf9dec63b1c2e1df067c372d82f20f3996bc (diff) |
Merge pull request #43583 from Calinou/test-add-object
Add a test suite for Object
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_main.cpp | 1 | ||||
-rw-r--r-- | tests/test_object.h | 92 |
2 files changed, 93 insertions, 0 deletions
diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 998b65190f..4388654d08 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -48,6 +48,7 @@ #include "test_method_bind.h" #include "test_node_path.h" #include "test_oa_hash_map.h" +#include "test_object.h" #include "test_ordered_hash_map.h" #include "test_pck_packer.h" #include "test_physics_2d.h" diff --git a/tests/test_object.h b/tests/test_object.h new file mode 100644 index 0000000000..6fef2576e7 --- /dev/null +++ b/tests/test_object.h @@ -0,0 +1,92 @@ +/*************************************************************************/ +/* test_object.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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_OBJECT_H +#define TEST_OBJECT_H + +#include "core/object/object.h" + +#include "thirdparty/doctest/doctest.h" + +namespace TestObject { + +TEST_CASE("[Object] Core getters") { + Object object; + + CHECK_MESSAGE( + object.is_class("Object"), + "is_class() should return the expected value."); + CHECK_MESSAGE( + object.get_class() == "Object", + "The returned class should match the expected value."); + CHECK_MESSAGE( + object.get_class_name() == "Object", + "The returned class name should match the expected value."); + CHECK_MESSAGE( + object.get_class_static() == "Object", + "The returned static class should match the expected value."); + CHECK_MESSAGE( + object.get_save_class() == "Object", + "The returned save class should match the expected value."); +} + +TEST_CASE("[Object] Metadata") { + const String meta_path = "hello/world complex métadata\n\n\t\tpath"; + Object object; + + object.set_meta(meta_path, Color(0, 1, 0)); + CHECK_MESSAGE( + Color(object.get_meta(meta_path)).is_equal_approx(Color(0, 1, 0)), + "The returned object metadata after setting should match the expected value."); + + List<String> meta_list; + object.get_meta_list(&meta_list); + CHECK_MESSAGE( + meta_list.size() == 1, + "The metadata list should only contain 1 item after adding one metadata item."); + + object.remove_meta(meta_path); + // Also try removing nonexistent metadata (it should do nothing, without printing an error message). + object.remove_meta("I don't exist"); + ERR_PRINT_OFF; + CHECK_MESSAGE( + object.get_meta(meta_path) == Variant(), + "The returned object metadata after removing should match the expected value."); + ERR_PRINT_ON; + + List<String> meta_list2; + object.get_meta_list(&meta_list2); + CHECK_MESSAGE( + meta_list2.size() == 0, + "The metadata list should contain 0 items after removing all metadata items."); +} +} // namespace TestObject + +#endif // TEST_OBJECT_H |