The Battle for Wesnoth  1.15.11+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_config.hpp"
24 #include "game_config_view.hpp"
25 #include "game_display.hpp"
26 #include "game_events/manager.hpp"
30 #include "game_launcher.hpp"
32 #include "gettext.hpp"
42 #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 <functional>
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_auth>();
418  test<addon_connect>();
419  test<addon_license_prompt>();
420  //test<addon_manager>();
421  //test<attack_predictions>();
422  test<campaign_difficulty>();
423  test<campaign_selection>();
424  test<chat_log>();
425  test<core_selection>();
426  test<custom_tod>();
427  test<depcheck_confirm_change>();
428  test<depcheck_select_new>();
429  test<edit_label>();
430  test<edit_text>();
431  test<editor_edit_label>();
432  test<editor_edit_side>();
433  test<editor_edit_scenario>();
434  test<editor_generate_map>();
435  test<editor_new_map>();
436  test<editor_resize_map>();
437  //test<end_credits>();
438  test<faction_select>();
439  test<file_dialog>();
440  test<folder_create>();
441  test<formula_debugger>();
442  test<game_cache_options>();
443  test<game_delete>();
444  test<game_load>();
445  test<game_version>();
446  test<game_save>();
447  test<game_save_message>();
448  test<game_save_oos>();
449  // test<game_stats>();
450  // test<gamestate_inspector>();
451  test<generator_settings>();
452  //test<help_browser>();
453  test<hotkey_bind>();
454  test<install_dependencies>();
455  test<language_selection>();
456  // test<loading_screen>(); TODO: enable
457  test<mp_lobby>();
458  test<lobby_player_info>();
459  test<log_settings>();
460  //test<lua_interpreter>(& lua_kernel_base());
461  test<message>();
462  test<mp_alerts_options>();
463  //test<mp_change_control>();
464  test<mp_connect>();
465  //test<mp_create_game>();
466  //test<mp_join_game>();
467  test<mp_join_game_password_prompt>();
468  test<mp_login>();
469  test<mp_method_selection>();
470  //test<mp_staging>();
471  //test<outro>();
472  test<simple_item_selector>();
473  test<screenshot_notification>();
474  test<select_orb_colors>();
475  test<sp_options_configure>();
476  test<statistics_dialog>();
477  test<surrender_quit>();
478  //test<story_viewer>();
479  test<theme_list>();
480  //test<terrain_layers>();
481  //test<title_screen>();
482  test<transient_message>();
483  //test<unit_advance>();
484  //test<unit_attack>();
485  test<unit_create>();
486  //test<unit_list>();
487  //test<unit_recall>();
488  //test<unit_recruit>();
489  test<wml_error>();
490  test<wml_message_left>();
491  test<wml_message_right>();
492  test<wml_message_double>();
493 
494  /* The modeless_dialog classes. */
495  test_popup<debug_clock>();
496 
497  /* The tooltip classes. */
498  test_tip("tooltip_large");
499  test_tip("tooltip");
500 
501  std::set<std::string>& list = gui2::unit_test_registered_window_list();
502  std::set<std::string> omitted {
503  /*
504  * The unit attack unit test are disabled for now, they calling parameters
505  * don't allow 'nullptr's needs to be fixed.
506  */
507  "unit_attack",
508  // No test for this right now, not sure how to use the test system
509  // for dialog with no default constructor
510  "lua_interpreter",
511  /*
512  * Disable label settings dialog test because we need a display_context
513  * object, which we don't have, and it's a lot of work to produce a dummy
514  * one.
515  */
516  "label_settings",
517  "addon_uninstall_list",
518  "addon_manager",
519  "loading_screen",
520  "network_transmission",
521  "synched_choice_wait",
522  "drop_down_menu",
523  "preferences_dialog",
524  "unit_recruit",
525  "unit_recall",
526  "unit_list",
527  "unit_advance",
528  "mp_host_game_prompt",
529  "mp_create_game",
530  // The title screen appears to be throwing a bad_alloc on Travis, so disable it for now
531  "title_screen",
532  "end_credits",
533  "mp_staging",
534  "mp_join_game",
535  "terrain_layers",
536  "attack_predictions",
537  "help_browser",
538  "story_viewer",
539  "outro",
540  "mp_change_control", // Basically useless without a game_board object, so disabling
541  "game_stats", // segfault with LTO
542  "gamestate_inspector", // segfault with LTO
543  "server_info",
544  };
545 
546  std::vector<std::string> missing;
547  std::set_difference(list.begin(), list.end(), omitted.begin(), omitted.end(), std::back_inserter(missing));
548 
549  // Test size() instead of empty() to get the number of offenders
550  BOOST_CHECK_EQUAL(missing.size(), 0);
551  for(const std::string& id : missing) {
552  std::cerr << "Window '" << id << "' registered but not tested.\n";
553  }
554 }
555 
556 BOOST_AUTO_TEST_CASE(test_make_test_fake)
557 {
559 
560  try {
561  message dlg("title", "message", true, false, false);
562  dlg.show(1);
563  } catch(const wml_exception& e) {
564  BOOST_CHECK(e.user_message == _("Failed to show a dialog, "
565  "which doesn't fit on the screen."));
566  return;
567  } catch(...) {
568  }
569  BOOST_ERROR("Didn't catch the wanted exception.");
570 }
571 
572 namespace {
573 
574 template<>
575 struct dialog_tester<addon_auth>
576 {
577  config cfg;
578  addon_auth* create()
579  {
580  return new addon_auth(cfg);
581  }
582 };
583 
584 template<>
585 struct dialog_tester<addon_connect>
586 {
587  std::string host_name = "host_name";
588  addon_connect* create()
589  {
590  return new addon_connect(host_name, true);
591  }
592 };
593 
594 template<>
595 struct dialog_tester<addon_license_prompt>
596 {
597  std::string license_terms = R"""(Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis ante nibh, dignissim ullamcorper tristique eget, condimentum sit amet enim. Aenean dictum pulvinar lacinia. Etiam eleifend, leo sed efficitur consectetur, augue nulla ornare lectus, vitae molestie lacus risus vitae libero. Quisque odio nunc, porttitor eget fermentum sit amet, faucibus eu risus. Praesent sit amet lacus tortor. Suspendisse volutpat quam vitae ipsum fermentum, in vulputate metus egestas. Nulla id consequat ex. Nulla ac dignissim nisl, nec euismod lectus. Duis vitae dolor ornare, convallis justo in, porta dui.
598 
599 Sed faucibus nibh sit amet ligula porta, non malesuada nibh tristique. Maecenas aliquam diam non eros convallis mattis. Proin rhoncus condimentum leo, sed condimentum magna. Phasellus cursus condimentum lacus, sed sodales lacus. Sed pharetra dictum metus, eget dictum nibh lobortis imperdiet. Nunc tempus sollicitudin bibendum. In porttitor interdum orci. Curabitur vitae nibh vestibulum, condimentum lectus quis, condimentum dui. In quis cursus nisl. Maecenas semper neque eu ipsum aliquam, id porta ligula lacinia. Integer sed blandit ex, eu accumsan magna.)""";
600  addon_license_prompt* create()
601  {
602  return new addon_license_prompt(license_terms);
603  }
604 };
605 
606 template<>
607 struct dialog_tester<addon_manager>
608 {
609  CVideo& video = test_utils::get_fake_display(10, 10).video();
610  dialog_tester()
611  {
612  }
613  addon_manager* create()
614  {
615  addons_client client("localhost:15999");
616  return new addon_manager(client);
617  }
618 };
619 
620 template<>
621 struct dialog_tester<campaign_difficulty>
622 {
623  campaign_difficulty* create()
624  {
625  const config items("difficulty");
626 
627  return new campaign_difficulty(items);
628  }
629 };
630 
631 template<>
632 struct dialog_tester<campaign_selection>
633 {
634  saved_game state;
636  dialog_tester() : state(config {"campaign_type", "scenario"}), ng(state)
637  {
638  }
639  campaign_selection* create()
640  {
641  return new campaign_selection(ng);
642  }
643 };
644 
645 template<>
646 struct dialog_tester<chat_log>
647 {
648  config cfg;
649  vconfig vcfg;
650  replay_recorder_base rbase;
651  replay r;
652  dialog_tester() : vcfg(cfg), r(rbase) {}
653  chat_log* create()
654  {
655  return new chat_log(vcfg, r);
656  }
657 };
658 
659 template<>
660 struct dialog_tester<core_selection>
661 {
662  std::vector<config> cores;
663  dialog_tester()
664  {
665  cores.resize(1);
666  }
667  core_selection* create()
668  {
669  return new core_selection(cores, 0);
670  }
671 };
672 
673 template<>
674 struct dialog_tester<custom_tod>
675 {
676  std::vector<time_of_day> times;
677  int current_tod = 0;
678  dialog_tester()
679  {
680  times.resize(1);
681  }
682  custom_tod* create()
683  {
684  return new custom_tod(times, current_tod);
685  }
686 };
687 
688 template<>
689 struct dialog_tester<edit_label>
690 {
691  std::string label = "Label text to modify";
692  bool team_only = false;
693  edit_label* create()
694  {
695  return new edit_label(label, team_only);
696  }
697 };
698 
699 template<>
700 struct dialog_tester<edit_text>
701 {
702  std::string text = "text to modify";
703  edit_text* create()
704  {
705  return new edit_text("title", "label", text);
706  }
707 };
708 
709 template<>
710 struct dialog_tester<editor_edit_label>
711 {
712  std::string label = "Label text to modify";
713  std::string category = "test";
714  bool immutable = false, fog = false, shroud = false;
715  color_t color;
716  editor_edit_label* create()
717  {
718  return new editor_edit_label(label, immutable, fog, shroud, color, category);
719  }
720 };
721 
722 template<>
723 struct dialog_tester<editor_edit_scenario>
724 {
725  std::string id, name, descr;
726  int turns = 0, xp_mod = 50;
727  bool defeat_enemies = false, random_start = false;
728  editor_edit_scenario* create()
729  {
730  return new editor_edit_scenario(id, name, descr, turns, xp_mod, defeat_enemies, random_start);
731  }
732 };
733 
734 template<>
735 struct dialog_tester<editor_edit_side>
736 {
737  team t;
739  dialog_tester() : info(t) {}
740  editor_edit_side* create()
741  {
742  return new editor_edit_side(info);
743  }
744 };
745 
746 template<>
747 struct dialog_tester<formula_debugger>
748 {
749  wfl::formula_debugger debugger;
750  formula_debugger* create()
751  {
752  return new formula_debugger(debugger);
753  }
754 };
755 
756 template<>
757 struct dialog_tester<game_load>
758 {
759  config cfg;
760  game_config_view view;
761  // It would be good to have a test directory instead of using the same directory as the player,
762  // however this code will support that - default_saves_dir() will respect --userdata-dir.
764  dialog_tester()
765  {
766  /** @todo Would be nice to add real data to the config. */
767  }
768  game_load* create()
769  {
770  view = game_config_view::wrap(cfg);
771  return new game_load(view, data);
772  }
773 
774 };
775 
776 template<>
777 struct dialog_tester<game_save>
778 {
779  std::string title = "Title";
780  std::string filename = "filename";
781  game_save* create()
782  {
783  return new game_save(title, filename);
784  }
785 
786 };
787 
788 template<>
789 struct dialog_tester<game_save_message>
790 {
791  std::string title = "Title";
792  std::string filename = "filename";
793  std::string message = "message";
794  game_save_message* create()
795  {
796  return new game_save_message(title, filename, message);
797  }
798 
799 };
800 
801 template<>
802 struct dialog_tester<game_save_oos>
803 {
804  bool ignore_all = false;
805  std::string title = "Title";
806  std::string filename = "filename";
807  std::string message = "message";
808  game_save_oos* create()
809  {
810  return new game_save_oos(ignore_all, title, filename, message);
811  }
812 
813 };
814 
815 #if 0
816 template<>
817 struct dialog_tester<gamestate_inspector>
818 {
819  config vars;
821  gamestate_inspector* create()
822  {
823  return new gamestate_inspector(vars, events, get_dummy_display_context(), "Unit Test");
824  }
825 
826 };
827 #endif
828 
829 template<>
830 struct dialog_tester<install_dependencies>
831 {
832  addons_list addons;
833  install_dependencies* create()
834  {
835  return new install_dependencies(addons);
836  }
837 };
838 
839 template<>
840 struct dialog_tester<hotkey_bind>
841 {
842  std::string id = "";
843 
844  hotkey_bind* create()
845  {
846  return new hotkey_bind(id);
847  }
848 };
849 
850 template<>
851 struct dialog_tester<mp_lobby>
852 {
854  wesnothd_connection connection;
855  std::vector<std::string> installed_addons;
856  mp::lobby_info li;
857  int selected_game;
858  dialog_tester() : connection("", ""), li(installed_addons)
859  {
860  }
861  mp_lobby* create()
862  {
863  return new mp_lobby(li, connection, selected_game);
864  }
865 };
866 
867 class fake_chat_handler : public events::chat_handler {
868  void add_chat_message(const std::time_t&,
869  const std::string&, int, const std::string&,
870  MESSAGE_TYPE) {}
871  void send_chat_message(const std::string&, bool) {}
872  void send_to_server(const config&) {}
873 };
874 
875 template<>
876 struct dialog_tester<lobby_player_info>
877 {
878  config c;
879  fake_chat_handler ch;
880  wesnothd_connection connection;
881  mp::user_info ui;
882  std::vector<std::string> installed_addons;
883  mp::lobby_info li;
884  dialog_tester()
885  : connection("", "")
886  , ui(c), li(installed_addons)
887  {
888  }
889  lobby_player_info* create()
890  {
891  return new lobby_player_info(ch, ui, li);
892  }
893 };
894 
895 template<>
896 struct dialog_tester<log_settings>
897 {
898  log_settings* create()
899  {
900  return new log_settings();
901  }
902 };
903 
904 template<>
905 struct dialog_tester<message>
906 {
907  message* create()
908  {
909  return new message("Title", "Message", false, false, false);
910  }
911 };
912 #if 0
913 template<>
914 struct dialog_tester<mp_change_control>
915 {
916  mp_change_control* create()
917  {
918  return new mp_change_control(nullptr);
919  }
920 };
921 #endif
922 
923 template<>
924 struct dialog_tester<mp_create_game>
925 {
926  saved_game state;
927  dialog_tester() : state(config {"campaign_type", "multiplayer"})
928  {
929  }
930  mp_create_game* create()
931  {
932  return new mp_create_game(state, true);
933  }
934 };
935 
936 template<>
937 struct dialog_tester<mp_join_game_password_prompt>
938 {
939  std::string password;
940  mp_join_game_password_prompt* create()
941  {
942  return new mp_join_game_password_prompt(password);
943  }
944 };
945 
946 static std::vector<std::string> depcheck_mods {"mod_one", "some other", "more"};
947 
948 template<>
949 struct dialog_tester<depcheck_confirm_change>
950 {
951  depcheck_confirm_change* create()
952  {
953  return new depcheck_confirm_change(true, depcheck_mods, "requester");
954  }
955 };
956 
957 template<>
958 struct dialog_tester<depcheck_select_new>
959 {
960  depcheck_select_new* create()
961  {
962  return new depcheck_select_new(ng::depcheck::MODIFICATION, depcheck_mods);
963  }
964 };
965 
966 template<>
967 struct dialog_tester<mp_login>
968 {
969  mp_login* create()
970  {
971  return new mp_login("wesnoth.org", "label", true);
972  }
973 };
974 
975 template<>
976 struct dialog_tester<simple_item_selector>
977 {
978  simple_item_selector* create()
979  {
980  return new simple_item_selector("title", "message", std::vector<std::string>(), false, false);
981  }
982 };
983 
984 template<>
985 struct dialog_tester<screenshot_notification>
986 {
987  screenshot_notification* create()
988  {
989  return new screenshot_notification("path", nullptr);
990  }
991 };
992 
993 template<>
994 struct dialog_tester<theme_list>
995 {
996  static theme_info make_theme(const std::string& name)
997  {
998  theme_info ti;
999  ti.id = name;
1000  ti.name = name;
1001  ti.description = name + " this is a description";
1002  return ti;
1003  }
1004  static std::vector<theme_info> themes;
1005  theme_list* create()
1006  {
1007  return new theme_list(themes, 0);
1008  }
1009 };
1010 std::vector<theme_info> dialog_tester<theme_list>::themes {make_theme("classic"), make_theme("new"), make_theme("more"), make_theme("themes")};
1011 
1012 template<>
1013 struct dialog_tester<editor_generate_map>
1014 {
1015  std::vector<std::unique_ptr<map_generator>> map_generators;
1016  editor_generate_map* create()
1017  {
1018  for(const config &i : main_config.child_range("multiplayer")) {
1019  if(i["scenario_generation"] == "default") {
1020  const config &generator_cfg = i.child("generator");
1021  if (generator_cfg) {
1022  map_generators.emplace_back(create_map_generator("", generator_cfg));
1023  }
1024  }
1025  }
1026 
1027  editor_generate_map* result = new editor_generate_map(map_generators);
1028  BOOST_REQUIRE_MESSAGE(result, "Failed to create a dialog.");
1029 
1030  return result;
1031  }
1032 };
1033 
1034 template<>
1035 struct dialog_tester<editor_new_map>
1036 {
1037  int width = 10;
1038  int height = 10;
1039  editor_new_map* create()
1040  {
1041  return new editor_new_map("Test", width, height);
1042  }
1043 };
1044 
1045 template<>
1046 struct dialog_tester<editor_resize_map>
1047 {
1048  int width = 0;
1049  int height = 0;
1051  bool copy = false;
1052  editor_resize_map* create()
1053  {
1054  return new editor_resize_map(width, height, expand_direction, copy);
1055  }
1056 };
1057 
1058 template<>
1059 struct dialog_tester<file_dialog>
1060 {
1061  file_dialog* create()
1062  {
1063  return new file_dialog();
1064  }
1065 };
1066 
1067 template<>
1068 struct dialog_tester<folder_create>
1069 {
1070  std::string folder_name;
1071  folder_create* create()
1072  {
1073  return new folder_create(folder_name);
1074  }
1075 };
1076 
1077 template<>
1078 struct dialog_tester<transient_message>
1079 {
1080  transient_message* create()
1081  {
1082  return new transient_message("Title", false, "Message", false, "");
1083  }
1084 };
1085 
1086 template<>
1087 struct dialog_tester<title_screen>
1088 {
1089  std::vector<std::string> args;
1090  commandline_options opts;
1092  dialog_tester() : opts(args), game(opts) {}
1093  title_screen* create()
1094  {
1095  return new title_screen(game);
1096  }
1097 };
1098 
1099 template<>
1100 struct dialog_tester<wml_error>
1101 {
1102  static std::vector<std::string> files;
1103  wml_error* create()
1104  {
1105  return new wml_error("Summary", "Post summary", files, "Details");
1106  }
1107 };
1108 std::vector<std::string> dialog_tester<wml_error>::files {"some", "files", "here"};
1109 
1110 template<>
1111 struct dialog_tester<wml_message_left>
1112 {
1113  wml_message_left* create()
1114  {
1115  return new wml_message_left("Title", "Message", "", false);
1116  }
1117 };
1118 
1119 template<>
1120 struct dialog_tester<wml_message_right>
1121 {
1122  wml_message_right* create()
1123  {
1124  return new wml_message_right("Title", "Message", "", false);
1125  }
1126 };
1127 
1128 template<>
1129 struct dialog_tester<wml_message_double>
1130 {
1131  wml_message_double* create()
1132  {
1133  return new wml_message_double("Title", "Message", "", false, "", true);
1134  }
1135 };
1136 
1137 template<>
1138 struct dialog_tester<faction_select>
1139 {
1140  config era_cfg, side_cfg;
1141  std::vector<const config*> eras;
1142  ng::flg_manager flg;
1143  std::string color;
1144  dialog_tester()
1145  : era_cfg(), side_cfg(), eras(1, &era_cfg) // TODO: Add an actual era definition
1146  , flg(eras, side_cfg, false, false, false)
1147  , color("teal")
1148  {}
1149  faction_select* create() {
1150  return new faction_select(flg, color, 1);
1151  }
1152 };
1153 
1154 #if 0
1155 template<>
1156 struct dialog_tester<game_stats>
1157 {
1158  int i = 1;
1159  game_stats* create()
1160  {
1161  return new game_stats(get_dummy_display_context(), 1, i);
1162  }
1163 };
1164 #endif
1165 
1166 template<>
1167 struct dialog_tester<generator_settings>
1168 {
1169  config cfg;
1170  generator_data data;
1171  dialog_tester() : data(cfg) {}
1172  generator_settings* create()
1173  {
1174  return new generator_settings(data);
1175  }
1176 };
1177 
1178 template<>
1179 struct dialog_tester<sp_options_configure>
1180 {
1181  saved_game state;
1182  ng::create_engine create_eng;
1183  ng::configure_engine config_eng;
1184  dialog_tester() : create_eng(state)
1185  , config_eng(create_eng.get_state()) {}
1186  sp_options_configure* create()
1187  {
1188  return new sp_options_configure(create_eng, config_eng);
1189  }
1190 };
1191 
1192 template<>
1193 struct dialog_tester<statistics_dialog>
1194 {
1195  team t;
1196  dialog_tester() : t() {}
1197  statistics_dialog* create()
1198  {
1199  return new statistics_dialog(t);
1200  }
1201 };
1202 
1203 template<>
1204 struct dialog_tester<surrender_quit>
1205 {
1206  dialog_tester() {}
1207  surrender_quit* create()
1208  {
1209  return new surrender_quit();
1210  }
1211 };
1212 
1213 } // 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:88
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:600
The paths manager is responsible for recording the various paths that binary files may be located at...
Definition: filesystem.hpp:387
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
static std::string _(const char *str)
Definition: gettext.hpp:92
FLG stands for faction, leader and gender.
Definition: flg_manager.hpp:28
bool show(const unsigned auto_close_time=0)
Shows the window.
void load_config(const config &v)
virtual const std::string & window_id() const =0
The id of the window to build.
Generic file dialog.
Definition: field-fwd.hpp:22
bool fog()
Definition: game.cpp:533
This class stores all the data for a single &#39;side&#39; (in game nomenclature).
Definition: team.hpp:44
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:170
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:177
Exception thrown when the width resizing has failed.
std::string path
Definition: game_config.cpp:38
Add-ons (campaignd) client class.
Definition: client.hpp:39
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:543
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:940
std::stringstream & wml_error()
Use this logger to send errors due to deprecated WML.
Definition: log.cpp:288
Game configuration data as global variables.
Definition: build_info.cpp:58
std::unique_ptr< window > window_
The window, used in show.
static tcache cache
Definition: minimap.cpp:123
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:553
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:198
Container associating units to locations.
Definition: map.hpp:97
point resolution()
Definition: general.cpp:387
#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:59
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:64
void add_define(const std::string &define)
Add a entry to preproc defines map.
Networked add-ons (campaignd) client interface.
void show(const std::string &window_id, const t_string &message, const point &mouse, const SDL_Rect &source_rect)
Shows a tip.
Definition: tooltip.cpp:139
Singleton class to manage game config file caching.