Author: mordante
Date: Sun Mar 6 15:14:15 2011
New Revision: 48787
URL: http://svn.gna.org/viewcvs/wesnoth?rev=48787&view=rev
Log:
Enable the unit test for gui2::tdebug_clock.
This also involves modifing the tpopup class. It's the first test using
a tpopup class so several unit test holes needed to be punctured.
Modified:
trunk/src/gui/dialogs/popup.hpp
trunk/src/tests/gui/test_gui2.cpp
Modified: trunk/src/gui/dialogs/popup.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/dialogs/popup.hpp?rev=48787&r1=48786&r2=48787&view=diff
==============================================================================
--- trunk/src/gui/dialogs/popup.hpp (original)
+++ trunk/src/gui/dialogs/popup.hpp Sun Mar 6 15:14:15 2011
@@ -32,6 +32,22 @@
*/
class tpopup
{
+ /**
+ * Special helper function to get the id of the window.
+ *
+ * This is used in the unit tests, but these implementation details
+ * shouldn't be used in the normal code.
+ */
+ friend std::string unit_test_mark_popup_as_tested(const tpopup& dialog);
+
+ /**
+ * Special helper function for the unit test to the the window.
+ *
+ * This is used in the unit tests, but these implementation details
+ * shouldn't be used in the normal code.
+ */
+ friend twindow* unit_test_window(const tpopup& dialog);
+
public:
tpopup();
Modified: trunk/src/tests/gui/test_gui2.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/gui/test_gui2.cpp?rev=48787&r1=48786&r2=48787&view=diff
==============================================================================
--- trunk/src/tests/gui/test_gui2.cpp (original)
+++ trunk/src/tests/gui/test_gui2.cpp Sun Mar 6 15:14:15 2011
@@ -55,6 +55,7 @@
#include "gui/dialogs/unit_create.hpp"
#include "gui/dialogs/wml_message.hpp"
#include "gui/widgets/settings.hpp"
+#include "gui/widgets/window.hpp"
#include "language.hpp"
#include "map_create.hpp"
#include "tests/utils/fake_display.hpp"
@@ -84,6 +85,19 @@
return dialog.window_id();
}
+std::string unit_test_mark_popup_as_tested(const tpopup& dialog)
+{
+ std::vector<std::string>& list = unit_test_registered_window_list();
+ list.erase(
+ std::remove(list.begin(), list.end(),
dialog.window_id())
+ , list.end());
+ return dialog.window_id();
+}
+
+twindow* unit_test_window(const tpopup& dialog)
+{
+ return dialog.window_;
+}
class tmp_server_list;
@@ -153,6 +167,50 @@
}
}
+ template<class T>
+ void test_popup_resolutions(const tresolution_list& resolutions)
+ {
+ bool interact = false;
+ for(int i = 0; i < 2; ++i) {
+ foreach(const tresolution& resolution, resolutions) {
+ video.make_test_fake(resolution.first,
resolution.second);
+
+ std::auto_ptr<gui2::tpopup>
dlg(twrapper<T>::create());
+ BOOST_REQUIRE_MESSAGE(dlg.get(), "Failed to
create a dialog.");
+
+ const std::string id =
gui2::unit_test_mark_popup_as_tested(*(dlg.get()));
+
+ std::string exception;
+ try {
+ dlg->show(video, interact);
+ gui2::twindow* window =
gui2::unit_test_window((*dlg.get()));
+ BOOST_REQUIRE_NE(window, (void*)NULL);
+ window->draw();
+ }
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 '" << id
+ << "' Failed\nnew widgets = "
<< gui2::new_widgets
+ << " small gui = " <<
game_config::small_gui
+ << " resolution = " <<
resolution.first
+ << 'x' << resolution.second
+ << "\nException caught: " <<
exception << '.');
+ }
+
+ interact = true;
+ }
+ }
const tresolution_list& get_small_gui_resolutions()
{
static tresolution_list result;
@@ -191,6 +249,23 @@
}
}
+template<class T>
+void test_popup()
+{
+ gui2::new_widgets = false;
+
+ for(size_t i = 0; i < 2; ++i) {
+
+ game_config::small_gui = true;
+ test_popup_resolutions<T>(get_small_gui_resolutions());
+
+ game_config::small_gui = false;
+ test_popup_resolutions<T>(get_gui_resolutions());
+
+ gui2::new_widgets = true;
+ }
+}
+
} // namespace
BOOST_AUTO_TEST_CASE(test_gui2)
@@ -209,6 +284,8 @@
game_config::load_config(main_config.child("game_config"));
/**** Run the tests. *****/
+
+ /* The tdialog classes. */
test<gui2::taddon_connect>();
test<gui2::taddon_list>();
test<gui2::tcampaign_selection>();
@@ -241,6 +318,9 @@
test<gui2::twml_message_left>();
test<gui2::twml_message_right>();
+ /* The tpopup classes. */
+ test_popup<gui2::tdebug_clock>();
+
std::vector<std::string>& list =
gui2::unit_test_registered_window_list();
/**
@@ -249,9 +329,6 @@
* This list marks some dialogs as tested that are not tested.
* This list should be removed so all dialogs are properly tested.
*/
- list.erase(
- std::remove(list.begin(), list.end(), "debug_clock")
- , list.end());
list.erase(
std::remove(list.begin(), list.end(), "unit_attack")
, list.end());
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits