Added scons compilation output files to svn:ignore

Made send_file  test sending multiple files simultanously

Added test_utils:one_of<class T> which test if value matches any one
in the given list

Made send_file report if there is problems streaming file for networking

Improved javascript code creating mouseover full text elements in test
website
This commit is contained in:
Pauli Nieminen 2008-08-10 16:37:28 +00:00
parent c9bd6576c2
commit 6c5a6aa32a
10 changed files with 231 additions and 84 deletions

6
.gitignore vendored
View file

@ -38,3 +38,9 @@ Lib
*.exe
*.dll
*.txt
wesnothd*
build
test*
wesnoth*
wesnoth_editor*
campaignd*

View file

@ -541,7 +541,7 @@ std::istream *istream_file(std::string const &fname)
std::ifstream *s = new std::ifstream((game_config::path + "/" + fname).c_str(),std::ios_base::binary);
if (s->is_open())
return s;
LOG_FS << "could not open " << fname << " for reading.\n";
LOG_FS << "could not open " << (game_config::path + "/" + fname) << " for reading.\n";
delete s;
}

View file

@ -23,6 +23,7 @@
#include "global.hpp"
#include "scoped_resource.hpp"
#include "log.hpp"
#include "network_worker.hpp"
#include "network.hpp"
@ -420,6 +421,28 @@ static SOCKET_STATE send_buffer(TCPsocket sock, std::vector<char>& buf, int in_s
}
}
struct cork_setter {
cork_setter(int socket) : cork_(1), socket_(socket)
{
setsockopt(socket_, IPPROTO_TCP, TCP_CORK, &cork_, sizeof(cork_));;
}
~cork_setter()
{
cork_ = 0;
setsockopt(socket_, IPPROTO_TCP, TCP_CORK, &cork_, sizeof(cork_));
}
private:
int cork_;
int socket_;
};
#ifdef USE_SENDFILE
#include <unistd.h>
struct close_fd {
void operator()(int fd) const { close(fd); }
};
typedef util::scoped_resource<int, close_fd> scoped_fd;
#endif
static SOCKET_STATE send_file(buffer* buf)
{
size_t upto = 0;
@ -433,11 +456,10 @@ static SOCKET_STATE send_file(buffer* buf)
buffer.reserve(4);
SDLNet_Write32(filesize,&buffer[0]);
int socket = reinterpret_cast<_TCPsocket*>(buf->sock)->channel;
int in_file = open(buf->config_error.c_str(),O_NOATIME | O_RDONLY);
int cock = 1;
const scoped_fd in_file(open(buf->config_error.c_str(),O_NOATIME | O_RDONLY));
cork_setter set_socket_cork(socket);
int poll_res;
struct pollfd fd = {socket, POLLOUT, 0 };
setsockopt(socket, IPPROTO_TCP, TCP_CORK, &cock, sizeof(cock));;
do {
poll_res = poll(&fd, 1, 600000);
} while(poll_res == -1 && errno == EINTR);
@ -451,9 +473,6 @@ static SOCKET_STATE send_file(buffer* buf)
if (result != SOCKET_READY)
{
close(in_file);
cock = 0;
setsockopt(socket, IPPROTO_TCP, TCP_CORK, &cock, sizeof(cock));
return result;
}
result = SOCKET_READY;
@ -492,9 +511,6 @@ static SOCKET_STATE send_file(buffer* buf)
}
}
close(in_file);
cock = 0;
setsockopt(socket, IPPROTO_TCP, TCP_CORK, &cock, sizeof(cock));
return result;
}
#endif
@ -507,11 +523,13 @@ static SOCKET_STATE send_file(buffer* buf)
scoped_istream file_stream = istream_file(buf->config_error);
SOCKET_STATE result = send_buffer(buf->sock, buf->raw_buffer, 4);
if (!file_stream->good())
ERR_NW << "send_file: Couldn't open file " << buf->config_error << "\n";
if (result != SOCKET_READY)
{
return result;
}
while (true)
while (file_stream->good())
{
// read data
file_stream->read(&buf->raw_buffer[0], buf->raw_buffer.size());
@ -531,6 +549,9 @@ static SOCKET_STATE send_file(buffer* buf)
}
}
if (upto != filesize
&& !file_stream->good())
ERR_NW << "send_file failed because stream not good from file " << buf->config_error << " upto: " << upto << " size: " << filesize << "\n";
return result;
}

View file

