The Battle for Wesnoth  1.19.5+dev
game_config_manager_tests.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
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;
57  }
58  public:
60  : 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();
79  gui2::switch_theme("default");
84  const std::vector<language_def>& languages = get_languages();
85  std::vector<language_def>::const_iterator English = std::find_if(languages.begin(),
86  languages.end(),
87  match_english); // Using German because the most active translation
88  ::set_language(*English);
89 
91 
93  const hotkey::scope_changer hk_scope{hotkey::scope_game, false};
94 
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 }
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
Definition: config.cpp:366
void add_define(const std::string &define)
Add a entry to preproc defines map.
static config_cache & instance()
Get reference to the singleton object.
void get_config(const std::string &path, config &cfg, abstract_validator *validator=nullptr)
Gets a config object from given path.
A class grating read only view to a vector of config objects, viewed as one config with all children ...
game_config_view merged_children_view(config_key_type key) const
this class is initialized once at game start put all initialization and wipe code in the methods here...
static game_config_manager * manager
filesystem::binary_paths_manager paths_manager_
void set_config(const game_config_view &cfg)
Resets all data based on the provided config.
Definition: types.cpp:1103
Definitions for the interface to Wesnoth Markup Language (WML).
Declarations for File-IO.
void init_textdomains(const game_config_view &cfg)
Initializes the list of textdomains from a configuration object.
Definition: language.cpp:365
bool load_language_list()
Definition: language.cpp:103
language_list get_languages(bool all)
Return a list of available translations.
Definition: language.cpp:126
std::string get_intl_dir()
bool load_font_config()
Definition: font_config.cpp:58
std::string path
Definition: filesystem.cpp:90
void load_config(const config &v)
void init()
Initializes the GUI subsystems.
Definition: gui.cpp:34
void switch_theme(const std::string &current_theme)
Set and activate the given gui2 theme.
Definition: gui.cpp:135
constexpr uint32_t scope_game
void load_default_hotkeys(const game_config_view &cfg)
Registers all hotkeys present in this config.
static bool match_english(const language_def &def)
const config & get_test_config_ref()
void set_language(const std::string &language, const std::vector< std::string > *)
Definition: gettext.cpp:494
void bind_textdomain(const char *domain, const char *directory, const char *)
Definition: gettext.cpp:479
void set_default_textdomain(const char *domain)
Definition: gettext.cpp:487
The paths manager is responsible for recording the various paths that binary files may be located at.
Definition: filesystem.hpp:438
void set_paths(const game_config_view &cfg)
std::string localename
Definition: language.hpp:53
unit_type_data unit_types
Definition: types.cpp:1500