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