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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
#include "uscxml/URL.h"
#include "uscxml/Message.h"
#include "uscxml/server/HTTPServer.h"
#include <assert.h>
#include <boost/algorithm/string.hpp>
#include <iostream>
using namespace uscxml;
using namespace boost;
class TestServlet : public HTTPServlet {
public:
TestServlet(bool adaptPath) : _canAdaptPath(adaptPath) {}
void httpRecvRequest(const HTTPServer::Request& request) {};
bool canAdaptPath() { return _canAdaptPath; }
void setURL(const std::string& url) { _actualUrl = url; }
std::string _actualUrl;
bool _canAdaptPath;
};
int main(int argc, char** argv) {
{
TestServlet* testServlet1 = new TestServlet(false);
TestServlet* testServlet2 = new TestServlet(false);
assert(HTTPServer::registerServlet("/foo", testServlet1));
assert(!HTTPServer::registerServlet("/foo", testServlet2));
HTTPServer::unregisterServlet(testServlet1);
assert(HTTPServer::registerServlet("/foo", testServlet2));
HTTPServer::unregisterServlet(testServlet1);
assert(HTTPServer::registerServlet("/foo/bar/", testServlet1));
assert(!HTTPServer::registerServlet("/foo/bar/", testServlet2));
HTTPServer::unregisterServlet(testServlet1);
HTTPServer::unregisterServlet(testServlet2);
}
{
TestServlet* testServlet1 = new TestServlet(true);
TestServlet* testServlet2 = new TestServlet(true);
TestServlet* testServlet3 = new TestServlet(true);
assert(HTTPServer::registerServlet("/foo", testServlet1));
assert(HTTPServer::registerServlet("/foo", testServlet2));
assert(HTTPServer::registerServlet("/foo", testServlet3));
assert(boost::ends_with(testServlet1->_actualUrl, "foo"));
assert(boost::ends_with(testServlet2->_actualUrl, "foo2"));
assert(boost::ends_with(testServlet3->_actualUrl, "foo3"));
HTTPServer::unregisterServlet(testServlet1);
HTTPServer::unregisterServlet(testServlet2);
HTTPServer::unregisterServlet(testServlet3);
}
{
Data data = Data::fromJSON("asdf");
std::cout << data << std::endl;
}
{
Data data = Data::fromJSON("[ '1', '2', '3', '4' ]");
std::cout << data << std::endl;
}
{
Data data = Data::fromJSON("{'foo1': 'bar2', 'foo3': { 'foo4': 'bar5' }, 'foo6': 'bar7', 'foo8': { 'foo9': 'foo10': { 'foo11': 'bar12' } } }");
std::cout << data << std::endl;
}
{
Data data = Data::fromJSON("{\"firstName\": \"John\", \"lastName\": \"Smith\", \"age\": 25, \"address\": { \"streetAddress\": \"21 2nd Street\", \"city\": \"New York\",\"state\": \"NY\",\"postalCode\": 10021},\"phoneNumber\": [{\"type\": \"home\",\"number\": \"212 555-1234\"},{ \"type\": \"fax\",\"number\": \"646 555-4567\"}]}");
std::cout << data << std::endl;
}
{
URL url("http://www.heise.de/index.html");
std::cout << url.asString() << std::endl;
assert(url.isAbsolute());
assert(iequals(url.scheme(), "http"));
assert(iequals(url.host(), "www.heise.de"));
assert(iequals(url.port(), "80"));
assert(iequals(url.path(), "/index.html"));
assert(iequals(url.asString(), "http://www.heise.de/index.html"));
std::stringstream content;
content << url;
}
{
URL url("https://raw.github.com/tklab-tud/uscxml/master/test/samples/uscxml/test-ecmascript.scxml");
std::cout << url.asString() << std::endl;
assert(url.isAbsolute());
assert(iequals(url.scheme(), "https"));
std::stringstream content;
content << url;
}
{
URL url("file:Document/Text.foo");
std::cout << url.asString() << std::endl;
assert(!url.isAbsolute());
assert(iequals(url.scheme(), "file"));
assert(iequals(url.host(), ""));
assert(iequals(url.port(), "0"));
assert(iequals(url.path(), "Document/Text.foo"));
assert(iequals(url.asString(), "file:Document/Text.foo"));
}
{
URL url("test/index.html");
assert(iequals(url.scheme(), ""));
url.toAbsoluteCwd();
assert(iequals(url.scheme(), "file"));
std::cout << url.asString() << std::endl;
}
{
URL url("C:\\Document\\Some Spaces\\index.txt");
assert(url.isAbsolute());
assert(iequals(url.scheme(), "file"));
std::cout << url.asString() << std::endl;
}
{
URL url = URL::toLocalFile("this is quite some content!", "txt");
std::cout << url.asLocalFile("txt");
assert(url.isAbsolute());
assert(iequals(url.scheme(), "file"));
}
{
URL url("C:\\Document\\Some Spaces\\index.txt");
assert(iequals(url.pathComponents()[0], "C:"));
assert(iequals(url.pathComponents()[1], "Document"));
assert(iequals(url.pathComponents()[2], "Some Spaces"));
assert(iequals(url.pathComponents()[3], "index.txt"));
}
}
|