fix test_upnp

This commit is contained in:
Arvid Norberg 2013-09-03 04:41:49 +00:00
parent 86dbf5b043
commit 1dc491e7e1
4 changed files with 69 additions and 28 deletions

View File

@ -1415,6 +1415,16 @@ void upnp::on_upnp_unmap_response(error_code const& e
log(msg, l);
}
error_code_parse_state s;
xml_parse((char*)p.get_body().begin, (char*)p.get_body().end
, boost::bind(&find_error_code, _1, _2, boost::ref(s)));
l.unlock();
m_callback(mapping, address(), 0, p.status_code() != 200
? error_code(p.status_code(), get_http_category())
: error_code(s.error_code, upnp_category));
l.lock();
d.mapping[mapping].protocol = none;
next(d, mapping, l);

View File

@ -60,7 +60,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <boost/detail/atomic_count.hpp>
#define DEBUG_WEB_SERVER 0
#define DEBUG_WEB_SERVER 1
#define DLOG if (DEBUG_WEB_SERVER) fprintf
@ -925,6 +925,7 @@ void send_content(socket_type& s, char const* file, int size, bool chunked)
else
{
write(s, boost::asio::buffer(file, size), boost::asio::transfer_all(), ec);
DLOG(stderr, " >> %s\n", std::string(file, size).c_str());
if (ec) fprintf(stderr, "*** send failed: %s\n", ec.message().c_str());
}
}
@ -1310,7 +1311,7 @@ void web_server_thread(int* port, bool ssl, bool chunked)
// remove the / from the path
path = path.substr(1);
error_code ec;
int res = load_file(path, file_buf, ec);
int res = load_file(path, file_buf, ec, 8000000);
if (res == -1)
{
fprintf(stderr, ">> file not found: %s\n", path.c_str());

View File

@ -84,7 +84,7 @@ int EXPORT print_failures();
#define TEST_EQUAL(x, y) \
if (x != y) { \
std::stringstream s__; \
s__ << "TEST_EQUAL_ERROR:\n" #x ": " << x << "\nexpected: " << y << std::endl; \
s__ << "TEST_EQUAL_ERROR:\n" #x ": " << x << "\nexpected: " << y; \
TEST_REPORT_AUX(s__.str().c_str(), __FILE__, __LINE__); \
}
#else
@ -107,7 +107,7 @@ int EXPORT print_failures();
try { \
if (x != y) { \
std::stringstream s__; \
s__ << "TEST_EQUAL_ERROR: " #x ": " << x << " expected: " << y << std::endl; \
s__ << "TEST_EQUAL_ERROR: " #x ": " << x << " expected: " << y; \
TEST_REPORT_AUX(s__.str().c_str(), __FILE__, __LINE__); \
} \
} \

View File

@ -118,7 +118,6 @@ void callback(int mapping, address const& ip, int port, error_code const& err)
callbacks.push_back(info);
std::cerr << "mapping: " << mapping << ", port: " << port << ", IP: " << ip
<< ", error: \"" << err.message() << "\"\n";
//TODO: store the callbacks and verify that the ports were successful
}
int run_upnp_test(char const* root_filename, char const* router_model, char const* control_name)
@ -158,37 +157,68 @@ int run_upnp_test(char const* root_filename, char const* router_model, char cons
, user_agent, &callback, &log_callback, false);
upnp_handler->discover_device();
libtorrent::deadline_timer timer(ios);
timer.expires_from_now(seconds(10), ec);
timer.async_wait(boost::bind(&libtorrent::io_service::stop, boost::ref(ios)));
for (int i = 0; i < 20; ++i)
{
ios.reset();
ios.poll(ec);
if (ec)
{
fprintf(stderr, "io_service::run(): %s\n", ec.message().c_str());
ec.clear();
break;
}
if (upnp_handler->router_model() != "") break;
test_sleep(100);
}
ios.reset();
ios.run(ec);
std::cerr << "router: " << upnp_handler->router_model() << std::endl;
TEST_EQUAL(upnp_handler->router_model(), router_model);
int mapping1 = upnp_handler->add_mapping(upnp::tcp, 500, 500);
int mapping2 = upnp_handler->add_mapping(upnp::udp, 501, 501);
timer.expires_from_now(seconds(10), ec);
timer.async_wait(boost::bind(&libtorrent::io_service::stop, boost::ref(ios)));
ios.reset();
ios.run(ec);
xml.open("WANIPConnection", std::ios::trunc);
xml.write(soap_delete_response, sizeof(soap_delete_response)-1);
xml.close();
std::cerr << "router: " << upnp_handler->router_model() << std::endl;
TEST_CHECK(upnp_handler->router_model() == router_model);
upnp_handler->close();
sock->close();
ios.reset();
ios.run(ec);
for (int i = 0; i < 40; ++i)
{
ios.reset();
ios.poll(ec);
if (ec)
{
fprintf(stderr, "io_service::run(): %s\n", ec.message().c_str());
ec.clear();
break;
}
if (callbacks.size() >= 2) break;
test_sleep(100);
}
callback_info expected1 = {mapping1, 500, error_code()};
callback_info expected2 = {mapping2, 501, error_code()};
TEST_CHECK(std::count(callbacks.begin(), callbacks.end(), expected1) == 1);
TEST_CHECK(std::count(callbacks.begin(), callbacks.end(), expected2) == 1);
TEST_EQUAL(std::count(callbacks.begin(), callbacks.end(), expected1), 1);
TEST_EQUAL(std::count(callbacks.begin(), callbacks.end(), expected2), 1);
xml.open(control_name, std::ios::trunc);
xml.write(soap_delete_response, sizeof(soap_delete_response)-1);
xml.close();
upnp_handler->close();
sock->close();
for (int i = 0; i < 40; ++i)
{
ios.reset();
ios.poll(ec);
if (ec)
{
fprintf(stderr, "io_service::run(): %s\n", ec.message().c_str());
ec.clear();
break;
}
if (callbacks.size() >= 4) break;
test_sleep(100);
}
// there should have been two DeleteMapping calls
TEST_EQUAL(callbacks.size(), 4);
stop_web_server();