Improved unit test log level selection
Added comments to drag&drop code
This commit is contained in:
parent
bd0891f7d6
commit
3978253e28
10 changed files with 49 additions and 21 deletions
|
@ -379,7 +379,7 @@ bool connect::side::is_owned_by(const std::string& name) const
|
|||
void connect::side::process_event()
|
||||
{
|
||||
int drop_target;
|
||||
if ( ( drop_target = combo_controller_->get_drag_target() )> -1)
|
||||
if ( ( drop_target = combo_controller_->get_drop_target() )> -1)
|
||||
{
|
||||
const std::string target_id = parent_->sides_[drop_target].get_id();
|
||||
const mp::controller target_controller = parent_->sides_[drop_target].get_controller();
|
||||
|
|
|
@ -25,7 +25,6 @@ BOOST_AUTO_TEST_SUITE( test_drop_target )
|
|||
|
||||
BOOST_AUTO_TEST_CASE( test_create_group )
|
||||
{
|
||||
BOOST_MESSAGE( "Starting drop target test!" );
|
||||
|
||||
gui::drop_group_manager group0;
|
||||
gui::drop_group_manager* group1 = new gui::drop_group_manager();
|
||||
|
|
|
@ -37,19 +37,10 @@ namespace test {
|
|||
struct save_dialog_fixture {
|
||||
save_dialog_fixture()
|
||||
{
|
||||
if (!started_)
|
||||
{
|
||||
BOOST_MESSAGE("Starting save dialog test!");
|
||||
started_ = true;
|
||||
}
|
||||
}
|
||||
test_utils::fake_event_source source;
|
||||
|
||||
private:
|
||||
static bool started_;
|
||||
};
|
||||
|
||||
bool save_dialog_fixture::started_ = false;
|
||||
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE( save_dialog , save_dialog_fixture)
|
||||
|
|
|
@ -45,14 +45,15 @@ static void exception_translator_game(const game::error& e)
|
|||
struct wesnoth_global_fixture {
|
||||
wesnoth_global_fixture()
|
||||
{
|
||||
|
||||
// Initialize unit tests
|
||||
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)
|
||||
if (boost::unit_test::runtime_config::log_level() == boost::unit_test::invalid_log_level)
|
||||
boost::unit_test::unit_test_log.set_threshold_level( boost::unit_test::log_messages );
|
||||
BOOST_MESSAGE("Initializing test!");
|
||||
boost::unit_test::unit_test_monitor.register_exception_translator<game::error>(&exception_translator_game);
|
||||
boost::unit_test::unit_test_monitor.register_exception_translator<network::error>(&exception_translator_network);
|
||||
boost::unit_test::unit_test_monitor.register_exception_translator<config::error>(&exception_translator_config);
|
||||
|
|
|
@ -47,7 +47,6 @@ network::connection server_client2;
|
|||
|
||||
BOOST_AUTO_TEST_CASE( test_connect )
|
||||
{
|
||||
BOOST_MESSAGE( "Starting network test!" );
|
||||
int connections = network::nconnections();
|
||||
|
||||
BOOST_WARN_MESSAGE(connections == 0, "There is open "<< connections <<" connections before test!");
|
||||
|
|
|
@ -18,7 +18,6 @@ BOOST_AUTO_TEST_SUITE( team )
|
|||
|
||||
BOOST_AUTO_TEST_CASE( test_user_team_name )
|
||||
{
|
||||
BOOST_MESSAGE( "Starting team test!" );
|
||||
}
|
||||
|
||||
/* vim: set ts=4 sw=4: */
|
||||
|
|
|
@ -19,7 +19,6 @@ BOOST_AUTO_TEST_SUITE( util )
|
|||
|
||||
BOOST_AUTO_TEST_CASE( test_lexical_cast )
|
||||
{
|
||||
BOOST_MESSAGE( "Starting utils test!" );
|
||||
/* First check if lexical_cast returns correct results for correct args */
|
||||
int result = lexical_cast<int, const std::string&>(std::string("1"));
|
||||
BOOST_CHECK( result == 1 );
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
namespace gui {
|
||||
|
||||
const int combo_drag::MIN_DRAG_DISTANCE = 30;
|
||||
const float combo_drag::MIN_DRAG_DISTANCE = 10.0;
|
||||
const float combo_drag::RETURN_SPEED = 25.0;
|
||||
|
||||
combo_drag::combo_drag(display& disp, const std::vector<std::string>& items, const drop_group_manager_ptr group)
|
||||
|
@ -34,7 +34,7 @@ namespace gui {
|
|||
{
|
||||
}
|
||||
|
||||
int combo_drag::get_drag_target()
|
||||
int combo_drag::get_drop_target()
|
||||
{
|
||||
old_drag_target_ = drag_target_;
|
||||
drag_target_ = -1;
|
||||
|
|
|
@ -34,7 +34,14 @@ namespace gui {
|
|||
public:
|
||||
combo_drag(display& disp, const std::vector<std::string>& items, const drop_group_manager_ptr group);
|
||||
|
||||
int get_drag_target();
|
||||
/**
|
||||
* used to query if this object was droped to a target
|
||||
* @return: -1 if not droped and other the id of target object
|
||||
**/
|
||||
int get_drop_target();
|
||||
/**
|
||||
* Implements return after drop
|
||||
**/
|
||||
virtual void process(events::pump_info& /*info*/);
|
||||
protected:
|
||||
virtual void process_event();
|
||||
|
@ -42,6 +49,7 @@ namespace gui {
|
|||
virtual void mouse_down(const SDL_MouseButtonEvent& event);
|
||||
virtual void mouse_up(const SDL_MouseButtonEvent& event);
|
||||
private:
|
||||
|
||||
void handle_move(const SDL_MouseMotionEvent& event);
|
||||
void handle_drop();
|
||||
int drag_target_, old_drag_target_;
|
||||
|
|
|
@ -29,6 +29,12 @@ namespace gui {
|
|||
typedef int drop_target_group;
|
||||
class drop_group_manager;
|
||||
typedef boost::shared_ptr<drop_group_manager> drop_group_manager_ptr;
|
||||
|
||||
/**
|
||||
* Handles droping for drag able ui items.
|
||||
* Widget class just has to inherit from drop_target,
|
||||
* call constructor and handle_drop.
|
||||
**/
|
||||
class drop_target : public boost::noncopyable {
|
||||
typedef std::multimap<drop_target_group, drop_target*> drop_groups;
|
||||
typedef std::map<drop_target_group, int> target_id;
|
||||
|
@ -43,6 +49,10 @@ namespace gui {
|
|||
const SDL_Rect& loc_;
|
||||
const int id_;
|
||||
drop_group_manager_ptr group_;
|
||||
|
||||
static drop_target_group create_group();
|
||||
static void delete_group(const drop_target_group id);
|
||||
|
||||
// We allow access for unit test to call handle_drop
|
||||
#ifdef BOOST_TEST_DYN_LINK
|
||||
public:
|
||||
|
@ -53,17 +63,39 @@ namespace gui {
|
|||
#else
|
||||
protected:
|
||||
#endif
|
||||
/**
|
||||
* Called by widget object when droping happens.
|
||||
*
|
||||
* Droping over multiple widget objects in same group
|
||||
* is undefined.
|
||||
*
|
||||
* @return: id which widget was hit when droping
|
||||
**/
|
||||
int handle_drop();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Registers drop target and saves reference to location.
|
||||
**/
|
||||
drop_target(const drop_group_manager_ptr group, const SDL_Rect& loc);
|
||||
~drop_target();
|
||||
|
||||
int get_id() const;
|
||||
/**
|
||||
* Checks if id matches id for this object.
|
||||
* Used by for_each/boost:bind
|
||||
**/
|
||||
bool is_this_id(const int id) const;
|
||||
static drop_target_group create_group();
|
||||
static void delete_group(const drop_target_group id);
|
||||
|
||||
friend class drop_group_manager;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Used to create and destroy drop groups.
|
||||
* To create drop_target widgets one has to have
|
||||
* drop_group_manager stored in drop_group_manager_ptr.
|
||||
**/
|
||||
class drop_group_manager : public boost::noncopyable {
|
||||
const drop_target_group group_id_;
|
||||
public:
|
||||
|
|
Loading…
Add table
Reference in a new issue