Remember cleared hotkeys

Added a bit of code to network unit tests

Added toys&whisles to unit tests
This commit is contained in:
Pauli Nieminen 2008-02-03 18:30:00 +00:00
parent 426eb69f48
commit b60c77c9e5
7 changed files with 127 additions and 24 deletions

View file

@ -25,6 +25,9 @@ Version 1.3.15+svn:
* Fixed reference to invalid pointer in attack::attack
* pressing shift affects acceleration immediately
* More gcc 4.3 fixed
* Remember cleared hotkey
* Added some toys&whisles to unit tests
* Added networking unit tests
* Hide race sections having only units with "hide_help=true"
* Optimize roads placing of random map
* when a unit miss an animation, the engine will base the replacement on

View file

@ -152,6 +152,8 @@ hotkey::hotkey_item null_hotkey_;
namespace hotkey {
const std::string CLEARED_TEXT = "__none__";
static void key_event_execute(display& disp, const SDL_KeyboardEvent& event, command_executor* executor);
@ -190,7 +192,11 @@ void hotkey_item::load_from_config(const config& cfg)
if (!key.empty()) {
// They may really want a specific key on the keyboard: we assume
// that any single character keyname is a character.
if (key.size() > 1) {
if (key == CLEARED_TEXT)
{
type_ = hotkey_item::CLEARED;
}
else if (key.size() > 1) {
type_ = BY_KEYCODE;
keycode_ = sdl_keysym_from_name(key);
@ -254,7 +260,7 @@ void hotkey_item::set_description(const std::string& description)
}
void hotkey_item::clear_hotkey()
{
type_ = UNBOUND;
type_ = CLEARED;
}
void hotkey_item::set_key(int character, int keycode, bool shift, bool ctrl, bool alt, bool cmd)
@ -344,8 +350,14 @@ void save_hotkeys(config& cfg)
for(std::vector<hotkey_item>::iterator i = hotkeys_.begin(); i != hotkeys_.end(); ++i) {
if (i->hidden() || i->get_type() == hotkey_item::UNBOUND)
continue;
config& item = cfg.add_child("hotkey");
if (i->get_type() == hotkey_item::CLEARED)
{
item["key"] == CLEARED_TEXT;
continue;
}
item["command"] = i->get_command();
if (i->get_type() == hotkey_item::BY_KEYCODE) {

View file

@ -100,7 +100,8 @@ public:
enum type {
UNBOUND,
BY_KEYCODE,
BY_CHARACTER
BY_CHARACTER,
CLEARED
};
enum type get_type() const { return type_; }

View file

@ -687,7 +687,7 @@ connection receive_data(config& cfg, connection connection_num)
}
}
if(!cfg.empty()) {
DBG_NW << "RECEIVED from: " << result << ": " << cfg.debug();
DBG_NW << "RECEIVED from: " << result << ": "; // expensive debug call removed (cfg.debug())
}
assert(result != 0);

View file

@ -18,6 +18,20 @@
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#endif
#include <iostream>
struct wesnoth_global_fixture {
wesnoth_global_fixture()
{
boost::unit_test::unit_test_log.set_threshold_level( boost::unit_test::log_messages );
BOOST_TEST_MESSAGE("Initializing test!");
}
~wesnoth_global_fixture()
{
}
};
BOOST_GLOBAL_FIXTURE( wesnoth_global_fixture );
/*
* This is a main compilation unit for the test program.

View file

@ -11,15 +11,18 @@
See the COPYING file for more details.
*/
//#define BOOST_TEST_MODULE networking
#include <boost/test/auto_unit_test.hpp>
#include <string>
#include "network.hpp"
#include "config.hpp"
//! Initial implementation. I will wokr more on this shortly
//! This sohuld be complit test for networking that there won't
//! be any crashes even in rarely used code paths.
//! Test networking to prevent bugs there.
//! Try to create all kind of unlikely error conditions
//! Some test should lock management_mutex from worker to settup stress test
//! It is like that this will need some threading also :(
const int TEST_PORT = 15010;
const int MIN_THREADS = 1;
const int MAX_THREADS = 0;
@ -28,35 +31,104 @@ const std::string LOCALHOST = "localhost";
network::manager* manager;
network::server_manager* server;
BOOST_AUTO_TEST_CASE( test_network_connect )
{
int connections = network::nconnections();
network::connection client_client;
network::connection server_client;
BOOST_WARN_MESSAGE(connections == 0, "There is open conenctions before test!");
manager = new network::manager(MIN_THREADS,MAX_THREADS);
network::connection client_client1;
network::connection client_client2;
server = new network::server_manager(TEST_PORT,network::server_manager::MUST_CREATE_SERVER);
network::connection server_client1;
network::connection server_client2;
BOOST_AUTO_TEST_SUITE( network );
BOOST_AUTO_TEST_CASE( test_connect )
{
BOOST_TEST_MESSAGE( "Starting network test!" );
int connections = network::nconnections();
BOOST_WARN_MESSAGE(connections == 0, "There is open "<< connections <<" connections before test!");
::manager = new network::manager(MIN_THREADS,MAX_THREADS);
::server = new network::server_manager(TEST_PORT,network::server_manager::MUST_CREATE_SERVER);
BOOST_REQUIRE_MESSAGE(server->is_running(), "Can't start server!");
client_client = network::connect(LOCALHOST, TEST_PORT);
client_client1 = network::connect(LOCALHOST, TEST_PORT);
BOOST_CHECK_MESSAGE(client_client > 0, "Can't connect to server");
BOOST_CHECK_MESSAGE(client_client1 > 0, "Can't connect to server");
server_client = network::accept_connection();
server_client1 = network::accept_connection();
BOOST_CHECK_MESSAGE(server_client > 0, "Can't accept connection");
BOOST_CHECK_MESSAGE(server_client1 > 0, "Can't accept connection");
}
BOOST_AUTO_TEST_CASE( test_network_shutdown )
BOOST_AUTO_TEST_CASE( test_send_client )
{
config cfg_send;
config& child = cfg_send.add_child("test_client_send");
child["test"] = "yes!";
cfg_send["test_running"] = "yes";
network::send_data(cfg_send, client_client1, true);
network::connection receive_from;
config received;
int max_tries = 100;
while ((receive_from = network::receive_data(received)) == network::null_connection)
{
// loop untill data is received
SDL_Delay(1);
if (--max_tries <= 0)
{
BOOST_TEST_MESSAGE("receiving data took too long. Preventing for ever loop");
break;
}
}
BOOST_CHECK_MESSAGE( receive_from == server_client1, "Received data is not from test client 1" );
}
BOOST_AUTO_TEST_CASE( test_send_server )
{
}
BOOST_AUTO_TEST_CASE( test_multiple_connections )
{
}
BOOST_AUTO_TEST_CASE( test_cancel_transfer )
{
}
BOOST_AUTO_TEST_CASE( test_detect_errors )
{
}
BOOST_AUTO_TEST_CASE( test_binary_wml )
{
}
BOOST_AUTO_TEST_CASE( test_broken_data )
{
}
BOOST_AUTO_TEST_CASE( test_config_with_macros )
{
}
BOOST_AUTO_TEST_CASE( test_disconnect )
{
network::disconnect(client_client1);
network::disconnect(server_client1);
}
BOOST_AUTO_TEST_CASE( test_shutdown )
{
delete server;
delete manager;
delete ::manager;
}
BOOST_AUTO_TEST_SUITE_END();
/* vim: set ts=4 sw=4: */

View file

@ -17,6 +17,7 @@
BOOST_AUTO_TEST_CASE( test_lexical_cast )
{
BOOST_TEST_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 );