annotate UnitTests/RestApi.cpp @ 627:b8f738685ad2

fix for visual studio
author jodogne
date Fri, 25 Oct 2013 13:24:19 +0200
parents c51c9ed603e6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #include "gtest/gtest.h"
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 #include <ctype.h>
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 #include <glog/logging.h>
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 #include "../Core/RestApi/RestApi.h"
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
7 #include "../Core/Uuid.h"
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
8 #include "../Core/OrthancException.h"
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
9 #include "../Core/Compression/ZlibCompressor.h"
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 using namespace Orthanc;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
13 TEST(RestApi, ParseCookies)
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
14 {
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
15 HttpHandler::Arguments headers;
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
16 HttpHandler::Arguments cookies;
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
17
332
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
18 headers["cookie"] = "a=b;c=d;;;e=f;;g=h;";
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
19 HttpHandler::ParseCookies(cookies, headers);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
20 ASSERT_EQ(4u, cookies.size());
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
21 ASSERT_EQ("b", cookies["a"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
22 ASSERT_EQ("d", cookies["c"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
23 ASSERT_EQ("f", cookies["e"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
24 ASSERT_EQ("h", cookies["g"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
25
332
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
26 headers["cookie"] = " name = value ; name2=value2";
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
27 HttpHandler::ParseCookies(cookies, headers);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
28 ASSERT_EQ(2u, cookies.size());
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
29 ASSERT_EQ("value", cookies["name"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
30 ASSERT_EQ("value2", cookies["name2"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
31
332
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
32 headers["cookie"] = " ;;; ";
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
33 HttpHandler::ParseCookies(cookies, headers);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
34 ASSERT_EQ(0u, cookies.size());
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
35
332
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
36 headers["cookie"] = " ; n=v ;; ";
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
37 HttpHandler::ParseCookies(cookies, headers);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
38 ASSERT_EQ(1u, cookies.size());
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
39 ASSERT_EQ("v", cookies["n"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
40 }
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
41
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 TEST(RestApi, RestApiPath)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 RestApiPath::Components args;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 UriComponents trail;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 RestApiPath uri("/coucou/{abc}/d/*");
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/e/f/g"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 ASSERT_EQ(1u, args.size());
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 ASSERT_EQ(3u, trail.size());
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 ASSERT_EQ("moi", args["abc"]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 ASSERT_EQ("e", trail[0]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 ASSERT_EQ("f", trail[1]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 ASSERT_EQ("g", trail[2]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi/f"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 ASSERT_FALSE(uri.Match(args, trail, "/a/moi/d"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 RestApiPath uri("/coucou/{abc}/d");
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi/d/e/f/g"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 ASSERT_EQ(1u, args.size());
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 ASSERT_EQ(0u, trail.size());
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 ASSERT_EQ("moi", args["abc"]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 RestApiPath uri("/*");
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 ASSERT_TRUE(uri.Match(args, trail, "/a/b/c"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 ASSERT_EQ(0u, args.size());
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 ASSERT_EQ(3u, trail.size());
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 ASSERT_EQ("a", trail[0]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 ASSERT_EQ("b", trail[1]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 ASSERT_EQ("c", trail[2]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 }