The Battle for Wesnoth  1.17.4+dev
test_gui2.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2022
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 // In this domain since it compares a shared string from this domain.
17 #define GETTEXT_DOMAIN "wesnoth-lib"
18 
19 #include "addon/client.hpp"
20 #include "addon/info.hpp"
21 #include "config_cache.hpp"
22 #include "filesystem.hpp"
23 #include "formula/debugger.hpp"
24 #include "game_config.hpp"
25 #include "game_config_view.hpp"
26 #include "game_display.hpp"
27 #include "game_events/manager.hpp"
31 #include "game_launcher.hpp"
33 #include "gettext.hpp"
43 #include "gui/dialogs/chat_log.hpp"
76 #include "gui/dialogs/message.hpp"
89 #include "gui/dialogs/outro.hpp"
100 #include "gui/dialogs/tooltip.hpp"
105 #include "gui/dialogs/unit_list.hpp"
108 #include "gui/dialogs/wml_error.hpp"
110 #include "gui/widgets/settings.hpp"
111 #include "gui/widgets/window.hpp"
112 #include "language.hpp"
113 #include "map/map.hpp"
114 #include "replay.hpp"
115 #include "save_index.hpp"
116 #include "saved_game.hpp"
117 #include "terrain/type_data.hpp"
119 //#include "scripting/lua_kernel_base.hpp"
120 #include <functional>
121 #include "video.hpp"
122 #include "wesnothd_connection.hpp"
123 #include "wml_exception.hpp"
124 
125 #include <boost/test/unit_test.hpp>
126 
127 #include <memory>
128 
129 using namespace gui2::dialogs;
130 
131 namespace gui2 {
132 
133 static
134 std::set<std::string>& unit_test_registered_window_list()
135 {
136  static std::set<std::string> result = registered_window_types();
137  return result;
138 }
139 
140 namespace dialogs {
141 
142 std::string unit_test_mark_as_tested(const modal_dialog& dialog)
143 {
144  std::set<std::string>& list = unit_test_registered_window_list();
145  list.erase(dialog.window_id());
146  return dialog.window_id();
147 }
148 
150 {
151  std::set<std::string>& list = unit_test_registered_window_list();
152  list.erase(dialog.window_id());
153  return dialog.window_id();
154 }
155 
157 {
158  return dialog.window_.get();
159 }
160 
161 } // namespace dialogs
162 } // namespace gui2
163 
164 namespace {
165 
166  /** The main config, which contains the entire WML tree. */
167  config main_config;
168  game_config_view game_config_view_ = game_config_view::wrap(main_config);
169 
170  /**
171  * Helper class to generate a dialog.
172  *
173  * This class makes sure the dialog is properly created and initialized.
174  * The specialized versions are at the end of this file.
175  */
176  template<class T>
177  struct dialog_tester
178  {
179  T* create() { return new T(); }
180  };
181 
182  typedef std::pair<unsigned, unsigned> resolution;
183  typedef std::vector<std::pair<unsigned, unsigned>> resolution_list;
184 
185  template<class T>
186  void test_resolutions(const resolution_list& resolutions)
187  {
188  for(const resolution& resolution : resolutions) {
189  test_utils::get_fake_display(resolution.first, resolution.second);
190 
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.");
194 
195  const std::string id = unit_test_mark_as_tested(*(dlg.get()));
196 
197  std::string exception;
198  try {
199  dlg->show(1);
200  } catch(const gui2::layout_exception_width_modified&) {
201  exception = "gui2::layout_exception_width_modified";
203  exception = "gui2::layout_exception_width_resize_failed";
205  exception = "gui2::layout_exception_height_resize_failed";
206  } catch(const wml_exception& e) {
207  exception = e.dev_message;
208  } catch(const std::exception& e) {
209  exception = e.what();
210  } catch(...) {
211  exception = "unknown";
212  }
213  BOOST_CHECK_MESSAGE(exception.empty(),
214  "Test for '" << id
215  << "' Failed\nnew widgets = " << gui2::new_widgets
216  << " resolution = " << resolution.first
217  << 'x' << resolution.second
218  << "\nException caught: " << exception << '.');
219  }
220  }
221 
222  template<class T>
223  void test_popup_resolutions(const resolution_list& resolutions)
224  {
225  bool interact = false;
226  for(int i = 0; i < 2; ++i) {
227  for(const resolution& resolution : resolutions) {
228  test_utils::get_fake_display(resolution.first, resolution.second);
229 
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.");
233 
234  const std::string id = unit_test_mark_popup_as_tested(*(dlg.get()));
235 
236  std::string exception;
237  try {
238  dlg->show(interact);
239  gui2::window* window = unit_test_window((*dlg.get()));
240  BOOST_REQUIRE_NE(window, static_cast<void*>(nullptr));
241  window->draw();
242  } catch(const gui2::layout_exception_width_modified&) {
243  exception = "gui2::layout_exception_width_modified";
245  exception = "gui2::layout_exception_width_resize_failed";
247  exception = "gui2::layout_exception_height_resize_failed";
248  } catch(const wml_exception& e) {
249  exception = e.dev_message;
250  } catch(const std::exception& e) {
251  exception = e.what();
252  } catch(...) {
253  exception = "unknown";
254  }
255  BOOST_CHECK_MESSAGE(exception.empty(),
256  "Test for '" << id
257  << "' Failed\nnew widgets = " << gui2::new_widgets
258  << " resolution = " << resolution.first
259  << 'x' << resolution.second
260  << "\nException caught: " << exception << '.');
261  }
262 
263  interact = true;
264  }
265  }
266 
267 #ifdef _MSC_VER
268 #pragma warning(push)
269 #pragma warning(disable: 4702)
270 #endif
271  void test_tip_resolutions(const resolution_list& resolutions
272  , const std::string& id)
273  {
274  for(const auto& resolution : resolutions) {
275  test_utils::get_fake_display(resolution.first, resolution.second);
276 
277  std::set<std::string>& list = gui2::unit_test_registered_window_list();
278  list.erase(id);
279 
280  std::string exception;
281  try {
282  tip::show(id
283  , "Test message for a tooltip."
284  , point(0, 0)
285  , {0,0,0,0});
286  } catch(const gui2::layout_exception_width_modified&) {
287  exception = "gui2::layout_exception_width_modified";
289  exception = "gui2::layout_exception_width_resize_failed";
291  exception = "gui2::layout_exception_height_resize_failed";
292  } catch(const wml_exception& e) {
293  exception = e.dev_message;
294  } catch(const std::exception& e) {
295  exception = e.what();
296  } catch(...) {
297  exception = "unknown";
298  }
299  BOOST_CHECK_MESSAGE(exception.empty(),
300  "Test for tip '" << id
301  << "' Failed\nnew widgets = " << gui2::new_widgets
302  << " resolution = " << resolution.first
303  << 'x' << resolution.second
304  << "\nException caught: " << exception << '.');
305  }
306  }
307 #ifdef _MSC_VER
308 #pragma warning(pop)
309 #endif
310 
311 const resolution_list& get_gui_resolutions()
312 {
313  static resolution_list result {
314  {800, 600},
315  {1024, 768},
316  {1280, 1024},
317  {1680, 1050},
318  };
319 
320  return result;
321 }
322 
323 template<class T>
324 void test()
325 {
326  gui2::new_widgets = false;
327 
328 // for(std::size_t i = 0; i < 2; ++i) {
329 
330  test_resolutions<T>(get_gui_resolutions());
331 
332 // break; // FIXME: New widgets break
333 // gui2::new_widgets = true;
334 // }
335 }
336 
337 template<class T>
338 void test_popup()
339 {
340  gui2::new_widgets = false;
341 
342  for(std::size_t i = 0; i < 2; ++i) {
343 
344  test_popup_resolutions<T>(get_gui_resolutions());
345 
346  gui2::new_widgets = true;
347  }
348 }
349 
350 void test_tip(const std::string& id)
351 {
352  gui2::new_widgets = false;
353 
354  for(std::size_t i = 0; i < 2; ++i) {
355 
356  test_tip_resolutions(get_gui_resolutions(), id);
357 
358  gui2::new_widgets = true;
359  }
360 }
361 
362 #if 0
363 class dummy_display_context : public display_context
364 {
365 public:
366  dummy_display_context()
367  : dummy_cfg()
368  , m(std::make_shared<terrain_type_data>(dummy_cfg), "")
369  , u()
370  , t()
371  , lbls()
372  {
373  }
374 
375  virtual ~dummy_display_context(){}
376 
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; }
381 
382 private:
383  config dummy_cfg;
384 
385  gamemap m;
386  unit_map u;
387  std::vector<team> t;
388  std::vector<std::string> lbls;
389 };
390 
391 const display_context& get_dummy_display_context()
392 {
393  static const dummy_display_context dedc = dummy_display_context();
394  return dedc;
395 }
396 #endif
397 
398 } // namespace
399 
401 {
402  /**** Initialize the environment. *****/
404 
405  cache.clear_defines();
406  cache.add_define("EDITOR");
407  cache.add_define("MULTIPLAYER");
408  cache.get_config(game_config::path +"/data", main_config);
409 
410  const filesystem::binary_paths_manager bin_paths_manager(game_config_view_);
411 
413  game_config::load_config(main_config.child("game_config"));
414 
415  /**** Run the tests. *****/
416 
417  /* The modal_dialog classes. */
418  test<addon_auth>();
419  test<addon_connect>();
420  test<addon_license_prompt>();
421  //test<addon_manager>();
422  //test<attack_predictions>();
423  test<campaign_difficulty>();
424  test<campaign_selection>();
425  test<chat_log>();
426  test<core_selection>();
427  test<custom_tod>();
428  test<depcheck_confirm_change>();
429  test<depcheck_select_new>();
430  test<edit_label>();
431  test<edit_text>();
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>();
438  //test<end_credits>();
439  test<faction_select>();
440  test<file_dialog>();
441  test<folder_create>();
442  test<formula_debugger>();
443  test<game_cache_options>();
444  test<game_delete>();
445  test<game_load>();
446  test<game_version>();
447  test<game_save>();
448  test<game_save_message>();
449  test<game_save_oos>();
450  // test<game_stats>();
451  // test<gamestate_inspector>();
452  test<generator_settings>();
453  //test<help_browser>();
454  test<hotkey_bind>();
455  test<install_dependencies>();
456  test<language_selection>();
457  // test<loading_screen>(); TODO: enable
458  test<mp_lobby>();
459  test<lobby_player_info>();
460  test<log_settings>();
461  //test<lua_interpreter>(& lua_kernel_base());
462  test<message>();
463  test<mp_alerts_options>();
464  //test<mp_change_control>();
465  test<mp_connect>();
466  //test<mp_create_game>();
467  //test<mp_join_game>();
468  test<mp_join_game_password_prompt>();
469  test<mp_login>();
470  test<mp_method_selection>();
471  //test<mp_staging>();
472  //test<outro>();
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>();
479  //test<story_viewer>();
480  test<theme_list>();
481  //test<terrain_layers>();
482  //test<title_screen>();
483  test<transient_message>();
484  //test<unit_advance>();
485  //test<unit_attack>();
486  test<unit_create>();
487  //test<unit_list>();
488  //test<unit_recall>();
489  //test<unit_recruit>();
490  test<wml_error>();
491  test<wml_message_left>();
492  test<wml_message_right>();
493  test<wml_message_double>();
494 
495  /* The modeless_dialog classes. */
496  test_popup<debug_clock>();
497 
498  /* The tooltip classes. */
499  test_tip("tooltip_large");
500  test_tip("tooltip");
501 
502  std::set<std::string>& list = gui2::unit_test_registered_window_list();
503  std::set<std::string> omitted {
504  /*
505  * The unit attack unit test are disabled for now, they calling parameters
506  * don't allow 'nullptr's needs to be fixed.
507  */
508  "unit_attack",
509  // No test for this right now, not sure how to use the test system
510  // for dialog with no default constructor
511  "lua_interpreter",
512  /*
513  * Disable label settings dialog test because we need a display_context
514  * object, which we don't have, and it's a lot of work to produce a dummy
515  * one.
516  */
517  "label_settings",
518  "addon_uninstall_list",
519  "addon_manager",
520  "loading_screen",
521  "network_transmission",
522  "synched_choice_wait",
523  "drop_down_menu",
524  "preferences_dialog",
525  "unit_recruit",
526  "unit_recall",
527  "unit_list",
528  "unit_advance",
529  "mp_host_game_prompt",
530  "mp_create_game",
531  // The title screen appears to be throwing a bad_alloc on Travis, so disable it for now
532  "title_screen",
533  "end_credits",
534  "mp_staging",
535  "mp_join_game",
536  "terrain_layers",
537  "attack_predictions",
538  "help_browser",
539  "story_viewer",
540  "outro",
541  "mp_change_control", // Basically useless without a game_board object, so disabling
542  "game_stats", // segfault with LTO
543  "gamestate_inspector", // segfault with LTO
544  "server_info",
545  };
546 
547  std::vector<std::string> missing;
548  std::set_difference(list.begin(), list.end(), omitted.begin(), omitted.end(), std::back_inserter(missing));
549 
550  // Test size() instead of empty() to get the number of offenders
551  BOOST_CHECK_EQUAL(missing.size(), 0);
552  for(const std::string& id : missing) {
553  std::cerr << "Window '" << id << "' registered but not tested.\n";
554  }
555 }
556 
557 BOOST_AUTO_TEST_CASE(test_make_test_fake)
558 {
560 
561  try {
562  message dlg("title", "message", true, false, false);
563  dlg.show(1);
564  } catch(const wml_exception& e) {
565  BOOST_CHECK(e.user_message == _("Failed to show a dialog, "
566  "which doesn't fit on the screen."));
567  return;
568  } catch(...) {
569  }
570  BOOST_ERROR("Didn't catch the wanted exception.");
571 }
572 
573 namespace {
574 
575 template<>
576 struct dialog_tester<addon_auth>
577 {
578  config cfg;
579  addon_auth* create()
580  {
581  return new addon_auth(cfg);
582  }
583 };
584 
585 template<>
586 struct dialog_tester<addon_connect>
587 {
588  std::string host_name = "host_name";
589  addon_connect* create()
590  {
591  return new addon_connect(host_name, true);
592  }
593 };
594 
595 template<>
596 struct dialog_tester<addon_license_prompt>
597 {
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.
599 
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()
602  {
603  return new addon_license_prompt(license_terms);
604  }
605 };
606 
607 template<>
608 struct dialog_tester<addon_manager>
609 {
610  CVideo& video = test_utils::get_fake_display(10, 10).video();
611  dialog_tester()
612  {
613  }
614  addon_manager* create()
615  {
616  addons_client client("localhost:15999");
617  return new addon_manager(client);
618  }
619 };
620 
621 template<>
622 struct dialog_tester<campaign_difficulty>
623 {
624  campaign_difficulty* create()
625  {
626  const config items("difficulty");
627 
628  return new campaign_difficulty(items);
629  }
630 };
631 
632 template<>
633 struct dialog_tester<campaign_selection>
634 {
635  saved_game state;
637  dialog_tester() : state(config {"campaign_type", "scenario"}), ng(state)
638  {
639  }
640  campaign_selection* create()
641  {
642  return new campaign_selection(ng);
643  }
644 };
645 
646 template<>
647 struct dialog_tester<chat_log>
648 {
649  config cfg;
650  vconfig vcfg;
651  replay_recorder_base rbase;
652  replay r;
653  dialog_tester() : vcfg(cfg), r(rbase) {}
654  chat_log* create()
655  {
656  return new chat_log(vcfg, r);
657  }
658 };
659 
660 template<>
661 struct dialog_tester<core_selection>
662 {
663  std::vector<config> cores;
664  dialog_tester()
665  {
666  cores.resize(1);
667  }
668  core_selection* create()
669  {
670  return new core_selection(cores, 0);
671  }
672 };
673 
674 template<>
675 struct dialog_tester<custom_tod>
676 {
677  std::vector<time_of_day> times;
678  int current_tod = 0;
679  dialog_tester()
680  {
681  times.resize(1);
682  }
683  custom_tod* create()
684  {
685  return new custom_tod(times, current_tod);
686  }
687 };
688 
689 template<>
690 struct dialog_tester<edit_label>
691 {
692  std::string label = "Label text to modify";
693  bool team_only = false;
694  edit_label* create()
695  {
696  return new edit_label(label, team_only);
697  }
698 };
699 
700 template<>
701 struct dialog_tester<edit_text>
702 {
703  std::string text = "text to modify";
704  edit_text* create()
705  {
706  return new edit_text("title", "label", text);
707  }
708 };
709 
710 template<>
711 struct dialog_tester<editor_edit_label>
712 {
713  std::string label = "Label text to modify";
714  std::string category = "test";
715  bool immutable = false, fog = false, shroud = false;
716  color_t color;
717  editor_edit_label* create()
718  {
719  return new editor_edit_label(label, immutable, fog, shroud, color, category);
720  }
721 };
722 
723 template<>
724 struct dialog_tester<editor_edit_scenario>
725 {
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()
730  {
731  return new editor_edit_scenario(id, name, descr, turns, xp_mod, defeat_enemies, random_start);
732  }
733 };
734 
735 template<>
736 struct dialog_tester<editor_edit_side>
737 {
738  team t;
740  dialog_tester() : info(t) {}
741  editor_edit_side* create()
742  {
743  return new editor_edit_side(info);
744  }
745 };
746 
747 template<>
748 struct dialog_tester<formula_debugger>
749 {
750  wfl::formula_debugger debugger;
751  formula_debugger* create()
752  {
753  return new formula_debugger(debugger);
754  }
755 };
756 
757 template<>
758 struct dialog_tester<game_load>
759 {
760  config cfg;
761  game_config_view view;
762  // It would be good to have a test directory instead of using the same directory as the player,
763  // however this code will support that - default_saves_dir() will respect --userdata-dir.
765  dialog_tester()
766  {
767  /** @todo Would be nice to add real data to the config. */
768  }
769  game_load* create()
770  {
771  view = game_config_view::wrap(cfg);
772  return new game_load(view, data);
773  }
774 
775 };
776 
777 template<>
778 struct dialog_tester<game_save>
779 {
780  std::string title = "Title";
781  std::string filename = "filename";
782  game_save* create()
783  {
784  return new game_save(title, filename);
785  }
786 
787 };
788 
789 template<>
790 struct dialog_tester<game_save_message>
791 {
792  std::string title = "Title";
793  std::string filename = "filename";
794  std::string message = "message";
795  game_save_message* create()
796  {
797  return new game_save_message(title, filename, message);
798  }
799 
800 };
801 
802 template<>
803 struct dialog_tester<game_save_oos>
804 {
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()
810  {
811  return new game_save_oos(ignore_all, title, filename, message);
812  }
813 
814 };
815 
816 #if 0
817 template<>
818 struct dialog_tester<gamestate_inspector>
819 {
820  config vars;
822  gamestate_inspector* create()
823  {
824  return new gamestate_inspector(vars, events, get_dummy_display_context(), "Unit Test");
825  }
826 
827 };
828 #endif
829 
830 template<>
831 struct dialog_tester<install_dependencies>
832 {
833  addons_list addons;
834  install_dependencies* create()
835  {
836  return new install_dependencies(addons);
837  }
838 };
839 
840 template<>
841 struct dialog_tester<hotkey_bind>
842 {
843  std::string id = "";
844 
845  hotkey_bind* create()
846  {
847  return new hotkey_bind(id);
848  }
849 };
850 
851 template<>
852 struct dialog_tester<mp_lobby>
853 {
855  wesnothd_connection connection;
856  mp::lobby_info li;
857  int selected_game;
858  dialog_tester() : connection("", ""), li()
859  {
860  }
861  mp_lobby* create()
862  {
863  return new mp_lobby(li, connection, selected_game);
864  }
865 };
866 
867 class fake_chat_handler : public events::chat_handler {
868  void add_chat_message(const std::time_t&,
869  const std::string&, int, const std::string&,
870  MESSAGE_TYPE) {}
871  void send_chat_message(const std::string&, bool) {}
872  void send_to_server(const config&) {}
873  void clear_messages() {}
874 };
875 
876 template<>
877 struct dialog_tester<lobby_player_info>
878 {
879  config c;
880  fake_chat_handler ch;
881  wesnothd_connection connection;
882  mp::user_info ui;
883  mp::lobby_info li;
884  dialog_tester()
885  : connection("", "")
886  , ui(c), li()
887  {
888  }
889  lobby_player_info* create()
890  {
891  return new lobby_player_info(ch, ui, li);
892  }
893 };
894 
895 template<>
896 struct dialog_tester<log_settings>
897 {
898  log_settings* create()
899  {
900  return new log_settings();
901  }
902 };
903 
904 template<>
905 struct dialog_tester<message>
906 {
907  message* create()
908  {
909  return new message("Title", "Message", false, false, false);
910  }
911 };
912 #if 0
913 template<>
914 struct dialog_tester<mp_change_control>
915 {
916  mp_change_control* create()
917  {
918  return new mp_change_control(nullptr);
919  }
920 };
921 #endif
922 
923 template<>
924 struct dialog_tester<mp_create_game>
925 {
926  saved_game state;
927  dialog_tester() : state(config {"campaign_type", "multiplayer"})
928  {
929  }
930  mp_create_game* create()
931  {
932  return new mp_create_game(state, true);
933  }
934 };
935 
936 template<>
937 struct dialog_tester<mp_join_game_password_prompt>
938 {
939  std::string password;
940  mp_join_game_password_prompt* create()
941  {
942  return new mp_join_game_password_prompt(password);
943  }
944 };
945 
946 static std::vector<std::string> depcheck_mods {"mod_one", "some other", "more"};
947 
948 template<>
949 struct dialog_tester<depcheck_confirm_change>
950 {
951  depcheck_confirm_change* create()
952  {
953  return new depcheck_confirm_change(true, depcheck_mods, "requester");
954  }
955 };
956 
957 template<>
958 struct dialog_tester<depcheck_select_new>
959 {
960  depcheck_select_new* create()
961  {
962  return new depcheck_select_new(ng::depcheck::MODIFICATION, depcheck_mods);
963  }
964 };
965 
966 template<>
967 struct dialog_tester<mp_login>
968 {
969  mp_login* create()
970  {
971  return new mp_login("wesnoth.org", "label", true);
972  }
973 };
974 
975 template<>
976 struct dialog_tester<simple_item_selector>
977 {
978  simple_item_selector* create()
979  {
980  return new simple_item_selector("title", "message", std::vector<std::string>(), false, false);
981  }
982 };
983 
984 template<>
985 struct dialog_tester<screenshot_notification>
986 {
987  screenshot_notification* create()
988  {
989  return new screenshot_notification("path", nullptr);
990  }
991 };
992 
993 template<>
994 struct dialog_tester<theme_list>
995 {
996  static theme_info make_theme(const std::string& name)
997  {
998  theme_info ti;
999  ti.id = name;
1000  ti.name = name;
1001  ti.description = name + " this is a description";
1002  return ti;
1003  }
1004  static std::vector<theme_info> themes;
1005  theme_list* create()
1006  {
1007  return new theme_list(themes, 0);
1008  }
1009 };
1010 std::vector<theme_info> dialog_tester<theme_list>::themes {make_theme("classic"), make_theme("new"), make_theme("more"), make_theme("themes")};
1011 
1012 template<>
1013 struct dialog_tester<editor_generate_map>
1014 {
1015  std::vector<std::unique_ptr<map_generator>> map_generators;
1016  editor_generate_map* create()
1017  {
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) {
1022  map_generators.emplace_back(create_map_generator("", generator_cfg));
1023  }
1024  }
1025  }
1026 
1027  editor_generate_map* result = new editor_generate_map(map_generators);
1028  BOOST_REQUIRE_MESSAGE(result, "Failed to create a dialog.");
1029 
1030  return result;
1031  }
1032 };
1033 
1034 template<>
1035 struct dialog_tester<editor_new_map>
1036 {
1037  int width = 10;
1038  int height = 10;
1039  editor_new_map* create()
1040  {
1041  return new editor_new_map("Test", width, height);
1042  }
1043 };
1044 
1045 template<>
1046 struct dialog_tester<editor_resize_map>
1047 {
1048  int width = 0;
1049  int height = 0;
1051  bool copy = false;
1052  editor_resize_map* create()
1053  {
1054  return new editor_resize_map(width, height, expand_direction, copy);
1055  }
1056 };
1057 
1058 template<>
1059 struct dialog_tester<file_dialog>
1060 {
1061  file_dialog* create()
1062  {
1063  return new file_dialog();
1064  }
1065 };
1066 
1067 template<>
1068 struct dialog_tester<folder_create>
1069 {
1070  std::string folder_name;
1071  folder_create* create()
1072  {
1073  return new folder_create(folder_name);
1074  }
1075 };
1076 
1077 template<>
1078 struct dialog_tester<transient_message>
1079 {
1080  transient_message* create()
1081  {
1082  return new transient_message("Title", false, "Message", false, "");
1083  }
1084 };
1085 
1086 template<>
1087 struct dialog_tester<title_screen>
1088 {
1089  std::vector<std::string> args;
1090  commandline_options opts;
1092  dialog_tester() : opts(args), game(opts) {}
1093  title_screen* create()
1094  {
1095  return new title_screen(game);
1096  }
1097 };
1098 
1099 template<>
1100 struct dialog_tester<wml_error>
1101 {
1102  static std::vector<std::string> files;
1103  wml_error* create()
1104  {
1105  return new wml_error("Summary", "Post summary", files, "Details");
1106  }
1107 };
1108 std::vector<std::string> dialog_tester<wml_error>::files {"some", "files", "here"};
1109 
1110 template<>
1111 struct dialog_tester<wml_message_left>
1112 {
1113  wml_message_left* create()
1114  {
1115  return new wml_message_left("Title", "Message", "", false);
1116  }
1117 };
1118 
1119 template<>
1120 struct dialog_tester<wml_message_right>
1121 {
1122  wml_message_right* create()
1123  {
1124  return new wml_message_right("Title", "Message", "", false);
1125  }
1126 };
1127 
1128 template<>
1129 struct dialog_tester<wml_message_double>
1130 {
1131  wml_message_double* create()
1132  {
1133  return new wml_message_double("Title", "Message", "", false, "", true);
1134  }
1135 };
1136 
1137 template<>
1138 struct dialog_tester<faction_select>
1139 {
1140  config era_cfg, side_cfg;
1141  std::vector<const config*> eras;
1142  ng::flg_manager flg;
1143  std::string color;
1144  dialog_tester()
1145  : era_cfg(), side_cfg(), eras(1, &era_cfg) // TODO: Add an actual era definition
1146  , flg(eras, side_cfg, false, false, false)
1147  , color("teal")
1148  {}
1149  faction_select* create() {
1150  return new faction_select(flg, color, 1);
1151  }
1152 };
1153 
1154 #if 0
1155 template<>
1156 struct dialog_tester<game_stats>
1157 {
1158  int i = 1;
1159  game_stats* create()
1160  {
1161  return new game_stats(get_dummy_display_context(), 1, i);
1162  }
1163 };
1164 #endif
1165 
1166 template<>
1167 struct dialog_tester<generator_settings>
1168 {
1169  config cfg;
1170  generator_data data;
1171  dialog_tester() : data(cfg) {}
1172  generator_settings* create()
1173  {
1174  return new generator_settings(data);
1175  }
1176 };
1177 
1178 template<>
1179 struct dialog_tester<sp_options_configure>
1180 {
1181  saved_game state;
1182  ng::create_engine create_eng;
1183  ng::configure_engine config_eng;
1184  dialog_tester() : create_eng(state)
1185  , config_eng(create_eng.get_state()) {}
1186  sp_options_configure* create()
1187  {
1188  return new sp_options_configure(create_eng, config_eng);
1189  }
1190 };
1191 
1192 template<>
1193 struct dialog_tester<statistics_dialog>
1194 {
1195  team t;
1196  dialog_tester() : t() {}
1197  statistics_dialog* create()
1198  {
1199  return new statistics_dialog(t);
1200  }
1201 };
1202 
1203 template<>
1204 struct dialog_tester<surrender_quit>
1205 {
1206  dialog_tester() {}
1207  surrender_quit* create()
1208  {
1209  return new surrender_quit();
1210  }
1211 };
1212 
1213 } // namespace
bool new_widgets
Do we wish to use the new library or not.
Definition: settings.cpp:25
t_string description
Definition: theme.hpp:38
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)
Definition: test_gui2.cpp:156
configure_engine
saved_game & get_state()
Add a special kind of assert to validate whether the input from WML doesn&#39;t contain any problems that...
Main class to show messages to the user.
Definition: message.hpp:35
static game_config_view wrap(const config &cfg)
Formula AI debugger.
logger & info()
Definition: log.cpp:89
static std::shared_ptr< save_index_class > default_saves_dir()
Returns an instance for managing saves in filesystem::get_saves_dir()
Definition: save_index.cpp:210
std::string id
Definition: theme.hpp:36
Definition: video.hpp:36
game_display & get_fake_display(const int width, const int height)
Gets a fake test display.
t_string name
Definition: theme.hpp:37
Exception thrown when the height resizing has failed.
This file contains the window object, this object is a top level container which has the event manage...
void draw()
Draws the window.
Definition: window.cpp:605
The paths manager is responsible for recording the various paths that binary files may be located at...
Definition: filesystem.hpp:400
This class represents the collective information the client has about the players and games on the se...
Definition: lobby_info.hpp:31
std::string user_message
The message for the user explaining what went wrong.
const std::vector< std::string > items
Replay control code.
static std::string _(const char *str)
Definition: gettext.hpp:93
FLG stands for faction, leader and gender.
Definition: flg_manager.hpp:29
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.
Generic file dialog.
Definition: field-fwd.hpp:23
bool fog()
Definition: game.cpp:525
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:75
Exception thrown when the width has been modified during resizing.
static std::set< std::string > & unit_test_registered_window_list()
Definition: test_gui2.cpp:134
std::string label
What to show in the filter&#39;s drop-down list.
Definition: manager.cpp:217
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.
Definition: map.hpp:171
std::string unit_test_mark_as_tested(const modal_dialog &dialog)
Definition: test_gui2.cpp:142
Exception thrown when the width resizing has failed.
std::string path
Definition: game_config.cpp:39
Add-ons (campaignd) client class.
Definition: client.hpp:40
Various uncategorised dialogs.
BOOST_AUTO_TEST_CASE(test_gui2)
Definition: test_gui2.cpp:400
Helper class, don&#39;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&#39;t be translated...
bool shroud()
Definition: game.cpp:535
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:215
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)
Definition: map_create.cpp:29
std::size_t i
Definition: function.cpp:967
Game configuration data as global variables.
Definition: build_info.cpp:60
std::unique_ptr< window > window_
The window, used in show.
static tcache cache
Definition: minimap.cpp:125
std::string password(const std::string &server, const std::string &login)
bool load_language_list()
Definition: language.cpp:104
Holds a 2D point.
Definition: point.hpp:24
Declarations for File-IO.
The game event manager loads the scenario configuration object, and ensures that events are handled a...
Definition: manager.hpp:44
std::string unit_test_mark_popup_as_tested(const modeless_dialog &dialog)
Definition: test_gui2.cpp:149
virtual const std::string & window_id() const =0
The id of the window to build.
Handling of system events.
Definition: manager.hpp:43
This class represents the information a client has about another player.
Definition: lobby_data.hpp:32
int turns()
Definition: game.cpp:545
double t
Definition: astarsearch.cpp:65
The popup class shows windows that are shown non-modal.
A variable-expanding proxy for the config class.
Definition: variable.hpp:44
Abstract base class for all modal dialogs.
CVideo & video()
Gets the underlying screen object.
Definition: display.hpp:205
Container associating units to locations.
Definition: map.hpp:98
point resolution()
Definition: general.cpp:399
#define e
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.
Definition: config.hpp:60
mock_char c
std::map< std::string, addon_info > addons_list
Definition: info.hpp:28
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:66
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.
Definition: tooltip.cpp:140
Singleton class to manage game config file caching.