@ -52,7 +52,7 @@ struct wesnoth_global_fixture {
SDL_Init(SDL_INIT_TIMER);
test_utils::get_fake_display();
//lg::set_log_domain_severity("all",3);
// lg::set_log_domain_severity("all",3);
// Set more report as default
if (boost::unit_test::runtime_config::log_level() == boost::unit_test::invalid_log_level)

View file

@ -20,6 +20,7 @@
#include <cstdlib>
#include "utils/auto_parameterized.hpp"
#include "utils/predicate.hpp"
#include "network.hpp"
#include "network_worker.hpp"
@ -182,13 +183,10 @@ std::ostream& operator<<(std::ostream& s, const sendfile_param& p)
sendfile_param sendfile_sizes[] = {sendfile_param(1*1024,true),
sendfile_param(500*1024,true),
sendfile_param(10*1024*1024,true),
// sendfile_param(50*1024*1024,true),
sendfile_param(30*1024*1024,true),
sendfile_param(1*1024,false),
sendfile_param(500*1024,false),
sendfile_param(10*1024*1024,false)//,
// sendfile_param(50*1024*1024,false)
};
sendfile_param(30*1024*1024,false)};
std::string create_random_sendfile(size_t size)
{
@ -228,29 +226,44 @@ class auto_resetter {
}
};
WESNOTH_PARAMETERIZED_TEST_CASE( test_system_sendfile, sendfile_param, sendfile_sizes, size )
WESNOTH_PARAMETERIZED_TEST_CASE( test_multi_sendfile, sendfile_param, sendfile_sizes, size )
{
auto_resetter<std::string> path("", game_config::path);
network::set_raw_data_only();
std::string file = create_random_sendfile(size.size_);
network_worker_pool::set_use_system_sendfile(size.system_);
network::connection client_client, server_client;
network::connection cl_client1, se_client1;
network::connection cl_client2, se_client2;
network::connection cl_client3, se_client3;
BOOST_CHECK_MESSAGE((client_client = network::connect(LOCALHOST, TEST_PORT)) > 0, "Can't connect to server!");
BOOST_CHECK_MESSAGE((cl_client1 = network::connect(LOCALHOST, TEST_PORT)) > 0, "Can't connect to server!");
BOOST_CHECK_MESSAGE((se_client1 = network::accept_connection()) > 0, "Coulnd't accept new connection");
BOOST_CHECK_MESSAGE((cl_client2 = network::connect(LOCALHOST, TEST_PORT)) > 0, "Can't connect to server!");
BOOST_CHECK_MESSAGE((se_client2 = network::accept_connection()) > 0, "Coulnd't accept new connection");
BOOST_CHECK_MESSAGE((cl_client3 = network::connect(LOCALHOST, TEST_PORT)) > 0, "Can't connect to server!");
BOOST_CHECK_MESSAGE((se_client3 = network::accept_connection()) > 0, "Coulnd't accept new connection");
BOOST_CHECK_MESSAGE((server_client = network::accept_connection()) > 0, "Coulnd't accept new connection");
network::send_file(file, client_client);
network::send_file(file, cl_client1);
network::send_file(file, cl_client2);
network::send_file(file, cl_client3);
std::vector<char> data;
BOOST_CHECK_EQUAL(server_client, receive(data,500));
BOOST_CHECK_PREDICATE(test_utils::one_of<network::connection> , (receive(data,500))(3)(se_client1)(se_client2)(se_client3));
BOOST_CHECK_EQUAL(data.size(), file_size(file));
BOOST_CHECK_PREDICATE(test_utils::one_of<network::connection> , (receive(data,500))(3)(se_client1)(se_client2)(se_client3));
BOOST_CHECK_EQUAL(data.size(), file_size(file));
BOOST_CHECK_PREDICATE(test_utils::one_of<network::connection> , (receive(data,500))(3)(se_client1)(se_client2)(se_client3));
BOOST_CHECK_EQUAL(data.size(), file_size(file));
network::disconnect(client_client);
network::disconnect(cl_client1);
network::disconnect(cl_client2);
network::disconnect(cl_client3);
BOOST_CHECK_THROW(receive(data),network::error);
BOOST_CHECK_THROW(receive(data),network::error);
BOOST_CHECK_THROW(receive(data),network::error);
delete_random_sendfile(file);

View file

@ -0,0 +1,50 @@
/* $Id$ */
/*
Copyright (C) 2008 by Pauli Nieminen <paniemin@cc.hut.fi>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef TESTS_UTILS_FAKE_DISPLAY_HPP_INCLUDED
#define TESTS_UTILS_FAKE_DISPLAY_HPP_INCLUDED
#include <cstdarg>
namespace test_utils {
/**
* Used to check if first parameter matches one of given values
* used with BOOST_CHECK_PREDICATE
**/
template<class T>
bool one_of(const T& val, int va_number, ...)
{
T param;
va_list vl;
va_start(vl, va_number);
bool ret = false;
for (int i = 0; i < va_number; ++i)
{
param = va_arg(vl, T);
if (param == val)
{
ret = true;
break;
}
}
va_end(vl);
return ret;
}
}
#endif

