annotate UnitTestsSources/RestApi.cpp @ 882:c9034d80775d jpeg

close jpeg branch
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 14 Jun 2014 15:44:28 +0200
parents 84513f2ee1f3
children 886652370ff2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
1 /**
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
4 * Belgium
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
5 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
6 * This program is free software: you can redistribute it and/or
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
7 * modify it under the terms of the GNU General Public License as
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
8 * published by the Free Software Foundation, either version 3 of the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
9 * License, or (at your option) any later version.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
10 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
11 * In addition, as a special exception, the copyright holders of this
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
12 * program give permission to link the code of its release with the
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
14 * that use the same license as the "OpenSSL" library), and distribute
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
15 * the linked executables. You must obey the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
16 * in all respects for all of the code used other than "OpenSSL". If you
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
17 * modify file(s) with this exception, you may extend this exception to
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
18 * your version of the file(s), but you are not obligated to do so. If
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
19 * you do not wish to do so, delete this exception statement from your
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
20 * version. If you delete this exception statement from all source files
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
21 * in the program, then also delete it here.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
22 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
23 * This program is distributed in the hope that it will be useful, but
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
24 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
26 * General Public License for more details.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
27 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
28 * You should have received a copy of the GNU General Public License
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
29 * along with this program. If not, see <http://www.gnu.org/licenses/>.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
30 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
31
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 707
diff changeset
32
831
84513f2ee1f3 pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 827
diff changeset
33 #include "PrecompiledHeadersUnitTests.h"
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include "gtest/gtest.h"
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #include <ctype.h>
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include <glog/logging.h>
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
707
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
39 #include "../Core/ChunkedBuffer.h"
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
40 #include "../Core/HttpClient.h"
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #include "../Core/RestApi/RestApi.h"
221
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
42 #include "../Core/Uuid.h"
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
43 #include "../Core/OrthancException.h"
e7432706b354 accessors to storage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 210
diff changeset
44 #include "../Core/Compression/ZlibCompressor.h"
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 using namespace Orthanc;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
707
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
48 #if !defined(UNIT_TESTS_WITH_HTTP_CONNEXIONS)
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
49 #error "Please set UNIT_TESTS_WITH_HTTP_CONNEXIONS"
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
50 #endif
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
51
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
52 TEST(HttpClient, Basic)
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
53 {
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
54 HttpClient c;
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
55 ASSERT_FALSE(c.IsVerbose());
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
56 c.SetVerbose(true);
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
57 ASSERT_TRUE(c.IsVerbose());
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
58 c.SetVerbose(false);
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
59 ASSERT_FALSE(c.IsVerbose());
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
60
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
61 #if UNIT_TESTS_WITH_HTTP_CONNEXIONS == 1
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
62 Json::Value v;
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
63 c.SetUrl("http://orthanc.googlecode.com/hg/Resources/Configuration.json");
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
64 c.Apply(v);
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
65 ASSERT_TRUE(v.isMember("StorageDirectory"));
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
66 //ASSERT_EQ(GetLastStatusText());
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
67
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
68 v = Json::nullValue;
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
69
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
70 HttpClient cc(c);
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
71 cc.SetUrl("https://orthanc.googlecode.com/hg/Resources/Configuration.json");
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
72 cc.Apply(v);
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
73 ASSERT_TRUE(v.isMember("LuaScripts"));
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
74 #endif
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
75 }
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
76
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
77 TEST(RestApi, ChunkedBuffer)
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
78 {
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
79 ChunkedBuffer b;
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
80 ASSERT_EQ(0, b.GetNumBytes());
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
81
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
82 b.AddChunk("hello", 5);
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
83 ASSERT_EQ(5, b.GetNumBytes());
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
84
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
85 b.AddChunk("world", 5);
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
86 ASSERT_EQ(10, b.GetNumBytes());
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
87
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
88 std::string s;
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
89 b.Flatten(s);
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
90 ASSERT_EQ("helloworld", s);
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
91 }
203157cb4fde unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
92
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
93 TEST(RestApi, ParseCookies)
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
94 {
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
95 HttpHandler::Arguments headers;
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
96 HttpHandler::Arguments cookies;
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
97
332
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
98 headers["cookie"] = "a=b;c=d;;;e=f;;g=h;";
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
99 HttpHandler::ParseCookies(cookies, headers);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
100 ASSERT_EQ(4u, cookies.size());
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
101 ASSERT_EQ("b", cookies["a"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
102 ASSERT_EQ("d", cookies["c"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
103 ASSERT_EQ("f", cookies["e"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
104 ASSERT_EQ("h", cookies["g"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
105
332
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
106 headers["cookie"] = " name = value ; name2=value2";
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
107 HttpHandler::ParseCookies(cookies, headers);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
108 ASSERT_EQ(2u, cookies.size());
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
109 ASSERT_EQ("value", cookies["name"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
110 ASSERT_EQ("value2", cookies["name2"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
111
332
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
112 headers["cookie"] = " ;;; ";
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
113 HttpHandler::ParseCookies(cookies, headers);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
114 ASSERT_EQ(0u, cookies.size());
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
115
332
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 330
diff changeset
116 headers["cookie"] = " ; n=v ;; ";
330
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
117 HttpHandler::ParseCookies(cookies, headers);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
118 ASSERT_EQ(1u, cookies.size());
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
119 ASSERT_EQ("v", cookies["n"]);
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
120 }
78a8eaa5f30b cookies
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 281
diff changeset
121
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 TEST(RestApi, RestApiPath)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 RestApiPath::Components args;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 UriComponents trail;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 RestApiPath uri("/coucou/{abc}/d/*");
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 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
130 ASSERT_EQ(1u, args.size());
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 ASSERT_EQ(3u, trail.size());
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 ASSERT_EQ("moi", args["abc"]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 ASSERT_EQ("e", trail[0]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 ASSERT_EQ("f", trail[1]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 ASSERT_EQ("g", trail[2]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi/f"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 ASSERT_FALSE(uri.Match(args, trail, "/a/moi/d"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 RestApiPath uri("/coucou/{abc}/d");
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 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
146 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 ASSERT_EQ(1u, args.size());
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 ASSERT_EQ(0u, trail.size());
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 ASSERT_EQ("moi", args["abc"]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 RestApiPath uri("/*");
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 ASSERT_TRUE(uri.Match(args, trail, "/a/b/c"));
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 ASSERT_EQ(0u, args.size());
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 ASSERT_EQ(3u, trail.size());
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 ASSERT_EQ("a", trail[0]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 ASSERT_EQ("b", trail[1]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 ASSERT_EQ("c", trail[2]);
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 }