15 #define GETTEXT_DOMAIN "wesnoth-test"
17 #include <boost/test/unit_test.hpp>
59 BOOST_WARN_MESSAGE(connections == 0,
"There is open "<< connections <<
" connections before test!");
60 BOOST_CHECK_MESSAGE(wes_manager =
new network::manager(MIN_THREADS,MAX_THREADS),
"network::manager failed to initialize");
63 "network::server_manager failed to initialize");
64 BOOST_REQUIRE_MESSAGE(wes_server->is_running(),
"Can't start server!");
68 BOOST_CHECK_MESSAGE(client_client1 > 0,
"Can't connect to server");
72 BOOST_CHECK_MESSAGE(server_client1 > 0,
"Can't accept connection");
87 BOOST_WARN_MESSAGE(max_tries > 0,
"receiving data took too long. Preventing for ever loop");
99 child[
"test"] =
"yes!";
100 cfg_send[
"test_running"] =
true;
106 receive_from =
receive(received);
108 BOOST_CHECK_MESSAGE( receive_from ==
server_client1,
"Received data is not from test client 1" );
110 BOOST_CHECK_EQUAL(cfg_send, received);
119 child[
"random_seed"] = seed_str;
120 child[
"random_calls"] = random_calls;
127 receive_from =
receive(received);
129 BOOST_CHECK_MESSAGE( receive_from ==
server_client1,
"Received data is not from test client 1" );
131 BOOST_CHECK_EQUAL(cfg_send, received);
135 std::string rec_seed_str = rec_command[
"random_seed"].str();
136 unsigned int rec_calls = rec_command[
"random_calls"];
138 BOOST_CHECK_EQUAL(seed_str, rec_seed_str);
139 BOOST_CHECK_EQUAL(random_calls, rec_calls);
169 if(SDL_GetTicks() -
start_ >= 5) {
184 BOOST_CHECK_MESSAGE(
wes_manager == 0,
"network::manager nono zero after delete");
188 BOOST_CHECK_MESSAGE(
client_client1 > 0,
"Can't connect to server");
204 BOOST_CHECK_MESSAGE(
client_client1 > 0,
"Can't connect to server");
227 const int buffer_size =
sizeof(
buffer)/
sizeof(buffer[0]);
228 int *begin =
reinterpret_cast<int*
>(&buffer[0]);
229 int *
end = begin +
sizeof(
buffer)/
sizeof(
int);
232 std::generate(begin,end,std::rand);
236 file->write(buffer, buffer_size);
252 auto_resetter(
const T& new_value, T& value_to_change) : value_to_change_(value_to_change), old_val_(value_to_change)
254 value_to_change_ = new_value;
284 std::vector<char>
data;
286 BOOST_CHECK_PREDICATE(test_utils::one_of<network::connection> , (
receive(data,500))(3)(se_client1)(se_client2)(se_client3));
288 BOOST_CHECK_PREDICATE(test_utils::one_of<network::connection> , (
receive(data,500))(3)(se_client1)(se_client2)(se_client3));
290 BOOST_CHECK_PREDICATE(test_utils::one_of<network::connection> , (
receive(data,500))(3)(se_client1)(se_client2)(se_client3));
335 BOOST_CHECK_MESSAGE(
true,
"Not true");
339 BOOST_AUTO_TEST_SUITE_END()
High level network layer for config object transport.
static void delete_random_sendfile(const std::string &file)
network::connection client_client2
auto_resetter(const T &new_value, T &value_to_change)
bool delete_file(const std::string &filename)
connection receive_data(config &cfg, connection connection_num, unsigned int timeout, bandwidth_in_ptr *bandwidth_in)
network::manager * wes_manager
BOOST_AUTO_TEST_SUITE(test_map_location)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definitions for the interface to Wesnoth Markup Language (WML).
network::connection client_client1
void send_file(const std::string &filename, connection connection_num, const std::string &packet_type)
static std::string create_random_sendfile(size_t size)
GLsizei const char ** path
static network::connection receive(T &cfg, int max_tries=100)
std::ostream * ostream_file(std::string const &fname, bool create_directory=true)
config & add_child(const std::string &key)
sendfile_param sendfile_sizes[]
const int TEST_PORT
Test networking to prevent bugs there.
static void try_send_random_seed(const std::string seed_str, const unsigned int random_calls)
size_t send_data(const config &cfg, connection connection_num, const std::string &packet_type)
Function to send data down a given connection, or broadcast to all peers if connection_num is 0...
Will throw exception on failure.
BOOST_AUTO_TEST_CASE(test_connect)
sendfile_param(size_t size, bool system)
network::connection server_client2
A server manager causes listening on a given port to occur for the duration of its lifetime...
connection accept_connection()
Function to accept a connection from a remote host.
Declarations for File-IO.
const std::string LOCALHOST
bool disconnect(connection s)
Function to disconnect from a certain host, or close all connections if connection_num is 0...
int file_size(const std::string &fname)
Returns the size of a file, or -1 if the file doesn't exist.
size_t nconnections()
The number of peers we are connected to.
connection connect(const std::string &host, int port)
Function to attempt to connect to a remote host.
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
WESNOTH_PARAMETERIZED_TEST_CASE(test_multi_sendfile, sendfile_param, sendfile_sizes, size)
void set_use_system_sendfile(bool use)
A config object defines a single node in a WML file, with access to child nodes.
network::connection server_client1
GLsizei const GLcharARB ** string
network::server_manager * wes_server
connection const null_connection