Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #define GETTEXT_DOMAIN "wesnoth-test"
00017
00018 #include "tests/utils/game_config_manager.hpp"
00019
00020 #include "config.hpp"
00021 #include "config_cache.hpp"
00022 #include "filesystem.hpp"
00023 #include "font.hpp"
00024 #include "game_config.hpp"
00025 #include "gettext.hpp"
00026 #include "hotkeys.hpp"
00027 #include "language.hpp"
00028 #include "playcampaign.hpp"
00029 #include "unit_types.hpp"
00030
00031 #include "gui/widgets/helper.hpp"
00032
00033 namespace test_utils {
00034
00035 static bool match_english(const language_def& def)
00036 {
00037 return def.localename == "en_US";
00038 }
00039
00040 class game_config_manager {
00041 config cfg_;
00042 binary_paths_manager paths_manager_;
00043 const hotkey::manager hotkey_manager_;
00044 font::manager font_manager_;
00045
00046 static game_config_manager* manager;
00047 static void check_manager()
00048 {
00049 if(manager)
00050 return;
00051 manager = new game_config_manager();
00052 }
00053 public:
00054 game_config_manager()
00055 : cfg_()
00056 , paths_manager_()
00057 , hotkey_manager_()
00058 , font_manager_()
00059 {
00060 #ifdef _WIN32
00061 setlocale(LC_ALL, "English");
00062 #else
00063 std::setlocale(LC_ALL, "C");
00064 std::setlocale(LC_MESSAGES, "");
00065 #endif
00066 const std::string& intl_dir = get_intl_dir();
00067 bindtextdomain ("wesnoth", intl_dir.c_str());
00068 bind_textdomain_codeset ("wesnoth", "UTF-8");
00069 bindtextdomain ("wesnoth-lib", intl_dir.c_str());
00070 bind_textdomain_codeset ("wesnoth-lib", "UTF-8");
00071 textdomain ("wesnoth");
00072
00073
00074 font::load_font_config();
00075 gui2::init();
00076 load_language_list();
00077 game_config::config_cache::instance().add_define("TEST");
00078 game_config::config_cache::instance().get_config(game_config::path + "/data/test/", cfg_);
00079 ::init_textdomains(cfg_);
00080 const std::vector<language_def>& languages = get_languages();
00081 std::vector<language_def>::const_iterator English = std::find_if(languages.begin(),
00082 languages.end(),
00083 match_english);
00084 ::set_language(*English);
00085
00086 cfg_.merge_children("units");
00087
00088 if (config &units = cfg_.child("units")) {
00089 unit_types.set_config(units);
00090 }
00091
00092 game_config::load_config(cfg_.child("game_config"));
00093 hotkey::deactivate_all_scopes();
00094 hotkey::set_scope_active(hotkey::SCOPE_GENERAL);
00095 hotkey::set_scope_active(hotkey::SCOPE_GAME);
00096
00097 hotkey::load_hotkeys(cfg_);
00098 paths_manager_.set_paths(cfg_);
00099 font::load_font_config();
00100
00101 }
00102
00103 static config& get_config_static()
00104 {
00105 check_manager();
00106 return manager->get_config();
00107 }
00108
00109 config& get_config()
00110 {
00111 return cfg_;
00112 }
00113 };
00114
00115
00116 game_config_manager* game_config_manager::manager;
00117
00118 const config& get_test_config_ref()
00119 {
00120 return game_config_manager::get_config_static();
00121 }
00122
00123 config get_test_config()
00124 {
00125 return game_config_manager::get_config_static();
00126 }
00127
00128 }