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