Author: suokko
Date: Mon Aug 18 13:15:52 2008
New Revision: 28701
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28701&view=rev
Log:
Minor improvements to config cache class code. It is still wip
Modified:
trunk/src/config_cache.cpp
trunk/src/config_cache.hpp
trunk/src/tests/data/test/_main.cfg
trunk/src/tests/test_config_cache.cpp
Modified: trunk/src/config_cache.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/config_cache.cpp?rev=28701&r1=28700&r2=28701&view=diff
==============================================================================
--- trunk/src/config_cache.cpp (original)
+++ trunk/src/config_cache.cpp Mon Aug 18 13:15:52 2008
@@ -12,14 +12,16 @@
See the COPYING file for more details.
*/
+#include "filesystem.hpp"
#include "config_cache.hpp"
#include "game_config.hpp"
namespace game_config {
config_cache::config_cache() :
game_config_(),
- dir_checksum_(),
force_valid_cache_(false),
+ use_cache_(true),
+ dirty_(true),
config_root_("data/"),
user_config_root_(get_addon_campaigns_dir()),
defines_map_()
@@ -31,6 +33,11 @@
std::string config_cache::get_config_root() const
{
return config_root_;
+ }
+
+ void config_cache::set_config_root(const std::string& path)
+ {
+ config_root_ = path;
}
std::string config_cache::get_user_config_root() const
@@ -46,5 +53,59 @@
void config_cache::clear_defines()
{
defines_map_.clear();
+ // settup default 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
+
+ }
+
+ void config_cache::reload_translations()
+ {
+ if (dirty_)
+ {
+ reload_configs();
+ } else {
+ game_config_.reset_translation();
+
game_config::load_config(game_config_.child("game_config"));
+ }
+ }
+
+ config& config_cache::get_config()
+ {
+ if (!dirty_)
+ return game_config_;
+
+ reload_configs();
+ dirty_ = true;
+
+ return game_config_;
+ }
+
+ void config_cache::reload_configs(bool recheck_cache)
+ {
+ file_tree_checksum checksum =
data_tree_checksum(recheck_cache);
+ }
+
+ void config_cache::set_use_cache(bool use)
+ {
+ use_cache_ = use;
+ }
+
+ void config_cache::add_define(const std::string& define)
+ {
+ defines_map_[define] = preproc_define();
}
}
Modified: trunk/src/config_cache.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/config_cache.hpp?rev=28701&r1=28700&r2=28701&view=diff
==============================================================================
--- trunk/src/config_cache.hpp (original)
+++ trunk/src/config_cache.hpp Mon Aug 18 13:15:52 2008
@@ -16,7 +16,6 @@
#define CONFIG_CACHE_HPP_INCLUDED
#include <boost/utility.hpp>
-#include "filesystem.hpp"
#include "config.hpp"
#include "serialization/preprocessor.hpp"
@@ -31,8 +30,7 @@
static config_cache cache_;
config game_config_;
- file_tree_checksum dir_checksum_;
- bool force_valid_cache_;
+ bool force_valid_cache_, use_cache_, dirty_;
std::string config_root_, user_config_root_;
preproc_map defines_map_;
@@ -50,7 +48,6 @@
void set_config_root(const std::string&);
void set_user_config_root(const std::string&);
- const config& get_config() const;
config& get_config();
void clear_defines();
@@ -58,6 +55,8 @@
void reload_translations();
void reload_configs(bool recheck_cache = false);
+
+ void set_use_cache(bool use);
};
}
Modified: trunk/src/tests/data/test/_main.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/data/test/_main.cfg?rev=28701&r1=28700&r2=28701&view=diff
==============================================================================
--- trunk/src/tests/data/test/_main.cfg (original)
+++ trunk/src/tests/data/test/_main.cfg Mon Aug 18 13:15:52 2008
@@ -10,6 +10,6 @@
#endif
#ifdef TEST_DEFINE
[test_key]
- define=test_define
+ define=_ "testing translation reset."
[/test_key]
#endif
Modified: trunk/src/tests/test_config_cache.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/test_config_cache.cpp?rev=28701&r1=28700&r2=28701&view=diff
==============================================================================
--- trunk/src/tests/test_config_cache.cpp (original)
+++ trunk/src/tests/test_config_cache.cpp Mon Aug 18 13:15:52 2008
@@ -16,6 +16,8 @@
#include "config_cache.hpp"
#include "filesystem.hpp"
#include "game_config.hpp"
+#include "language.hpp"
+#include "gettext.hpp"
#include "serialization/preprocessor.hpp"
@@ -68,8 +70,6 @@
defines_map["APPLE"] = preproc_define();
#endif
- defines_map["NORMAL"] = preproc_define();
- defines_map["MEDIUM"] = preproc_define();
return defines_map;
}
@@ -91,10 +91,10 @@
BOOST_AUTO_TEST_CASE( test_load_config )
{
test_config_cache& cache = test_config_cache::instance();
- cache.add_define("test");
+ cache.add_define("TEST");
preproc_map defines_map(settup_test_preproc_map());
- defines_map["test"] = preproc_define();
+ defines_map["TEST"] = preproc_define();
const preproc_map& test_defines = cache.get_preproc_map();
BOOST_CHECK_EQUAL_COLLECTIONS(test_defines.begin(),test_defines.end(),
defines_map.begin() ,defines_map.end());
@@ -104,14 +104,55 @@
BOOST_CHECK_EQUAL(test_data_path, cache.get_config_root());
config test_config;
- {
- config& child = test_config.add_child("textdomain");
- child["name"] = "wesnoth";
- }
- {
- config& child = test_config.add_child("test_key");
- child["define"] = "test";
- }
+ config* child = &test_config.add_child("textdomain");
+ (*child)["name"] = "wesnoth";
+
+ child = &test_config.add_child("test_key");
+ (*child)["define"] = "test";
+
+
+ BOOST_CHECK_EQUAL(test_config, cache.get_config());
+
+ cache.add_define("TEST_DEFINE");
+
+ child = &test_config.add_child("test_key");
+ (*child)["define"] = _("testing translation reset");
+
+
+ BOOST_CHECK_EQUAL(test_config, cache.get_config());
+}
+
+bool match_german(const language_def& def)
+{
+ return def.localename == "de_DE";
+}
+
+BOOST_AUTO_TEST_CASE( test_translation_reload )
+{
+ test_config_cache& cache = test_config_cache::instance();
+ config test_config;
+ config* child = &test_config.add_child("textdomain");
+ (*child)["name"] = "wesnoth";
+
+ child = &test_config.add_child("test_key");
+ (*child)["define"] = "test";
+
+ child = &test_config.add_child("test_key");
+ (*child)["define"] = _("testing translation reset");
+
+ // Change language
+ const std::vector<language_def>& languages = get_languages();
+ BOOST_CHECK_MESSAGE(languages.size()>0, "No languages found!");
+ std::vector<language_def>::const_iterator German =
std::find_if(languages.begin(),
+
languages.end(),
+
match_german); // Using German because the most active translation
+ BOOST_REQUIRE_MESSAGE(German != languages.end(), "German translation
not found");
+ ::set_language(*German);
+ cache.reload_translations();
+
+ BOOST_CHECK_MESSAGE( test_config != cache.get_config(), "Translation
update failed update translations!" );
+
+ (*child)["define"] = _("test translation reset");
BOOST_CHECK_EQUAL(test_config, cache.get_config());
}
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits