Fixed 2 static initialization problems...

...causing core dumps with unit_tests under GCC 4.6
This commit is contained in:
Thonsew 2011-08-30 04:38:22 +00:00
parent a3ceeb83b0
commit ccd299b577
2 changed files with 18 additions and 16 deletions

View File

@ -131,13 +131,16 @@ namespace {
typedef std::pair<unsigned, unsigned> tresolution; typedef std::pair<unsigned, unsigned> tresolution;
typedef std::vector<std::pair<unsigned, unsigned> > tresolution_list; typedef std::vector<std::pair<unsigned, unsigned> > tresolution_list;
CVideo video(CVideo::FAKE_TEST); CVideo & video() {
CVideo * v_ = new CVideo(CVideo::FAKE_TEST);
return *v_;
}
template<class T> template<class T>
void test_resolutions(const tresolution_list& resolutions) void test_resolutions(const tresolution_list& resolutions)
{ {
foreach(const tresolution& resolution, 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<gui2::tdialog> dlg(twrapper<T>::create()); std::auto_ptr<gui2::tdialog> dlg(twrapper<T>::create());
BOOST_REQUIRE_MESSAGE(dlg.get(), "Failed to create a dialog."); BOOST_REQUIRE_MESSAGE(dlg.get(), "Failed to create a dialog.");
@ -146,7 +149,7 @@ namespace {
std::string exception; std::string exception;
try { try {
dlg->show(video, 1); dlg->show(video(), 1);
} catch(gui2::tlayout_exception_width_modified&) { } catch(gui2::tlayout_exception_width_modified&) {
exception = "gui2::tlayout_exception_width_modified"; exception = "gui2::tlayout_exception_width_modified";
} catch(gui2::tlayout_exception_width_resize_failed&) { } catch(gui2::tlayout_exception_width_resize_failed&) {
@ -176,7 +179,7 @@ namespace {
bool interact = false; bool interact = false;
for(int i = 0; i < 2; ++i) { for(int i = 0; i < 2; ++i) {
foreach(const tresolution& resolution, 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<gui2::tpopup> dlg(twrapper<T>::create()); std::auto_ptr<gui2::tpopup> dlg(twrapper<T>::create());
BOOST_REQUIRE_MESSAGE(dlg.get(), "Failed to create a dialog."); BOOST_REQUIRE_MESSAGE(dlg.get(), "Failed to create a dialog.");
@ -185,7 +188,7 @@ namespace {
std::string exception; std::string exception;
try { try {
dlg->show(video, interact); dlg->show(video(), interact);
gui2::twindow* window = gui2::unit_test_window((*dlg.get())); gui2::twindow* window = gui2::unit_test_window((*dlg.get()));
BOOST_REQUIRE_NE(window, (void*)NULL); BOOST_REQUIRE_NE(window, (void*)NULL);
window->draw(); window->draw();
@ -219,7 +222,7 @@ namespace {
, const std::string& id) , const std::string& id)
{ {
foreach(const tresolution& resolution, resolutions) { foreach(const tresolution& resolution, resolutions) {
video.make_test_fake(resolution.first, resolution.second); video().make_test_fake(resolution.first, resolution.second);
std::vector<std::string>& list = std::vector<std::string>& list =
gui2::unit_test_registered_window_list(); gui2::unit_test_registered_window_list();
@ -235,7 +238,7 @@ namespace {
* compilers and try to find the cause. * compilers and try to find the cause.
*/ */
#if 0 #if 0
gui2::tip::show(video gui2::tip::show(video()
, id , id
, "Test messsage for a tooltip." , "Test messsage for a tooltip."
, gui2::tpoint(0, 0)); , gui2::tpoint(0, 0));
@ -413,11 +416,11 @@ BOOST_AUTO_TEST_CASE(test_gui2)
BOOST_AUTO_TEST_CASE(test_make_test_fake) BOOST_AUTO_TEST_CASE(test_make_test_fake)
{ {
video.make_test_fake(10, 10); video().make_test_fake(10, 10);
try { try {
gui2::tmessage dlg("title", "message", true); gui2::tmessage dlg("title", "message", true);
dlg.show(video, 1); dlg.show(video(), 1);
} catch(twml_exception& e) { } catch(twml_exception& e) {
BOOST_CHECK(e.user_message == _("Failed to show a dialog, " BOOST_CHECK(e.user_message == _("Failed to show a dialog, "
"which doesn't fit on the screen.")); "which doesn't fit on the screen."));

View File

@ -54,12 +54,8 @@ static preproc_map setup_test_preproc_map()
class test_config_cache : public game_config::config_cache { class test_config_cache : public game_config::config_cache {
test_config_cache() : game_config::config_cache() {} test_config_cache() : game_config::config_cache() {}
static test_config_cache cache_;
public: public:
static test_config_cache& instance() { static test_config_cache& instance() ;
return cache_;
}
void set_force_invalid_cache(bool force) 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 * Used to redirect defines settings to test cache
**/ **/
typedef game_config::scoped_preproc_define_internal<test_config_cache> test_scoped_define; typedef game_config::scoped_preproc_define_internal<test_config_cache> test_scoped_define;
test_config_cache test_config_cache::cache_;
struct config_cache_fixture { struct config_cache_fixture {
config_cache_fixture() : cache(test_config_cache::instance()), old_locale(get_language()), test_def("TEST") config_cache_fixture() : cache(test_config_cache::instance()), old_locale(get_language()), test_def("TEST")
{ {