[[frame counter and build recipe fixes]]

Changed test_utils::fake_event_source to use frame counter as time
source instead of real time. This makes test cases more predictable
and easier to write.

Removed linker workarounds and added --start-group --end-group linker
parameters
This commit is contained in:
Pauli Nieminen 2008-07-05 19:09:24 +00:00
parent bf6355c760
commit 1e8880e604
5 changed files with 23 additions and 45 deletions

View file

@ -302,6 +302,7 @@ env.MergeFlags(env["extra_flags_" + build])
test_env = env.Clone()
if not env['static_test']:
test_env.Append(CPPDEFINES = "BOOST_TEST_DYN_LINK")
test_env['LINKCOM'] = '$LINK -o $TARGET $LINKFLAGS -Wl,--start-group $SOURCES -Wl,--end-group $_LIBDIRFLAGS $_LIBFLAGS'
Export("test_env")

View file

@ -35,7 +35,7 @@ noinst_LIBRARIES = libwesnoth-core.a libwesnoth.a
pkgdatadir=$(datadir)/@DATADIR@
INTERNALLIBS = -lwesnoth-core -lwesnoth
INTERNALLIBS = -Wl,--start-group -lwesnoth-core -lwesnoth -Wl,--end-group
THELIBS = -L. $(SDL_IMAGE_LIBS) $(SDL_MIXER_LIBS) $(SDL_NET_LIBS) \
$(SDL_TTF_LIBS) $(SDL_LIBS) $(PYTHON_LIBS) $(LIBINTL) \

View file

@ -30,31 +30,6 @@
#include "tests/utils/auto_parameterized.hpp"
// Linker workarounds start here
//#define LD_WA
#ifdef LD_WA
#include "config.hpp"
#include "serialization/parser.hpp"
#include "serialization/preprocessor.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";
{
config cfg;
scoped_istream stream = preprocess_file("data/hardwired/language.cfg");
read(cfg, *stream);
}
}
#endif
// Linker workarounds end here
namespace test {
@ -86,10 +61,10 @@ namespace test {
test_utils::event_node_ptr new_keypress = source.press_key(2, keyid);
test_utils::event_node_ptr new_keyrelease = source.release_key(4,keyid);
source.press_key(100, keyid);
source.release_key(150,keyid);
// Protection against forever loop
source.press_key(6, keyid);
source.release_key(8,keyid);
CKey key;
source.start();
while(true)
{
@ -114,18 +89,18 @@ namespace test {
{
// fill in events to be used in test
test_utils::event_node_ptr press_return_before = source.press_key(0, keyid);
test_utils::event_node_ptr release_return_before = source.release_key(200, keyid);
test_utils::event_node_ptr press_return_after = source.press_key(240, keyid);
test_utils::event_node_ptr release_return_after = source.release_key(1000, keyid);
test_utils::event_node_ptr release_return_before = source.release_key(3, keyid);
test_utils::event_node_ptr press_return_after = source.press_key(5, keyid);
test_utils::event_node_ptr release_return_after = source.release_key(7, keyid);
// Just to make sure no forever loops happening
source.press_key(1500, keyid);
source.release_key(2000, keyid);
// Protection agains for ever loop
source.press_key(10, keyid);
source.release_key(13, keyid);
std::string fname("press_enter");
write_file(get_saves_dir() + "/" + fname +".gz", "böö");
// Start test (set ticks start time)
source.start();
// Activated enter press
events::pump();

View file

@ -36,9 +36,9 @@ namespace test_utils {
/**
* @return true if this should stop firing events
**/
bool event_node::test_if_should_fire(const size_t start_time, const size_t time_now) const
bool event_node::test_if_should_fire(const size_t frame_count) const
{
return time_now - start_time >= time_;
return frame_count >= time_;
}
bool event_node::is_fired() const
@ -65,7 +65,7 @@ namespace test_utils {
key_list[event_.key.keysym.sym] = 0;
}
fake_event_source::fake_event_source() : start_time_(SDL_GetTicks())
fake_event_source::fake_event_source() : frame_count_(0)
{
}
@ -95,7 +95,7 @@ namespace test_utils {
void fake_event_source::start()
{
start_time_ = SDL_GetTicks();
frame_count_ = 0;
}
SDL_Event fake_event_source::make_key_event(Uint8 type, const SDLKey key, const SDLMod mod)
@ -131,11 +131,11 @@ namespace test_utils {
void fake_event_source::process(events::pump_info& /*info*/)
{
++frame_count_;
if (queue_.empty())
return;
size_t now = SDL_GetTicks();
while (!queue_.empty()
&& queue_.top()->test_if_should_fire(start_time_, now))
&& queue_.top()->test_if_should_fire(frame_count_))
{
queue_.top()->fire_event();
queue_.pop();

View file

@ -52,7 +52,7 @@ namespace test_utils {
/**
* @return true if this should stop firing events
**/
bool test_if_should_fire(const size_t start_time, const size_t time_now) const;
bool test_if_should_fire(const size_t frame_count ) const;
bool is_fired() const;
@ -73,17 +73,20 @@ namespace test_utils {
/**
* fake_event_source is used to generate new events in
* events::pump()
* Timing used in function is loop counter incremented
* everytime events::pump() is called.
**/
class fake_event_source
: public events::pump_monitor,
public boost::noncopyable
{
size_t start_time_;
size_t frame_count_;
typedef std::priority_queue<event_node_ptr,std::vector<event_node_ptr>,less_ptr<event_node_ptr> > event_queue;
event_queue queue_;
SDL_Event make_key_event(Uint8 type, const SDLKey key, const SDLMod mod);
public:
fake_event_source();
~fake_event_source();
@ -91,7 +94,6 @@ namespace test_utils {
void add_event(event_node_ptr new_node);
void start();
SDL_Event make_key_event(Uint8 type, const SDLKey key, const SDLMod mod);
event_node_ptr press_key(const size_t time, const SDLKey key, const SDLMod mod = KMOD_NONE);
event_node_ptr release_key(const size_t time, const SDLKey key, const SDLMod mod =KMOD_NONE);