Mercurial > hg > orthanc
comparison OrthancFramework/UnitTestsSources/FrameworkTests.cpp @ 4330:a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 25 Nov 2020 14:39:10 +0100 |
parents | 9684a690ca63 |
children | 52166629239f |
comparison
equal
deleted
inserted
replaced
4329:9dc0e42f868b | 4330:a01b1c9cbef4 |
---|---|
32 #include "../Sources/EnumerationDictionary.h" | 32 #include "../Sources/EnumerationDictionary.h" |
33 | 33 |
34 #include <gtest/gtest.h> | 34 #include <gtest/gtest.h> |
35 | 35 |
36 #include "../Sources/DicomFormat/DicomTag.h" | 36 #include "../Sources/DicomFormat/DicomTag.h" |
37 #include "../Sources/HttpServer/HttpToolbox.h" | |
37 #include "../Sources/Logging.h" | 38 #include "../Sources/Logging.h" |
38 #include "../Sources/OrthancException.h" | 39 #include "../Sources/OrthancException.h" |
39 #include "../Sources/Toolbox.h" | 40 #include "../Sources/Toolbox.h" |
40 | 41 |
41 #if ORTHANC_SANDBOXED != 1 | 42 #if ORTHANC_SANDBOXED != 1 |
42 # include "../Sources/FileBuffer.h" | 43 # include "../Sources/FileBuffer.h" |
43 # include "../Sources/HttpServer/HttpToolbox.h" | |
44 # include "../Sources/MetricsRegistry.h" | 44 # include "../Sources/MetricsRegistry.h" |
45 # include "../Sources/SystemToolbox.h" | 45 # include "../Sources/SystemToolbox.h" |
46 # include "../Sources/TemporaryFile.h" | 46 # include "../Sources/TemporaryFile.h" |
47 #endif | 47 #endif |
48 | 48 |
99 | 99 |
100 ASSERT_FALSE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b_")); | 100 ASSERT_FALSE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b_")); |
101 } | 101 } |
102 | 102 |
103 | 103 |
104 #if ORTHANC_SANDBOXED != 1 | |
105 TEST(ParseGetArguments, Basic) | 104 TEST(ParseGetArguments, Basic) |
106 { | 105 { |
107 IHttpHandler::GetArguments b; | 106 HttpToolbox::GetArguments b; |
108 HttpToolbox::ParseGetArguments(b, "aaa=baaa&bb=a&aa=c"); | 107 HttpToolbox::ParseGetArguments(b, "aaa=baaa&bb=a&aa=c"); |
109 | 108 |
110 IHttpHandler::Arguments a; | 109 HttpToolbox::Arguments a; |
111 HttpToolbox::CompileGetArguments(a, b); | 110 HttpToolbox::CompileGetArguments(a, b); |
112 | 111 |
113 ASSERT_EQ(3u, a.size()); | 112 ASSERT_EQ(3u, a.size()); |
114 ASSERT_EQ(a["aaa"], "baaa"); | 113 ASSERT_EQ(a["aaa"], "baaa"); |
115 ASSERT_EQ(a["bb"], "a"); | 114 ASSERT_EQ(a["bb"], "a"); |
116 ASSERT_EQ(a["aa"], "c"); | 115 ASSERT_EQ(a["aa"], "c"); |
117 } | 116 } |
118 #endif | 117 |
119 | 118 |
120 #if ORTHANC_SANDBOXED != 1 | |
121 TEST(ParseGetArguments, BasicEmpty) | 119 TEST(ParseGetArguments, BasicEmpty) |
122 { | 120 { |
123 IHttpHandler::GetArguments b; | 121 HttpToolbox::GetArguments b; |
124 HttpToolbox::ParseGetArguments(b, "aaa&bb=aa&aa"); | 122 HttpToolbox::ParseGetArguments(b, "aaa&bb=aa&aa"); |
125 | 123 |
126 IHttpHandler::Arguments a; | 124 HttpToolbox::Arguments a; |
127 HttpToolbox::CompileGetArguments(a, b); | 125 HttpToolbox::CompileGetArguments(a, b); |
128 | 126 |
129 ASSERT_EQ(3u, a.size()); | 127 ASSERT_EQ(3u, a.size()); |
130 ASSERT_EQ(a["aaa"], ""); | 128 ASSERT_EQ(a["aaa"], ""); |
131 ASSERT_EQ(a["bb"], "aa"); | 129 ASSERT_EQ(a["bb"], "aa"); |
132 ASSERT_EQ(a["aa"], ""); | 130 ASSERT_EQ(a["aa"], ""); |
133 } | 131 } |
134 #endif | 132 |
135 | 133 |
136 #if ORTHANC_SANDBOXED != 1 | |
137 TEST(ParseGetArguments, Single) | 134 TEST(ParseGetArguments, Single) |
138 { | 135 { |
139 IHttpHandler::GetArguments b; | 136 HttpToolbox::GetArguments b; |
140 HttpToolbox::ParseGetArguments(b, "aaa=baaa"); | 137 HttpToolbox::ParseGetArguments(b, "aaa=baaa"); |
141 | 138 |
142 IHttpHandler::Arguments a; | 139 HttpToolbox::Arguments a; |
143 HttpToolbox::CompileGetArguments(a, b); | 140 HttpToolbox::CompileGetArguments(a, b); |
144 | 141 |
145 ASSERT_EQ(1u, a.size()); | 142 ASSERT_EQ(1u, a.size()); |
146 ASSERT_EQ(a["aaa"], "baaa"); | 143 ASSERT_EQ(a["aaa"], "baaa"); |
147 } | 144 } |
148 #endif | 145 |
149 | 146 |
150 #if ORTHANC_SANDBOXED != 1 | |
151 TEST(ParseGetArguments, SingleEmpty) | 147 TEST(ParseGetArguments, SingleEmpty) |
152 { | 148 { |
153 IHttpHandler::GetArguments b; | 149 HttpToolbox::GetArguments b; |
154 HttpToolbox::ParseGetArguments(b, "aaa"); | 150 HttpToolbox::ParseGetArguments(b, "aaa"); |
155 | 151 |
156 IHttpHandler::Arguments a; | 152 HttpToolbox::Arguments a; |
157 HttpToolbox::CompileGetArguments(a, b); | 153 HttpToolbox::CompileGetArguments(a, b); |
158 | 154 |
159 ASSERT_EQ(1u, a.size()); | 155 ASSERT_EQ(1u, a.size()); |
160 ASSERT_EQ(a["aaa"], ""); | 156 ASSERT_EQ(a["aaa"], ""); |
161 } | 157 } |
162 #endif | 158 |
163 | 159 |
164 #if ORTHANC_SANDBOXED != 1 | |
165 TEST(ParseGetQuery, Test1) | 160 TEST(ParseGetQuery, Test1) |
166 { | 161 { |
167 UriComponents uri; | 162 UriComponents uri; |
168 IHttpHandler::GetArguments b; | 163 HttpToolbox::GetArguments b; |
169 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world?aaa=baaa&bb=a&aa=c"); | 164 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world?aaa=baaa&bb=a&aa=c"); |
170 | 165 |
171 IHttpHandler::Arguments a; | 166 HttpToolbox::Arguments a; |
172 HttpToolbox::CompileGetArguments(a, b); | 167 HttpToolbox::CompileGetArguments(a, b); |
173 | 168 |
174 ASSERT_EQ(3u, uri.size()); | 169 ASSERT_EQ(3u, uri.size()); |
175 ASSERT_EQ("instances", uri[0]); | 170 ASSERT_EQ("instances", uri[0]); |
176 ASSERT_EQ("test", uri[1]); | 171 ASSERT_EQ("test", uri[1]); |
178 ASSERT_EQ(3u, a.size()); | 173 ASSERT_EQ(3u, a.size()); |
179 ASSERT_EQ(a["aaa"], "baaa"); | 174 ASSERT_EQ(a["aaa"], "baaa"); |
180 ASSERT_EQ(a["bb"], "a"); | 175 ASSERT_EQ(a["bb"], "a"); |
181 ASSERT_EQ(a["aa"], "c"); | 176 ASSERT_EQ(a["aa"], "c"); |
182 } | 177 } |
183 #endif | 178 |
184 | 179 |
185 #if ORTHANC_SANDBOXED != 1 | |
186 TEST(ParseGetQuery, Test2) | 180 TEST(ParseGetQuery, Test2) |
187 { | 181 { |
188 UriComponents uri; | 182 UriComponents uri; |
189 IHttpHandler::GetArguments b; | 183 HttpToolbox::GetArguments b; |
190 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world"); | 184 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world"); |
191 | 185 |
192 IHttpHandler::Arguments a; | 186 HttpToolbox::Arguments a; |
193 HttpToolbox::CompileGetArguments(a, b); | 187 HttpToolbox::CompileGetArguments(a, b); |
194 | 188 |
195 ASSERT_EQ(3u, uri.size()); | 189 ASSERT_EQ(3u, uri.size()); |
196 ASSERT_EQ("instances", uri[0]); | 190 ASSERT_EQ("instances", uri[0]); |
197 ASSERT_EQ("test", uri[1]); | 191 ASSERT_EQ("test", uri[1]); |
198 ASSERT_EQ("world", uri[2]); | 192 ASSERT_EQ("world", uri[2]); |
199 ASSERT_EQ(0u, a.size()); | 193 ASSERT_EQ(0u, a.size()); |
200 } | 194 } |
201 #endif | 195 |
202 | 196 |
203 TEST(Uri, SplitUriComponents) | 197 TEST(Uri, SplitUriComponents) |
204 { | 198 { |
205 UriComponents c, d; | 199 UriComponents c, d; |
206 Toolbox::SplitUriComponents(c, "/cou/hello/world"); | 200 Toolbox::SplitUriComponents(c, "/cou/hello/world"); |