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