Author: suokko
Date: Sat Jul 5 00:43:05 2008
New Revision: 27734
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27734&view=rev
Log:
* fake_display for unit tests
* added first get_save_name dialog test case
Added:
trunk/src/tests/utils/fake_display.cpp (with props)
trunk/src/tests/utils/fake_display.hpp (with props)
Modified:
trunk/src/SConscript
trunk/src/construct_dialog.cpp
trunk/src/display.cpp
trunk/src/key.cpp
trunk/src/tests/main.cpp
trunk/src/tests/test_endlevel.cpp
trunk/src/tests/utils/fake_event_source.cpp
trunk/src/video.cpp
trunk/src/video.hpp
Modified: trunk/src/SConscript
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/SConscript?rev=27734&r1=27733&r2=27734&view=diff
==============================================================================
--- trunk/src/SConscript (original)
+++ trunk/src/SConscript Sat Jul 5 00:43:05 2008
@@ -320,6 +320,7 @@
test_utils_sources = Split("""
tests/utils/fake_event_source.cpp
+ tests/utils/fake_display.cpp
""")
libtest_utils = env.Library("test_utils", test_utils_sources)
Modified: trunk/src/construct_dialog.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/construct_dialog.cpp?rev=27734&r1=27733&r2=27734&view=diff
==============================================================================
--- trunk/src/construct_dialog.cpp (original)
+++ trunk/src/construct_dialog.cpp Sat Jul 5 00:43:05 2008
@@ -706,8 +706,8 @@
const bool use_text_input = (text_widget_!=NULL);
const bool has_input = (use_menu||use_text_input);//input of any sort
has to be made
- if(((!info.key_down && info.key[SDLK_RETURN]) ||
info.key[SDLK_KP_ENTER] || info.double_clicked) &&
- (type_ == YES_NO || type_ == OK_CANCEL || type_ == OK_ONLY || type_
== CLOSE_ONLY)) {
+ if(((!info.key_down && (info.key[SDLK_RETURN] ||
info.key[SDLK_KP_ENTER]) || info.double_clicked) &&
+ (type_ == YES_NO || type_ == OK_CANCEL || type_ == OK_ONLY || type_
== CLOSE_ONLY))) {
return (use_menu ? menu_->selection() : 0);
}
Modified: trunk/src/display.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/display.cpp?rev=27734&r1=27733&r2=27734&view=diff
==============================================================================
--- trunk/src/display.cpp (original)
+++ trunk/src/display.cpp Sat Jul 5 00:43:05 2008
@@ -122,7 +122,9 @@
idle_anim_rate_(1.0),
map_screenshot_surf_(NULL)
{
- if(non_interactive()) {
+ if(non_interactive()
+ && (get_video_surface() != NULL
+ && video.faked())) {
screen_.lock_updates(true);
}
Modified: trunk/src/key.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/key.cpp?rev=27734&r1=27733&r2=27734&view=diff
==============================================================================
--- trunk/src/key.cpp (original)
+++ trunk/src/key.cpp Sat Jul 5 00:43:05 2008
@@ -25,7 +25,7 @@
int CKey::operator[]( int code ) const
{
- return (code == SDLK_ESCAPE || is_enabled) && int(key_list[code]);
+ return int(key_list[code]);
}
void CKey::SetEnabled( bool enable )
Modified: trunk/src/tests/main.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/main.cpp?rev=27734&r1=27733&r2=27734&view=diff
==============================================================================
--- trunk/src/tests/main.cpp (original)
+++ trunk/src/tests/main.cpp Sat Jul 5 00:43:05 2008
@@ -20,7 +20,9 @@
#include "game_errors.hpp"
#include "network.hpp"
#include "config.hpp"
+#include "log.hpp"
+#include "tests/utils/fake_display.hpp"
/**
* @todo: add all others exception handlers too
**/
@@ -44,6 +46,10 @@
wesnoth_global_fixture()
{
SDL_Init(SDL_INIT_TIMER);
+ test_utils::get_fake_display();
+
+// lg::set_log_domain_severity("all",3);
+
if (boost::unit_test::runtime_config::log_level() <
boost::unit_test::log_messages)
boost::unit_test::unit_test_log.set_threshold_level(
boost::unit_test::log_messages );
BOOST_MESSAGE("Initializing test!");
Modified: trunk/src/tests/test_endlevel.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/test_endlevel.cpp?rev=27734&r1=27733&r2=27734&view=diff
==============================================================================
--- trunk/src/tests/test_endlevel.cpp (original)
+++ trunk/src/tests/test_endlevel.cpp Sat Jul 5 00:43:05 2008
@@ -14,13 +14,15 @@
#include <boost/test/auto_unit_test.hpp>
+#include "dialogs.hpp"
#include "key.hpp"
+#include "filesystem.hpp"
+#include "gamestatus.hpp"
#include "unit_types.hpp"
-#include "dialogs.hpp"
-#include "gamestatus.hpp"
//
#include "tests/utils/fake_event_source.hpp"
+#include "tests/utils/fake_display.hpp"
// Linker workarounds start here
@@ -30,7 +32,6 @@
#include "config.hpp"
#include "serialization/parser.hpp"
#include "serialization/preprocessor.hpp"
-#include "filesystem.hpp"
#include "sdl_utils.hpp"
#include "game_events.hpp"
#include "network.hpp"
@@ -53,47 +54,36 @@
namespace test {
- struct endlevel_fixture {
+ struct save_dialog_fixture {
test_utils::fake_event_source source;
- SDL_Event event;
};
- BOOST_FIXTURE_TEST_SUITE( endlevel , endlevel_fixture)
+ BOOST_FIXTURE_TEST_SUITE( save_dialog , save_dialog_fixture)
BOOST_AUTO_TEST_CASE( test_fake_input )
{
BOOST_MESSAGE("Starting endlevel test!");
- event.type = SDL_KEYDOWN;
- event.key.state = SDL_PRESSED;
- event.key.keysym.sym = SDLK_ESCAPE;
- event.key.keysym.scancode = 65;
- event.key.keysym.mod = KMOD_NONE;
- event.key.keysym.unicode = 0;
-
- test_utils::event_node_ptr new_keypress(new
test_utils::event_node_keyboard(3, event));
- event.type = SDL_KEYUP;
- event.key.state = SDL_RELEASED;
- test_utils::event_node_ptr new_keyrelease(new
test_utils::event_node_keyboard(5, event));
- source.add_event(new_keypress);
- source.add_event(new_keyrelease);
-
+ test_utils::event_node_ptr new_keypress =
source.press_key(2, SDLK_RETURN);
+ test_utils::event_node_ptr new_keyrelease =
source.release_key(4, SDLK_RETURN);
CKey key;
+ source.start();
+
while(true)
{
events::pump();
- BOOST_CHECK_EQUAL(key[SDLK_ESCAPE],
new_keypress->is_fired());
- if (key[SDLK_ESCAPE])
+ BOOST_CHECK_EQUAL(key[SDLK_RETURN],
new_keypress->is_fired());
+ if (key[SDLK_RETURN])
break;
}
while(true)
{
events::pump();
- BOOST_CHECK_EQUAL(key[SDLK_ESCAPE],
!new_keyrelease->is_fired());
- if (!key[SDLK_ESCAPE])
+ BOOST_CHECK_EQUAL(key[SDLK_RETURN],
!new_keyrelease->is_fired());
+ if (!key[SDLK_RETURN])
break;
}
}
@@ -102,24 +92,16 @@
{
// fill in events to be used in test
test_utils::event_node_ptr press_return_before =
source.press_key(0, SDLK_RETURN);
- test_utils::event_node_ptr release_return_before =
source.release_key(3, SDLK_RETURN);
- test_utils::event_node_ptr press_return_after =
source.press_key(6, SDLK_RETURN);
- test_utils::event_node_ptr release_return_after =
source.release_key(9, SDLK_RETURN);
+ test_utils::event_node_ptr release_return_before =
source.release_key(200, SDLK_RETURN);
+ test_utils::event_node_ptr press_return_after =
source.press_key(240, SDLK_RETURN);
+ test_utils::event_node_ptr release_return_after =
source.release_key(1000, SDLK_RETURN);
+
+ // Just to make sure no forever loops happening
+ source.press_key(1100, SDLK_RETURN);
+ source.release_key(1200, SDLK_RETURN);
- CVideo video_;
- video_.make_test_fake();
- unit_map dummy_umap;
- config dummy_cfg;
- gamemap dummy_map(dummy_cfg, "");
- gamestatus dummy_status(dummy_cfg, 0);
- std::vector<team> dummy_teams;
- const events::event_context main_event_context_;
-
- game_display disp(dummy_umap, video_, dummy_map,
dummy_status,
- dummy_teams, dummy_cfg,
dummy_cfg, dummy_cfg);
-
std::string fname("press_enter");
-
+ write_file(get_saves_dir() + "/" + fname +".gz",
"böö");
// Start test (set ticks start time)
source.start();
// Activated enter press
@@ -128,7 +110,7 @@
BOOST_CHECK_MESSAGE(press_return_before->is_fired(),
"Enter wasn't activated");
BOOST_CHECK_MESSAGE(!release_return_before->is_fired(),
"Enter was released before test");
- BOOST_CHECK_EQUAL(dialogs::get_save_name(disp, "Save
game?", "file", &fname,gui::OK_CANCEL, "Save game", false, true), 0);
+
BOOST_CHECK_EQUAL(dialogs::get_save_name(test_utils::get_fake_display(), "Save
game?", "file", &fname,gui::OK_CANCEL, "Save game", false, false), 0);
BOOST_CHECK_MESSAGE(release_return_before->is_fired(),
"get_save_name returned before releasing first enter.");
BOOST_CHECK_MESSAGE(press_return_after->is_fired(),
"get_save_name returned before 2nd enter event was sent");
Added: trunk/src/tests/utils/fake_display.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/utils/fake_display.cpp?rev=27734&view=auto
==============================================================================
--- trunk/src/tests/utils/fake_display.cpp (added)
+++ trunk/src/tests/utils/fake_display.cpp Sat Jul 5 00:43:05 2008
@@ -1,0 +1,83 @@
+/* $Id$ */
+/*
+ Copyright (C) 2008 by Pauli Nieminen <[EMAIL PROTECTED]>
+ 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.
+*/
+
+#include <iostream>
+#include "tests/utils/fake_display.hpp"
+
+#include "game_display.hpp"
+#include "video.hpp"
+#include "config.hpp"
+#include "unit_types.hpp"
+#include "gamestatus.hpp"
+
+namespace test_utils {
+
+ class fake_display_manager {
+ static fake_display_manager* manager_;
+
+ CVideo video_;
+ unit_map dummy_umap_;
+ config dummy_cfg_;
+ gamemap dummy_map_;
+ gamestatus dummy_status_;
+ std::vector<team> dummy_teams_;
+ const events::event_context main_event_context_;
+
+
+ game_display disp_;
+
+ public:
+ static fake_display_manager* get_manager();
+ game_display& get_display();
+
+ fake_display_manager();
+// ~fake_display_manager();
+ };
+
+ fake_display_manager* fake_display_manager::manager_ = 0;
+
+ fake_display_manager* fake_display_manager::get_manager()
+ {
+ if (!manager_)
+ {
+ manager_ = new fake_display_manager();
+ }
+ return manager_;
+ }
+
+ fake_display_manager::fake_display_manager() :
+ video_(CVideo::FAKE_TEST),
+ dummy_umap_(),
+ dummy_cfg_(),
+ dummy_map_(dummy_cfg_,""),
+ dummy_status_(dummy_cfg_, 0),
+ dummy_teams_(),
+ main_event_context_(),
+ disp_(dummy_umap_, video_, dummy_map_, dummy_status_,
+ dummy_teams_, dummy_cfg_, dummy_cfg_,
dummy_cfg_)
+ {
+ }
+
+ game_display& fake_display_manager::get_display()
+ {
+ return disp_;
+ }
+
+ game_display& get_fake_display()
+ {
+ return fake_display_manager::get_manager()->get_display();
+ }
+
+
+}
Propchange: trunk/src/tests/utils/fake_display.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/src/tests/utils/fake_display.cpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: trunk/src/tests/utils/fake_display.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/utils/fake_display.hpp?rev=27734&view=auto
==============================================================================
--- trunk/src/tests/utils/fake_display.hpp (added)
+++ trunk/src/tests/utils/fake_display.hpp Sat Jul 5 00:43:05 2008
@@ -1,0 +1,26 @@
+/* $Id$ */
+/*
+ Copyright (C) 2008 by Pauli Nieminen <[EMAIL PROTECTED]>
+ 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.
+*/
+
+#ifndef TESTS_UTILS_FAKE_DISPLAY_HPP_INCLUDED
+#define TESTS_UTILS_FAKE_DISPLAY_HPP_INCLUDED
+
+class game_display;
+
+namespace test_utils {
+
+ game_display& get_fake_display();
+
+
+}
+#endif
Propchange: trunk/src/tests/utils/fake_display.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/src/tests/utils/fake_display.hpp
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: trunk/src/tests/utils/fake_event_source.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/utils/fake_event_source.cpp?rev=27734&r1=27733&r2=27734&view=diff
==============================================================================
--- trunk/src/tests/utils/fake_event_source.cpp (original)
+++ trunk/src/tests/utils/fake_event_source.cpp Sat Jul 5 00:43:05 2008
@@ -60,9 +60,9 @@
static int num_keys = 300;
Uint8* key_list = SDL_GetKeyState( &num_keys );
if (event_.type == SDL_KEYDOWN)
- key_list[SDLK_ESCAPE] = 5;
+ key_list[event_.key.keysym.sym] = 1;
else
- key_list[SDLK_ESCAPE] = 0;
+ key_list[event_.key.keysym.sym] = 0;
}
fake_event_source::fake_event_source() : start_time_(SDL_GetTicks())
Modified: trunk/src/video.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/video.cpp?rev=27734&r1=27733&r2=27734&view=diff
==============================================================================
--- trunk/src/video.cpp (original)
+++ trunk/src/video.cpp Sat Jul 5 00:43:05 2008
@@ -230,13 +230,24 @@
{
update_all = true;
}
-CVideo::CVideo() : mode_changed_(false), bpp_(0), fake_screen_(false),
help_string_(0), updatesLocked_(0)
+CVideo::CVideo(FAKE_TYPES type) : mode_changed_(false), bpp_(0),
fake_screen_(false), help_string_(0), updatesLocked_(0)
{
const int res = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
if(res < 0) {
ERR_DP << "Could not initialize SDL: " << SDL_GetError() <<
"\n";
throw CVideo::error();
+ }
+ switch(type)
+ {
+ case NO_FAKE:
+ break;
+ case FAKE:
+ make_fake();
+ break;
+ case FAKE_TEST:
+ make_test_fake();
+ break;
}
}
Modified: trunk/src/video.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/video.hpp?rev=27734&r1=27733&r2=27734&view=diff
==============================================================================
--- trunk/src/video.hpp (original)
+++ trunk/src/video.hpp Sat Jul 5 00:43:05 2008
@@ -36,7 +36,12 @@
class CVideo {
public:
- CVideo();
+ enum FAKE_TYPES {
+ NO_FAKE,
+ FAKE,
+ FAKE_TEST
+ };
+ CVideo(FAKE_TYPES type = NO_FAKE);
CVideo(int x, int y, int bits_per_pixel, int flags);
~CVideo();
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits