Skip to content

Commit 426f555

Browse files
committed
improve and extend the upnp unit test
1 parent a583c2f commit 426f555

File tree

3 files changed

+154
-86
lines changed

3 files changed

+154
-86
lines changed

test/root1.xml

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?xml version="1.0"?>
2+
<root xmlns="urn:schemas-upnp-org:device-1-0">
3+
<specVersion>
4+
<major>1</major>
5+
<minor>0</minor>
6+
</specVersion>
7+
<URLBase>http://127.0.0.1</URLBase>
8+
9+
10+
<device>
11+
12+
<deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType>
13+
<presentationURL>/</presentationURL>
14+
<friendlyName>Xtreme N GIGABIT Router</friendlyName>
15+
<manufacturer>D-Link Systems</manufacturer>
16+
<manufacturerURL>http://www.dlink.com</manufacturerURL>
17+
<modelDescription>Xtreme N GIGABIT Router</modelDescription>
18+
<modelName>Xtreme N GIGABIT Router</modelName>
19+
<modelNumber>DIR-655</modelNumber>
20+
<modelURL>http://www.dlink.com</modelURL>
21+
<serialNumber>none</serialNumber>
22+
<UDN>uuid:E17FAEB7-CABB-3BCC-9C36-7207D5397C0E</UDN>
23+
24+
25+
26+
<UPC>00000-00001</UPC>
27+
<serviceList>
28+
<service>
29+
<serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>
30+
31+
<serviceId>urn:upnp-org:serviceId:L3Forwarding1</serviceId>
32+
<controlURL>http://192.168.0.1:4444/l3fw</controlURL>
33+
<eventSubURL>http://192.168.0.1:9393/l3fw</eventSubURL>
34+
<SCPDURL>http://192.168.0.1/l3fw.xml</SCPDURL>
35+
</service>
36+
</serviceList>
37+
<deviceList>
38+
<device>
39+
<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>
40+
41+
<friendlyName>Xtreme N GIGABIT Router</friendlyName>
42+
<manufacturer>D-Link Systems</manufacturer>
43+
<manufacturerURL>http://www.dlink.com</manufacturerURL>
44+
<modelDescription>Xtreme N GIGABIT Router</modelDescription>
45+
<modelName>Xtreme N GIGABIT Router</modelName>
46+
<modelNumber>DIR-655</modelNumber>
47+
<modelURL>http://www.dlink.com</modelURL>
48+
<serialNumber>none</serialNumber>
49+
<UDN>uuid:EC4A6889-B956-363F-9849-62C053B72D72</UDN>
50+
51+
<UPC>00000-00001</UPC>
52+
<serviceList>
53+
<service>
54+
<serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType>
55+
56+
<serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId>
57+
<controlURL>http://192.168.0.1:4444/wcommifc</controlURL>
58+
<eventSubURL>http://192.168.0.1:9393/wcommifc</eventSubURL>
59+
<SCPDURL>http://192.168.0.1/WANCommonIFC1.xml</SCPDURL>
60+
</service>
61+
</serviceList>
62+
<deviceList>
63+
<device>
64+
<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>
65+
66+
<friendlyName>Xtreme N GIGABIT Router</friendlyName>
67+
<manufacturer>D-Link Systems</manufacturer>
68+
<manufacturerURL>http://www.dlink.com</manufacturerURL>
69+
<modelDescription>Xtreme N GIGABIT Router</modelDescription>
70+
<modelName>Xtreme N GIGABIT Router</modelName>
71+
<modelNumber>DIR-655</modelNumber>
72+
<modelURL>http://www.dlink.com</modelURL>
73+
<serialNumber>none</serialNumber>
74+
<UDN>uuid:8843AAB0-7191-39C5-A763-9592A8C5AB32</UDN>
75+
76+
<UPC>00000-00001</UPC>
77+
<serviceList>
78+
<service>
79+
<serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>
80+
81+
<serviceId>urn:upnp-org:serviceId:WANIPConn1</serviceId>
82+
<controlURL>http://127.0.0.1:%d/wipconn</controlURL>
83+
<eventSubURL>http://192.168.0.1:9393/wipconn</eventSubURL>
84+
<SCPDURL>http://192.168.0.1/WANIPConn1.xml</SCPDURL>
85+
</service>
86+
</serviceList>
87+
</device>
88+
</deviceList>
89+
</device>
90+
91+
92+
93+
<device>
94+
<deviceType>urn:schemas-wifialliance-org:device:WFADevice:1</deviceType>
95+
<presentationURL>/</presentationURL>
96+
<friendlyName>WFADevice</friendlyName>
97+
<manufacturer>D-Link Systems</manufacturer>
98+
<manufacturerURL>http://www.dlink.com</manufacturerURL>
99+
<modelDescription>Xtreme N GIGABIT Router</modelDescription>
100+
<modelName>Xtreme N GIGABIT Router</modelName>
101+
<modelNumber>DIR-655</modelNumber>
102+
<modelURL>http://www.dlink.com</modelURL>
103+
<serialNumber>none</serialNumber>
104+
105+
<UDN>uuid:003F35AE-C81C-3EE7-972E-8AEF712289D5</UDN>
106+
107+
108+
109+
110+
111+
112+
113+
114+
<UPC>00000-00001</UPC>
115+
<serviceList>
116+
<service>
117+
<serviceType>urn:schemas-wifialliance-org:service:WFAWLANConfig:1</serviceType>
118+
119+
120+
121+
<serviceId>urn:wifialliance-org:serviceId:WFAWLANConfig1</serviceId>
122+
<controlURL>http://192.168.0.1:8832/wfawc</controlURL>
123+
<eventSubURL>http://192.168.0.1:8456/wfawc</eventSubURL>
124+
<SCPDURL>http://192.168.0.1/WFAwc.xml</SCPDURL>
125+
</service>
126+
</serviceList>
127+
</device>
128+
129+
130+
131+
</deviceList>
132+
</device>
133+
134+
135+
</root>

