Fix unit tests
This commit is contained in:
parent
b6c88df9e7
commit
3da8a27ae7
12 changed files with 85 additions and 82 deletions
|
@ -49,11 +49,11 @@ chat_message::chat_message(const time_t& timestamp,
|
|||
{
|
||||
}
|
||||
|
||||
chat_log::chat_log() : history_()
|
||||
chat_session::chat_session() : history_()
|
||||
{
|
||||
}
|
||||
|
||||
void chat_log::add_message(const time_t& timestamp,
|
||||
void chat_session::add_message(const time_t& timestamp,
|
||||
const std::string& user,
|
||||
const std::string& message)
|
||||
{
|
||||
|
@ -61,12 +61,12 @@ void chat_log::add_message(const time_t& timestamp,
|
|||
}
|
||||
|
||||
|
||||
void chat_log::add_message(const std::string& user, const std::string& message)
|
||||
void chat_session::add_message(const std::string& user, const std::string& message)
|
||||
{
|
||||
add_message(time(nullptr), user, message);
|
||||
}
|
||||
|
||||
void chat_log::clear()
|
||||
void chat_session::clear()
|
||||
{
|
||||
history_.clear();
|
||||
}
|
||||
|
|
|
@ -37,10 +37,10 @@ struct chat_message
|
|||
};
|
||||
|
||||
/** this class memorizes a chat session. */
|
||||
class chat_log
|
||||
class chat_session
|
||||
{
|
||||
public:
|
||||
chat_log();
|
||||
chat_session();
|
||||
|
||||
void add_message(const time_t& timestamp,
|
||||
const std::string& user,
|
||||
|
@ -80,11 +80,11 @@ public:
|
|||
void remove_member(const std::string& user);
|
||||
void process_room_members(const config& data);
|
||||
|
||||
const chat_log& log() const
|
||||
const chat_session& log() const
|
||||
{
|
||||
return log_;
|
||||
}
|
||||
chat_log& log()
|
||||
chat_session& log()
|
||||
{
|
||||
return log_;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
private:
|
||||
std::string name_;
|
||||
std::set<std::string> members_;
|
||||
chat_log log_;
|
||||
chat_session log_;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -301,7 +301,7 @@ bool lobby_info::has_room(const std::string& name) const
|
|||
return get_room(name) != nullptr;
|
||||
}
|
||||
|
||||
chat_log& lobby_info::get_whisper_log(const std::string& name)
|
||||
chat_session& lobby_info::get_whisper_log(const std::string& name)
|
||||
{
|
||||
return whispers_[name];
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ public:
|
|||
|
||||
user_info& get_user(const std::string& name);
|
||||
|
||||
chat_log& get_whisper_log(const std::string& name);
|
||||
chat_session& get_whisper_log(const std::string& name);
|
||||
|
||||
void update_user_statuses(int game_id, const room_info* room);
|
||||
|
||||
|
@ -113,7 +113,7 @@ private:
|
|||
std::vector<game_info*> games_filtered_;
|
||||
std::vector<user_info> users_;
|
||||
std::vector<user_info*> users_sorted_;
|
||||
std::map<std::string, chat_log> whispers_;
|
||||
std::map<std::string, chat_session> whispers_;
|
||||
std::vector<game_filter_func> game_filters_;
|
||||
bool game_filter_invert_;
|
||||
boost::dynamic_bitset<> games_visibility_;
|
||||
|
|
|
@ -340,9 +340,9 @@ void grid::request_reduce_height(const unsigned maximum_height)
|
|||
}
|
||||
|
||||
/* Reducing the height of a widget causes the widget to save its new size
|
||||
in twidget::layout_size_. After that, get_best_size() will return that
|
||||
in widget::layout_size_. After that, get_best_size() will return that
|
||||
size and not the originally calculated optimal size.
|
||||
Thus, it's perfectly correct that tgrid::calculate_best_size() that we
|
||||
Thus, it's perfectly correct that grid::calculate_best_size() that we
|
||||
call later calls get_best_size() for child widgets as if size reduction
|
||||
had never happened. */
|
||||
const unsigned height = grid_implementation::row_request_reduce_height(
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace implementation {
|
|||
, typename ToEnable = void
|
||||
, typename FromEnable = void
|
||||
>
|
||||
struct lexical_cast;
|
||||
struct lexical_caster;
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
|
@ -91,7 +91,7 @@ namespace implementation {
|
|||
template<typename To, typename From>
|
||||
inline To lexical_cast(From value)
|
||||
{
|
||||
return implementation::lexical_cast<To, From>().operator()(value);
|
||||
return implementation::lexical_caster<To, From>().operator()(value);
|
||||
}
|
||||
|
||||
/** Thrown when a lexical_cast fails. */
|
||||
|
@ -116,7 +116,7 @@ template<
|
|||
, typename ToEnable
|
||||
, typename FromEnable
|
||||
>
|
||||
struct lexical_cast
|
||||
struct lexical_caster
|
||||
{
|
||||
To operator()(From value)
|
||||
{
|
||||
|
@ -140,7 +140,7 @@ struct lexical_cast
|
|||
* integral type.
|
||||
*/
|
||||
template <typename From>
|
||||
struct lexical_cast<
|
||||
struct lexical_caster<
|
||||
std::string
|
||||
, From
|
||||
, void
|
||||
|
@ -166,7 +166,7 @@ struct lexical_cast<
|
|||
* performance penalty at 32 bit systems.
|
||||
*/
|
||||
template <class From>
|
||||
struct lexical_cast<
|
||||
struct lexical_caster<
|
||||
long long
|
||||
, From
|
||||
, void
|
||||
|
@ -197,7 +197,7 @@ struct lexical_cast<
|
|||
* performance penalty at 32 bit systems.
|
||||
*/
|
||||
template <>
|
||||
struct lexical_cast<
|
||||
struct lexical_caster<
|
||||
long long
|
||||
, std::string
|
||||
>
|
||||
|
@ -216,7 +216,7 @@ struct lexical_cast<
|
|||
* Specialized for returning a signed type from a (const) char*.
|
||||
*/
|
||||
template <class To, class From>
|
||||
struct lexical_cast<
|
||||
struct lexical_caster<
|
||||
To
|
||||
, From
|
||||
, typename std::enable_if<std::is_signed<To>::value >::type
|
||||
|
@ -245,7 +245,7 @@ struct lexical_cast<
|
|||
* Specialized for returning a signed type from a std::string.
|
||||
*/
|
||||
template <class To>
|
||||
struct lexical_cast<
|
||||
struct lexical_caster<
|
||||
To
|
||||
, std::string
|
||||
, typename std::enable_if<std::is_signed<To>::value >::type
|
||||
|
@ -267,7 +267,7 @@ struct lexical_cast<
|
|||
* has a performance penalty at 32 bit systems.
|
||||
*/
|
||||
template <class From>
|
||||
struct lexical_cast<
|
||||
struct lexical_caster<
|
||||
unsigned long long
|
||||
, From
|
||||
, void
|
||||
|
@ -299,7 +299,7 @@ struct lexical_cast<
|
|||
* has a performance penalty at 32 bit systems.
|
||||
*/
|
||||
template <>
|
||||
struct lexical_cast<
|
||||
struct lexical_caster<
|
||||
unsigned long long
|
||||
, std::string
|
||||
>
|
||||
|
@ -318,7 +318,7 @@ struct lexical_cast<
|
|||
* Specialized for returning a unsigned type from a (const) char*.
|
||||
*/
|
||||
template <class To, class From>
|
||||
struct lexical_cast<
|
||||
struct lexical_caster<
|
||||
To
|
||||
, From
|
||||
, typename std::enable_if<std::is_unsigned<To>::value >::type
|
||||
|
@ -347,7 +347,7 @@ struct lexical_cast<
|
|||
* Specialized for returning a unsigned type from a std::string.
|
||||
*/
|
||||
template <class To>
|
||||
struct lexical_cast<
|
||||
struct lexical_caster<
|
||||
To
|
||||
, std::string
|
||||
, typename std::enable_if<std::is_unsigned<To>::value >::type
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "gui/widgets/tree_view.hpp"
|
||||
#include "gui/widgets/tree_view_node.hpp"
|
||||
#include "gui/widgets/unit_preview_pane.hpp"
|
||||
#include "gui/widgets/widget.hpp" // for twidget
|
||||
#include "gui/widgets/widget.hpp" // for widget
|
||||
#include "gui/widgets/window.hpp" // for window
|
||||
|
||||
#ifdef GUI2_EXPERIMENTAL_LISTBOX
|
||||
|
|
|
@ -36,7 +36,7 @@ static void print(std::stringstream& sstr
|
|||
template<gui2::event::event_t E>
|
||||
void connect_queue(
|
||||
std::stringstream& sstr
|
||||
, gui2::twidget& widget)
|
||||
, gui2::widget& widget)
|
||||
{
|
||||
widget.connect_signal<E>(
|
||||
std::bind(print, std::ref(sstr), "pre", widget.id())
|
||||
|
@ -53,7 +53,7 @@ void connect_queue(
|
|||
|
||||
static void connect_signals(
|
||||
std::stringstream& sstr
|
||||
, gui2::twidget& widget)
|
||||
, gui2::widget& widget)
|
||||
{
|
||||
/** @todo Add the rest of the events. */
|
||||
connect_queue<gui2::event::DRAW>(sstr, widget);
|
||||
|
@ -74,20 +74,20 @@ static void connect_signals(
|
|||
connect_queue<gui2::event::RIGHT_BUTTON_DOUBLE_CLICK>(sstr, widget);
|
||||
}
|
||||
|
||||
static void add_widget(gui2::tgrid& grid
|
||||
, gui2::twidget* widget
|
||||
static void add_widget(gui2::grid& grid
|
||||
, gui2::widget* widget
|
||||
, const std::string& id
|
||||
, const unsigned row
|
||||
, const unsigned column)
|
||||
{
|
||||
BOOST_REQUIRE_NE(widget, static_cast<gui2::twidget*>(nullptr));
|
||||
BOOST_REQUIRE_NE(widget, static_cast<gui2::widget*>(nullptr));
|
||||
|
||||
widget->set_id(id);
|
||||
grid.set_child(widget
|
||||
, row
|
||||
, column
|
||||
, gui2::tgrid::VERTICAL_GROW_SEND_TO_CLIENT
|
||||
| gui2::tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT
|
||||
, gui2::grid::VERTICAL_GROW_SEND_TO_CLIENT
|
||||
| gui2::grid::HORIZONTAL_GROW_SEND_TO_CLIENT
|
||||
, 0);
|
||||
}
|
||||
|
||||
|
@ -125,15 +125,15 @@ BOOST_AUTO_TEST_CASE(test_fire_event)
|
|||
std::stringstream sstr;
|
||||
|
||||
/**** Initialize the grid. *****/
|
||||
gui2::tgrid grid(1, 1);
|
||||
gui2::grid grid(1, 1);
|
||||
grid.set_id("root");
|
||||
connect_signals(sstr, grid);
|
||||
|
||||
gui2::tgrid *child_grid = new gui2::tgrid(1, 1);
|
||||
gui2::grid *child_grid = new gui2::grid(1, 1);
|
||||
add_widget(grid, child_grid, "level 1", 0, 0);
|
||||
connect_signals(sstr, *child_grid);
|
||||
|
||||
gui2::twidget *child = new gui2::tgrid(1, 1);
|
||||
gui2::widget *child = new gui2::grid(1, 1);
|
||||
add_widget(*child_grid, child, "level 2", 0, 0);
|
||||
connect_signals(sstr, *child);
|
||||
|
||||
|
|
|
@ -103,20 +103,20 @@ static std::string bottom_up_t_t_t_result()
|
|||
return result;
|
||||
}
|
||||
|
||||
static void add_widget(gui2::tgrid& grid
|
||||
, gui2::twidget* widget
|
||||
static void add_widget(gui2::grid& grid
|
||||
, gui2::widget* widget
|
||||
, const std::string& id
|
||||
, const unsigned row
|
||||
, const unsigned column)
|
||||
{
|
||||
BOOST_REQUIRE_NE(widget, static_cast<gui2::twidget*>(nullptr));
|
||||
BOOST_REQUIRE_NE(widget, static_cast<gui2::widget*>(nullptr));
|
||||
|
||||
widget->set_id(id);
|
||||
grid.set_child(widget
|
||||
, row
|
||||
, column
|
||||
, gui2::tgrid::VERTICAL_GROW_SEND_TO_CLIENT
|
||||
| gui2::tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT
|
||||
, gui2::grid::VERTICAL_GROW_SEND_TO_CLIENT
|
||||
| gui2::grid::HORIZONTAL_GROW_SEND_TO_CLIENT
|
||||
, 0);
|
||||
}
|
||||
|
||||
|
@ -170,29 +170,29 @@ static void test_control()
|
|||
static void test_control()
|
||||
{
|
||||
/* Could add more widgets to the list. */
|
||||
test_control<gui2::tlabel>();
|
||||
test_control<gui2::label>();
|
||||
|
||||
}
|
||||
|
||||
static void test_grid()
|
||||
{
|
||||
/* An empty grid behaves the same as a control so test here. */
|
||||
test_control<gui2::tgrid>();
|
||||
test_control<gui2::grid>();
|
||||
|
||||
/* Test the child part here. */
|
||||
gui2::tgrid grid(2 ,2);
|
||||
gui2::grid grid(2 ,2);
|
||||
grid.set_id("0");
|
||||
|
||||
gui2::tgrid* g = new gui2::tgrid(2, 2);
|
||||
gui2::grid* g = new gui2::grid(2, 2);
|
||||
add_widget(grid, g, "1", 0, 0);
|
||||
add_widget(grid, new gui2::tlabel(), "2", 1, 0);
|
||||
add_widget(grid, new gui2::tlabel(), "3", 0, 1);
|
||||
add_widget(grid, new gui2::tlabel(), "4", 1, 1);
|
||||
add_widget(grid, new gui2::label(), "2", 1, 0);
|
||||
add_widget(grid, new gui2::label(), "3", 0, 1);
|
||||
add_widget(grid, new gui2::label(), "4", 1, 1);
|
||||
|
||||
add_widget(*g, new gui2::tlabel(), "5", 0, 0);
|
||||
add_widget(*g, new gui2::tlabel(), "6", 1, 0);
|
||||
add_widget(*g, new gui2::tlabel(), "7", 0, 1);
|
||||
add_widget(*g, new gui2::tlabel(), "8", 1, 1);
|
||||
add_widget(*g, new gui2::label(), "5", 0, 0);
|
||||
add_widget(*g, new gui2::label(), "6", 1, 0);
|
||||
add_widget(*g, new gui2::label(), "7", 0, 1);
|
||||
add_widget(*g, new gui2::label(), "8", 1, 1);
|
||||
|
||||
{
|
||||
std::stringstream sstr;
|
||||
|
|
|
@ -115,6 +115,8 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
using namespace gui2::dialogs;
|
||||
|
||||
namespace gui2 {
|
||||
|
||||
std::vector<std::string>& unit_test_registered_window_list()
|
||||
|
@ -125,6 +127,8 @@ std::vector<std::string>& unit_test_registered_window_list()
|
|||
return result;
|
||||
}
|
||||
|
||||
namespace dialogs {
|
||||
|
||||
std::string unit_test_mark_as_tested(const modal_dialog& dialog)
|
||||
{
|
||||
std::vector<std::string>& list = unit_test_registered_window_list();
|
||||
|
@ -155,10 +159,9 @@ modal_dialog* unit_test_mp_server_list()
|
|||
return mp_connect::mp_server_list_for_unit_test();
|
||||
}
|
||||
|
||||
} // namespace dialogs
|
||||
} // namespace gui2
|
||||
|
||||
using namespace gui2::dialogs;
|
||||
|
||||
namespace {
|
||||
|
||||
/** The main config, which contains the entire WML tree. */
|
||||
|
@ -189,7 +192,7 @@ namespace {
|
|||
const std::unique_ptr<modal_dialog> dlg(ctor.create());
|
||||
BOOST_REQUIRE_MESSAGE(dlg.get(), "Failed to create a dialog.");
|
||||
|
||||
const std::string id = gui2::unit_test_mark_as_tested(*(dlg.get()));
|
||||
const std::string id = unit_test_mark_as_tested(*(dlg.get()));
|
||||
|
||||
std::string exception;
|
||||
try {
|
||||
|
@ -228,12 +231,12 @@ namespace {
|
|||
const std::unique_ptr<modeless_dialog> dlg(ctor.create());
|
||||
BOOST_REQUIRE_MESSAGE(dlg.get(), "Failed to create a dialog.");
|
||||
|
||||
const std::string id = gui2::unit_test_mark_popup_as_tested(*(dlg.get()));
|
||||
const std::string id = unit_test_mark_popup_as_tested(*(dlg.get()));
|
||||
|
||||
std::string exception;
|
||||
try {
|
||||
dlg->show(video, interact);
|
||||
gui2::window* window = gui2::unit_test_window((*dlg.get()));
|
||||
gui2::window* window = unit_test_window((*dlg.get()));
|
||||
BOOST_REQUIRE_NE(window, static_cast<void*>(nullptr));
|
||||
window->draw();
|
||||
} catch(gui2::layout_exception_width_modified&) {
|
||||
|
|
|
@ -24,20 +24,20 @@
|
|||
#include <iostream>
|
||||
#include <typeinfo>
|
||||
|
||||
static void add_widget(gui2::tgrid& grid
|
||||
, gui2::twidget* widget
|
||||
static void add_widget(gui2::grid& grid
|
||||
, gui2::widget* widget
|
||||
, const std::string& id
|
||||
, const unsigned row
|
||||
, const unsigned column)
|
||||
{
|
||||
BOOST_REQUIRE_NE(widget, static_cast<gui2::twidget*>(nullptr));
|
||||
BOOST_REQUIRE_NE(widget, static_cast<gui2::widget*>(nullptr));
|
||||
|
||||
widget->set_id(id);
|
||||
grid.set_child(widget
|
||||
, row
|
||||
, column
|
||||
, gui2::tgrid::VERTICAL_GROW_SEND_TO_CLIENT
|
||||
| gui2::tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT
|
||||
, gui2::grid::VERTICAL_GROW_SEND_TO_CLIENT
|
||||
| gui2::grid::HORIZONTAL_GROW_SEND_TO_CLIENT
|
||||
, 0);
|
||||
}
|
||||
|
||||
|
@ -53,53 +53,53 @@ static void test_control()
|
|||
|
||||
/***** INITIAL STATE *****/
|
||||
|
||||
BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::walker_base::widget), false);
|
||||
BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::walker_base::grid), true);
|
||||
BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::walker_base::self), false);
|
||||
BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::walker_base::internal), true);
|
||||
BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::walker_base::child), true);
|
||||
|
||||
BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::walker_base::widget), &control);
|
||||
BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::walker_base::grid), static_cast<void*>(nullptr));
|
||||
BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::walker_base::self), &control);
|
||||
BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::walker_base::internal), static_cast<void*>(nullptr));
|
||||
BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::walker_base::child), static_cast<void*>(nullptr));
|
||||
|
||||
/***** VISITING WIDGET *****/
|
||||
|
||||
BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::walker_base::widget), gui2::iterator::walker_base::invalid);
|
||||
BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::walker_base::grid), gui2::iterator::walker_base::fail);
|
||||
BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::walker_base::self), gui2::iterator::walker_base::invalid);
|
||||
BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::walker_base::internal), gui2::iterator::walker_base::fail);
|
||||
BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::walker_base::child), gui2::iterator::walker_base::fail);
|
||||
|
||||
BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::walker_base::widget), true);
|
||||
BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::walker_base::grid), true);
|
||||
BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::walker_base::self), true);
|
||||
BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::walker_base::internal), true);
|
||||
BOOST_CHECK_EQUAL(visitor->at_end(gui2::iterator::walker_base::child), true);
|
||||
|
||||
BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::walker_base::widget), static_cast<void*>(nullptr));
|
||||
BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::walker_base::grid), static_cast<void*>(nullptr));
|
||||
BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::walker_base::self), static_cast<void*>(nullptr));
|
||||
BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::walker_base::internal), static_cast<void*>(nullptr));
|
||||
BOOST_CHECK_EQUAL(visitor->get(gui2::iterator::walker_base::child), static_cast<void*>(nullptr));
|
||||
|
||||
/***** POST END *****/
|
||||
|
||||
BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::walker_base::widget), gui2::iterator::walker_base::fail);
|
||||
BOOST_CHECK_EQUAL(visitor->next(gui2::iterator::walker_base::self), gui2::iterator::walker_base::fail);
|
||||
}
|
||||
|
||||
static void test_control()
|
||||
{
|
||||
/* Could add more widgets to the list. */
|
||||
test_control<gui2::tlabel>();
|
||||
test_control<gui2::label>();
|
||||
|
||||
}
|
||||
|
||||
static void test_grid()
|
||||
{
|
||||
/* An empty grid behaves the same as a control so test here. */
|
||||
test_control<gui2::tgrid>();
|
||||
test_control<gui2::grid>();
|
||||
|
||||
//std::cerr << __func__ << ": Detailed test.\n";
|
||||
|
||||
/* Test the child part here. */
|
||||
gui2::tgrid grid(2 ,2);
|
||||
add_widget(grid, new gui2::tlabel(), "(1,1)", 0, 0);
|
||||
add_widget(grid, new gui2::tlabel(), "(1,2)", 0, 1);
|
||||
add_widget(grid, new gui2::tlabel(), "(2,1)", 1, 0);
|
||||
add_widget(grid, new gui2::tlabel(), "(2,2)", 1, 1);
|
||||
gui2::grid grid(2 ,2);
|
||||
add_widget(grid, new gui2::label(), "(1,1)", 0, 0);
|
||||
add_widget(grid, new gui2::label(), "(1,2)", 0, 1);
|
||||
add_widget(grid, new gui2::label(), "(2,1)", 1, 0);
|
||||
add_widget(grid, new gui2::label(), "(2,2)", 1, 1);
|
||||
|
||||
const std::unique_ptr<gui2::iterator::walker_base> visitor(grid.create_walker());
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ struct wesnoth_global_fixture {
|
|||
test_utils::get_fake_display(1024, 768);
|
||||
|
||||
gui2::init();
|
||||
static const gui2::event::tmanager gui_event_manager;
|
||||
static const gui2::event::manager gui_event_manager;
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue