The Battle for Wesnoth  1.15.1+dev
game_config_manager_tests.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by Pauli Nieminen <paniemin@cc.hut.fi>
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 #define GETTEXT_DOMAIN "wesnoth-test"
16 
18 
19 #include "config.hpp"
20 #include "config_cache.hpp"
21 #include "filesystem.hpp"
22 #include "font/font_config.hpp"
23 #include "game_config.hpp"
24 #include "gettext.hpp"
27 #include "hotkey/hotkey_item.hpp"
28 #include "language.hpp"
29 #include "units/types.hpp"
30 
31 #include "gui/gui.hpp"
32 
33 #include <clocale>
34 
35 namespace test_utils {
36 
37  static bool match_english(const language_def& def)
38  {
39  return def.localename == "en_US";
40  }
41 
47 
49  static void check_manager()
50  {
51  if(manager)
52  return;
53  manager = new game_config_manager();
54  }
55  public:
57  : cfg_()
58  , paths_manager_()
59  , hotkey_manager_()
60  , font_manager_()
61  {
62 #ifdef _WIN32
63  setlocale(LC_ALL, "English");
64 #else
65  std::setlocale(LC_ALL, "C");
66 #endif
67  const std::string& intl_dir = filesystem::get_intl_dir();
68  translation::bind_textdomain("wesnoth", intl_dir.c_str(), "UTF-8");
69  translation::bind_textdomain("wesnoth-lib", intl_dir.c_str(), "UTF-8");
71 
72 
74  gui2::init();
78  ::init_textdomains(cfg_);
79  const std::vector<language_def>& languages = get_languages();
80  std::vector<language_def>::const_iterator English = std::find_if(languages.begin(),
81  languages.end(),
82  match_english); // Using German because the most active translation
83  ::set_language(*English);
84 
85  cfg_.merge_children("units");
86 
87  if (config &units = cfg_.child("units")) {
88  unit_types.set_config(units);
89  }
90 
91  game_config::load_config(cfg_.child("game_config"));
94 
96  paths_manager_.set_paths(cfg_);
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 }
void set_config(config &cfg)
Resets all data based on the provided config.
Definition: types.cpp:1113
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:420
void bind_textdomain(const char *domain, const char *directory, const char *)
Definition: gettext.cpp:432
void set_paths(const config &cfg)
this class is initialized once at game start put all initialization and wipe code in the methods here...
void merge_children(const std::string &key)
All children with the given key will be merged into the first element with that key.
Definition: config.cpp:325
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:360
void set_language(const std::string &language, const std::vector< std::string > *)
Definition: gettext.cpp:449
unit_type_data unit_types
Definition: types.cpp:1525
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:35
std::string localename
Definition: language.hpp:52
static bool match_english(const language_def &def)
std::string path
Definition: game_config.cpp:39
void init_textdomains(const config &cfg)
Initializes the list of textdomains from a configuration object.
Definition: language.cpp:303
void set_default_textdomain(const char *domain)
Definition: gettext.cpp:441
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:92
language_list get_languages()
Definition: language.cpp:115
Declarations for File-IO.
static game_config_manager * manager
void load_hotkeys(const config &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:92
void add_define(const std::string &define)
Add a entry to preproc defines map.
filesystem::binary_paths_manager paths_manager_