The Battle for Wesnoth  1.15.7+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 "game_config_view.hpp"
21 #include "config_cache.hpp"
22 #include "filesystem.hpp"
23 #include "font/font_config.hpp"
24 #include "game_config.hpp"
25 #include "gettext.hpp"
28 #include "hotkey/hotkey_item.hpp"
29 #include "language.hpp"
30 #include "units/types.hpp"
31 
32 #include "gui/gui.hpp"
33 
34 #include <clocale>
35 
36 namespace test_utils {
37 
38  static bool match_english(const language_def& def)
39  {
40  return def.localename == "en_US";
41  }
42 
49 
51  static void check_manager()
52  {
53  if(manager)
54  return;
55  manager = new game_config_manager();
56  }
57  public:
59  : cfg_()
60  , game_config_view_(game_config_view::wrap(cfg_))
61  , paths_manager_()
62  , hotkey_manager_()
63  , font_manager_()
64  {
65 #ifdef _WIN32
66  setlocale(LC_ALL, "English");
67 #else
68  std::setlocale(LC_ALL, "C");
69 #endif
70  const std::string& intl_dir = filesystem::get_intl_dir();
71  translation::bind_textdomain("wesnoth", intl_dir.c_str(), "UTF-8");
72  translation::bind_textdomain("wesnoth-lib", intl_dir.c_str(), "UTF-8");
74 
75 
77  gui2::init();
81  ::init_textdomains(game_config_view_);
82  const std::vector<language_def>& languages = get_languages();
83  std::vector<language_def>::const_iterator English = std::find_if(languages.begin(),
84  languages.end(),
85  match_english); // Using German because the most active translation
86  ::set_language(*English);
87 
88  unit_types.set_config(game_config_view_.merged_children_view("units"));
89 
90  game_config::load_config(cfg_.child("game_config"));
93 
94  hotkey::load_hotkeys(game_config_view_);
95  paths_manager_.set_paths(game_config_view_);
97 
98  }
99 
101  {
102  check_manager();
103  return manager->get_config();
104  }
105 
107  {
108  return cfg_;
109  }
110  };
111 
112 
114 
116  {
118  }
119 
121  {
123  }
124 
125 }
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:431
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:386
void set_language(const std::string &language, const std::vector< std::string > *)
Definition: gettext.cpp:448
unit_type_data unit_types
Definition: types.cpp:1378
void init_textdomains(const game_config_view &cfg)
Initializes the list of textdomains from a configuration object.
Definition: language.cpp:356
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:54
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:440
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:93
language_list get_languages()
Definition: language.cpp:116
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:1018
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:68
void add_define(const std::string &define)
Add a entry to preproc defines map.
filesystem::binary_paths_manager paths_manager_