The Battle for Wesnoth  1.17.0-dev
test_gui2.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2021
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 };
874 
875 template<>
876 struct dialog_tester<lobby_player_info>
877 {
878  config c;
879  fake_chat_handler ch;
880  wesnothd_connection connection;
881  mp::user_info ui;
882  mp::lobby_info li;
883  dialog_tester()
884  : connection("", "")
885  , ui(c), li()
886  {
887  }
888  lobby_player_info* create()
889  {
890  return new lobby_player_info(ch, ui, li);
891  }
892 };
893 
894 template<>
895 struct dialog_tester<log_settings>
896 {
897  log_settings* create()
898  {
899  return new log_settings();
900  }
901 };
902 
903 template<>
904 struct dialog_tester<message>
905 {
906  message* create()
907  {
908  return new message("Title", "Message", false, false, false);
909  }
910 };
911 #if 0
912 template<>
913 struct dialog_tester<mp_change_control>
914 {
915  mp_change_control* create()
916  {
917  return new mp_change_control(nullptr);
918  }
919 };
920 #endif
921 
922 template<>
923 struct dialog_tester<mp_create_game>
924 {
925  saved_game state;
926  dialog_tester() : state(config {"campaign_type", "multiplayer"})
927  {
928  }
929  mp_create_game* create()
930  {
931  return new mp_create_game(state, true);
932  }
933 };
934 
935 template<>
936 struct dialog_tester<mp_join_game_password_prompt>
937 {
938  std::string password;
939  mp_join_game_password_prompt* create()
940  {
941  return new mp_join_game_password_prompt(password);
942  }
943 };
944 
945 static std::vector<std::string> depcheck_mods {"mod_one", "some other", "more"};
946 
947 template<>
948 struct dialog_tester<depcheck_confirm_change>
949 {
950  depcheck_confirm_change* create()
951  {
952  return new depcheck_confirm_change(true, depcheck_mods, "requester");
953  }
954 };
955 
956 template<>
957 struct dialog_tester<depcheck_select_new>
958 {
959  depcheck_select_new* create()
960  {
961  return new depcheck_select_new(ng::depcheck::MODIFICATION, depcheck_mods);
962  }
963 };
964 
965 template<>
966 struct dialog_tester<mp_login>
967 {
968  mp_login* create()
969  {
970  return new mp_login("wesnoth.org", "label", true);
971  }
972 };
973 
974 template<>
975 struct dialog_tester<simple_item_selector>
976 {
977  simple_item_selector* create()
978  {
979  return new simple_item_selector("title", "message", std::vector<std::string>(), false, false);
980  }
981 };
982 
983 template<>
984 struct dialog_tester<screenshot_notification>
985 {
986  screenshot_notification* create()
987  {
988  return new screenshot_notification("path", nullptr);
989  }
990 };
991 
992 template<>
993 struct dialog_tester<theme_list>
994 {
995  static theme_info make_theme(const std::string& name)
996  {
997  theme_info ti;
998  ti.id = name;
999  ti.name = name;
1000  ti.description = name + " this is a description";
1001  return ti;
1002  }
1003  static std::vector<theme_info> themes;
1004  theme_list* create()
1005  {
1006  return new theme_list(themes, 0);
1007  }
1008 };
1009 std::vector<theme_info> dialog_tester<theme_list>::themes {make_theme("classic"), make_theme("new"), make_theme("more"), make_theme("themes")};
1010 
1011 template<>
1012 struct dialog_tester<editor_generate_map>
1013 {
1014  std::vector<std::unique_ptr<map_generator>> map_generators;
1015  editor_generate_map* create()
1016  {
1017  for(const config &i : main_config.child_range("multiplayer")) {
1018  if(i["scenario_generation"] == "default") {
1019  const config &generator_cfg = i.child("generator");
1020  if (generator_cfg) {
1021  map_generators.emplace_back(create_map_generator("", generator_cfg));
1022  }
1023  }
1024  }
1025 
1026  editor_generate_map* result = new editor_generate_map(map_generators);
1027  BOOST_REQUIRE_MESSAGE(result, "Failed to create a dialog.");
1028 
1029  return result;
1030  }
1031 };
1032 
1033 template<>
1034 struct dialog_tester<editor_new_map>
1035 {
1036  int width = 10;
1037  int height = 10;
1038  editor_new_map* create()
1039  {
1040  return new editor_new_map("Test", width, height);
1041  }
1042 };
1043 
1044 template<>
1045 struct dialog_tester<editor_resize_map>
1046 {
1047  int width = 0;
1048  int height = 0;
1050  bool copy = false;
1051  editor_resize_map* create()
1052  {
1053  return new editor_resize_map(width, height, expand_direction, copy);
1054  }
1055 };
1056 
1057 template<>
1058 struct dialog_tester<file_dialog>
1059 {
1060  file_dialog* create()
1061  {
1062  return new file_dialog();
1063  }
1064 };
1065 
1066 template<>
1067 struct dialog_tester<folder_create>
1068 {
1069  std::string folder_name;
1070  folder_create* create()
1071  {
1072  return new folder_create(folder_name);
1073  }
1074 };
1075 
1076 template<>
1077 struct dialog_tester<transient_message>
1078 {
1079  transient_message* create()
1080  {
1081  return new transient_message("Title", false, "Message", false, "");
1082  }
1083 };
1084 
1085 template<>
1086 struct dialog_tester<title_screen>
1087 {
1088  std::vector<std::string> args;
1089  commandline_options opts;
1091  dialog_tester() : opts(args), game(opts) {}
1092  title_screen* create()
1093  {
1094  return new title_screen(game);
1095  }
1096 };
1097 
1098 template<>
1099 struct dialog_tester<wml_error>
1100 {
1101  static std::vector<std::string> files;
1102  wml_error* create()
1103  {
1104  return new wml_error("Summary", "Post summary", files, "Details");
1105  }
1106 };
1107 std::vector<std::string> dialog_tester<wml_error>::files {"some", "files", "here"};
1108 
1109 template<>
1110 struct dialog_tester<wml_message_left>
1111 {
1112  wml_message_left* create()
1113  {
1114  return new wml_message_left("Title", "Message", "", false);
1115  }
1116 };
1117 
1118 template<>
1119 struct dialog_tester<wml_message_right>
1120 {
1121  wml_message_right* create()
1122  {
1123  return new wml_message_right("Title", "Message", "", false);
1124  }
1125 };
1126 
1127 template<>
1128 struct dialog_tester<wml_message_double>
1129 {
1130  wml_message_double* create()
1131  {
1132  return new wml_message_double("Title", "Message", "", false, "", true);
1133  }
1134 };
1135 
1136 template<>
1137 struct dialog_tester<faction_select>
1138 {
1139  config era_cfg, side_cfg;
1140  std::vector<const config*> eras;
1141  ng::flg_manager flg;
1142  std::string color;
1143  dialog_tester()
1144  : era_cfg(), side_cfg(), eras(1, &era_cfg) // TODO: Add an actual era definition
1145  , flg(eras, side_cfg, false, false, false)
1146  , color("teal")
1147  {}
1148  faction_select* create() {
1149  return new faction_select(flg, color, 1);
1150  }
1151 };
1152 
1153 #if 0
1154 template<>
1155 struct dialog_tester<game_stats>
1156 {
1157  int i = 1;
1158  game_stats* create()
1159  {
1160  return new game_stats(get_dummy_display_context(), 1, i);
1161  }
1162 };
1163 #endif
1164 
1165 template<>
1166 struct dialog_tester<generator_settings>
1167 {
1168  config cfg;
1169  generator_data data;
1170  dialog_tester() : data(cfg) {}
1171  generator_settings* create()
1172  {
1173  return new generator_settings(data);
1174  }
1175 };
1176 
1177 template<>
1178 struct dialog_tester<sp_options_configure>
1179 {
1180  saved_game state;
1181  ng::create_engine create_eng;
1182  ng::configure_engine config_eng;
1183  dialog_tester() : create_eng(state)
1184  , config_eng(create_eng.get_state()) {}
1185  sp_options_configure* create()
1186  {
1187  return new sp_options_configure(create_eng, config_eng);
1188  }
1189 };
1190 
1191 template<>
1192 struct dialog_tester<statistics_dialog>
1193 {
1194  team t;
1195  dialog_tester() : t() {}
1196  statistics_dialog* create()
1197  {
1198  return new statistics_dialog(t);
1199  }
1200 };
1201 
1202 template<>
1203 struct dialog_tester<surrender_quit>
1204 {
1205  dialog_tester() {}
1206  surrender_quit* create()
1207  {
1208  return new surrender_quit();
1209  }
1210 };
1211 
1212 } // 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:32
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:603
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.
Replay control code.
const std::vector< std::string > items
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:539
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:72
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:549
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:59
std::unique_ptr< window > window_
The window, used in show.
static tcache cache
Definition: minimap.cpp:124
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:105
int turns()
Definition: game.cpp:559
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:201
Container associating units to locations.
Definition: map.hpp:98
point resolution()
Definition: general.cpp:393
#define e
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:61
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:65
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.