View file

@ -3,20 +3,61 @@
* show whole text over the page
**/
var next_id = 1;
var autohide_next_id = 0;
var autohide_store = new Array();
function make_hide_text(text, length, split_from_space, take_en)
var onload_registered = false;
function addOnloadFunction(func)
{
var id = next_id++;
var short_text;
var split_text = text.split(' ');
if (split_from_space)
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
function onload_autohide()
{
for (var hide in autohide_store)
{
autohide_store[hide].make_hide_text();
}
}
function Autohide(text, length, split_from_space, take_end)
{
this.id = autohide_store.length;
this.text = text;
this.length = length;
this.split_from_space = split_from_space;
this.take_end = take_end;
document.write('<div id="autohide' + this.id + '"></div>');
if (!onload_registered)
{
addOnloadFunction(onload_autohide);
onload_registered = true;
}
}
Autohide.prototype.make_hide_text = function()
{
var short_text;
var split_text;
if (this.split_from_space)
{
split_text = this.text.split(' ');
short_text = "";
var i = 0;
while(i < split_text.length && short_text.length + split_text[i].length < length)
while(i < split_text.length && short_text.length + split_text[i].length < this.length)
{
if (i>0)
short_text += ' ';
@ -26,51 +67,65 @@ function make_hide_text(text, length, split_from_space, take_en)
short_text = document.createTextNode(short_text);
} else {
var start=0;
if (take_end)
if (this.take_end)
{
start = text.length - length;
start = this.text.length - this.length;
if (start < 0)
start =0;
}
short_text = document.createTextNode(text.substr(start,length));
short_text = document.createTextNode(this.text.substr(start,this.length));
}
text = text.split("\n");
this.text = this.text.split("\n");
split_text = new Array();
while(true)
for(var index in this.text)
{
split_text.push(document.createTextNode(text.shift()));
if (text.length)
{
split_text.push(document.createElement('BR'));
} else {
break;
}
split_text.push(document.createTextNode(this.text[index]));
split_text.push(document.createElement('BR'));
}
// Create short text element
var new_elem = document.createElement('DIV');
new_elem.id='autohide_' + id;
new_elem.id='autohide_' + this.id;
new_elem.className="autohide";
// create full text element
var elem_over = new_elem.cloneNode(true);
elem_over.id='autohide_over_' + id;
elem_over.id='autohide_over_' + this.id;
elem_over.onmouseout=autohide_mouseout;
elem_over.style.visibility = 'hidden';
for(var i = 0; i < split_text.length; ++i)
{
elem_over.appendChild(split_text[i]);
}
var target = document.getElementById('autohide');
var target = document.getElementById('autohide'+this.id);
// Fill short text element
new_elem.appendChild(short_text);
new_elem.onmouseover=autohide_mouseover;
elem_over.className="autohide_over";
// add elements to document
target.parentNode.replaceChild(new_elem, target);
new_elem.parentNode.appendChild(elem_over);
// Make over element apear in same place
elem_over.className="autohide_over";
var max_iter = 3;
do {
var is_hitting_side = (elem_over.offsetLeft + elem_over.offsetWidth >= document.width)
|| (elem_over.offsetTop + elem_over.offsetHeight > document.height);
var y_pos = getYpos(new_elem);
var x_pos = getXpos(new_elem);
var y_pos2 = y_pos + new_elem.scrollHeight;
var x_pos2 = x_pos + new_elem.scrollWidth;
y_pos = (y_pos+y_pos2)/2;
x_pos = (x_pos+x_pos2)/2;
y_pos = y_pos - elem_over.scrollHeight/2;
x_pos = x_pos - elem_over.scrollWidth/2;
// console.log(this.id + ' x:' + x_pos + ' y:' + y_pos + ' ny:' + new_elem.scrollWidth + ' gy:' + getYpos(new_elem));
elem_over.style.top = y_pos + 'px';
elem_over.style.left = x_pos + 'px';
} while(is_hitting_side && --max_iter);
}
function getYpos(element)
@ -91,44 +146,45 @@ function getXpos(element)
function autohide_mouseover(e)
{
var targ;
var new_elem;
if(!e) e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
if (e.target) new_elem = e.target;
else if (e.srcElement) new_elem = e.srcElement;
if (new_elem.nodeType == 3) // defeat Safari bug
new_elem = new_elem.parentNode;
var over_id = new String(targ.id).replace('hide','hide_over');
var over_elem = document.getElementById(over_id);
over_elem.style.visibility='visible';
var y_pos = getYpos(targ);
var x_pos = getXpos(targ);
var y_pos2 = y_pos + targ.scrollHeight;
var x_pos2 = x_pos + targ.scrollWidth;
var over_id = new String(new_elem.id).replace('hide','hide_over');
var elem_over = document.getElementById(over_id);
var y_pos = getYpos(new_elem);
var x_pos = getXpos(new_elem);
var y_pos2 = y_pos + new_elem.scrollHeight;
var x_pos2 = x_pos + new_elem.scrollWidth;
y_pos = (y_pos+y_pos2)/2;
x_pos = (x_pos+x_pos2)/2;
y_pos = y_pos - over_elem.scrollHeight/2;
x_pos = x_pos - over_elem.scrollWidth/2;
y_pos = y_pos - elem_over.scrollHeight/2;
x_pos = x_pos - elem_over.scrollWidth/2;
over_elem.style.top = y_pos + 'px';
over_elem.style.left = x_pos + 'px';
targ.style.visibility='hidden';
// console.log(this.id + ' x:' + x_pos + ' y:' + y_pos + ' ny:' + new_elem.scrollWidth + ' gy:' + getYpos(new_elem));
elem_over.style.top = y_pos + 'px';
elem_over.style.left = x_pos + 'px';
elem_over.style.visibility='visible';
new_elem.style.visibility='hidden';
}
function autohide_mouseout(e)
{
var targ;
var elem_over;
if(!e) e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
if (e.target) elem_over = e.target;
else if (e.srcElement) elem_over = e.srcElement;
if (elem_over.nodeType == 3) // defeat Safari bug
elem_over = elem_over.parentNode;
targ.style.visibility='hidden';
var orig_id = new String(targ.id).replace('_over','');
var orig = document.getElementById(orig_id);
// orig.onmouseover=autohide_mouseover;
orig.style.visibility='visible';
elem_over.style.visibility='hidden';
var new_elem_id = new String(elem_over.id).replace('_over','');
var new_elem = document.getElementById(new_elem_id);
new_elem.style.visibility='visible';
}

View file

@ -36,7 +36,7 @@ div.autohide_over {
background:#FFFBF0 none repeat scroll 0 0;
border: 1px solid #AAAAAA;
padding: 0.5em;
max-width: 30em;
max-width: 60em;
}
table.test_error {
@ -51,3 +51,7 @@ table.test_error {
.test_error .Warning {
color: #FF00FF;
}
.test_error td {
text-align: center;
}

View file

@ -24,7 +24,7 @@ class Build {
$this->previous_id = -1;
$this->result = null;
$this->errors = array();
if ($revision > 0)
if ($revision >= 0)
$this->fetch("WHERE svn_version=?", array($revision));
}
@ -113,7 +113,8 @@ class Build {
{
return false;
}
if (preg_match_all('/^.*(error:|warning:|undefined reference|ld returned \d exit status).*$/mi',$compiler_log, $m,PREG_SET_ORDER))
$compiler_log = preg_replace('/^(.*\/)?([^\/]+:[0-9]+:.*)$/m','$2',$compiler_log);
if (preg_match_all('/^.*(error:|warning:|note:|undefined reference|ld returned \d exit status).*$/mi',$compiler_log, $m,PREG_SET_ORDER))
{
foreach($m as $match)

View file

@ -6,13 +6,9 @@ function smarty_modifier_autohide($text, $min_length_to_hide, $split_from_space,
{
$split_from_space = $split_from_space?"true":"false";
$take_end = $take_end?"true":"false";
return "<div id='autohide'></div><script type='text/javascript'>
return "<script type='text/javascript'>
/*<![CDATA[*/
var text = '$text';
var length = $min_length_to_hide;
var split_from_space = $split_from_space;
var take_end = $take_end;
make_hide_text(text, length, split_from_space, take_end);
autohide_store.push(new Autohide('$text', $min_length_to_hide, $split_from_space, $take_end));
/*]]>*/
</script>";
} else {