16 #define GETTEXT_DOMAIN "wesnoth-lib" 118 #include <functional> 123 #include <boost/test/unit_test.hpp> 177 T* create() {
return new T(); }
180 typedef std::pair<unsigned, unsigned>
resolution;
181 typedef std::vector<std::pair<unsigned, unsigned>> resolution_list;
184 void test_resolutions(
const resolution_list& resolutions)
186 for(
const resolution& resolution : resolutions) {
189 dialog_tester<T> ctor;
190 const std::unique_ptr<modal_dialog> dlg(ctor.create());
191 BOOST_REQUIRE_MESSAGE(dlg.get(),
"Failed to create a dialog.");
195 std::string exception;
199 exception =
"gui2::layout_exception_width_modified";
201 exception =
"gui2::layout_exception_width_resize_failed";
203 exception =
"gui2::layout_exception_height_resize_failed";
206 }
catch(
const std::exception& e) {
207 exception = e.what();
209 exception =
"unknown";
211 BOOST_CHECK_MESSAGE(exception.empty(),
214 <<
" resolution = " << resolution.first
215 <<
'x' << resolution.second
216 <<
"\nException caught: " << exception <<
'.');
221 void test_popup_resolutions(
const resolution_list& resolutions)
223 bool interact =
false;
224 for(
int i = 0;
i < 2; ++
i) {
225 for(
const resolution& resolution : resolutions) {
228 dialog_tester<T> ctor;
229 const std::unique_ptr<modeless_dialog> dlg(ctor.create());
230 BOOST_REQUIRE_MESSAGE(dlg.get(),
"Failed to create a dialog.");
234 std::string exception;
238 BOOST_REQUIRE_NE(window, static_cast<void*>(
nullptr));
241 exception =
"gui2::layout_exception_width_modified";
243 exception =
"gui2::layout_exception_width_resize_failed";
245 exception =
"gui2::layout_exception_height_resize_failed";
248 }
catch(
const std::exception& e) {
249 exception = e.what();
251 exception =
"unknown";
253 BOOST_CHECK_MESSAGE(exception.empty(),
256 <<
" resolution = " << resolution.first
257 <<
'x' << resolution.second
258 <<
"\nException caught: " << exception <<
'.');
266 #pragma warning(push) 267 #pragma warning(disable: 4702) 269 void test_tip_resolutions(
const resolution_list& resolutions
270 ,
const std::string&
id)
272 for(
const auto& resolution : resolutions) {
278 std::string exception;
281 ,
"Test message for a tooltip." 285 exception =
"gui2::layout_exception_width_modified";
287 exception =
"gui2::layout_exception_width_resize_failed";
289 exception =
"gui2::layout_exception_height_resize_failed";
292 }
catch(
const std::exception& e) {
293 exception = e.what();
295 exception =
"unknown";
297 BOOST_CHECK_MESSAGE(exception.empty(),
298 "Test for tip '" <<
id 300 <<
" resolution = " << resolution.first
301 <<
'x' << resolution.second
302 <<
"\nException caught: " << exception <<
'.');
309 const resolution_list& get_gui_resolutions()
311 static resolution_list result {
328 test_resolutions<T>(get_gui_resolutions());
340 for(std::size_t
i = 0;
i < 2; ++
i) {
342 test_popup_resolutions<T>(get_gui_resolutions());
348 void test_tip(
const std::string&
id)
352 for(std::size_t
i = 0;
i < 2; ++
i) {
354 test_tip_resolutions(get_gui_resolutions(),
id);
364 dummy_display_context()
366 , m(std::make_shared<terrain_type_data>(dummy_cfg),
"")
373 virtual ~dummy_display_context(){}
375 virtual const gamemap & map()
const override {
return m; }
376 virtual const unit_map & units()
const override {
return u; }
377 virtual const std::vector<team> & teams()
const override {
return t; }
378 virtual const std::vector<std::string> & hidden_label_categories()
const override {
return lbls; }
386 std::vector<std::string> lbls;
391 static const dummy_display_context dedc = dummy_display_context();
416 test<addon_connect>();
417 test<addon_license_prompt>();
420 test<campaign_difficulty>();
421 test<campaign_selection>();
423 test<core_selection>();
425 test<depcheck_confirm_change>();
426 test<depcheck_select_new>();
429 test<editor_edit_label>();
430 test<editor_edit_side>();
431 test<editor_edit_scenario>();
432 test<editor_generate_map>();
433 test<editor_new_map>();
434 test<editor_resize_map>();
436 test<faction_select>();
438 test<folder_create>();
439 test<formula_debugger>();
440 test<game_cache_options>();
443 test<game_version>();
445 test<game_save_message>();
446 test<game_save_oos>();
449 test<generator_settings>();
452 test<install_dependencies>();
453 test<language_selection>();
456 test<lobby_player_info>();
457 test<log_settings>();
460 test<mp_alerts_options>();
465 test<mp_join_game_password_prompt>();
467 test<mp_method_selection>();
470 test<simple_item_selector>();
471 test<screenshot_notification>();
472 test<select_orb_colors>();
473 test<sp_options_configure>();
474 test<statistics_dialog>();
475 test<surrender_quit>();
480 test<transient_message>();
488 test<wml_message_left>();
489 test<wml_message_right>();
490 test<wml_message_double>();
493 test_popup<debug_clock>();
496 test_tip(
"tooltip_large");
500 std::set<std::string> omitted {
515 "addon_uninstall_list",
518 "network_transmission",
519 "synched_choice_wait",
521 "preferences_dialog",
526 "mp_host_game_prompt",
534 "attack_predictions",
540 "gamestate_inspector",
544 std::vector<std::string>
missing;
545 std::set_difference(list.begin(), list.end(), omitted.begin(), omitted.end(), std::back_inserter(missing));
548 BOOST_CHECK_EQUAL(missing.size(), 0);
549 for(
const std::string&
id : missing) {
550 std::cerr <<
"Window '" <<
id <<
"' registered but not tested.\n";
559 message dlg(
"title",
"message",
true,
false,
false);
563 "which doesn't fit on the screen."));
567 BOOST_ERROR(
"Didn't catch the wanted exception.");
573 struct dialog_tester<addon_connect>
575 std::string host_name =
"host_name";
576 addon_connect* create()
578 return new addon_connect(host_name,
true);
583 struct dialog_tester<addon_license_prompt>
585 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. 587 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.)"""; 588 addon_license_prompt* create() 590 return new addon_license_prompt(license_terms);
595 struct dialog_tester<addon_manager>
601 addon_manager* create()
604 return new addon_manager(client);
609 struct dialog_tester<campaign_difficulty>
611 campaign_difficulty* create()
615 return new campaign_difficulty(items);
620 struct dialog_tester<campaign_selection>
624 dialog_tester() : state(
config {
"campaign_type",
"scenario"}), ng(state)
627 campaign_selection* create()
629 return new campaign_selection(ng);
634 struct dialog_tester<chat_log>
640 dialog_tester() : vcfg(cfg), r(rbase) {}
643 return new chat_log(vcfg, r);
648 struct dialog_tester<core_selection>
650 std::vector<config> cores;
655 core_selection* create()
657 return new core_selection(cores, 0);
662 struct dialog_tester<custom_tod>
664 std::vector<time_of_day> times;
672 return new custom_tod(times, current_tod);
677 struct dialog_tester<edit_label>
679 std::string label =
"Label text to modify";
680 bool team_only =
false;
683 return new edit_label(label, team_only);
688 struct dialog_tester<edit_text>
690 std::string text =
"text to modify";
693 return new edit_text(
"title",
"label", text);
698 struct dialog_tester<editor_edit_label>
700 std::string label =
"Label text to modify";
701 std::string category =
"test";
702 bool immutable =
false,
fog =
false,
shroud =
false;
704 editor_edit_label* create()
706 return new editor_edit_label(label, immutable,
fog,
shroud, color, category);
711 struct dialog_tester<editor_edit_scenario>
713 std::string id,
name, descr;
714 int turns = 0, xp_mod = 50;
715 bool defeat_enemies =
false, random_start =
false;
716 editor_edit_scenario* create()
718 return new editor_edit_scenario(
id, name, descr, turns, xp_mod, defeat_enemies, random_start);
723 struct dialog_tester<editor_edit_side>
727 dialog_tester() :
info(t) {}
728 editor_edit_side* create()
730 return new editor_edit_side(info);
735 struct dialog_tester<formula_debugger>
738 formula_debugger* create()
740 return new formula_debugger(debugger);
745 struct dialog_tester<game_load>
759 return new game_load(view, data);
765 struct dialog_tester<game_save>
767 std::string title =
"Title";
768 std::string filename =
"filename";
771 return new game_save(title, filename);
777 struct dialog_tester<game_save_message>
779 std::string title =
"Title";
780 std::string filename =
"filename";
781 std::string
message =
"message";
782 game_save_message* create()
784 return new game_save_message(title, filename, message);
790 struct dialog_tester<game_save_oos>
792 bool ignore_all =
false;
793 std::string title =
"Title";
794 std::string filename =
"filename";
795 std::string
message =
"message";
796 game_save_oos* create()
798 return new game_save_oos(ignore_all, title, filename, message);
805 struct dialog_tester<gamestate_inspector>
809 gamestate_inspector* create()
811 return new gamestate_inspector(vars, events, get_dummy_display_context(),
"Unit Test");
818 struct dialog_tester<install_dependencies>
821 install_dependencies* create()
823 return new install_dependencies(addons);
828 struct dialog_tester<hotkey_bind>
832 hotkey_bind* create()
834 return new hotkey_bind(
id);
839 struct dialog_tester<mp_lobby>
846 dialog_tester() : connection(
"",
""), li(installed_addons)
851 return new mp_lobby(li, connection, selected_game);
856 void add_chat_message(
const std::time_t&,
857 const std::string&,
int,
const std::string&,
859 void send_chat_message(
const std::string&,
bool) {}
860 void send_to_server(
const config&) {}
864 struct dialog_tester<lobby_player_info>
867 fake_chat_handler ch;
874 , ui(c), li(installed_addons)
877 lobby_player_info* create()
879 return new lobby_player_info(ch, ui, li);
884 struct dialog_tester<log_settings>
886 log_settings* create()
888 return new log_settings();
893 struct dialog_tester<message>
897 return new message(
"Title",
"Message",
false,
false,
false);
902 struct dialog_tester<mp_change_control>
904 mp_change_control* create()
906 return new mp_change_control(
nullptr);
912 struct dialog_tester<mp_create_game>
915 dialog_tester() : state(
config {
"campaign_type",
"multiplayer"})
918 mp_create_game* create()
920 return new mp_create_game(state,
true);
925 struct dialog_tester<mp_join_game_password_prompt>
928 mp_join_game_password_prompt* create()
930 return new mp_join_game_password_prompt(password);
934 static std::vector<std::string> depcheck_mods {
"mod_one",
"some other",
"more"};
937 struct dialog_tester<depcheck_confirm_change>
939 depcheck_confirm_change* create()
941 return new depcheck_confirm_change(
true, depcheck_mods,
"requester");
946 struct dialog_tester<depcheck_select_new>
948 depcheck_select_new* create()
955 struct dialog_tester<mp_login>
959 return new mp_login(
"wesnoth.org",
"label",
true);
964 struct dialog_tester<simple_item_selector>
966 simple_item_selector* create()
968 return new simple_item_selector(
"title",
"message", std::vector<std::string>(),
false,
false);
973 struct dialog_tester<screenshot_notification>
975 screenshot_notification* create()
977 return new screenshot_notification(
"path",
nullptr);
982 struct dialog_tester<theme_list>
992 static std::vector<theme_info> themes;
995 return new theme_list(themes, 0);
998 std::vector<theme_info> dialog_tester<theme_list>::themes {make_theme(
"classic"), make_theme(
"new"), make_theme(
"more"), make_theme(
"themes")};
1001 struct dialog_tester<editor_generate_map>
1003 std::vector<std::unique_ptr<map_generator>> map_generators;
1004 editor_generate_map* create()
1006 for(
const config &
i : main_config.child_range(
"multiplayer")) {
1007 if(
i[
"scenario_generation"] ==
"default") {
1008 const config &generator_cfg =
i.child(
"generator");
1009 if (generator_cfg) {
1015 editor_generate_map* result =
new editor_generate_map(map_generators);
1016 BOOST_REQUIRE_MESSAGE(result,
"Failed to create a dialog.");
1023 struct dialog_tester<editor_new_map>
1027 editor_new_map* create()
1029 return new editor_new_map(
"Test", width, height);
1034 struct dialog_tester<editor_resize_map>
1040 editor_resize_map* create()
1042 return new editor_resize_map(width, height, expand_direction, copy);
1047 struct dialog_tester<file_dialog>
1049 file_dialog* create()
1051 return new file_dialog();
1056 struct dialog_tester<folder_create>
1058 std::string folder_name;
1059 folder_create* create()
1061 return new folder_create(folder_name);
1066 struct dialog_tester<transient_message>
1068 transient_message* create()
1070 return new transient_message(
"Title",
false,
"Message",
false,
"");
1075 struct dialog_tester<title_screen>
1077 std::vector<std::string> args;
1080 dialog_tester() : opts(args), game(opts) {}
1081 title_screen* create()
1083 return new title_screen(game);
1088 struct dialog_tester<wml_error>
1090 static std::vector<std::string> files;
1093 return new wml_error(
"Summary",
"Post summary", files,
"Details");
1096 std::vector<std::string> dialog_tester<wml_error>::files {
"some",
"files",
"here"};
1099 struct dialog_tester<wml_message_left>
1101 wml_message_left* create()
1103 return new wml_message_left(
"Title",
"Message",
"",
false);
1108 struct dialog_tester<wml_message_right>
1110 wml_message_right* create()
1112 return new wml_message_right(
"Title",
"Message",
"",
false);
1117 struct dialog_tester<wml_message_double>
1119 wml_message_double* create()
1121 return new wml_message_double(
"Title",
"Message",
"",
false,
"",
true);
1126 struct dialog_tester<faction_select>
1128 config era_cfg, side_cfg;
1129 std::vector<const config*> eras;
1133 : era_cfg(), side_cfg(), eras(1, &era_cfg)
1134 , flg(eras, side_cfg,
false,
false,
false)
1137 faction_select* create() {
1138 return new faction_select(flg, color, 1);
1144 struct dialog_tester<game_stats>
1147 game_stats* create()
1149 return new game_stats(get_dummy_display_context(), 1, i);
1155 struct dialog_tester<generator_settings>
1159 dialog_tester() : data(cfg) {}
1160 generator_settings* create()
1162 return new generator_settings(data);
1167 struct dialog_tester<sp_options_configure>
1172 dialog_tester() : create_eng(state)
1174 sp_options_configure* create()
1176 return new sp_options_configure(create_eng, config_eng);
1181 struct dialog_tester<statistics_dialog>
1184 dialog_tester() :
t() {}
1185 statistics_dialog* create()
1187 return new statistics_dialog(t);
1192 struct dialog_tester<surrender_quit>
1195 surrender_quit* create()
1197 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()
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)
std::vector< std::string > installed_addons()
Retrieves the names of all installed add-ons.
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...
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)
std::stringstream & wml_error()
Use this logger to send errors due to deprecated WML.
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.
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.