The Battle for Wesnoth  1.17.0-dev
game_config_manager_tests.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2021
3  by Pauli Nieminen <paniemin@cc.hut.fi>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-test"
17 
19 
20 #include "config.hpp"
21 #include "game_config_view.hpp"
22 #include "config_cache.hpp"
23 #include "filesystem.hpp"
24 #include "font/font_config.hpp"
25 #include "game_config.hpp"
26 #include "gettext.hpp"
29 #include "hotkey/hotkey_item.hpp"
30 #include "language.hpp"
31 #include "units/types.hpp"
32 
33 #include "gui/gui.hpp"
34 
35 #include <clocale>
36 
37 namespace test_utils {
38 
39  static bool match_english(const language_def& def)
40  {
41  return def.localename == "en_US";
42  }
43 
50 
52  static void check_manager()
53  {
54  if(manager)
55  return;
56  manager = new game_config_manager();
57  }
58  public:
60  : cfg_()
61  , game_config_view_(game_config_view::wrap(cfg_))
62  , paths_manager_()
63  , hotkey_manager_()
64  , font_manager_()
65  {
66 #ifdef _WIN32
67  setlocale(LC_ALL, "English");
68 #else
69  std::setlocale(LC_ALL, "C");
70 #endif
71  const std::string& intl_dir = filesystem::get_intl_dir();
72  translation::bind_textdomain("wesnoth", intl_dir.c_str(), "UTF-8");
73  translation::bind_textdomain("wesnoth-lib", intl_dir.c_str(), "UTF-8");
75 
76 
78  gui2::init();
82  ::init_textdomains(game_config_view_);
83  const std::vector<language_def>& languages = get_languages();
84  std::vector<language_def>::const_iterator English = std::find_if(languages.begin(),
85  languages.end(),
86  match_english); // Using German because the most active translation
87  ::set_language(*English);
88 
89  unit_types.set_config(game_config_view_.merged_children_view("units"));
90 
91  game_config::load_config(cfg_.child("game_config"));
94 
95  hotkey::load_hotkeys(game_config_view_);
96  paths_manager_.set_paths(game_config_view_);
98 
99  }
100 
102  {
103  check_manager();
104  return manager->get_config();
105  }
106 
108  {
109  return cfg_;
110  }
111  };
112 
113 
115 
117  {
119  }
120 
122  {
124  }
125 
126 }
static config_cache & instance()
Get reference to the singleton object.
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
Definition: config.cpp:402
void bind_textdomain(const char *domain, const char *directory, const char *)
Definition: gettext.cpp:447
this class is initialized once at game start put all initialization and wipe code in the methods here...
void set_scope_active(scope s, bool set)
The paths manager is responsible for recording the various paths that binary files may be located at...
Definition: filesystem.hpp:400
void set_language(const std::string &language, const std::vector< std::string > *)
Definition: gettext.cpp:464
unit_type_data unit_types
Definition: types.cpp:1481
void init_textdomains(const game_config_view &cfg)
Initializes the list of textdomains from a configuration object.
Definition: language.cpp:367
Definitions for the interface to Wesnoth Markup Language (WML).
const config & get_test_config_ref()
void load_config(const config &v)
std::string get_intl_dir()
void init()
Initializes the GUI subsystems.
Definition: gui.cpp:36
std::string localename
Definition: language.hpp:55
language_list get_languages(bool all)
Return a list of available translations.
Definition: language.cpp:127
static bool match_english(const language_def &def)
std::string path
Definition: game_config.cpp:39
game_config_view merged_children_view(config_key_type key) const
void set_default_textdomain(const char *domain)
Definition: gettext.cpp:456
void deactivate_all_scopes()
bool load_font_config()
void get_config(const std::string &path, config &cfg, abstract_validator *validator=nullptr)
Gets a config object from given path.
bool load_language_list()
Definition: language.cpp:104
Declarations for File-IO.
void set_paths(const game_config_view &cfg)
void set_config(const game_config_view &cfg)
Resets all data based on the provided config.
Definition: types.cpp:1096
static game_config_manager * manager
void load_hotkeys(const game_config_view &cfg, bool set_as_default)
Iterates through all hotkeys present in the config struct and creates and adds them to the hotkey lis...
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
void add_define(const std::string &define)
Add a entry to preproc defines map.
filesystem::binary_paths_manager paths_manager_