17 #define GETTEXT_DOMAIN "wesnoth-lib"
135 #include <boost/test/unit_test.hpp>
137 #include <functional>
145 , dummy_args({
"wesnoth",
"--noaddons"})
202 T* create() {
return new T(); }
205 typedef std::pair<unsigned, unsigned> resolution;
206 typedef std::vector<std::pair<unsigned, unsigned>> resolution_list;
209 void test_resolutions(
const resolution_list& resolutions)
211 for(
const resolution& resolution : resolutions) {
214 dialog_tester<T> ctor;
215 const std::unique_ptr<modal_dialog> dlg(ctor.create());
216 BOOST_REQUIRE_MESSAGE(dlg.get(),
"Failed to create a dialog.");
221 std::string exception;
225 exception =
"gui2::layout_exception_width_modified";
227 exception =
"gui2::layout_exception_width_resize_failed";
229 exception =
"gui2::layout_exception_height_resize_failed";
231 exception =
e.dev_message;
232 }
catch(
const std::exception&
e) {
233 exception =
e.what();
237 BOOST_CHECK_MESSAGE(exception.empty(),
240 <<
" resolution = " << resolution.first
241 <<
'x' << resolution.second
242 <<
"\nException caught: " << exception <<
'.');
247 void test_popup_resolutions(
const resolution_list& resolutions)
249 bool interact =
false;
250 for(
int i = 0;
i < 2; ++
i) {
251 for(
const resolution& resolution : resolutions) {
254 dialog_tester<T> ctor;
255 const std::unique_ptr<modeless_dialog> dlg(ctor.create());
256 BOOST_REQUIRE_MESSAGE(dlg.get(),
"Failed to create a dialog.");
261 std::string exception;
265 BOOST_REQUIRE_NE(window,
static_cast<void*
>(
nullptr));
268 exception =
"gui2::layout_exception_width_modified";
270 exception =
"gui2::layout_exception_width_resize_failed";
272 exception =
"gui2::layout_exception_height_resize_failed";
274 exception =
e.dev_message;
275 }
catch(
const std::exception&
e) {
276 exception =
e.what();
280 BOOST_CHECK_MESSAGE(exception.empty(),
283 <<
" resolution = " << resolution.first
284 <<
'x' << resolution.second
285 <<
"\nException caught: " << exception <<
'.');
293 #pragma warning(push)
294 #pragma warning(disable: 4702)
296 void test_tip_resolutions(
const resolution_list& resolutions
297 ,
const std::string&
id)
299 for(
const auto& resolution : resolutions) {
304 std::string exception;
307 ,
"Test message for a tooltip."
312 exception =
"gui2::layout_exception_width_modified";
314 exception =
"gui2::layout_exception_width_resize_failed";
316 exception =
"gui2::layout_exception_height_resize_failed";
318 exception =
e.dev_message;
319 }
catch(
const std::exception&
e) {
320 exception =
e.what();
324 BOOST_CHECK_MESSAGE(exception.empty(),
325 "Test for tip '" <<
id
327 <<
" resolution = " << resolution.first
328 <<
'x' << resolution.second
329 <<
"\nException caught: " << exception <<
'.');
336 const resolution_list& get_gui_resolutions()
338 static resolution_list result {
354 test_resolutions<T>(get_gui_resolutions());
366 for(std::size_t
i = 0;
i < 2; ++
i) {
368 test_popup_resolutions<T>(get_gui_resolutions());
374 void test_tip(
const std::string&
id)
378 for(std::size_t
i = 0;
i < 2; ++
i) {
380 test_tip_resolutions(get_gui_resolutions(),
id);
396 test<addon_connect>();
400 test<addon_license_prompt>();
404 test<campaign_difficulty>();
412 test<editor_choose_addon>();
420 test<core_selection>();
424 test<depcheck_confirm_change>();
428 test<depcheck_select_new>();
436 test<editor_edit_pbl>();
440 test<editor_edit_pbl_translation>();
448 test<editor_edit_label>();
452 test<editor_edit_side>();
456 test<editor_edit_scenario>();
460 test<editor_generate_map>();
464 test<editor_new_map>();
468 test<editor_resize_map>();
472 test<faction_select>();
480 test<folder_create>();
484 test<formula_debugger>();
488 test<game_cache_options>();
496 test<game_version>();
504 test<game_save_message>();
508 test<game_save_oos>();
512 test<generator_settings>();
516 test<gui_test_dialog>();
524 test<install_dependencies>();
528 test<language_selection>();
536 test<lobby_player_info>();
540 test<log_settings>();
548 test<mp_alerts_options>();
556 test<mp_join_game_password_prompt>();
564 test<mp_method_selection>();
572 test<simple_item_selector>();
576 test<screenshot_notification>();
580 test<select_orb_colors>();
584 test<reachmap_options>();
588 test<statistics_dialog>();
592 test<surrender_quit>();
600 test<transient_message>();
608 test<wml_message_left>();
612 test<wml_message_right>();
616 test<wml_message_double>();
620 test<achievements_dialog>();
624 test<addon_server_info>();
628 test<mp_match_history>();
632 test<gui2::dialogs::migrate_version_selection>();
636 test_popup<debug_clock>();
640 test_tip(
"tooltip_large");
648 test<tod_new_schedule>();
653 test<editor_edit_unit>();
661 std::set<std::string> omitted {
676 "addon_uninstall_list",
679 "network_transmission",
680 "synched_choice_wait",
682 "preferences_dialog",
685 "mp_host_game_prompt",
693 "attack_predictions",
699 "gamestate_inspector",
701 "sp_options_configure",
702 "campaign_selection",
710 for(
const std::string& item : widgets_tested)
712 widget_list.erase(item);
714 BOOST_CHECK_EQUAL(omitted.count(item), 0);
716 for(
const std::string& item : omitted)
718 widget_list.erase(item);
722 BOOST_CHECK_EQUAL(widget_list.size(), 0);
723 for(
const std::string&
id : widget_list) {
724 PLAIN_LOG <<
"Window '" <<
id <<
"' registered but not tested.";
733 message dlg(
"title",
"message",
true,
false,
false);
741 BOOST_ERROR(
"Didn't catch the wanted exception, instead caught nothing.");
744 BOOST_AUTO_TEST_SUITE_END()
773 std::string host_name =
"host_name";
783 std::string license_terms = R
"(Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ante nibh, dignissim ullamcorper tristique eget, condimentum sit amet enim. Aenean dictum pulvinar lacinia. Etiam eleifend, leo sed efficitur consectetur, augue nulla ornare lectus, vitae molestie lacus risus vitae libero. Quisque odio nunc, porttitor eget fermentum sit amet, faucibus eu risus. Praesent sit amet lacus tortor. Suspendisse volutpat quam vitae ipsum fermentum, in vulputate metus egestas. Nulla id consequat ex. Nulla ac dignissim nisl, nec euismod lectus. Duis vitae dolor ornare, convallis justo in, porta dui.
785 Sed faucibus nibh sit amet ligula porta, non malesuada nibh tristique. Maecenas aliquam diam non eros convallis mattis. Proin rhoncus condimentum leo, sed condimentum magna. Phasellus cursus condimentum lacus, sed sodales lacus. Sed pharetra dictum metus, eget dictum nibh lobortis imperdiet. Nunc tempus sollicitudin bibendum. In porttitor interdum orci. Curabitur vitae nibh vestibulum, condimentum lectus quis, condimentum dui. In quis cursus nisl. Maecenas semper neque eu ipsum aliquam, id porta ligula lacinia. Integer sed blandit ex, eu accumsan magna.)";
811 const config items(
"difficulty");
822 dialog_tester() : state(
config {
"campaign_type",
"scenario"}),
ng(state)
838 dialog_tester() : vcfg(
cfg), r(rbase) {}
856 struct dialog_tester<
prompt>
868 std::vector<config> cores;
882 std::vector<time_of_day> times;
897 std::string
label =
"Label text to modify";
898 bool team_only =
false;
908 std::string text =
"text to modify";
911 return new edit_text(
"title",
"label", text);
918 std::string
label =
"Label text to modify";
919 std::string category =
"test";
920 bool immutable =
false, fog =
false, shroud =
false;
954 std::string
id, name, descr;
955 int turns = 0, xp_mod = 50;
956 bool defeat_enemies =
false, random_start =
false;
968 dialog_tester() :
info(
t) {}
1005 std::string title =
"Title";
1017 std::string title =
"Title";
1019 std::string
message =
"message";
1030 bool ignore_all =
false;
1031 std::string title =
"Title";
1033 std::string
message =
"message";
1054 std::string
id =
"";
1069 dialog_tester() : connection(
"",
""), li()
1074 return new mp_lobby(li, connection, selected_game);
1082 dialog_tester() : connection(
"",
"")
1092 struct dialog_tester<
gui2::dialogs::migrate_version_selection>
1101 void add_chat_message(
const std::chrono::system_clock::time_point&,
1102 const std::string&,
int,
const std::string&,
1104 void send_chat_message(
const std::string&,
bool) {}
1106 void clear_messages() {}
1113 fake_chat_handler ch;
1118 : connection(
"",
"")
1142 return new message(
"Title",
"Message",
false,
false,
false);
1150 dialog_tester() : state(
config {
"campaign_type",
"multiplayer"})
1162 std::string password;
1172 std::string report_text;
1179 static std::vector<std::string> depcheck_mods {
"mod_one",
"some other",
"more"};
1204 return new mp_login(
"wesnoth.org",
"label",
true);
1229 static theme_info make_theme(
const std::string& name)
1237 static std::vector<theme_info> themes;
1243 std::vector<theme_info> dialog_tester<theme_list>::themes {make_theme(
"classic"), make_theme(
"new"), make_theme(
"more"), make_theme(
"themes")};
1248 std::vector<std::unique_ptr<map_generator>> map_generators;
1252 if(
i[
"scenario_generation"] ==
"default") {
1253 auto generator_cfg =
i.optional_child(
"generator");
1254 if (generator_cfg) {
1261 BOOST_REQUIRE_MESSAGE(result,
"Failed to create a dialog.");
1303 std::string folder_name;
1322 std::vector<std::string> args;
1325 dialog_tester() : opts(args),
game(opts) {}
1335 static std::vector<std::string> files;
1338 return new wml_error(
"Summary",
"Post summary", files,
"Details");
1341 std::vector<std::string> dialog_tester<wml_error>::files {
"some",
"files",
"here"};
1373 config era_cfg, side_cfg;
1374 std::vector<const config*> eras;
1379 : era_cfg(), side_cfg(), eras(1, &era_cfg), era(era_cfg)
1380 , flg(era, eras, side_cfg, false, false, false)
1393 dialog_tester() :
data(
cfg) {}
1405 dialog_tester() : create_eng(state) {}
1418 dialog_tester() :
t() , stats_record(), stats(stats_record) {}
1438 std::string
id =
"id";
1459 movetype[
"name"] =
"Test Movetype";
1462 movetype.add_child(
"movement_costs");
Add-ons (campaignd) client class.
A config object defines a single node in a WML file, with access to child nodes.
config & add_child(std::string_view key)
Singleton class to manage game config file caching.
void add_define(const std::string &define)
Add a entry to preproc defines map.
static config_cache & instance()
Get reference to the singleton object.
void clear_defines()
Clear stored defines map to default values.
config get_config(const std::string &path, abstract_validator *validator=nullptr)
Gets a config object from given path.
A class grating read only view to a vector of config objects, viewed as one config with all children ...
static game_config_view wrap(const config &cfg)
Dialog that allows user to create custom unit types.
A test dialog for testing various gui2 features.
Main class to show messages to the user.
This shows the dialog to select a previous version of Wesnoth to migrate preferences from and redownl...
Abstract base class for all modal dialogs.
virtual const std::string & window_id() const =0
The ID of the window to build.
bool show(const unsigned auto_close_time=0)
Shows the window.
The popup class shows windows that are shown non-modal.
virtual const std::string & window_id() const
The ID of the window to build.
This shows the dialog to confirm surrender and/or quitting the game.
This class implements the title screen.
Dialog that takes new schedule ID and name from the player.
Shows a transient message.
Shows a dialog with two portraits, one on each side.
Shows a dialog with the portrait on the left side.
Shows a dialog with the portrait on the right side.
base class of top level items, the only item which needs to store the final canvases to draw on.
void draw()
Draws the window.
The basic "size" of the unit - flying, small land, large land, etc.
This class represents the collective information the client has about the players and games on the se...
FLG stands for faction, leader and gender.
static std::shared_ptr< save_index_class > default_saves_dir()
Returns an instance for managing saves in filesystem::get_saves_dir()
This class stores all the data for a single 'side' (in game nomenclature).
A variable-expanding proxy for the config class.
A class that represents a TCP/IP connection to the wesnothd server.
Networked add-ons (campaignd) client interface.
Declarations for File-IO.
std::string label
What to show in the filter's drop-down list.
std::string id
Text to match against addon_info.tags()
std::map< std::string, addon_info > addons_list
bool load_language_list()
Defines the exception classes for the layout algorithm.
map_generator * create_map_generator(const std::string &name, const config &cfg, const config *vars)
Various uncategorised dialogs.
void point(int x, int y)
Draw a single point.
bool delete_file(const std::string &filename)
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
void write_file(const std::string &fname, const std::string &data, std::ios_base::openmode mode)
Throws io_exception if an error occurs.
Game configuration data as global variables.
void load_config(const config &v)
void remove()
Removes a tip.
void show(const std::string &window_id, const t_string &message, const point &mouse, const rect &source_rect)
Shows a tip.
std::string get_modal_dialog_id(const modal_dialog &dialog)
std::string get_modeless_dialog_id(const modeless_dialog &dialog)
std::set< std::string > & registered_window_types()
Returns the list of registered windows.
bool new_widgets
Do we wish to use the new library or not.
void send_to_server(const config &data)
Attempts to send given data to server if a connection is open.
void set_test_resolution(const int width, const int height)
Sets the dummy display resolution for use by the tests.
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
std::vector< std::string > split(const config_attribute_value &val)
This file contains the settings handling of the widget library.
std::string filename
Filename.
The basic class for representing 8-bit RGB or RGBA colour values.
The paths manager is responsible for recording the various paths that binary files may be located at.
Exception thrown when the height resizing has failed.
Exception thrown when the width has been modified during resizing.
Exception thrown when the width resizing has failed.
This class represents the information a client has about another player.
static config main_config
std::unique_ptr< game_config_manager > config_manager
std::vector< std::string > dummy_args
static const std::string widgets_file
Helper class, don't construct this directly.
BOOST_AUTO_TEST_CASE(modal_dialog_test_addon_auth)
BOOST_FIXTURE_TEST_SUITE(test_map_location, MLFixture)
static map_location::direction s
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...