17 #define GETTEXT_DOMAIN "wesnoth-lib" 120 #include <functional> 125 #include <boost/test/unit_test.hpp> 179 T* create() {
return new T(); }
182 typedef std::pair<unsigned, unsigned>
resolution;
183 typedef std::vector<std::pair<unsigned, unsigned>> resolution_list;
186 void test_resolutions(
const resolution_list& resolutions)
188 for(
const resolution& resolution : resolutions) {
191 dialog_tester<T> ctor;
192 const std::unique_ptr<modal_dialog> dlg(ctor.create());
193 BOOST_REQUIRE_MESSAGE(dlg.get(),
"Failed to create a dialog.");
197 std::string exception;
201 exception =
"gui2::layout_exception_width_modified";
203 exception =
"gui2::layout_exception_width_resize_failed";
205 exception =
"gui2::layout_exception_height_resize_failed";
208 }
catch(
const std::exception& e) {
209 exception = e.what();
211 exception =
"unknown";
213 BOOST_CHECK_MESSAGE(exception.empty(),
216 <<
" resolution = " << resolution.first
217 <<
'x' << resolution.second
218 <<
"\nException caught: " << exception <<
'.');
223 void test_popup_resolutions(
const resolution_list& resolutions)
225 bool interact =
false;
226 for(
int i = 0;
i < 2; ++
i) {
227 for(
const resolution& resolution : resolutions) {
230 dialog_tester<T> ctor;
231 const std::unique_ptr<modeless_dialog> dlg(ctor.create());
232 BOOST_REQUIRE_MESSAGE(dlg.get(),
"Failed to create a dialog.");
236 std::string exception;
240 BOOST_REQUIRE_NE(window, static_cast<void*>(
nullptr));
243 exception =
"gui2::layout_exception_width_modified";
245 exception =
"gui2::layout_exception_width_resize_failed";
247 exception =
"gui2::layout_exception_height_resize_failed";
250 }
catch(
const std::exception& e) {
251 exception = e.what();
253 exception =
"unknown";
255 BOOST_CHECK_MESSAGE(exception.empty(),
258 <<
" resolution = " << resolution.first
259 <<
'x' << resolution.second
260 <<
"\nException caught: " << exception <<
'.');
268 #pragma warning(push) 269 #pragma warning(disable: 4702) 271 void test_tip_resolutions(
const resolution_list& resolutions
272 ,
const std::string&
id)
274 for(
const auto& resolution : resolutions) {
280 std::string exception;
283 ,
"Test message for a tooltip." 287 exception =
"gui2::layout_exception_width_modified";
289 exception =
"gui2::layout_exception_width_resize_failed";
291 exception =
"gui2::layout_exception_height_resize_failed";
294 }
catch(
const std::exception& e) {
295 exception = e.what();
297 exception =
"unknown";
299 BOOST_CHECK_MESSAGE(exception.empty(),
300 "Test for tip '" <<
id 302 <<
" resolution = " << resolution.first
303 <<
'x' << resolution.second
304 <<
"\nException caught: " << exception <<
'.');
311 const resolution_list& get_gui_resolutions()
313 static resolution_list result {
330 test_resolutions<T>(get_gui_resolutions());
342 for(std::size_t
i = 0;
i < 2; ++
i) {
344 test_popup_resolutions<T>(get_gui_resolutions());
350 void test_tip(
const std::string&
id)
354 for(std::size_t
i = 0;
i < 2; ++
i) {
356 test_tip_resolutions(get_gui_resolutions(),
id);
366 dummy_display_context()
368 , m(std::make_shared<terrain_type_data>(dummy_cfg),
"")
375 virtual ~dummy_display_context(){}
377 virtual const gamemap & map()
const override {
return m; }
378 virtual const unit_map & units()
const override {
return u; }
379 virtual const std::vector<team> & teams()
const override {
return t; }
380 virtual const std::vector<std::string> & hidden_label_categories()
const override {
return lbls; }
388 std::vector<std::string> lbls;
393 static const dummy_display_context dedc = dummy_display_context();
419 test<addon_connect>();
420 test<addon_license_prompt>();
423 test<campaign_difficulty>();
424 test<campaign_selection>();
426 test<core_selection>();
428 test<depcheck_confirm_change>();
429 test<depcheck_select_new>();
432 test<editor_edit_label>();
433 test<editor_edit_side>();
434 test<editor_edit_scenario>();
435 test<editor_generate_map>();
436 test<editor_new_map>();
437 test<editor_resize_map>();
439 test<faction_select>();
441 test<folder_create>();
442 test<formula_debugger>();
443 test<game_cache_options>();
446 test<game_version>();
448 test<game_save_message>();
449 test<game_save_oos>();
452 test<generator_settings>();
455 test<install_dependencies>();
456 test<language_selection>();
459 test<lobby_player_info>();
460 test<log_settings>();
463 test<mp_alerts_options>();
468 test<mp_join_game_password_prompt>();
470 test<mp_method_selection>();
473 test<simple_item_selector>();
474 test<screenshot_notification>();
475 test<select_orb_colors>();
476 test<sp_options_configure>();
477 test<statistics_dialog>();
478 test<surrender_quit>();
483 test<transient_message>();
491 test<wml_message_left>();
492 test<wml_message_right>();
493 test<wml_message_double>();
496 test_popup<debug_clock>();
499 test_tip(
"tooltip_large");
503 std::set<std::string> omitted {
518 "addon_uninstall_list",
521 "network_transmission",
522 "synched_choice_wait",
524 "preferences_dialog",
529 "mp_host_game_prompt",
537 "attack_predictions",
543 "gamestate_inspector",
547 std::vector<std::string>
missing;
548 std::set_difference(list.begin(), list.end(), omitted.begin(), omitted.end(), std::back_inserter(missing));
551 BOOST_CHECK_EQUAL(missing.size(), 0);
552 for(
const std::string&
id : missing) {
553 std::cerr <<
"Window '" <<
id <<
"' registered but not tested.\n";
562 message dlg(
"title",
"message",
true,
false,
false);
566 "which doesn't fit on the screen."));
570 BOOST_ERROR(
"Didn't catch the wanted exception.");
576 struct dialog_tester<addon_auth>
581 return new addon_auth(cfg);
586 struct dialog_tester<addon_connect>
588 std::string host_name =
"host_name";
589 addon_connect* create()
591 return new addon_connect(host_name,
true);
596 struct dialog_tester<addon_license_prompt>
598 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. 600 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.)"""; 601 addon_license_prompt* create() 603 return new addon_license_prompt(license_terms);
608 struct dialog_tester<addon_manager>
614 addon_manager* create()
617 return new addon_manager(client);
622 struct dialog_tester<campaign_difficulty>
624 campaign_difficulty* create()
628 return new campaign_difficulty(items);
633 struct dialog_tester<campaign_selection>
637 dialog_tester() : state(
config {
"campaign_type",
"scenario"}), ng(state)
640 campaign_selection* create()
642 return new campaign_selection(ng);
647 struct dialog_tester<chat_log>
653 dialog_tester() : vcfg(cfg), r(rbase) {}
656 return new chat_log(vcfg, r);
661 struct dialog_tester<core_selection>
663 std::vector<config> cores;
668 core_selection* create()
670 return new core_selection(cores, 0);
675 struct dialog_tester<custom_tod>
677 std::vector<time_of_day> times;
685 return new custom_tod(times, current_tod);
690 struct dialog_tester<edit_label>
692 std::string
label =
"Label text to modify";
693 bool team_only =
false;
696 return new edit_label(label, team_only);
701 struct dialog_tester<edit_text>
703 std::string text =
"text to modify";
706 return new edit_text(
"title",
"label", text);
711 struct dialog_tester<editor_edit_label>
713 std::string
label =
"Label text to modify";
714 std::string category =
"test";
715 bool immutable =
false,
fog =
false,
shroud =
false;
717 editor_edit_label* create()
719 return new editor_edit_label(label, immutable,
fog,
shroud, color, category);
724 struct dialog_tester<editor_edit_scenario>
726 std::string
id, name, descr;
727 int turns = 0, xp_mod = 50;
728 bool defeat_enemies =
false, random_start =
false;
729 editor_edit_scenario* create()
731 return new editor_edit_scenario(
id, name, descr, turns, xp_mod, defeat_enemies, random_start);
736 struct dialog_tester<editor_edit_side>
740 dialog_tester() :
info(t) {}
741 editor_edit_side* create()
743 return new editor_edit_side(info);
748 struct dialog_tester<formula_debugger>
751 formula_debugger* create()
753 return new formula_debugger(debugger);
758 struct dialog_tester<game_load>
772 return new game_load(view, data);
778 struct dialog_tester<game_save>
780 std::string title =
"Title";
781 std::string filename =
"filename";
784 return new game_save(title, filename);
790 struct dialog_tester<game_save_message>
792 std::string title =
"Title";
793 std::string filename =
"filename";
794 std::string
message =
"message";
795 game_save_message* create()
797 return new game_save_message(title, filename, message);
803 struct dialog_tester<game_save_oos>
805 bool ignore_all =
false;
806 std::string title =
"Title";
807 std::string filename =
"filename";
808 std::string
message =
"message";
809 game_save_oos* create()
811 return new game_save_oos(ignore_all, title, filename, message);
818 struct dialog_tester<gamestate_inspector>
822 gamestate_inspector* create()
824 return new gamestate_inspector(vars, events, get_dummy_display_context(),
"Unit Test");
831 struct dialog_tester<install_dependencies>
834 install_dependencies* create()
836 return new install_dependencies(addons);
841 struct dialog_tester<hotkey_bind>
845 hotkey_bind* create()
847 return new hotkey_bind(
id);
852 struct dialog_tester<mp_lobby>
858 dialog_tester() : connection(
"",
""), li()
863 return new mp_lobby(li, connection, selected_game);
868 void add_chat_message(
const std::time_t&,
869 const std::string&,
int,
const std::string&,
871 void send_chat_message(
const std::string&,
bool) {}
873 void clear_messages() {}
877 struct dialog_tester<lobby_player_info>
880 fake_chat_handler ch;
889 lobby_player_info* create()
891 return new lobby_player_info(ch, ui, li);
896 struct dialog_tester<log_settings>
898 log_settings* create()
900 return new log_settings();
905 struct dialog_tester<message>
909 return new message(
"Title",
"Message",
false,
false,
false);
914 struct dialog_tester<mp_change_control>
916 mp_change_control* create()
918 return new mp_change_control(
nullptr);
924 struct dialog_tester<mp_create_game>
927 dialog_tester() : state(
config {
"campaign_type",
"multiplayer"})
930 mp_create_game* create()
932 return new mp_create_game(state,
true);
937 struct dialog_tester<mp_join_game_password_prompt>
940 mp_join_game_password_prompt* create()
942 return new mp_join_game_password_prompt(password);
946 static std::vector<std::string> depcheck_mods {
"mod_one",
"some other",
"more"};
949 struct dialog_tester<depcheck_confirm_change>
951 depcheck_confirm_change* create()
953 return new depcheck_confirm_change(
true, depcheck_mods,
"requester");
958 struct dialog_tester<depcheck_select_new>
960 depcheck_select_new* create()
967 struct dialog_tester<mp_login>
971 return new mp_login(
"wesnoth.org",
"label",
true);
976 struct dialog_tester<simple_item_selector>
978 simple_item_selector* create()
980 return new simple_item_selector(
"title",
"message", std::vector<std::string>(),
false,
false);
985 struct dialog_tester<screenshot_notification>
987 screenshot_notification* create()
989 return new screenshot_notification(
"path",
nullptr);
994 struct dialog_tester<theme_list>
996 static theme_info make_theme(
const std::string& name)
1004 static std::vector<theme_info> themes;
1005 theme_list* create()
1007 return new theme_list(themes, 0);
1010 std::vector<theme_info> dialog_tester<theme_list>::themes {make_theme(
"classic"), make_theme(
"new"), make_theme(
"more"), make_theme(
"themes")};
1013 struct dialog_tester<editor_generate_map>
1015 std::vector<std::unique_ptr<map_generator>> map_generators;
1016 editor_generate_map* create()
1018 for(
const config &
i : main_config.child_range(
"multiplayer")) {
1019 if(
i[
"scenario_generation"] ==
"default") {
1020 const config &generator_cfg =
i.child(
"generator");
1021 if (generator_cfg) {
1027 editor_generate_map* result =
new editor_generate_map(map_generators);
1028 BOOST_REQUIRE_MESSAGE(result,
"Failed to create a dialog.");
1035 struct dialog_tester<editor_new_map>
1039 editor_new_map* create()
1041 return new editor_new_map(
"Test", width, height);
1046 struct dialog_tester<editor_resize_map>
1052 editor_resize_map* create()
1054 return new editor_resize_map(width, height, expand_direction, copy);
1059 struct dialog_tester<file_dialog>
1061 file_dialog* create()
1063 return new file_dialog();
1068 struct dialog_tester<folder_create>
1070 std::string folder_name;
1071 folder_create* create()
1073 return new folder_create(folder_name);
1078 struct dialog_tester<transient_message>
1080 transient_message* create()
1082 return new transient_message(
"Title",
false,
"Message",
false,
"");
1087 struct dialog_tester<title_screen>
1089 std::vector<std::string> args;
1092 dialog_tester() : opts(args), game(opts) {}
1093 title_screen* create()
1095 return new title_screen(game);
1100 struct dialog_tester<wml_error>
1102 static std::vector<std::string> files;
1105 return new wml_error(
"Summary",
"Post summary", files,
"Details");
1108 std::vector<std::string> dialog_tester<wml_error>::files {
"some",
"files",
"here"};
1111 struct dialog_tester<wml_message_left>
1113 wml_message_left* create()
1115 return new wml_message_left(
"Title",
"Message",
"",
false);
1120 struct dialog_tester<wml_message_right>
1122 wml_message_right* create()
1124 return new wml_message_right(
"Title",
"Message",
"",
false);
1129 struct dialog_tester<wml_message_double>
1131 wml_message_double* create()
1133 return new wml_message_double(
"Title",
"Message",
"",
false,
"",
true);
1138 struct dialog_tester<faction_select>
1140 config era_cfg, side_cfg;
1141 std::vector<const config*> eras;
1145 : era_cfg(), side_cfg(), eras(1, &era_cfg)
1146 , flg(eras, side_cfg,
false,
false,
false)
1149 faction_select* create() {
1150 return new faction_select(flg, color, 1);
1156 struct dialog_tester<game_stats>
1159 game_stats* create()
1161 return new game_stats(get_dummy_display_context(), 1, i);
1167 struct dialog_tester<generator_settings>
1171 dialog_tester() : data(cfg) {}
1172 generator_settings* create()
1174 return new generator_settings(data);
1179 struct dialog_tester<sp_options_configure>
1184 dialog_tester() : create_eng(state)
1186 sp_options_configure* create()
1188 return new sp_options_configure(create_eng, config_eng);
1193 struct dialog_tester<statistics_dialog>
1196 dialog_tester() :
t() {}
1197 statistics_dialog* create()
1199 return new statistics_dialog(t);
1204 struct dialog_tester<surrender_quit>
1207 surrender_quit* create()
1209 return new surrender_quit();
bool new_widgets
Do we wish to use the new library or not.
Defines the exception classes for the layout algorithm.
static config_cache & instance()
Get reference to the singleton object.
window * unit_test_window(const modeless_dialog &dialog)
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
Main class to show messages to the user.
static game_config_view wrap(const config &cfg)
static std::shared_ptr< save_index_class > default_saves_dir()
Returns an instance for managing saves in filesystem::get_saves_dir()
game_display & get_fake_display(const int width, const int height)
Gets a fake test display.
Exception thrown when the height resizing has failed.
void draw()
Draws the window.
The paths manager is responsible for recording the various paths that binary files may be located at...
This class represents the collective information the client has about the players and games on the se...
std::string user_message
The message for the user explaining what went wrong.
const std::vector< std::string > items
static std::string _(const char *str)
FLG stands for faction, leader and gender.
bool show(const unsigned auto_close_time=0)
Shows the window.
void load_config(const config &v)
virtual const std::string & window_id() const =0
The id of the window to build.
This class stores all the data for a single 'side' (in game nomenclature).
Exception thrown when the width has been modified during resizing.
static std::set< std::string > & unit_test_registered_window_list()
std::string label
What to show in the filter's drop-down list.
This file contains the settings handling of the widget library.
A class that represents a TCP/IP connection to the wesnothd server.
Encapsulates the map of the game.
std::string unit_test_mark_as_tested(const modal_dialog &dialog)
Exception thrown when the width resizing has failed.
Add-ons (campaignd) client class.
Various uncategorised dialogs.
BOOST_AUTO_TEST_CASE(test_gui2)
Helper class, don't construct this directly.
void get_config(const std::string &path, config &cfg, abstract_validator *validator=nullptr)
Gets a config object from given path.
std::string dev_message
The message for developers telling which problem was triggered, this shouldn't be translated...
std::string id
Text to match against addon_info.tags()
void clear_defines()
Clear stored defines map to default values.
map_generator * create_map_generator(const std::string &name, const config &cfg, const config *vars)
Game configuration data as global variables.
std::unique_ptr< window > window_
The window, used in show.
std::string password(const std::string &server, const std::string &login)
bool load_language_list()
Declarations for File-IO.
The game event manager loads the scenario configuration object, and ensures that events are handled a...
std::string unit_test_mark_popup_as_tested(const modeless_dialog &dialog)
virtual const std::string & window_id() const =0
The id of the window to build.
Handling of system events.
This class represents the information a client has about another player.
The popup class shows windows that are shown non-modal.
A variable-expanding proxy for the config class.
Abstract base class for all modal dialogs.
CVideo & video()
Gets the underlying screen object.
Container associating units to locations.
void send_to_server(const config &data)
Attempts to send given data to server if a connection is open.
std::set< std::string > & registered_window_types()
Returns the list of registered windows.
A config object defines a single node in a WML file, with access to child nodes.
std::map< std::string, addon_info > addons_list
base class of top level items, the only item which needs to store the final canvases to draw on...
void add_define(const std::string &define)
Add a entry to preproc defines map.
Networked add-ons (campaignd) client interface.
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
Singleton class to manage game config file caching.