Added WIP config_cache class
Changed unit test default report level to short report
This commit is contained in:
parent
7c18ce1613
commit
8369d1c9d8
10 changed files with 259 additions and 13 deletions
|
@ -209,6 +209,7 @@ SET(wesnoth-main_SRC
|
|||
attack_prediction.cpp
|
||||
attack_prediction_display.cpp
|
||||
callable_objects.cpp
|
||||
config_cache.cpp
|
||||
config_adapter.cpp
|
||||
controller_base.cpp
|
||||
dialogs.cpp
|
||||
|
@ -467,6 +468,7 @@ SET(test_SRC
|
|||
tests/main.cpp
|
||||
tests/utils/fake_display.cpp
|
||||
tests/utils/fake_event_source.cpp
|
||||
tests/test_config_cache.cpp
|
||||
tests/test_util.cpp
|
||||
tests/test_network_worker.cpp
|
||||
tests/test_team.cpp
|
||||
|
|
|
@ -56,6 +56,7 @@ wesnoth_source = \
|
|||
attack_prediction.cpp \
|
||||
attack_prediction_display.cpp \
|
||||
callable_objects.cpp \
|
||||
config_cache.cpp \
|
||||
config_adapter.cpp \
|
||||
controller_base.cpp \
|
||||
dialogs.cpp \
|
||||
|
@ -273,6 +274,7 @@ test_SOURCES = \
|
|||
tests/main.cpp \
|
||||
tests/utils/fake_display.cpp \
|
||||
tests/utils/fake_event_source.cpp \
|
||||
tests/test_config_cache.cpp \
|
||||
tests/test_util.cpp \
|
||||
tests/test_network_worker.cpp \
|
||||
tests/gui/test_save_dialog.cpp \
|
||||
|
|
|
@ -35,13 +35,13 @@ libwesnoth_core_sources.extend(env.Object("network_worker.cpp", EXTRA_DEFINE = e
|
|||
game_config_env = env.Clone()
|
||||
filesystem_env = env.Clone()
|
||||
if env["PLATFORM"] != "win32":
|
||||
game_config_env.Append(CPPDEFINES = "WESNOTH_PATH='\"$datadir\"'")
|
||||
game_config_env.Append(CPPDEFINES = "WESNOTH_PATH='\"$datadir\"'")
|
||||
if env['localedirname']:
|
||||
filesystem_env.Append(CPPDEFINES = "LOCALEDIR='\"$localedirname\"'")
|
||||
if not os.path.isabs(env['localedirname']):
|
||||
filesystem_env.Append(CPPDEFINES = "HAS_RELATIVE_LOCALEDIR")
|
||||
filesystem_env.Append(CPPDEFINES = "LOCALEDIR='\"$localedirname\"'")
|
||||
if not os.path.isabs(env['localedirname']):
|
||||
filesystem_env.Append(CPPDEFINES = "HAS_RELATIVE_LOCALEDIR")
|
||||
if env['prefsdir']:
|
||||
filesystem_env.Append(CPPDEFINES = "PREFERENCES_DIR='\"$prefsdir\"'")
|
||||
filesystem_env.Append(CPPDEFINES = "PREFERENCES_DIR='\"$prefsdir\"'")
|
||||
|
||||
libwesnoth_core_sources.extend([
|
||||
game_config_env.Object("game_config.cpp"),
|
||||
|
@ -145,6 +145,7 @@ wesnoth_sources = Split("""
|
|||
attack_prediction_display.cpp
|
||||
callable_objects.cpp
|
||||
config_adapter.cpp
|
||||
config_cache.cpp
|
||||
controller_base.cpp
|
||||
dialogs.cpp
|
||||
floating_textbox.cpp
|
||||
|
@ -306,14 +307,14 @@ campaignd_sources.extend(env.Object("campaign_server/campaign_server.cpp", EXTRA
|
|||
env.WesnothProgram("campaignd", campaignd_sources + [libwesnoth_core, libwesnothd, libcampaignd], have_server_prereqs)
|
||||
|
||||
wesnothd_sources = Split("""
|
||||
server/ban.cpp
|
||||
server/ban.cpp
|
||||
server/game.cpp
|
||||
server/input_stream.cpp
|
||||
server/metrics.cpp
|
||||
server/player.cpp
|
||||
server/proxy.cpp
|
||||
server/simple_wml.cpp
|
||||
time.cpp
|
||||
time.cpp
|
||||
""")
|
||||
wesnothd_sources.extend(env.Object("server/server.cpp", EXTRA_DEFINE = env['fifodir'] and "FIFODIR='\"$fifodir\"'" or None))
|
||||
|
||||
|
@ -333,19 +334,20 @@ env.WesnothProgram("exploder", exploder_sources + [libcutter, libwesnoth_core, l
|
|||
LIBS = env["LIBS"] + ["png"])
|
||||
|
||||
test_utils_sources = Split("""
|
||||
tests/utils/fake_event_source.cpp
|
||||
tests/utils/fake_display.cpp
|
||||
""")
|
||||
tests/utils/fake_event_source.cpp
|
||||
tests/utils/fake_display.cpp
|
||||
""")
|
||||
|
||||
libtest_utils = env.Library("test_utils", test_utils_sources)
|
||||
|
||||
test_sources = Split("""
|
||||
tests/main.cpp
|
||||
tests/test_util.cpp
|
||||
tests/test_config_cache.cpp
|
||||
tests/test_network_worker.cpp
|
||||
tests/gui/test_save_dialog.cpp
|
||||
tests/gui/test_drop_target.cpp
|
||||
tests/test_team.cpp
|
||||
tests/test_util.cpp
|
||||
tests/gui/test_drop_target.cpp
|
||||
tests/gui/test_save_dialog.cpp
|
||||
""")
|
||||
test = test_env.WesnothProgram("test", test_sources + [libwesnoth_extras, libwesnoth_core, libwesnoth_sdl, libwesnoth,libtest_utils], have_test_prereqs)
|
||||
#Export("test")
|
||||
|
|
50
src/config_cache.cpp
Normal file
50
src/config_cache.cpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 by Pauli Nieminen <paniemin@cc.hut.fi>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "config_cache.hpp"
|
||||
#include "game_config.hpp"
|
||||
|
||||
namespace game_config {
|
||||
config_cache::config_cache() :
|
||||
game_config_(),
|
||||
dir_checksum_(),
|
||||
force_valid_cache_(false),
|
||||
config_root_("data/"),
|
||||
user_config_root_(get_addon_campaigns_dir()),
|
||||
defines_map_()
|
||||
{
|
||||
// To settup initial defines map correctly
|
||||
clear_defines();
|
||||
}
|
||||
|
||||
std::string config_cache::get_config_root() const
|
||||
{
|
||||
return config_root_;
|
||||
}
|
||||
|
||||
std::string config_cache::get_user_config_root() const
|
||||
{
|
||||
return user_config_root_;
|
||||
}
|
||||
|
||||
const preproc_map& config_cache::get_preproc_map() const
|
||||
{
|
||||
return defines_map_;
|
||||
}
|
||||
|
||||
void config_cache::clear_defines()
|
||||
{
|
||||
defines_map_.clear();
|
||||
}
|
||||
}
|
63
src/config_cache.hpp
Normal file
63
src/config_cache.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 by Pauli Nieminen <paniemin@cc.hut.fi>
|
||||
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_CACHE_HPP_INCLUDED
|
||||
#define CONFIG_CACHE_HPP_INCLUDED
|
||||
|
||||
#include <boost/utility.hpp>
|
||||
#include "filesystem.hpp"
|
||||
#include "config.hpp"
|
||||
#include "serialization/preprocessor.hpp"
|
||||
|
||||
namespace game_config {
|
||||
|
||||
|
||||
/**
|
||||
* Singleton object to manage game configs
|
||||
* and cache reading.
|
||||
**/
|
||||
class config_cache : private boost::noncopyable {
|
||||
static config_cache cache_;
|
||||
|
||||
config game_config_;
|
||||
file_tree_checksum dir_checksum_;
|
||||
bool force_valid_cache_;
|
||||
std::string config_root_, user_config_root_;
|
||||
preproc_map defines_map_;
|
||||
|
||||
protected:
|
||||
config_cache();
|
||||
|
||||
|
||||
std::string get_config_root() const;
|
||||
std::string get_user_config_root() const;
|
||||
const preproc_map& get_preproc_map() const;
|
||||
|
||||
public:
|
||||
static config_cache& instance();
|
||||
|
||||
void set_config_root(const std::string&);
|
||||
void set_user_config_root(const std::string&);
|
||||
|
||||
config& get_game_config() const;
|
||||
|
||||
void clear_defines();
|
||||
void add_define(const std::string& define);
|
||||
|
||||
void reload_translations();
|
||||
void reload_configs(bool recheck_cache = false);
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
|
@ -40,6 +40,12 @@ bool preproc_define::operator==(preproc_define const &v) const {
|
|||
return value == v.value && arguments == v.arguments;
|
||||
}
|
||||
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const preproc_define& def)
|
||||
{
|
||||
return stream << "value: " << def.value << " arguments: " << def.location;
|
||||
}
|
||||
|
||||
class preprocessor;
|
||||
class preprocessor_file;
|
||||
class preprocessor_data;
|
||||
|
|
|
@ -39,6 +39,8 @@ struct preproc_define
|
|||
bool operator!=(preproc_define const &v) const { return !operator==(v); }
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const preproc_define& def);
|
||||
|
||||
struct preproc_config {
|
||||
struct error {
|
||||
error(const std::string& msg) : message(msg) {}
|
||||
|
|
15
src/tests/data/test/_main.cfg
Normal file
15
src/tests/data/test/_main.cfg
Normal file
|
@ -0,0 +1,15 @@
|
|||
#textdomain wesnoth
|
||||
[textdomain]
|
||||
name=wesnoth
|
||||
[/textdomain]
|
||||
|
||||
#ifdef TEST
|
||||
[test_key]
|
||||
define=test
|
||||
[/test_key]
|
||||
#endif
|
||||
#ifdef TEST_DEFINE
|
||||
[test_key]
|
||||
define=test_define
|
||||
[/test_key]
|
||||
#endif
|
|
@ -15,6 +15,8 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/unit_test_monitor.hpp>
|
||||
#include <boost/test/detail/unit_test_parameters.hpp>
|
||||
#include <boost/test/results_reporter.hpp>
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#include "game_errors.hpp"
|
||||
|
@ -52,8 +54,12 @@ struct wesnoth_global_fixture {
|
|||
|
||||
// lg::set_log_domain_severity("all",3);
|
||||
|
||||
// Set more report as default
|
||||
if (boost::unit_test::runtime_config::log_level() == boost::unit_test::invalid_log_level)
|
||||
boost::unit_test::unit_test_log.set_threshold_level( boost::unit_test::log_messages );
|
||||
if (boost::unit_test::runtime_config::report_level() == boost::unit_test::INV_REPORT_LEVEL)
|
||||
boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT);
|
||||
|
||||
boost::unit_test::unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game);
|
||||
boost::unit_test::unit_test_monitor.register_exception_translator<network::error>(&exception_translator_network);
|
||||
boost::unit_test::unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config);
|
||||
|
|
98
src/tests/test_config_cache.cpp
Normal file
98
src/tests/test_config_cache.cpp
Normal file
|
@ -0,0 +1,98 @@
|
|||
/* $Id$ */
|
||||
/*
|
||||
Copyright (C) 2008 by Pauli Nieminen <paniemin@cc.hut.fi>
|
||||
Part of thie Battle for Wesnoth Project http://www.wesnoth.org/
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2
|
||||
or at your option any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
|
||||
#include "config_cache.hpp"
|
||||
#include "filesystem.hpp"
|
||||
#include "game_config.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE( config_cache )
|
||||
|
||||
/**
|
||||
* Used to make distinct singleton for testing it
|
||||
* because other tests will need original one to load data
|
||||
**/
|
||||
class test_config_cache : public game_config::config_cache {
|
||||
test_config_cache() : game_config::config_cache() {}
|
||||
|
||||
static test_config_cache cache_;
|
||||
|
||||
public:
|
||||
static test_config_cache& instance() {
|
||||
return cache_;
|
||||
}
|
||||
|
||||
std::string get_config_root() const {
|
||||
return game_config::config_cache::get_config_root();
|
||||
}
|
||||
std::string get_user_config_root() const {
|
||||
return game_config::config_cache::get_user_config_root();
|
||||
}
|
||||
|
||||
const preproc_map& get_preproc_map() const {
|
||||
return game_config::config_cache::get_preproc_map();
|
||||
}
|
||||
};
|
||||
|
||||
test_config_cache test_config_cache::cache_;
|
||||
|
||||
preproc_map settup_test_preproc_map()
|
||||
{
|
||||
preproc_map defines_map;
|
||||
|
||||
#ifdef USE_TINY_GUI
|
||||
defines_map["TINY"] = preproc_define();
|
||||
#endif
|
||||
|
||||
if (game_config::small_gui)
|
||||
defines_map["SMALL_GUI"] = preproc_define();
|
||||
|
||||
#ifdef HAVE_PYTHON
|
||||
defines_map["PYTHON"] = preproc_define();
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
defines_map["APPLE"] = preproc_define();
|
||||
#endif
|
||||
|
||||
defines_map["NORMAL"] = preproc_define();
|
||||
defines_map["MEDIUM"] = preproc_define();
|
||||
return defines_map;
|
||||
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_config_cache_defaults )
|
||||
{
|
||||
preproc_map defines_map(settup_test_preproc_map());
|
||||
test_config_cache& cache = test_config_cache::instance();
|
||||
|
||||
BOOST_CHECK_EQUAL("data/", cache.get_config_root());
|
||||
BOOST_CHECK_EQUAL(get_addon_campaigns_dir(), cache.get_user_config_root());
|
||||
|
||||
BOOST_CHECK_EQUAL(defines_map.size(), cache.get_preproc_map().size());
|
||||
const preproc_map& test_defines = cache.get_preproc_map();
|
||||
preproc_map::const_iterator test_def = test_defines.begin();
|
||||
for(preproc_map::iterator def = defines_map.begin();
|
||||
def != defines_map.end(); ++def, ++test_def)
|
||||
{
|
||||
if (test_def == test_defines.end())
|
||||
break;
|
||||
BOOST_CHECK_EQUAL(def->first, test_def->first);
|
||||
BOOST_CHECK_EQUAL(def->second, test_def->second);
|
||||
}
|
||||
}
|
||||
|
||||
/* vim: set ts=4 sw=4: */
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
Loading…
Add table
Reference in a new issue