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
|
#include "uscxml/URL.h"
#include "uscxml/Message.h"
#include <assert.h>
#include <boost/algorithm/string.hpp>
#include <iostream>
using namespace uscxml;
using namespace boost;
int main(int argc, char** argv) {
{
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"));
}
{
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"));
}
}
|