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.
This commit is contained in:
Rafael Fillipe Silva 2023-12-19 23:32:33 -03:00 committed by Pentarctagon
parent dafb78cdf1
commit fd6cd7c2a2
7 changed files with 111 additions and 0 deletions

View file

@ -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

View file

@ -1227,6 +1227,7 @@
<Unit filename="../../src/tests/utils/wml_equivalence.cpp" />
<Unit filename="../../src/tests/utils/wml_equivalence.hpp" />
<Unit filename="../../src/tests/wml/test_macro_define.cpp" />
<Unit filename="../../src/tests/wml/schema/test_schema_self_validator.cpp" />
<Unit filename="../../src/theme.cpp" />
<Unit filename="../../src/theme.hpp" />
<Unit filename="../../src/time_of_day.cpp" />

View file

@ -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 = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
27764FB68F02032F1C0B6748 /* statistics_record.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = statistics_record.cpp; sourceTree = "<group>"; };
46081FED2B2F0F6A006ACAD7 /* libpcre2-8.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libpcre2-8.0.dylib"; path = "lib/libpcre2-8.0.dylib"; sourceTree = "<group>"; };
46081FF02B2F103E006ACAD7 /* libwebpdemux.2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libwebpdemux.2.dylib; path = lib/libwebpdemux.2.dylib; sourceTree = "<group>"; };
@ -3156,6 +3158,14 @@
name = "Linked System Frameworks";
sourceTree = "<group>";
};
1137492AA597586E8B20036C /* schema */ = {
isa = PBXGroup;
children = (
26A04033A9545CFE8A226FBD /* test_schema_self_validator.cpp */,
);
path = schema;
sourceTree = "<group>";
};
19C28FACFE9D520D11CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
@ -4293,6 +4303,7 @@
isa = PBXGroup;
children = (
919797A6261A6FDB001E8133 /* test_macro_define.cpp */,
1137492AA597586E8B20036C /* schema */,
);
path = wml;
sourceTree = "<group>";
@ -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;
};

View file

@ -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

View file

@ -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 <boost/test/unit_test.hpp>
#include <boost/algorithm/string/predicate.hpp>
#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()

View file

@ -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]

View file

@ -0,0 +1,9 @@
[wml_schema]
[tag]
name="root"
[tag]
name="main"
super="main"
[/tag]
[/tag]
[/wml_schema]