test/root2.xml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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>

test/test_upnp.cpp

+18-86
Original file line numberDiff line numberDiff line change
@@ -47,87 +47,6 @@ using namespace libtorrent;
4747
broadcast_socket* sock = 0;
4848
int g_port = 0;
4949

50-
char upnp_xml[] =
51-
"<root>"
52-
"<specVersion>"
53-
"<major>1</major>"
54-
"<minor>0</minor>"
55-
"</specVersion>"
56-
"<URLBase>http://127.0.0.1:%d</URLBase>"
57-
"<device>"
58-
"<deviceType>"
59-
"urn:schemas-upnp-org:device:InternetGatewayDevice:1"
60-
"</deviceType>"
61-
"<presentationURL>http://192.168.0.1:80</presentationURL>"
62-
"<friendlyName>D-Link Router</friendlyName>"
63-
"<manufacturer>D-Link</manufacturer>"
64-
"<manufacturerURL>http://www.dlink.com</manufacturerURL>"
65-
"<modelDescription>Internet Access Router</modelDescription>"
66-
"<modelName>D-Link Router</modelName>"
67-
"<UDN>uuid:upnp-InternetGatewayDevice-1_0-12345678900001</UDN>"
68-
"<UPC>123456789001</UPC>"
69-
"<serviceList>"
70-
"<service>"
71-
"<serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>"
72-
"<serviceId>urn:upnp-org:serviceId:L3Forwarding1</serviceId>"
73-
"<controlURL>/Layer3Forwarding</controlURL>"
74-
"<eventSubURL>/Layer3Forwarding</eventSubURL>"
75-
"<SCPDURL>/Layer3Forwarding.xml</SCPDURL>"
76-
"</service>"
77-
"</serviceList>"
78-
"<deviceList>"
79-
"<device>"
80-
"<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>"
81-
"<friendlyName>WANDevice</friendlyName>"
82-
"<manufacturer>D-Link</manufacturer>"
83-
"<manufacturerURL>http://www.dlink.com</manufacturerURL>"
84-
"<modelDescription>Internet Access Router</modelDescription>"
85-
"<modelName>D-Link Router</modelName>"
86-
"<modelNumber>1</modelNumber>"
87-
"<modelURL>http://support.dlink.com</modelURL>"
88-
"<serialNumber>12345678900001</serialNumber>"
89-
"<UDN>uuid:upnp-WANDevice-1_0-12345678900001</UDN>"
90-
"<UPC>123456789001</UPC>"
91-
"<serviceList>"
92-
"<service>"
93-
"<serviceType>"
94-
"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"
95-
"</serviceType>"
96-
"<serviceId>urn:upnp-org:serviceId:WANCommonInterfaceConfig</serviceId>"
97-
"<controlURL>/WANCommonInterfaceConfig</controlURL>"
98-
"<eventSubURL>/WANCommonInterfaceConfig</eventSubURL>"
99-
"<SCPDURL>/WANCommonInterfaceConfig.xml</SCPDURL>"
100-
"</service>"
101-
"</serviceList>"
102-
"<deviceList>"
103-
"<device>"
104-
"<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>"
105-
"<friendlyName>WAN Connection Device</friendlyName>"
106-
"<manufacturer>D-Link</manufacturer>"
107-
"<manufacturerURL>http://www.dlink.com</manufacturerURL>"
108-
"<modelDescription>Internet Access Router</modelDescription>"
109-
"<modelName>D-Link Router</modelName>"
110-
"<modelNumber>1</modelNumber>"
111-
"<modelURL>http://support.dlink.com</modelURL>"
112-
"<serialNumber>12345678900001</serialNumber>"
113-
"<UDN>uuid:upnp-WANConnectionDevice-1_0-12345678900001</UDN>"
114-
"<UPC>123456789001</UPC>"
115-
"<serviceList>"
116-
"<service>"
117-
"<serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>"
118-
"<serviceId>urn:upnp-org:serviceId:WANIPConnection</serviceId>"
119-
"<controlURL>/WANIPConnection</controlURL>"
120-
"<eventSubURL>/WANIPConnection</eventSubURL>"
121-
"<SCPDURL>/WANIPConnection.xml</SCPDURL>"
122-
"</service>"
123-
"</serviceList>"
124-
"</device>"
125-
"</deviceList>"
126-
"</device>"
127-
"</deviceList>"
128-
"</device>"
129-
"</root>";
130-
13150
char soap_add_response[] =
13251
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" "
13352
"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)
202121
//TODO: store the callbacks and verify that the ports were successful
203122
}
204123

