From 489074b0a4738a8cc7aa41fcb9ffd7c726fc4e8f Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Sat, 6 Dec 2014 17:18:35 -0500 Subject: [PATCH] add --mp-tests option and preproc defines, and mp unit tests folder These tests are meant to be run in a networked context to check for OOS and similar. --- data/_main.cfg | 5 ++ data/test/multiplayer/_main.cfg | 15 +++++ .../macros/mp_unit_test_macros.cfg | 58 +++++++++++++++++++ data/test/multiplayer/scenarios/test1.cfg | 33 +++++++++++ data/test/multiplayer/scenarios/test2.cfg | 33 +++++++++++ src/commandline_options.cpp | 4 ++ src/commandline_options.hpp | 2 + src/game_config_manager.cpp | 3 + 8 files changed, 153 insertions(+) create mode 100644 data/test/multiplayer/_main.cfg create mode 100644 data/test/multiplayer/macros/mp_unit_test_macros.cfg create mode 100644 data/test/multiplayer/scenarios/test1.cfg create mode 100644 data/test/multiplayer/scenarios/test2.cfg diff --git a/data/_main.cfg b/data/_main.cfg index d6c79c1fab8..bda776be6e8 100644 --- a/data/_main.cfg +++ b/data/_main.cfg @@ -26,6 +26,11 @@ #ifdef MULTIPLAYER {multiplayer/} + +#ifdef MP_TEST +{test/multiplayer/} +#endif + #else {era_blank.cfg} #endif diff --git a/data/test/multiplayer/_main.cfg b/data/test/multiplayer/_main.cfg new file mode 100644 index 00000000000..e161498e945 --- /dev/null +++ b/data/test/multiplayer/_main.cfg @@ -0,0 +1,15 @@ +#textdomain wesnoth-test + +[textdomain] + name="wesnoth-test" +[/textdomain] + +#ifdef MP_TEST + +#Load test macros +{test/multiplayer/macros} + +#Load mp test scenarios +{test/multiplayer/scenarios} + +#endif diff --git a/data/test/multiplayer/macros/mp_unit_test_macros.cfg b/data/test/multiplayer/macros/mp_unit_test_macros.cfg new file mode 100644 index 00000000000..83521359bb4 --- /dev/null +++ b/data/test/multiplayer/macros/mp_unit_test_macros.cfg @@ -0,0 +1,58 @@ +#textdomain wesnoth +#define RETURN X + [if] + {X} + [then] + [endlevel] + result=victory + linger_mode = yes + [/endlevel] + [/then] + [else] + [endlevel] + result=defeat + linger_mode = yes + [/endlevel] + [/else] + [/if] +#enddef + +#define ASSERT X + [if] + {X} + [else] + [endlevel] + result=defeat + linger_mode = yes + [/endlevel] + [/else] + [/if] +#enddef + +#define MP_UNIT_TEST NAME CONTENT + [multiplayer] + name = "Multiplayer Unit Test " + {NAME} + map_data = "{test/maps/generic_unit_test.map}" + turns = -1 + id = {NAME} + + {DAWN} + + [side] + side=1 + controller=human + name = "Alice" + type = Elvish Archer + id=alice + [/side] + [side] + side=2 + controller=human + name = "Bob" + type = Orcish Grunt + id=bob + [/side] + + {CONTENT} + [/multiplayer] +#enddef diff --git a/data/test/multiplayer/scenarios/test1.cfg b/data/test/multiplayer/scenarios/test1.cfg new file mode 100644 index 00000000000..fabf2bf46b4 --- /dev/null +++ b/data/test/multiplayer/scenarios/test1.cfg @@ -0,0 +1,33 @@ +{MP_UNIT_TEST "test1" ( + + [event] + name = side 1 turn 2 + + [chat] + message="second turn" + [/chat] + [/event] + + [event] + name = side 2 turn 2 + [endlevel] + result=victory + next_scenario=test2 + + carryover_percentage=50 + carryover_report=false + carryover_add=true + + linger_mode=true + save=no + replay_save=no + [/endlevel] + [/event] + + [event] + name = side turn + first_time_only = no + [end_turn] + [/end_turn] + [/event] +)} diff --git a/data/test/multiplayer/scenarios/test2.cfg b/data/test/multiplayer/scenarios/test2.cfg new file mode 100644 index 00000000000..3dfd3cb2825 --- /dev/null +++ b/data/test/multiplayer/scenarios/test2.cfg @@ -0,0 +1,33 @@ +{MP_UNIT_TEST "test2" ( + allow_new_game = false + + [event] + name = side 1 turn 2 + + [chat] + message="second turn" + [/chat] + [/event] + + [event] + name = side 2 turn 2 + [endlevel] + result=victory + + carryover_percentage=50 + carryover_report=false + carryover_add=true + + linger_mode=true + save=no + replay_save=no + [/endlevel] + [/event] + + [event] + name = side turn + first_time_only = no + [end_turn] + [/end_turn] + [/event] +)} diff --git a/src/commandline_options.cpp b/src/commandline_options.cpp index 2a98560ba61..695b028b13a 100644 --- a/src/commandline_options.cpp +++ b/src/commandline_options.cpp @@ -139,6 +139,7 @@ commandline_options::commandline_options (const std::vector& args) unit_test(), headless_unit_test(false), noreplaycheck(false), + mptest(false), userconfig_path(false), userconfig_dir(), userdata_path(false), @@ -256,6 +257,7 @@ commandline_options::commandline_options (const std::vector& args) ("timeout", po::value(), "sets a timeout (milliseconds) for the unit test. (DEPRECATED)") ("log-strict", po::value(), "sets the strict level of the logger. any messages sent to log domains of this level or more severe will cause the unit test to fail regardless of the victory result.") ("noreplaycheck", "don't try to validate replay of unit test") + ("mp-test", "load the test mp scenarios") ; po::options_description preprocessor_opts("Preprocessor mode options"); @@ -371,6 +373,8 @@ commandline_options::commandline_options (const std::vector& args) parse_log_strictness(vm["log-strict"].as()); if (vm.count("max-fps")) max_fps = vm["max-fps"].as(); + if (vm.count("mp-test")) + mptest = true; if (vm.count("multiplayer")) multiplayer = true; if (vm.count("multiplayer-repeat")) diff --git a/src/commandline_options.hpp b/src/commandline_options.hpp index 459db88a646..57af2451218 100644 --- a/src/commandline_options.hpp +++ b/src/commandline_options.hpp @@ -206,6 +206,8 @@ public: boost::optional timeout; /// True if --noreplaycheck was given on the comand line. Dependent on --unit. bool noreplaycheck; + /// True if --mp-test was given on the command line. + bool mptest; /// True if --userconfig-path was given on the command line. Prints path to user config directory and exits. bool userconfig_path; /// Non-empty if --userconfig-dir was given on the command line. Sets the user config dir to the specified one. diff --git a/src/game_config_manager.cpp b/src/game_config_manager.cpp index 47ba5c16370..266eb830a55 100644 --- a/src/game_config_manager.cpp +++ b/src/game_config_manager.cpp @@ -81,6 +81,7 @@ bool game_config_manager::init_game_config(FORCE_RELOAD_CONFIG force_reload) game_config::scoped_preproc_define multiplayer("MULTIPLAYER", cmdline_opts_.multiplayer); game_config::scoped_preproc_define test("TEST", cmdline_opts_.test); + game_config::scoped_preproc_define mptest("MP_TEST", cmdline_opts_.mptest); game_config::scoped_preproc_define editor("EDITOR", jump_to_editor_); game_config::scoped_preproc_define title_screen("TITLE_SCREEN", !cmdline_opts_.multiplayer && !cmdline_opts_.test && !jump_to_editor_); @@ -490,6 +491,8 @@ void game_config_manager::load_game_config_for_game( !classification.era_define.empty()); game_config::scoped_preproc_define multiplayer("MULTIPLAYER", classification.campaign_type == game_classification::MULTIPLAYER); + game_config::scoped_preproc_define mptest("MP_TEST", cmdline_opts_.mptest && + classification.campaign_type == game_classification::MULTIPLAYER); typedef boost::shared_ptr define; std::deque extra_defines;