mail[Wesnoth-commits] r28699 - in /trunk/src: ./ serialization/ tests/ tests/macros/ tests/scenarios/


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by paniemin on August 18, 2008 - 14:14:
Author: suokko
Date: Mon Aug 18 13:15:11 2008
New Revision: 28699

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28699&view=rev
Log:
* Continued work on spliting config_cache from game.cpp

Added:
    trunk/src/tests/macros/
    trunk/src/tests/macros/readme.txt
    trunk/src/tests/scenarios/
    trunk/src/tests/scenarios/reame.txt
Modified:
    trunk/src/config_cache.hpp
    trunk/src/serialization/preprocessor.cpp
    trunk/src/serialization/preprocessor.hpp
    trunk/src/tests/test_config_cache.cpp

Modified: trunk/src/config_cache.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/config_cache.hpp?rev=28699&r1=28698&r2=28699&view=diff
==============================================================================
--- trunk/src/config_cache.hpp (original)
+++ trunk/src/config_cache.hpp Mon Aug 18 13:15:11 2008
@@ -50,7 +50,8 @@
        void set_config_root(const std::string&);
        void set_user_config_root(const std::string&);
 
-       config& get_game_config() const;
+       const config& get_config() const;
+       config& get_config();
        
        void clear_defines();
        void add_define(const std::string& define);

Modified: trunk/src/serialization/preprocessor.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/serialization/preprocessor.cpp?rev=28699&r1=28698&r2=28699&view=diff
==============================================================================
--- trunk/src/serialization/preprocessor.cpp (original)
+++ trunk/src/serialization/preprocessor.cpp Mon Aug 18 13:15:11 2008
@@ -30,6 +30,8 @@
 #include <sstream>
 #include <vector>
 
+#include <boost/bind.hpp>
+
 #define ERR_CF LOG_STREAM(err, config)
 #define LOG_CF LOG_STREAM(info, config)
 #define DBG_CF LOG_STREAM(debug, config)
@@ -43,7 +45,12 @@
 
 std::ostream& operator<<(std::ostream& stream, const preproc_define& def)
 {
-       return stream << "value: " << def.value << " arguments: " << 
def.location;
+       return stream << std::string("value: ") << def.value << std::string(" 
arguments: ") << def.location;
+}
+
+std::ostream& operator<<(std::ostream& stream, const 
preproc_map::value_type& def)
+{
+       return stream << def.second;
 }
 
 class preprocessor;

Modified: trunk/src/serialization/preprocessor.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/serialization/preprocessor.hpp?rev=28699&r1=28698&r2=28699&view=diff
==============================================================================
--- trunk/src/serialization/preprocessor.hpp (original)
+++ trunk/src/serialization/preprocessor.hpp Mon Aug 18 13:15:11 2008
@@ -50,6 +50,8 @@
 
 typedef std::map< std::string, preproc_define > preproc_map;
 
+std::ostream& operator<<(std::ostream& stream, const 
preproc_map::value_type& def);
+
 //! Function to use the WML preprocessor on a file, 
 //! and returns the resulting preprocessed file data. 
 //! defines is a map of symbols defined.

Added: trunk/src/tests/macros/readme.txt
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/macros/readme.txt?rev=28699&view=auto
==============================================================================
--- trunk/src/tests/macros/readme.txt (added)
+++ trunk/src/tests/macros/readme.txt Mon Aug 18 13:15:11 2008
@@ -1,0 +1,1 @@
+This is place to put macros that are only usefull for running unit tests.

Added: trunk/src/tests/scenarios/reame.txt
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/scenarios/reame.txt?rev=28699&view=auto
==============================================================================
--- trunk/src/tests/scenarios/reame.txt (added)
+++ trunk/src/tests/scenarios/reame.txt Mon Aug 18 13:15:11 2008
@@ -1,0 +1,5 @@
+This is place to put any scenarios used by unit tests.
+
+It is good idea to reuse same scenario file as much as possible and just 
inject wml to that.
+Injection can be done creating config object with event code inside and then 
registering that
+manualy for game_events.

Modified: trunk/src/tests/test_config_cache.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/test_config_cache.cpp?rev=28699&r1=28698&r2=28699&view=diff
==============================================================================
--- trunk/src/tests/test_config_cache.cpp (original)
+++ trunk/src/tests/test_config_cache.cpp Mon Aug 18 13:15:11 2008
@@ -16,6 +16,8 @@
 #include "config_cache.hpp"
 #include "filesystem.hpp"
 #include "game_config.hpp"
+
+#include "serialization/preprocessor.hpp"
 
 BOOST_AUTO_TEST_SUITE( config_cache )
 
@@ -81,24 +83,39 @@
        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);
-       }
+       
BOOST_CHECK_EQUAL_COLLECTIONS(test_defines.begin(),test_defines.end(), 
+                                                                
defines_map.begin() ,defines_map.end());
 }
 
 BOOST_AUTO_TEST_CASE( test_load_config )
 {
+       test_config_cache& cache = test_config_cache::instance();
+       cache.add_define("test");
+       
+       preproc_map defines_map(settup_test_preproc_map());
+       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());
+       
+       std::string test_data_path("data/test/test/");
+       cache.set_config_root(test_data_path);
+       BOOST_CHECK_EQUAL(test_data_path, cache.get_config_root());
 
-       BOOST_CHECK_EQUAL(2,2);
+       config test_config;
+       {
+               config& child = test_config.add_child("textdomain");
+               child["name"] = "wesnoth";
+       }
+       {
+               config& child = test_config.add_child("test_key");
+               child["define"] = "test";
+       }
+
+       BOOST_CHECK_EQUAL(test_config, cache.get_config());
 }
 
 /* vim: set ts=4 sw=4: */
 BOOST_AUTO_TEST_SUITE_END()
+




Related Messages


Powered by MHonArc, Updated Mon Aug 18 14:41:26 2008