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