17 #define GETTEXT_DOMAIN "wesnoth-lib" 128 #include <boost/test/unit_test.hpp> 130 #include <functional> 138 , dummy_args({
"wesnoth",
"--noaddons"})
195 T* create() {
return new T(); }
198 typedef std::pair<unsigned, unsigned>
resolution;
199 typedef std::vector<std::pair<unsigned, unsigned>> resolution_list;
202 void test_resolutions(
const resolution_list& resolutions)
204 for(
const resolution& resolution : resolutions) {
207 dialog_tester<T> ctor;
208 const std::unique_ptr<modal_dialog> dlg(ctor.create());
209 BOOST_REQUIRE_MESSAGE(dlg.get(),
"Failed to create a dialog.");
214 std::string exception;
218 exception =
"gui2::layout_exception_width_modified";
220 exception =
"gui2::layout_exception_width_resize_failed";
222 exception =
"gui2::layout_exception_height_resize_failed";
225 }
catch(
const std::exception& e) {
226 exception = e.what();
230 BOOST_CHECK_MESSAGE(exception.empty(),
233 <<
" resolution = " << resolution.first
234 <<
'x' << resolution.second
235 <<
"\nException caught: " << exception <<
'.');
240 void test_popup_resolutions(
const resolution_list& resolutions)
242 bool interact =
false;
243 for(
int i = 0;
i < 2; ++
i) {
244 for(
const resolution& resolution : resolutions) {
246 if(resolution.first == 800 && resolution.second == 600) {
251 dialog_tester<T> ctor;
252 const std::unique_ptr<modeless_dialog> dlg(ctor.create());
253 BOOST_REQUIRE_MESSAGE(dlg.get(),
"Failed to create a dialog.");
258 std::string exception;
262 BOOST_REQUIRE_NE(window, static_cast<void*>(
nullptr));
265 exception =
"gui2::layout_exception_width_modified";
267 exception =
"gui2::layout_exception_width_resize_failed";
269 exception =
"gui2::layout_exception_height_resize_failed";
272 }
catch(
const std::exception& e) {
273 exception = e.what();
277 BOOST_CHECK_MESSAGE(exception.empty(),
280 <<
" resolution = " << resolution.first
281 <<
'x' << resolution.second
282 <<
"\nException caught: " << exception <<
'.');
290 #pragma warning(push) 291 #pragma warning(disable: 4702) 293 void test_tip_resolutions(
const resolution_list& resolutions
294 ,
const std::string&
id)
296 for(
const auto& resolution : resolutions) {
301 std::string exception;
304 ,
"Test message for a tooltip." 309 exception =
"gui2::layout_exception_width_modified";
311 exception =
"gui2::layout_exception_width_resize_failed";
313 exception =
"gui2::layout_exception_height_resize_failed";
316 }
catch(
const std::exception& e) {
317 exception = e.what();
321 BOOST_CHECK_MESSAGE(exception.empty(),
322 "Test for tip '" <<
id 324 <<
" resolution = " << resolution.first
325 <<
'x' << resolution.second
326 <<
"\nException caught: " << exception <<
'.');
333 const resolution_list& get_gui_resolutions()
335 static resolution_list result {
352 test_resolutions<T>(get_gui_resolutions());
364 for(std::size_t
i = 0;
i < 2; ++
i) {
366 test_popup_resolutions<T>(get_gui_resolutions());
372 void test_tip(
const std::string&
id)
376 for(std::size_t
i = 0;
i < 2; ++
i) {
378 test_tip_resolutions(get_gui_resolutions(),
id);
394 test<addon_connect>();
398 test<addon_license_prompt>();
402 test<campaign_difficulty>();
410 test<core_selection>();
418 test<depcheck_confirm_change>();
422 test<depcheck_select_new>();
434 test<editor_edit_label>();
438 test<editor_edit_side>();
442 test<editor_edit_scenario>();
446 test<editor_generate_map>();
450 test<editor_new_map>();
454 test<editor_resize_map>();
458 test<faction_select>();
466 test<folder_create>();
470 test<formula_debugger>();
474 test<game_cache_options>();
482 test<game_version>();
490 test<game_save_message>();
494 test<game_save_oos>();
498 test<generator_settings>();
506 test<install_dependencies>();
510 test<language_selection>();
518 test<lobby_player_info>();
522 test<log_settings>();
530 test<mp_alerts_options>();
538 test<mp_join_game_password_prompt>();
546 test<mp_method_selection>();
554 test<simple_item_selector>();
558 test<screenshot_notification>();
562 test<select_orb_colors>();
566 test<statistics_dialog>();
570 test<surrender_quit>();
578 test<transient_message>();
590 test<wml_message_left>();
594 test<wml_message_right>();
598 test<wml_message_double>();
602 test<achievements_dialog>();
606 test<mp_match_history>();
610 test_popup<debug_clock>();
614 test_tip(
"tooltip_large");
626 std::set<std::string> omitted {
641 "addon_uninstall_list",
644 "network_transmission",
645 "synched_choice_wait",
647 "preferences_dialog",
652 "mp_host_game_prompt",
660 "attack_predictions",
666 "gamestate_inspector",
668 "sp_options_configure",
669 "campaign_selection",
675 for(
const std::string&
item : widgets_tested)
677 widget_list.erase(
item);
679 BOOST_CHECK_EQUAL(omitted.count(item), 0);
681 for(
const std::string&
item : omitted)
683 widget_list.erase(
item);
687 BOOST_CHECK_EQUAL(widget_list.size(), 0);
688 for(
const std::string&
id : widget_list) {
689 PLAIN_LOG <<
"Window '" <<
id <<
"' registered but not tested.";
698 message dlg(
"title",
"message",
true,
false,
false);
701 BOOST_CHECK(e.
user_message ==
_(
"Failed to show a dialog, which doesn't fit on the screen."));
706 BOOST_ERROR(
"Didn't catch the wanted exception, instead caught nothing.");
709 BOOST_AUTO_TEST_SUITE_END()
714 struct dialog_tester<addon_auth>
719 return new addon_auth(cfg);
724 struct dialog_tester<addon_connect>
726 std::string host_name =
"host_name";
727 addon_connect* create()
729 return new addon_connect(host_name,
true);
734 struct dialog_tester<addon_license_prompt>
736 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. 738 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.)"""; 739 addon_license_prompt* create() 741 return new addon_license_prompt(license_terms);
746 struct dialog_tester<addon_manager>
752 addon_manager* create()
755 return new addon_manager(client);
760 struct dialog_tester<campaign_difficulty>
762 campaign_difficulty* create()
766 return new campaign_difficulty(items);
771 struct dialog_tester<campaign_selection>
775 dialog_tester() : state(
config {
"campaign_type",
"scenario"}), ng(state)
778 campaign_selection* create()
780 return new campaign_selection(ng);
785 struct dialog_tester<chat_log>
791 dialog_tester() : vcfg(cfg), r(rbase) {}
794 return new chat_log(vcfg, r);
799 struct dialog_tester<core_selection>
801 std::vector<config> cores;
806 core_selection* create()
808 return new core_selection(cores, 0);
813 struct dialog_tester<custom_tod>
815 std::vector<time_of_day> times;
823 return new custom_tod(times, current_tod);
828 struct dialog_tester<edit_label>
830 std::string
label =
"Label text to modify";
831 bool team_only =
false;
834 return new edit_label(label, team_only);
839 struct dialog_tester<edit_text>
841 std::string text =
"text to modify";
844 return new edit_text(
"title",
"label", text);
849 struct dialog_tester<editor_edit_label>
851 std::string
label =
"Label text to modify";
852 std::string category =
"test";
853 bool immutable =
false,
fog =
false,
shroud =
false;
855 editor_edit_label* create()
857 return new editor_edit_label(label, immutable,
fog,
shroud, color, category);
862 struct dialog_tester<editor_edit_scenario>
864 std::string
id, name, descr;
865 int turns = 0, xp_mod = 50;
866 bool defeat_enemies =
false, random_start =
false;
867 editor_edit_scenario* create()
869 return new editor_edit_scenario(
id, name, descr, turns, xp_mod, defeat_enemies, random_start);
874 struct dialog_tester<editor_edit_side>
878 dialog_tester() :
info(t) {}
879 editor_edit_side* create()
881 return new editor_edit_side(info);
886 struct dialog_tester<formula_debugger>
889 formula_debugger* create()
891 return new formula_debugger(debugger);
896 struct dialog_tester<game_load>
910 return new game_load(view,
data);
916 struct dialog_tester<game_save>
918 std::string title =
"Title";
919 std::string filename =
"filename";
922 return new game_save(title, filename);
928 struct dialog_tester<game_save_message>
930 std::string title =
"Title";
931 std::string filename =
"filename";
932 std::string
message =
"message";
933 game_save_message* create()
935 return new game_save_message(title, filename, message);
941 struct dialog_tester<game_save_oos>
943 bool ignore_all =
false;
944 std::string title =
"Title";
945 std::string filename =
"filename";
946 std::string
message =
"message";
947 game_save_oos* create()
949 return new game_save_oos(ignore_all, title, filename, message);
955 struct dialog_tester<install_dependencies>
958 install_dependencies* create()
960 return new install_dependencies(addons);
965 struct dialog_tester<hotkey_bind>
969 hotkey_bind* create()
971 return new hotkey_bind(
id);
976 struct dialog_tester<mp_lobby>
982 dialog_tester() : connection(
"",
""), li()
987 return new mp_lobby(li, connection, selected_game);
992 struct dialog_tester<mp_match_history>
995 dialog_tester() : connection(
"",
"")
998 mp_match_history* create()
1000 return new mp_match_history(
"", connection,
false);
1005 void add_chat_message(
const std::time_t&,
1006 const std::string&,
int,
const std::string&,
1008 void send_chat_message(
const std::string&,
bool) {}
1010 void clear_messages() {}
1014 struct dialog_tester<lobby_player_info>
1017 fake_chat_handler ch;
1022 : connection(
"",
"")
1026 lobby_player_info* create()
1028 return new lobby_player_info(ch, ui, li);
1033 struct dialog_tester<log_settings>
1035 log_settings* create()
1037 return new log_settings();
1042 struct dialog_tester<message>
1046 return new message(
"Title",
"Message",
false,
false,
false);
1051 struct dialog_tester<mp_create_game>
1054 dialog_tester() : state(
config {
"campaign_type",
"multiplayer"})
1057 mp_create_game* create()
1059 return new mp_create_game(state,
true);
1064 struct dialog_tester<mp_join_game_password_prompt>
1067 mp_join_game_password_prompt* create()
1069 return new mp_join_game_password_prompt(password);
1074 struct dialog_tester<mp_report>
1076 std::string report_text;
1079 return new mp_report(report_text);
1083 static std::vector<std::string> depcheck_mods {
"mod_one",
"some other",
"more"};
1086 struct dialog_tester<depcheck_confirm_change>
1088 depcheck_confirm_change* create()
1090 return new depcheck_confirm_change(
true, depcheck_mods,
"requester");
1095 struct dialog_tester<depcheck_select_new>
1097 depcheck_select_new* create()
1104 struct dialog_tester<mp_login>
1108 return new mp_login(
"wesnoth.org",
"label",
true);
1113 struct dialog_tester<simple_item_selector>
1115 simple_item_selector* create()
1117 return new simple_item_selector(
"title",
"message", std::vector<std::string>(),
false,
false);
1122 struct dialog_tester<screenshot_notification>
1124 screenshot_notification* create()
1126 return new screenshot_notification(
"path",
nullptr);
1131 struct dialog_tester<theme_list>
1133 static theme_info make_theme(
const std::string& name)
1141 static std::vector<theme_info> themes;
1142 theme_list* create()
1144 return new theme_list(themes, 0);
1147 std::vector<theme_info> dialog_tester<theme_list>::themes {make_theme(
"classic"), make_theme(
"new"), make_theme(
"more"), make_theme(
"themes")};
1150 struct dialog_tester<editor_generate_map>
1152 std::vector<std::unique_ptr<map_generator>> map_generators;
1153 editor_generate_map* create()
1155 for(
const config &
i : test_gui2_fixture::main_config.child_range(
"multiplayer")) {
1156 if(
i[
"scenario_generation"] ==
"default") {
1157 const config &generator_cfg =
i.child(
"generator");
1158 if (generator_cfg) {
1164 editor_generate_map* result =
new editor_generate_map(map_generators);
1165 BOOST_REQUIRE_MESSAGE(result,
"Failed to create a dialog.");
1172 struct dialog_tester<editor_new_map>
1176 editor_new_map* create()
1178 return new editor_new_map(
"Test", width, height);
1183 struct dialog_tester<editor_resize_map>
1189 editor_resize_map* create()
1191 return new editor_resize_map(width, height, expand_direction, copy);
1196 struct dialog_tester<file_dialog>
1198 file_dialog* create()
1200 return new file_dialog();
1205 struct dialog_tester<folder_create>
1207 std::string folder_name;
1208 folder_create* create()
1210 return new folder_create(folder_name);
1215 struct dialog_tester<transient_message>
1217 transient_message* create()
1219 return new transient_message(
"Title",
false,
"Message",
false,
"");
1224 struct dialog_tester<title_screen>
1226 std::vector<std::string> args;
1229 dialog_tester() : opts(args), game(opts) {}
1230 title_screen* create()
1232 return new title_screen(game);
1237 struct dialog_tester<wml_error>
1239 static std::vector<std::string> files;
1242 return new wml_error(
"Summary",
"Post summary", files,
"Details");
1245 std::vector<std::string> dialog_tester<wml_error>::files {
"some",
"files",
"here"};
1248 struct dialog_tester<wml_message_left>
1250 wml_message_left* create()
1252 return new wml_message_left(
"Title",
"Message",
"",
false);
1257 struct dialog_tester<wml_message_right>
1259 wml_message_right* create()
1261 return new wml_message_right(
"Title",
"Message",
"",
false);
1266 struct dialog_tester<wml_message_double>
1268 wml_message_double* create()
1270 return new wml_message_double(
"Title",
"Message",
"",
false,
"",
true);
1275 struct dialog_tester<faction_select>
1277 config era_cfg, side_cfg;
1278 std::vector<const config*> eras;
1282 : era_cfg(), side_cfg(), eras(1, &era_cfg)
1283 , flg(eras, side_cfg,
false,
false,
false)
1286 faction_select* create() {
1287 return new faction_select(flg, color, 1);
1292 struct dialog_tester<generator_settings>
1296 dialog_tester() :
data(cfg) {}
1297 generator_settings* create()
1299 return new generator_settings(data);
1304 struct dialog_tester<sp_options_configure>
1309 dialog_tester() : create_eng(state)
1311 sp_options_configure* create()
1313 return new sp_options_configure(create_eng, config_eng);
1318 struct dialog_tester<statistics_dialog>
1321 dialog_tester() :
t() {}
1322 statistics_dialog* create()
1324 return new statistics_dialog(t);
1329 struct dialog_tester<surrender_quit>
1332 surrender_quit* create()
1334 return new surrender_quit();
bool new_widgets
Do we wish to use the new library or not.
void remove()
Removes a tip.
Defines the exception classes for the layout algorithm.
static config_cache & instance()
Get reference to the singleton object.
static config main_config
std::string get_modeless_dialog_id(const modeless_dialog &dialog)
bool delete_file(const std::string &filename)
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.
std::unique_ptr< game_config_manager > config_manager
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
std::string get_unknown_exception_type()
Utility function for finding the type of thing caught with catch(...).
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)
BOOST_FIXTURE_TEST_SUITE(test_map_location, MLFixture)
This class stores all the data for a single 'side' (in game nomenclature).
static const std::string widgets_file
Exception thrown when the width has been modified during resizing.
BOOST_AUTO_TEST_CASE(modal_dialog_test_addon_auth)
std::string label
What to show in the filter's drop-down list.
This file contains the settings handling of the widget library.
virtual const std::string & window_id() const
The ID of the window to build.
A class that represents a TCP/IP connection to the wesnothd server.
The basic class for representing 8-bit RGB or RGBA colour values.
Exception thrown when the width resizing has failed.
std::string read_file(const std::string &fname)
Basic disk I/O - read file.
Add-ons (campaignd) client class.
Various uncategorised dialogs.
std::vector< std::string > dummy_args
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 write_file(const std::string &fname, const std::string &data, std::ios_base::openmode mode)
Throws io_exception if an error occurs.
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::string get_modal_dialog_id(const modal_dialog &dialog)
std::string password(const std::string &server, const std::string &login)
bool load_language_list()
Declarations for File-IO.
virtual const std::string & window_id() const =0
The ID of the window to build.
This class represents the information a client has about another player.
std::vector< std::string > split(const config_attribute_value &val)
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.
void point(int x, int y)
Draw a single point.
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.
std::pair< std::string, unsigned > item
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.