improve and extend the upnp unit test

This commit is contained in:
Arvid Norberg
2012-06-28 06:47:59 +00:00
parent a583c2fe88
commit 426f555ce0
3 changed files with 154 additions and 86 deletions

View File

@@ -47,87 +47,6 @@ using namespace libtorrent;
broadcast_socket* sock = 0;
int g_port = 0;
char upnp_xml[] =
"<root>"
"<specVersion>"
"<major>1</major>"
"<minor>0</minor>"
"</specVersion>"
"<URLBase>http://127.0.0.1:%d</URLBase>"
"<device>"
"<deviceType>"
"urn:schemas-upnp-org:device:InternetGatewayDevice:1"
"</deviceType>"
"<presentationURL>http://192.168.0.1:80</presentationURL>"
"<friendlyName>D-Link Router</friendlyName>"
"<manufacturer>D-Link</manufacturer>"
"<manufacturerURL>http://www.dlink.com</manufacturerURL>"
"<modelDescription>Internet Access Router</modelDescription>"
"<modelName>D-Link Router</modelName>"
"<UDN>uuid:upnp-InternetGatewayDevice-1_0-12345678900001</UDN>"
"<UPC>123456789001</UPC>"
"<serviceList>"
"<service>"
"<serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>"
"<serviceId>urn:upnp-org:serviceId:L3Forwarding1</serviceId>"
"<controlURL>/Layer3Forwarding</controlURL>"
"<eventSubURL>/Layer3Forwarding</eventSubURL>"
"<SCPDURL>/Layer3Forwarding.xml</SCPDURL>"
"</service>"
"</serviceList>"
"<deviceList>"
"<device>"
"<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>"
"<friendlyName>WANDevice</friendlyName>"
"<manufacturer>D-Link</manufacturer>"
"<manufacturerURL>http://www.dlink.com</manufacturerURL>"
"<modelDescription>Internet Access Router</modelDescription>"
"<modelName>D-Link Router</modelName>"
"<modelNumber>1</modelNumber>"
"<modelURL>http://support.dlink.com</modelURL>"
"<serialNumber>12345678900001</serialNumber>"
"<UDN>uuid:upnp-WANDevice-1_0-12345678900001</UDN>"
"<UPC>123456789001</UPC>"
"<serviceList>"
"<service>"
"<serviceType>"
"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"
"</serviceType>"
"<serviceId>urn:upnp-org:serviceId:WANCommonInterfaceConfig</serviceId>"
"<controlURL>/WANCommonInterfaceConfig</controlURL>"
"<eventSubURL>/WANCommonInterfaceConfig</eventSubURL>"
"<SCPDURL>/WANCommonInterfaceConfig.xml</SCPDURL>"
"</service>"
"</serviceList>"
"<deviceList>"
"<device>"
"<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>"
"<friendlyName>WAN Connection Device</friendlyName>"
"<manufacturer>D-Link</manufacturer>"
"<manufacturerURL>http://www.dlink.com</manufacturerURL>"
"<modelDescription>Internet Access Router</modelDescription>"
"<modelName>D-Link Router</modelName>"
"<modelNumber>1</modelNumber>"
"<modelURL>http://support.dlink.com</modelURL>"
"<serialNumber>12345678900001</serialNumber>"
"<UDN>uuid:upnp-WANConnectionDevice-1_0-12345678900001</UDN>"
"<UPC>123456789001</UPC>"
"<serviceList>"
"<service>"
"<serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>"
"<serviceId>urn:upnp-org:serviceId:WANIPConnection</serviceId>"
"<controlURL>/WANIPConnection</controlURL>"
"<eventSubURL>/WANIPConnection</eventSubURL>"
"<SCPDURL>/WANIPConnection.xml</SCPDURL>"
"</service>"
"</serviceList>"
"</device>"
"</deviceList>"
"</device>"
"</deviceList>"
"</device>"
"</root>";
char soap_add_response[] =
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"
@@ -202,16 +121,22 @@ void callback(int mapping, address const& ip, int port, error_code const& err)
//TODO: store the callbacks and verify that the ports were successful
}
int test_main()
int run_upnp_test(char const* root_filename, char const* router_model, char const* control_name)
{
libtorrent::io_service ios;
g_port = start_web_server();
std::vector<char> buf;
error_code ec;
load_file(root_filename, buf, ec);
buf.push_back(0);
FILE* xml_file = fopen("upnp.xml", "w+");
fprintf(xml_file, upnp_xml, g_port);
fprintf(xml_file, &buf[0], g_port);
fclose(xml_file);
std::ofstream xml("WANIPConnection", std::ios::trunc);
std::ofstream xml(control_name, std::ios::trunc);
xml.write(soap_add_response, sizeof(soap_add_response)-1);
xml.close();
@@ -226,7 +151,6 @@ int test_main()
upnp_handler->discover_device();
libtorrent::deadline_timer timer(ios);
error_code ec;
timer.expires_from_now(seconds(10), ec);
timer.async_wait(boost::bind(&libtorrent::io_service::stop, boost::ref(ios)));
@@ -246,7 +170,7 @@ int test_main()
xml.close();
std::cerr << "router: " << upnp_handler->router_model() << std::endl;
TEST_CHECK(upnp_handler->router_model() == "D-Link Router");
TEST_CHECK(upnp_handler->router_model() == router_model);
upnp_handler->close();
sock->close();
@@ -260,8 +184,16 @@ int test_main()
stop_web_server();
callbacks.clear();
delete sock;
return 0;
}
int test_main()
{
run_upnp_test("root1.xml", "Xtreme N GIGABIT Router", "wipconn");
run_upnp_test("root2.xml", "D-Link Router", "WANIPConnection");
return 0;
}