From 2f314e909884f6a9aa6f5ca03532ec03d008af1b Mon Sep 17 00:00:00 2001 From: Mark de Wever Date: Fri, 1 May 2009 15:27:25 +0000 Subject: [PATCH] Add a new unit test for gui2. Not all dialogs have been implemented yet, but they'll follow later. --- po/wesnoth-test/POTFILES.in | 1 + src/CMakeLists.txt | 3 +- src/Makefile.am | 3 +- src/SConscript | 1 + src/tests/gui/test_gui2.cpp | 170 ++++++++++++++++++++++++++++++++++++ 5 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 src/tests/gui/test_gui2.cpp diff --git a/po/wesnoth-test/POTFILES.in b/po/wesnoth-test/POTFILES.in index bfccb298ac3..57c85f5ad2d 100644 --- a/po/wesnoth-test/POTFILES.in +++ b/po/wesnoth-test/POTFILES.in @@ -1,5 +1,6 @@ src/tests/test_formula_ai.cpp src/tests/gui/test_drop_target.cpp +src/tests/gui/test_gui2.cpp src/tests/gui/test_save_dialog.cpp src/tests/main.cpp src/tests/test_config_cache.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0301a506b57..b72acba200b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -503,8 +503,9 @@ SET(test_SRC tests/test_util.cpp tests/test_serialization.cpp tests/test_version.cpp + tests/gui/test_drop_target.cpp + tests/gui/test_gui2.cpp tests/gui/test_save_dialog.cpp - tests/gui/test_drop_target.cpp ${wesnoth-main_SRC} ) diff --git a/src/Makefile.am b/src/Makefile.am index d14e250a6f1..7498205d730 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -309,8 +309,9 @@ test_SOURCES = \ tests/test_util.cpp \ tests/test_serialization.cpp \ tests/test_version.cpp \ - tests/gui/test_save_dialog.cpp \ tests/gui/test_drop_target.cpp \ + tests/gui/test_gui2.cpp \ + tests/gui/test_save_dialog.cpp \ $(wesnoth_source) test_LDADD = $(INTERNALLIBS) $(THELIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIBS) $(PANGO_LIBS) $(FONTCONFIG_LIBS) diff --git a/src/SConscript b/src/SConscript index a6bec3d5119..9ca4b23fa93 100644 --- a/src/SConscript +++ b/src/SConscript @@ -384,6 +384,7 @@ test_sources = Split(""" tests/test_serialization.cpp tests/test_version.cpp tests/gui/test_drop_target.cpp + tests/gui/test_gui2.cpp tests/gui/test_save_dialog.cpp tests/utils/play_scenario.cpp """) diff --git a/src/tests/gui/test_gui2.cpp b/src/tests/gui/test_gui2.cpp new file mode 100644 index 00000000000..535f8bf2667 --- /dev/null +++ b/src/tests/gui/test_gui2.cpp @@ -0,0 +1,170 @@ +/* $Id$ */ +/* + Copyright (C) 2009 by Mark de Wever + 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. +*/ + +#define GETTEXT_DOMAIN "wesnoth-test" + +#include "tests/utils/test_support.hpp" + +#include "foreach.hpp" +#include "game_config.hpp" +#include "gui/auxiliary/layout_exception.hpp" +#include "gui/dialogs/addon_connect.hpp" +#include "gui/dialogs/addon_list.hpp" +#include "gui/dialogs/campaign_selection.hpp" +#ifndef DISABLE_EDITOR2 +#include "gui/dialogs/editor_generate_map.hpp" +#include "gui/dialogs/editor_new_map.hpp" +#include "gui/dialogs/editor_resize_map.hpp" +#include "gui/dialogs/editor_settings.hpp" +#endif +#include "gui/dialogs/game_save.hpp" +#include "gui/dialogs/language_selection.hpp" +#include "gui/dialogs/message.hpp" +#include "gui/dialogs/mp_connect.hpp" +#include "gui/dialogs/mp_create_game.hpp" +#include "gui/dialogs/mp_method_selection.hpp" +#include "gui/dialogs/mp_cmd_wrapper.hpp" +#include "gui/dialogs/title_screen.hpp" +#include "gui/dialogs/wml_message.hpp" +#include "gui/widgets/helper.hpp" +#include "gui/widgets/settings.hpp" +#include "video.hpp" +#include "wml_exception.hpp" + +namespace { + + typedef std::pair tresolution; + typedef std::vector > tresolution_list; + + CVideo video(CVideo::FAKE_TEST); + + template + void test_resolutions(const tresolution_list& resolutions) + { + foreach(const tresolution& resolution, resolutions) { + video.make_test_fake(resolution.first, resolution.second); + + T dlg; + std::string exception; + try { + dlg.show(video, 1); + } catch(gui2::tlayout_exception_width_modified&) { + exception = "gui2::tlayout_exception_width_modified"; + } catch(gui2::tlayout_exception_width_resize_failed&) { + exception = "gui2::tlayout_exception_width_resize_failed"; + } catch(gui2::tlayout_exception_height_resize_failed&) { + exception = "gui2::tlayout_exception_height_resize_failed"; + } catch(twml_exception& e) { + exception = e.dev_message; + } catch(std::exception& e) { + exception = e.what(); + } catch(...) { + exception = "unknown"; + } + BOOST_CHECK_MESSAGE(exception.empty(), + "Test for " << typeid(T).name() + << " Failed\nnew widgets = " << gui2::new_widgets + << " small gui = " << game_config::small_gui + << " resolution = " << resolution.first + << 'x' << resolution.second + << "\nException caught: " << exception << '.'); + } + } + +#ifdef USE_TINY_GUI + +const tresolution_list& get_tiny_gui_resolutions() +{ + static tresolution_list result; + if(result.empty()) { + result.push_back(std::make_pair(320, 240)); + result.push_back(std::make_pair(640, 480)); + } + return result; +} + +template +void test() +{ + test_resolutions(get_small_tiny_resolutions()); +} + +#else + +const tresolution_list& get_small_gui_resolutions() +{ + static tresolution_list result; + if(result.empty()) { + result.push_back(std::make_pair(800, 480)); + } + return result; +} + +const tresolution_list& get_gui_resolutions() +{ + static tresolution_list result; + if(result.empty()) { + result.push_back(std::make_pair(800, 600)); + result.push_back(std::make_pair(1024, 768)); + result.push_back(std::make_pair(1280, 1024)); + result.push_back(std::make_pair(1680, 1050)); + } + return result; +} + +template +void test() +{ + gui2::new_widgets = false; + + for(size_t i = 0; i < 2; ++i) { + + game_config::small_gui = true; + test_resolutions(get_small_gui_resolutions()); + + game_config::small_gui = false; + test_resolutions(get_gui_resolutions()); + + gui2::new_widgets = true; + } +} +#endif + +} // namespace + +BOOST_AUTO_TEST_CASE(test_gui2) +{ + gui2::init(); + + test(); +// test(); +// test(); +#ifndef DISABLE_EDITOR2 +//// test(); + test(); + test(); +//// test(); +#endif +// test(); + test(); +// test(); +// test(); +//// test(); +// test(); +//// test(); +//// test(); +// test(); +// test(); + +}