From fd6cd7c2a20a5425dd1a62f0f08be05304d3648e Mon Sep 17 00:00:00 2001 From: Rafael Fillipe Silva Date: Tue, 19 Dec 2023 23:32:33 -0300 Subject: [PATCH] add tests for super cycle detection on schema self validator Add test for the already existing validation where a tag shouldn't set itself as its own super. Add test for the new cycle detection when validating a schema. --- boost_test_schedule | 2 + projectfiles/CodeBlocks/tests.cbp | 1 + .../project.pbxproj | 12 ++++ source_lists/boost_unit_tests | 1 + .../wml/schema/test_schema_self_validator.cpp | 63 +++++++++++++++++++ .../test_schema_super_cycle.cfg | 23 +++++++ .../test_schema_super_self_reference.cfg | 9 +++ 7 files changed, 111 insertions(+) create mode 100644 src/tests/wml/schema/test_schema_self_validator.cpp create mode 100644 src/tests/wml/schema/test_schema_self_validator/test_schema_super_cycle.cfg create mode 100644 src/tests/wml/schema/test_schema_self_validator/test_schema_super_self_reference.cfg diff --git a/boost_test_schedule b/boost_test_schedule index adbe3d9e11c..589c809a2aa 100644 --- a/boost_test_schedule +++ b/boost_test_schedule @@ -261,3 +261,5 @@ whiteboard_side_actions_container/test_insertion whiteboard_side_actions_container/test_removal feature_test_WML_macro_define/macro_define_noArgument_ParseAsExpected feature_test_WML_macro_define/macro_define_1Argument_ParseAsExpected +test_schema_self_validator/test_schema_super_self_reference +test_schema_self_validator/test_schema_super_cycle diff --git a/projectfiles/CodeBlocks/tests.cbp b/projectfiles/CodeBlocks/tests.cbp index a65359a5624..314252a7410 100644 --- a/projectfiles/CodeBlocks/tests.cbp +++ b/projectfiles/CodeBlocks/tests.cbp @@ -1227,6 +1227,7 @@ + diff --git a/projectfiles/Xcode/The Battle for Wesnoth.xcodeproj/project.pbxproj b/projectfiles/Xcode/The Battle for Wesnoth.xcodeproj/project.pbxproj index a3fa58ee312..63ee6426566 100644 --- a/projectfiles/Xcode/The Battle for Wesnoth.xcodeproj/project.pbxproj +++ b/projectfiles/Xcode/The Battle for Wesnoth.xcodeproj/project.pbxproj @@ -619,6 +619,7 @@ 49478714172FF6F8002B7ABA /* tristate_button.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 49478712172FF6F8002B7ABA /* tristate_button.cpp */; }; 4E19429E82899A42A73BBE91 /* choose_addon.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 20E644DC98F26C756364EC2C /* choose_addon.cpp */; }; 508C40A885166B2E3F4245F4 /* general.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84234C54BB84519421FD4136 /* general.cpp */; }; + 529242A8856DE8D00988B9BD /* test_schema_self_validator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 26A04033A9545CFE8A226FBD /* test_schema_self_validator.cpp */; }; 620A386E15E9364E00A4F513 /* attack.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 620A386215E9364E00A4F513 /* attack.cpp */; }; 620A386F15E9364E00A4F513 /* create.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 620A386415E9364E00A4F513 /* create.cpp */; }; 620A387015E9364F00A4F513 /* heal.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 620A386615E9364E00A4F513 /* heal.cpp */; }; @@ -1567,6 +1568,7 @@ 1234567890ABCDEF12345681 /* file_progress.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = file_progress.hpp; sourceTree = ""; }; 1C58BBDF21822A930078D25A /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; 20E644DC98F26C756364EC2C /* choose_addon.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = choose_addon.cpp; sourceTree = ""; }; + 26A04033A9545CFE8A226FBD /* test_schema_self_validator.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = test_schema_self_validator.cpp; path = test_schema_self_validator.cpp; sourceTree = ""; }; 27764FB68F02032F1C0B6748 /* statistics_record.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = statistics_record.cpp; sourceTree = ""; }; 46081FED2B2F0F6A006ACAD7 /* libpcre2-8.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libpcre2-8.0.dylib"; path = "lib/libpcre2-8.0.dylib"; sourceTree = ""; }; 46081FF02B2F103E006ACAD7 /* libwebpdemux.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libwebpdemux.2.dylib; path = lib/libwebpdemux.2.dylib; sourceTree = ""; }; @@ -3156,6 +3158,14 @@ name = "Linked System Frameworks"; sourceTree = ""; }; + 1137492AA597586E8B20036C /* schema */ = { + isa = PBXGroup; + children = ( + 26A04033A9545CFE8A226FBD /* test_schema_self_validator.cpp */, + ); + path = schema; + sourceTree = ""; + }; 19C28FACFE9D520D11CA2CBB /* Products */ = { isa = PBXGroup; children = ( @@ -4293,6 +4303,7 @@ isa = PBXGroup; children = ( 919797A6261A6FDB001E8133 /* test_macro_define.cpp */, + 1137492AA597586E8B20036C /* schema */, ); path = wml; sourceTree = ""; @@ -6568,6 +6579,7 @@ D1254FCA82471825B83AA786 /* multiline_text.cpp in Sources */, E6CF415F9FD04C35A55FB24D /* scroll_text.cpp in Sources */, 62714C2FBE84B66CF14E3722 /* test_sdl.cpp in Sources */, + 529242A8856DE8D00988B9BD /* test_schema_self_validator.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/source_lists/boost_unit_tests b/source_lists/boost_unit_tests index 0e9b878f654..2adb9b019df 100644 --- a/source_lists/boost_unit_tests +++ b/source_lists/boost_unit_tests @@ -31,3 +31,4 @@ tests/utils/fake_display.cpp tests/utils/game_config_manager_tests.cpp tests/utils/wml_equivalence.cpp tests/wml/test_macro_define.cpp +tests/wml/schema/test_schema_self_validator.cpp diff --git a/src/tests/wml/schema/test_schema_self_validator.cpp b/src/tests/wml/schema/test_schema_self_validator.cpp new file mode 100644 index 00000000000..6ba2d90d173 --- /dev/null +++ b/src/tests/wml/schema/test_schema_self_validator.cpp @@ -0,0 +1,63 @@ +/* + Copyright (C) 2003 - 2023 + Part of the Battle for Wesnoth Project https://www.wesnoth.org/ + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY. + + See the COPYING file for more details. + COPYING file for more details. +*/ + +#define GETTEXT_DOMAIN "wesnoth-test" + +#include + +#include + +#include "serialization/schema_validator.hpp" +#include "wml_exception.hpp" + +BOOST_AUTO_TEST_SUITE( test_schema_self_validator ) + +BOOST_AUTO_TEST_CASE( test_schema_super_self_reference ) +{ + strict_validation_enabled = true; + + constexpr auto schema_path = "src/tests/wml/schema/test_schema_self_validator/test_schema_super_self_reference.cfg"; + + BOOST_CHECK_EXCEPTION( + schema_validation::schema_validator(schema_path, true), + wml_exception, + [] (const wml_exception& e) { + return boost::algorithm::contains( + e.dev_message, + "Inheritance loop super=main found" + ); + } + ); +} + +BOOST_AUTO_TEST_CASE( test_schema_super_cycle ) +{ + strict_validation_enabled = true; + + constexpr auto schema_path = "src/tests/wml/schema/test_schema_self_validator/test_schema_super_cycle.cfg"; + + BOOST_CHECK_EXCEPTION( + schema_validation::schema_validator(schema_path, true), + wml_exception, + [] (const wml_exception& e) { + return boost::algorithm::contains( + e.dev_message, + "Inheritance loop super=main/first found" + ); + } + ); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/src/tests/wml/schema/test_schema_self_validator/test_schema_super_cycle.cfg b/src/tests/wml/schema/test_schema_self_validator/test_schema_super_cycle.cfg new file mode 100644 index 00000000000..a98a6e57ce7 --- /dev/null +++ b/src/tests/wml/schema/test_schema_self_validator/test_schema_super_cycle.cfg @@ -0,0 +1,23 @@ +[wml_schema] + [tag] + name="root" + [tag] + name="main" + [tag] + name="first" + super="second" + [/tag] + [/tag] + [tag] + name="other" + [tag] + name="second" + super="main/first" + [/tag] + [/tag] + [tag] + name="second" + super="other/second" + [/tag] + [/tag] +[/wml_schema] diff --git a/src/tests/wml/schema/test_schema_self_validator/test_schema_super_self_reference.cfg b/src/tests/wml/schema/test_schema_self_validator/test_schema_super_self_reference.cfg new file mode 100644 index 00000000000..e24049198c3 --- /dev/null +++ b/src/tests/wml/schema/test_schema_self_validator/test_schema_super_self_reference.cfg @@ -0,0 +1,9 @@ +[wml_schema] + [tag] + name="root" + [tag] + name="main" + super="main" + [/tag] + [/tag] +[/wml_schema]