/
test_uri.cc
59 lines (46 loc) · 1.52 KB
/
test_uri.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* davep 20210806 ; split uri into a library and a test file */
#include <iostream>
#include <array>
#include <boost/assert.hpp>
#include "uri.h"
int main(int argc, char *argv[])
{
std::string uri;
std::array<std::string,10> tests {
"http://",
"ftp://",
"sftp://",
"http://hythloday@www.utopia.com:1516",
"https://www.infradead.org/~tgr/libnl/",
"https://tools.ietf.org/html/rfc3986#page-50",
"https://www.google.com/search?client=firefox-b-1&q=std%3A%3Aarray",
"127.0.0.1",
// https://tools.ietf.org/html/rfc3986#page-35
"http://a/b/c/d;p?q",
// https://tools.ietf.org/html/rfc3986#page-45
"ftp://cnn.example.com&story=breaking_news@10.0.0.1/top_story.htm",
};
std::array<std::string,1> fail_tests {
// username:password is deprecated so this should fail
"ftp://anonymous:complaints@whitehouse.gov/pub/taxreturns/",
};
/* these should succeed */
for (auto test_iter = tests.begin(); test_iter < tests.end() ; test_iter++ ) {
std::cout << "testing \"" << *test_iter << "\"...\n";
parse_uri(*test_iter);
}
/* these should fail */
/* FIXME username:password should fail but doesn't */
for (auto test_iter = fail_tests.begin(); test_iter < fail_tests.end() ; test_iter++ ) {
std::cout << "testing \"" << *test_iter << "\"...\n";
parse_uri(*test_iter);
}
/* also parse any from the command line */
for (int i=1 ; i<argc ; i++ ) {
uri.assign(argv[i]);
std::cout << "testing \"" << uri << "\"...\n";
bool flag = parse_uri(uri);
BOOST_ASSERT_MSG(flag, "u failed");
}
return EXIT_SUCCESS;
}