205-
int test_main()
124+
int run_upnp_test(char const* root_filename, char const* router_model, char const* control_name)
206125
{
207126
libtorrent::io_service ios;
208127

209128
g_port = start_web_server();
129+
130+
std::vector<char> buf;
131+
error_code ec;
132+
load_file(root_filename, buf, ec);
133+
buf.push_back(0);
134+
210135
FILE* xml_file = fopen("upnp.xml", "w+");
211-
fprintf(xml_file, upnp_xml, g_port);
136+
fprintf(xml_file, &buf[0], g_port);
212137
fclose(xml_file);
213138

214-
std::ofstream xml("WANIPConnection", std::ios::trunc);
139+
std::ofstream xml(control_name, std::ios::trunc);
215140
xml.write(soap_add_response, sizeof(soap_add_response)-1);
216141
xml.close();
217142

@@ -226,7 +151,6 @@ int test_main()
226151
upnp_handler->discover_device();
227152

228153
libtorrent::deadline_timer timer(ios);
229-
error_code ec;
230154
timer.expires_from_now(seconds(10), ec);
231155
timer.async_wait(boost::bind(&libtorrent::io_service::stop, boost::ref(ios)));
232156

@@ -246,7 +170,7 @@ int test_main()
246170
xml.close();
247171

248172
std::cerr << "router: " << upnp_handler->router_model() << std::endl;
249-
TEST_CHECK(upnp_handler->router_model() == "D-Link Router");
173+
TEST_CHECK(upnp_handler->router_model() == router_model);
250174
upnp_handler->close();
251175
sock->close();
252176

@@ -260,8 +184,16 @@ int test_main()
260184

261185
stop_web_server();
262186

187+
callbacks.clear();
188+
263189
delete sock;
264190
return 0;
265191
}
266192

193+
int test_main()
194+
{
195+
run_upnp_test("root1.xml", "Xtreme N GIGABIT Router", "wipconn");
196+
run_upnp_test("root2.xml", "D-Link Router", "WANIPConnection");
197+
return 0;
198+
}
267199

0 commit comments

Comments
 (0)