The Battle for Wesnoth  1.15.5+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 
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  "server_info",
543  };
544 
545  std::vector<std::string> missing;
546  std::set_difference(list.begin(), list.end(), omitted.begin(), omitted.end(), std::back_inserter(missing));
547 
548  // Test size() instead of empty() to get the number of offenders
549  BOOST_CHECK_EQUAL(missing.size(), 0);
550  for(const std::string& id : missing) {
551  std::cerr << "Window '" << id << "' registered but not tested.\n";
552  }
553 }
554 
555 BOOST_AUTO_TEST_CASE(test_make_test_fake)
556 {
558 
559  try {
560  message dlg("title", "message", true, false, false);
561  dlg.show(1);
562  } catch(const wml_exception& e) {
563  BOOST_CHECK(e.user_message == _("Failed to show a dialog, "
564  "which doesn't fit on the screen."));
565  return;
566  } catch(...) {
567  }
568  BOOST_ERROR("Didn't catch the wanted exception.");
569 }
570 
571 namespace {
572 
573 template<>
574 struct dialog_tester<addon_connect>
575 {
576  std::string host_name = "host_name";
577  addon_connect* create()
578  {
579  return new addon_connect(host_name, true);
580  }
581 };
582 
583 template<>
584 struct dialog_tester<addon_manager>
585 {
586  CVideo& video = test_utils::get_fake_display(10, 10).video();
587  dialog_tester()
588  {
589  }
590  addon_manager* create()
591  {
592  addons_client client("localhost:15999");
593  return new addon_manager(client);
594  }
595 };
596 
597 template<>
598 struct dialog_tester<campaign_difficulty>
599 {
600  campaign_difficulty* create()
601  {
602  const config items("difficulty");
603 
604  return new campaign_difficulty(items);
605  }
606 };
607 
608 template<>
609 struct dialog_tester<campaign_selection>
610 {
611  saved_game state;
613  dialog_tester() : state(config {"campaign_type", "scenario"}), ng(state)
614  {
615  }
616  campaign_selection* create()
617  {
618  return new campaign_selection(ng);
619  }
620 };
621 
622 template<>
623 struct dialog_tester<chat_log>
624 {
625  config cfg;
626  vconfig vcfg;
627  replay_recorder_base rbase;
628  replay r;
629  dialog_tester() : vcfg(cfg), r(rbase) {}
630  chat_log* create()
631  {
632  return new chat_log(vcfg, r);
633  }
634 };
635 
636 template<>
637 struct dialog_tester<core_selection>
638 {
639  std::vector<config> cores;
640  dialog_tester()
641  {
642  cores.resize(1);
643  }
644  core_selection* create()
645  {
646  return new core_selection(cores, 0);
647  }
648 };
649 
650 template<>
651 struct dialog_tester<custom_tod>
652 {
653  std::vector<time_of_day> times;
654  int current_tod = 0;
655  dialog_tester()
656  {
657  times.resize(1);
658  }
659  custom_tod* create()
660  {
661  return new custom_tod(times, current_tod);
662  }
663 };
664 
665 template<>
666 struct dialog_tester<edit_label>
667 {
668  std::string label = "Label text to modify";
669  bool team_only = false;
670  edit_label* create()
671  {
672  return new edit_label(label, team_only);
673  }
674 };
675 
676 template<>
677 struct dialog_tester<edit_text>
678 {
679  std::string text = "text to modify";
680  edit_text* create()
681  {
682  return new edit_text("title", "label", text);
683  }
684 };
685 
686 template<>
687 struct dialog_tester<editor_edit_label>
688 {
689  std::string label = "Label text to modify";
690  std::string category = "test";
691  bool immutable = false, fog = false, shroud = false;
692  color_t color;
693  editor_edit_label* create()
694  {
695  return new editor_edit_label(label, immutable, fog, shroud, color, category);
696  }
697 };
698 
699 template<>
700 struct dialog_tester<editor_edit_scenario>
701 {
702  std::string id, name, descr;
703  int turns = 0, xp_mod = 50;
704  bool defeat_enemies = false, random_start = false;
705  editor_edit_scenario* create()
706  {
707  return new editor_edit_scenario(id, name, descr, turns, xp_mod, defeat_enemies, random_start);
708  }
709 };
710 
711 template<>
712 struct dialog_tester<editor_edit_side>
713 {
714  team t;
716  dialog_tester() : info(t) {}
717  editor_edit_side* create()
718  {
719  return new editor_edit_side(info);
720  }
721 };
722 
723 template<>
724 struct dialog_tester<formula_debugger>
725 {
726  wfl::formula_debugger debugger;
727  formula_debugger* create()
728  {
729  return new formula_debugger(debugger);
730  }
731 };
732 
733 template<>
734 struct dialog_tester<game_load>
735 {
736  config cfg;
737  game_config_view view;
738  // It would be good to have a test directory instead of using the same directory as the player,
739  // however this code will support that - default_saves_dir() will respect --userdata-dir.
741  dialog_tester()
742  {
743  /** @todo Would be nice to add real data to the config. */
744  }
745  game_load* create()
746  {
747  view = game_config_view::wrap(cfg);
748  return new game_load(view, data);
749  }
750 
751 };
752 
753 template<>
754 struct dialog_tester<game_save>
755 {
756  std::string title = "Title";
757  std::string filename = "filename";
758  game_save* create()
759  {
760  return new game_save(title, filename);
761  }
762 
763 };
764 
765 template<>
766 struct dialog_tester<game_save_message>
767 {
768  std::string title = "Title";
769  std::string filename = "filename";
770  std::string message = "message";
771  game_save_message* create()
772  {
773  return new game_save_message(title, filename, message);
774  }
775 
776 };
777 
778 template<>
779 struct dialog_tester<game_save_oos>
780 {
781  bool ignore_all = false;
782  std::string title = "Title";
783  std::string filename = "filename";
784  std::string message = "message";
785  game_save_oos* create()
786  {
787  return new game_save_oos(ignore_all, title, filename, message);
788  }
789 
790 };
791 
792 #if 0
793 template<>
794 struct dialog_tester<gamestate_inspector>
795 {
796  config vars;
798  gamestate_inspector* create()
799  {
800  return new gamestate_inspector(vars, events, get_dummy_display_context(), "Unit Test");
801  }
802 
803 };
804 #endif
805 
806 template<>
807 struct dialog_tester<install_dependencies>
808 {
809  addons_list addons;
810  install_dependencies* create()
811  {
812  return new install_dependencies(addons);
813  }
814 };
815 
816 template<>
817 struct dialog_tester<hotkey_bind>
818 {
819  std::string id = "";
820 
821  hotkey_bind* create()
822  {
823  return new hotkey_bind(id);
824  }
825 };
826 
827 template<>
828 struct dialog_tester<mp_lobby>
829 {
831  game_config_view gc_view;
832  wesnothd_connection connection;
833  std::vector<std::string> installed_addons;
834  mp::lobby_info li;
835  dialog_tester() : connection("", ""), li(installed_addons)
836  {
837  gc_view = game_config_view::wrap(game_config);
838  }
839  mp_lobby* create()
840  {
841  return new mp_lobby(gc_view, 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(game_config_view_, state, true, nullptr);
911  }
912 };
913 
914 template<>
915 struct dialog_tester<mp_join_game_password_prompt>
916 {
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<transient_message>
1067 {
1068  transient_message* create()
1069  {
1070  return new transient_message("Title", false, "Message", false, "");
1071  }
1072 };
1073 
1074 template<>
1075 struct dialog_tester<title_screen>
1076 {
1077  std::vector<std::string> args;
1078  commandline_options opts;
1080  dialog_tester() : opts(args), game(opts, "unit_tests") {}
1081  title_screen* create()
1082  {
1083  return new title_screen(game);
1084  }
1085 };
1086 
1087 template<>
1088 struct dialog_tester<wml_error>
1089 {
1090  static std::vector<std::string> files;
1091  wml_error* create()
1092  {
1093  return new wml_error("Summary", "Post summary", files, "Details");
1094  }
1095 };
1096 std::vector<std::string> dialog_tester<wml_error>::files {"some", "files", "here"};
1097 
1098 template<>
1099 struct dialog_tester<wml_message_left>
1100 {
1101  wml_message_left* create()
1102  {
1103  return new wml_message_left("Title", "Message", "", false);
1104  }
1105 };
1106 
1107 template<>
1108 struct dialog_tester<wml_message_right>
1109 {
1110  wml_message_right* create()
1111  {
1112  return new wml_message_right("Title", "Message", "", false);
1113  }
1114 };
1115 
1116 template<>
1117 struct dialog_tester<wml_message_double>
1118 {
1119  wml_message_double* create()
1120  {
1121  return new wml_message_double("Title", "Message", "", false, "", true);
1122  }
1123 };
1124 
1125 template<>
1126 struct dialog_tester<faction_select>
1127 {
1128  config era_cfg, side_cfg;
1129  std::vector<const config*> eras;
1130  ng::flg_manager flg;
1131  std::string color;
1132  dialog_tester()
1133  : era_cfg(), side_cfg(), eras(1, &era_cfg) // TODO: Add an actual era definition
1134  , flg(eras, side_cfg, false, false, false)
1135  , color("teal")
1136  {}
1137  faction_select* create() {
1138  return new faction_select(flg, color, 1);
1139  }
1140 };
1141 
1142 #if 0
1143 template<>
1144 struct dialog_tester<game_stats>
1145 {
1146  int i = 1;
1147  game_stats* create()
1148  {
1149  return new game_stats(get_dummy_display_context(), 1, i);
1150  }
1151 };
1152 #endif
1153 
1154 template<>
1155 struct dialog_tester<generator_settings>
1156 {
1157  config cfg;
1159  dialog_tester() : data(cfg) {}
1160  generator_settings* create()
1161  {
1162  return new generator_settings(data);
1163  }
1164 };
1165 
1166 template<>
1167 struct dialog_tester<sp_options_configure>
1168 {
1169  saved_game state;
1170  ng::create_engine create_eng;
1171  ng::configure_engine config_eng;
1172  dialog_tester() : create_eng(state)
1173  , config_eng(create_eng.get_state()) {}
1174  sp_options_configure* create()
1175  {
1176  return new sp_options_configure(create_eng, config_eng);
1177  }
1178 };
1179 
1180 template<>
1181 struct dialog_tester<statistics_dialog>
1182 {
1183  team t;
1184  dialog_tester() : t() {}
1185  statistics_dialog* create()
1186  {
1187  return new statistics_dialog(t);
1188  }
1189 };
1190 
1191 template<>
1192 struct dialog_tester<surrender_quit>
1193 {
1194  dialog_tester() {}
1195  surrender_quit* create()
1196  {
1197  return new surrender_quit();
1198  }
1199 };
1200 
1201 } // 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:562
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:100
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:572
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:582
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:372
#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.