From ccd299b57774570807ac05552f2b9d4160b99a2b Mon Sep 17 00:00:00 2001 From: Thonsew Date: Tue, 30 Aug 2011 04:38:22 +0000 Subject: [PATCH] Fixed 2 static initialization problems... ...causing core dumps with unit_tests under GCC 4.6 --- src/tests/gui/test_gui2.cpp | 21 ++++++++++++--------- src/tests/test_config_cache.cpp | 13 ++++++------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/tests/gui/test_gui2.cpp b/src/tests/gui/test_gui2.cpp index cf3e578974b..391393f32a4 100644 --- a/src/tests/gui/test_gui2.cpp +++ b/src/tests/gui/test_gui2.cpp @@ -131,13 +131,16 @@ namespace { typedef std::pair tresolution; typedef std::vector > tresolution_list; - CVideo video(CVideo::FAKE_TEST); +CVideo & video() { + CVideo * v_ = new CVideo(CVideo::FAKE_TEST); + return *v_; +} template void test_resolutions(const tresolution_list& resolutions) { foreach(const tresolution& resolution, resolutions) { - video.make_test_fake(resolution.first, resolution.second); + video().make_test_fake(resolution.first, resolution.second); std::auto_ptr dlg(twrapper::create()); BOOST_REQUIRE_MESSAGE(dlg.get(), "Failed to create a dialog."); @@ -146,7 +149,7 @@ namespace { std::string exception; try { - dlg->show(video, 1); + dlg->show(video(), 1); } catch(gui2::tlayout_exception_width_modified&) { exception = "gui2::tlayout_exception_width_modified"; } catch(gui2::tlayout_exception_width_resize_failed&) { @@ -176,7 +179,7 @@ namespace { bool interact = false; for(int i = 0; i < 2; ++i) { foreach(const tresolution& resolution, resolutions) { - video.make_test_fake(resolution.first, resolution.second); + video().make_test_fake(resolution.first, resolution.second); std::auto_ptr dlg(twrapper::create()); BOOST_REQUIRE_MESSAGE(dlg.get(), "Failed to create a dialog."); @@ -185,7 +188,7 @@ namespace { std::string exception; try { - dlg->show(video, interact); + dlg->show(video(), interact); gui2::twindow* window = gui2::unit_test_window((*dlg.get())); BOOST_REQUIRE_NE(window, (void*)NULL); window->draw(); @@ -219,7 +222,7 @@ namespace { , const std::string& id) { foreach(const tresolution& resolution, resolutions) { - video.make_test_fake(resolution.first, resolution.second); + video().make_test_fake(resolution.first, resolution.second); std::vector& list = gui2::unit_test_registered_window_list(); @@ -235,7 +238,7 @@ namespace { * compilers and try to find the cause. */ #if 0 - gui2::tip::show(video + gui2::tip::show(video() , id , "Test messsage for a tooltip." , gui2::tpoint(0, 0)); @@ -413,11 +416,11 @@ BOOST_AUTO_TEST_CASE(test_gui2) BOOST_AUTO_TEST_CASE(test_make_test_fake) { - video.make_test_fake(10, 10); + video().make_test_fake(10, 10); try { gui2::tmessage dlg("title", "message", true); - dlg.show(video, 1); + dlg.show(video(), 1); } catch(twml_exception& e) { BOOST_CHECK(e.user_message == _("Failed to show a dialog, " "which doesn't fit on the screen.")); diff --git a/src/tests/test_config_cache.cpp b/src/tests/test_config_cache.cpp index 77577b346bc..311f67f2139 100644 --- a/src/tests/test_config_cache.cpp +++ b/src/tests/test_config_cache.cpp @@ -54,12 +54,8 @@ static preproc_map setup_test_preproc_map() 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_; - } + static test_config_cache& instance() ; void set_force_invalid_cache(bool force) { @@ -67,13 +63,16 @@ class test_config_cache : public game_config::config_cache { } }; +test_config_cache & test_config_cache::instance() { + static test_config_cache * cache_ = new test_config_cache; + return *cache_; +} + /** * Used to redirect defines settings to test cache **/ typedef game_config::scoped_preproc_define_internal test_scoped_define; -test_config_cache test_config_cache::cache_; - struct config_cache_fixture { config_cache_fixture() : cache(test_config_cache::instance()), old_locale(get_language()), test_def("TEST") {