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

135
test/root1.xml Normal file
View File

@ -0,0 +1,135 @@
<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<URLBase>http://127.0.0.1</URLBase>
<device>
<deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType>
<presentationURL>/</presentationURL>
<friendlyName>Xtreme N GIGABIT Router</friendlyName>
<manufacturer>D-Link Systems</manufacturer>
<manufacturerURL>http://www.dlink.com</manufacturerURL>
<modelDescription>Xtreme N GIGABIT Router</modelDescription>
<modelName>Xtreme N GIGABIT Router</modelName>
<modelNumber>DIR-655</modelNumber>
<modelURL>http://www.dlink.com</modelURL>
<serialNumber>none</serialNumber>
<UDN>uuid:E17FAEB7-CABB-3BCC-9C36-7207D5397C0E</UDN>
<UPC>00000-00001</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>
<serviceId>urn:upnp-org:serviceId:L3Forwarding1</serviceId>
<controlURL>http://192.168.0.1:4444/l3fw</controlURL>
<eventSubURL>http://192.168.0.1:9393/l3fw</eventSubURL>
<SCPDURL>http://192.168.0.1/l3fw.xml</SCPDURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>
<friendlyName>Xtreme N GIGABIT Router</friendlyName>
<manufacturer>D-Link Systems</manufacturer>
<manufacturerURL>http://www.dlink.com</manufacturerURL>
<modelDescription>Xtreme N GIGABIT Router</modelDescription>
<modelName>Xtreme N GIGABIT Router</modelName>
<modelNumber>DIR-655</modelNumber>
<modelURL>http://www.dlink.com</modelURL>
<serialNumber>none</serialNumber>
<UDN>uuid:EC4A6889-B956-363F-9849-62C053B72D72</UDN>
<UPC>00000-00001</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId>
<controlURL>http://192.168.0.1:4444/wcommifc</controlURL>
<eventSubURL>http://192.168.0.1:9393/wcommifc</eventSubURL>
<SCPDURL>http://192.168.0.1/WANCommonIFC1.xml</SCPDURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>
<friendlyName>Xtreme N GIGABIT Router</friendlyName>
<manufacturer>D-Link Systems</manufacturer>
<manufacturerURL>http://www.dlink.com</manufacturerURL>
<modelDescription>Xtreme N GIGABIT Router</modelDescription>
<modelName>Xtreme N GIGABIT Router</modelName>
<modelNumber>DIR-655</modelNumber>
<modelURL>http://www.dlink.com</modelURL>
<serialNumber>none</serialNumber>
<UDN>uuid:8843AAB0-7191-39C5-A763-9592A8C5AB32</UDN>
<UPC>00000-00001</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANIPConn1</serviceId>
<controlURL>http://127.0.0.1:%d/wipconn</controlURL>
<eventSubURL>http://192.168.0.1:9393/wipconn</eventSubURL>
<SCPDURL>http://192.168.0.1/WANIPConn1.xml</SCPDURL>
</service>
</serviceList>
</device>
</deviceList>
</device>
<device>
<deviceType>urn:schemas-wifialliance-org:device:WFADevice:1</deviceType>
<presentationURL>/</presentationURL>
<friendlyName>WFADevice</friendlyName>
<manufacturer>D-Link Systems</manufacturer>
<manufacturerURL>http://www.dlink.com</manufacturerURL>
<modelDescription>Xtreme N GIGABIT Router</modelDescription>
<modelName>Xtreme N GIGABIT Router</modelName>
<modelNumber>DIR-655</modelNumber>
<modelURL>http://www.dlink.com</modelURL>
<serialNumber>none</serialNumber>
<UDN>uuid:003F35AE-C81C-3EE7-972E-8AEF712289D5</UDN>
<UPC>00000-00001</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-wifialliance-org:service:WFAWLANConfig:1</serviceType>
<serviceId>urn:wifialliance-org:serviceId:WFAWLANConfig1</serviceId>
<controlURL>http://192.168.0.1:8832/wfawc</controlURL>
<eventSubURL>http://192.168.0.1:8456/wfawc</eventSubURL>
<SCPDURL>http://192.168.0.1/WFAwc.xml</SCPDURL>
</service>
</serviceList>
</device>
</deviceList>
</device>
</root>

1
test/root2.xml Normal file
View File

@ -0,0 +1 @@
<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>

View File

@ -47,87 +47,6 @@ using namespace libtorrent;
broadcast_socket* sock = 0; broadcast_socket* sock = 0;
int g_port = 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[] = char soap_add_response[] =
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" " "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
"s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" "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 //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; libtorrent::io_service ios;
g_port = start_web_server(); 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+"); FILE* xml_file = fopen("upnp.xml", "w+");
fprintf(xml_file, upnp_xml, g_port); fprintf(xml_file, &buf[0], g_port);
fclose(xml_file); 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.write(soap_add_response, sizeof(soap_add_response)-1);
xml.close(); xml.close();
@ -226,7 +151,6 @@ int test_main()
upnp_handler->discover_device(); upnp_handler->discover_device();
libtorrent::deadline_timer timer(ios); libtorrent::deadline_timer timer(ios);
error_code ec;
timer.expires_from_now(seconds(10), ec); timer.expires_from_now(seconds(10), ec);
timer.async_wait(boost::bind(&libtorrent::io_service::stop, boost::ref(ios))); timer.async_wait(boost::bind(&libtorrent::io_service::stop, boost::ref(ios)));
@ -246,7 +170,7 @@ int test_main()
xml.close(); xml.close();
std::cerr << "router: " << upnp_handler->router_model() << std::endl; 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(); upnp_handler->close();
sock->close(); sock->close();
@ -260,8 +184,16 @@ int test_main()
stop_web_server(); stop_web_server();
callbacks.clear();
delete sock; delete sock;
return 0; 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;
}