Mercurial > hg > orthanc
annotate UnitTests/RestApi.cpp @ 332:c51c9ed603e6
fixes
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Jan 2013 13:57:58 +0100 |
parents | 78a8eaa5f30b |
children |
rev | line source |
---|---|
209 | 1 #include "gtest/gtest.h" |
2 | |
3 #include <ctype.h> | |
4 #include <glog/logging.h> | |
5 | |
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 | 10 |
11 using namespace Orthanc; | |
12 | |
330 | 13 TEST(RestApi, ParseCookies) |
14 { | |
15 HttpHandler::Arguments headers; | |
16 HttpHandler::Arguments cookies; | |
17 | |
332 | 18 headers["cookie"] = "a=b;c=d;;;e=f;;g=h;"; |
330 | 19 HttpHandler::ParseCookies(cookies, headers); |
20 ASSERT_EQ(4u, cookies.size()); | |
21 ASSERT_EQ("b", cookies["a"]); | |
22 ASSERT_EQ("d", cookies["c"]); | |
23 ASSERT_EQ("f", cookies["e"]); | |
24 ASSERT_EQ("h", cookies["g"]); | |
25 | |
332 | 26 headers["cookie"] = " name = value ; name2=value2"; |
330 | 27 HttpHandler::ParseCookies(cookies, headers); |
28 ASSERT_EQ(2u, cookies.size()); | |
29 ASSERT_EQ("value", cookies["name"]); | |
30 ASSERT_EQ("value2", cookies["name2"]); | |
31 | |
332 | 32 headers["cookie"] = " ;;; "; |
330 | 33 HttpHandler::ParseCookies(cookies, headers); |
34 ASSERT_EQ(0u, cookies.size()); | |
35 | |
332 | 36 headers["cookie"] = " ; n=v ;; "; |
330 | 37 HttpHandler::ParseCookies(cookies, headers); |
38 ASSERT_EQ(1u, cookies.size()); | |
39 ASSERT_EQ("v", cookies["n"]); | |
40 } | |
41 | |
209 | 42 TEST(RestApi, RestApiPath) |
43 { | |
44 RestApiPath::Components args; | |
45 UriComponents trail; | |
46 | |
47 { | |
48 RestApiPath uri("/coucou/{abc}/d/*"); | |
49 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/e/f/g")); | |
50 ASSERT_EQ(1u, args.size()); | |
51 ASSERT_EQ(3u, trail.size()); | |
52 ASSERT_EQ("moi", args["abc"]); | |
53 ASSERT_EQ("e", trail[0]); | |
54 ASSERT_EQ("f", trail[1]); | |
55 ASSERT_EQ("g", trail[2]); | |
56 | |
57 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi/f")); | |
58 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/")); | |
59 ASSERT_FALSE(uri.Match(args, trail, "/a/moi/d")); | |
60 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi")); | |
61 } | |
62 | |
63 { | |
64 RestApiPath uri("/coucou/{abc}/d"); | |
65 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi/d/e/f/g")); | |
66 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d")); | |
67 ASSERT_EQ(1u, args.size()); | |
68 ASSERT_EQ(0u, trail.size()); | |
69 ASSERT_EQ("moi", args["abc"]); | |
70 } | |
71 | |
72 { | |
73 RestApiPath uri("/*"); | |
74 ASSERT_TRUE(uri.Match(args, trail, "/a/b/c")); | |
75 ASSERT_EQ(0u, args.size()); | |
76 ASSERT_EQ(3u, trail.size()); | |
77 ASSERT_EQ("a", trail[0]); | |
78 ASSERT_EQ("b", trail[1]); | |
79 ASSERT_EQ("c", trail[2]); | |
80 } | |
81 } |