Changed scons build to include libwesnoth_extras
Added code to send timed fake SDL events (This still needs to be moved to src/tests/utils/)
This commit is contained in:
parent
427b624294
commit
388d67f190
4 changed files with 205 additions and 6 deletions
|
@ -248,6 +248,7 @@ wesnoth_editor2_sources = Split("""
|
|||
if env['editor2']:
|
||||
wesnoth_sources += wesnoth_editor2_sources
|
||||
|
||||
libwesnoth_extras = env.Library("wesnoth_extras", wesnoth_sources)
|
||||
#
|
||||
# Target declarations
|
||||
#
|
||||
|
@ -265,7 +266,7 @@ SConsEnvironment.WesnothProgram = WesnothProgram
|
|||
|
||||
game_cpp = python_env.Object("game.cpp");
|
||||
|
||||
env.WesnothProgram("wesnoth", [game_cpp] + wesnoth_sources + [libwesnoth_core, libwesnoth_sdl, libwesnoth, libcampaignd] + wesnoth_res, have_client_prereqs)
|
||||
env.WesnothProgram("wesnoth", [game_cpp] + [libwesnoth_extras, libwesnoth_core, libwesnoth_sdl, libwesnoth, libcampaignd] + wesnoth_res, have_client_prereqs)
|
||||
|
||||
wesnoth_editor_sources = Split("""
|
||||
editor/editor.cpp
|
||||
|
@ -322,7 +323,7 @@ test_sources = Split("""
|
|||
tests/test_network_worker.cpp
|
||||
tests/test_endlevel.cpp
|
||||
""")
|
||||
test = test_env.WesnothProgram("test", test_sources + [libwesnoth_core, libwesnothd], have_test_prereqs)
|
||||
test = test_env.WesnothProgram("test", test_sources + [libwesnoth_extras, libwesnoth_core, libwesnoth_sdl, libwesnoth], have_test_prereqs)
|
||||
#Export("test")
|
||||
|
||||
if env["svnrev"] != "" and env["svnrev"] != "exported":
|
||||
|
|
|
@ -343,6 +343,7 @@ LEVEL_RESULT playsingle_controller::play_scenario(const std::vector<config*>& st
|
|||
try {
|
||||
game_events::fire("victory");
|
||||
} catch(end_level_exception&) {
|
||||
ERR_NG << "[endlevel] used in victory even handler\n";
|
||||
}
|
||||
if (first_human_team_ != -1)
|
||||
log.victory(status_.turn(), teams_[first_human_team_].gold());
|
||||
|
|
|
@ -14,10 +14,207 @@
|
|||
|
||||
#include <boost/test/auto_unit_test.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE( endlevel )
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <queue>
|
||||
#include "SDL.h"
|
||||
|
||||
BOOST_AUTO_TEST_CASE( dialog_reseting_keys )
|
||||
#include "key.hpp"
|
||||
#include "events.hpp"
|
||||
//#include "dialogs.hpp"
|
||||
|
||||
|
||||
// Linker workarounds start here
|
||||
#define LD_WA
|
||||
|
||||
#ifdef LD_WA
|
||||
#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"
|
||||
// to load libwesnoth_extras
|
||||
WML_HANDLER_FUNCTION(test_sources, , , )
|
||||
{
|
||||
// To load libwesnoth_core
|
||||
network::get_pending_stats();
|
||||
// To load libwesnoth_sdl
|
||||
SDL_Color color = int_to_color(255);
|
||||
std::cerr << "Fooled you\n";
|
||||
}
|
||||
#endif
|
||||
// Linker workarounds end here
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
/**
|
||||
* fake_sdl_event_source is used to generate new events in
|
||||
* events::pump()
|
||||
**/
|
||||
namespace test {
|
||||
|
||||
// bool event_fired = false;
|
||||
|
||||
template<class T>
|
||||
struct test_less_ptr {
|
||||
bool operator()(const T& a, const T& b) const
|
||||
{
|
||||
return (*a) < (*b);
|
||||
}
|
||||
};
|
||||
|
||||
class fake_sdl_event_source
|
||||
: public events::pump_monitor,
|
||||
public boost::noncopyable
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Base class for all event nodes to be used to fire fake input events
|
||||
**/
|
||||
class event_node :
|
||||
public boost::noncopyable
|
||||
{
|
||||
size_t time_;
|
||||
bool fired_;
|
||||
protected:
|
||||
SDL_Event event_;
|
||||
|
||||
public:
|
||||
event_node(const size_t time, const SDL_Event& event) : time_(time), fired_(false), event_(event)
|
||||
{}
|
||||
virtual ~event_node()
|
||||
{ }
|
||||
|
||||
virtual void fire_event()
|
||||
{
|
||||
const int number_of_events = 1;
|
||||
const Uint32 mask = 0;
|
||||
SDL_PeepEvents(&event_, number_of_events, SDL_ADDEVENT, mask);
|
||||
fired_ = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if this should stop firing events
|
||||
**/
|
||||
bool test_if_should_fire(const size_t time_now) const
|
||||
{
|
||||
return time_ <= time_now;
|
||||
}
|
||||
|
||||
bool is_fired() const
|
||||
{
|
||||
return fired_;
|
||||
}
|
||||
|
||||
/**
|
||||
* We want the smallestat the top
|
||||
**/
|
||||
bool operator<(const event_node& o) const
|
||||
{ return time_ > o.time_; }
|
||||
};
|
||||
|
||||
class event_node_keyboard : public event_node {
|
||||
public:
|
||||
event_node_keyboard(size_t time, SDL_Event& event) : event_node(time,event)
|
||||
{}
|
||||
void fire_event()
|
||||
{
|
||||
event_node::fire_event();
|
||||
static int num_keys = 300;
|
||||
Uint8* key_list = SDL_GetKeyState( &num_keys );
|
||||
if (event_.type == SDL_KEYDOWN)
|
||||
key_list[SDLK_ESCAPE] = 5;
|
||||
else
|
||||
key_list[SDLK_ESCAPE] = 0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef boost::shared_ptr<event_node> event_node_ptr;
|
||||
|
||||
private:
|
||||
typedef std::priority_queue<event_node_ptr,std::vector<event_node_ptr>,test_less_ptr<event_node_ptr> > event_queue;
|
||||
|
||||
event_queue queue_;
|
||||
|
||||
public:
|
||||
void add_event(const size_t time, const SDL_Event& event)
|
||||
{
|
||||
event_node_ptr new_node(new event_node(time,event));
|
||||
queue_.push(new_node);
|
||||
}
|
||||
|
||||
void add_event(event_node_ptr new_node)
|
||||
{
|
||||
queue_.push(new_node);
|
||||
}
|
||||
|
||||
void process(events::pump_info& /*info*/);
|
||||
};
|
||||
|
||||
void fake_sdl_event_source::process(events::pump_info& /*info*/)
|
||||
{
|
||||
if (queue_.empty())
|
||||
return;
|
||||
size_t now = SDL_GetTicks();
|
||||
if (queue_.top()->test_if_should_fire(now))
|
||||
{
|
||||
queue_.top()->fire_event();
|
||||
queue_.pop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE( endlevel )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( test_fake_input )
|
||||
{
|
||||
#ifdef LD_WA
|
||||
{
|
||||
config cfg;
|
||||
scoped_istream stream = preprocess_file("data/hardwired/language.cfg");
|
||||
read(cfg, *stream);
|
||||
}
|
||||
#endif
|
||||
|
||||
fake_sdl_event_source source;
|
||||
SDL_Event event;
|
||||
|
||||
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;
|
||||
const size_t now = SDL_GetTicks();
|
||||
|
||||
fake_sdl_event_source::event_node_ptr new_keypress(new fake_sdl_event_source::event_node_keyboard(now + 10, event));
|
||||
event.type = SDL_KEYUP;
|
||||
event.key.state = SDL_RELEASED;
|
||||
fake_sdl_event_source::event_node_ptr new_keyrelease(new fake_sdl_event_source::event_node_keyboard(now + 20, event));
|
||||
source.add_event(new_keypress);
|
||||
source.add_event(new_keyrelease);
|
||||
|
||||
|
||||
BOOST_MESSAGE("Starting endlevel test!");
|
||||
CKey key;
|
||||
// dialogs::get_save_name();
|
||||
while(true)
|
||||
{
|
||||
events::pump();
|
||||
|
||||
BOOST_CHECK_EQUAL(key[SDLK_ESCAPE], new_keypress->is_fired());
|
||||
if (key[SDLK_ESCAPE])
|
||||
break;
|
||||
}
|
||||
while(true)
|
||||
{
|
||||
events::pump();
|
||||
BOOST_CHECK_EQUAL(key[SDLK_ESCAPE], !new_keyrelease->is_fired());
|
||||
if (!key[SDLK_ESCAPE])
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
//! It is like that this will need some threading also :(
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE( network )
|
||||
BOOST_AUTO_TEST_SUITE( test_network )
|
||||
|
||||
const int TEST_PORT = 15010;
|
||||
const int MIN_THREADS = 1;
|
||||
|
|
Loading…
Add table
Reference in a new issue