Mercurial > hg > orthanc
annotate OrthancFramework/UnitTestsSources/RestApiTests.cpp @ 5539:2b3eeacf636c
added SetRootUri(), SetDescription() and ExtendOrthancExplorer() in OrthancPluginCppWrapper
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 16 Mar 2024 11:46:27 +0100 |
parents | 48b8dae6dc77 |
children | f7adfb22e20e |
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 |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1064
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5432
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
7 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
11 * the License, or (at your option) any later version. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
12 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
13 * 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
|
14 * 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
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
16 * Lesser General Public License for more details. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
17 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
19 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4072
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
707
diff
changeset
|
21 **/ |
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 |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3853
diff
changeset
|
24 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1 |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
25 // Must be the first to be sure to use the Orthanc framework shared library |
4014
27628b0f6ada
merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3992
diff
changeset
|
26 # include <OrthancFramework.h> |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3853
diff
changeset
|
27 #endif |
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3853
diff
changeset
|
28 |
4062 | 29 #include <gtest/gtest.h> |
209 | 30 |
4045 | 31 #include "../Sources/ChunkedBuffer.h" |
32 #include "../Sources/Compression/ZlibCompressor.h" | |
33 #include "../Sources/HttpServer/HttpContentNegociation.h" | |
34 #include "../Sources/HttpServer/MultipartStreamReader.h" | |
4652
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
35 #include "../Sources/HttpServer/StringMatcher.h" |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
36 #include "../Sources/Logging.h" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
37 #include "../Sources/OrthancException.h" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
38 #include "../Sources/RestApi/RestApiHierarchy.h" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
39 #include "../Sources/WebServiceParameters.h" |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
40 |
4062 | 41 #include <ctype.h> |
42 #include <boost/lexical_cast.hpp> | |
43 #include <algorithm> | |
44 | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
45 #if ORTHANC_SANDBOXED != 1 |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
46 # include "../Sources/RestApi/RestApi.h" |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
47 #endif |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
48 |
209 | 49 |
50 using namespace Orthanc; | |
51 | |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
52 #if !defined(UNIT_TESTS_WITH_HTTP_CONNEXIONS) && (ORTHANC_SANDBOXED != 1) |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
53 # error UNIT_TESTS_WITH_HTTP_CONNEXIONS is not defined |
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
54 #endif |
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
55 |
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
56 #if !defined(ORTHANC_ENABLE_SSL) |
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
57 # error ORTHANC_ENABLE_SSL is not defined |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
58 #endif |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
59 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
60 #if ORTHANC_SANDBOXED != 1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
61 # include "../Sources/HttpClient.h" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
62 # include "../Sources/SystemToolbox.h" |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
63 #endif |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
64 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
65 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
66 #if ORTHANC_SANDBOXED != 1 |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
67 TEST(HttpClient, Basic) |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
68 { |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
69 HttpClient c; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
70 ASSERT_FALSE(c.IsVerbose()); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
71 c.SetVerbose(true); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
72 ASSERT_TRUE(c.IsVerbose()); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
73 c.SetVerbose(false); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
74 ASSERT_FALSE(c.IsVerbose()); |
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 #if UNIT_TESTS_WITH_HTTP_CONNEXIONS == 1 |
2386
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
77 // The "http://www.orthanc-server.com/downloads/third-party/" does |
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
78 // not automatically redirect to HTTPS, so we cas use it even if the |
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
79 // OpenSSL/HTTPS support is disabled in curl |
883387e2b379
remove dependendy upon ULg Montefiore Web server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2363
diff
changeset
|
80 const std::string BASE = "http://www.orthanc-server.com/downloads/third-party/"; |
2363
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
81 |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
82 Json::Value v; |
2363
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
83 c.SetUrl(BASE + "Product.json"); |
f8ef157f2d73
fix unit tests given www.orthanc-server.com now mandatory uses HTTPS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
84 |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
85 c.Apply(v); |
2187
ad72fbd700b7
move of third party downloads to the main server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
86 ASSERT_TRUE(v.type() == Json::objectValue); |
ad72fbd700b7
move of third party downloads to the main server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2143
diff
changeset
|
87 ASSERT_TRUE(v.isMember("Description")); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
88 #endif |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
89 } |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
90 #endif |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
91 |
1532 | 92 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
93 #if (UNIT_TESTS_WITH_HTTP_CONNEXIONS == 1) && (ORTHANC_ENABLE_SSL == 1) && (ORTHANC_SANDBOXED != 1) |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
94 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
95 /** |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
96 The HTTPS CA certificates for BitBucket were extracted as follows: |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
97 |
5292 | 98 (1) We retrieve the URI of the root CA of BitBucket: |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
99 |
5292 | 100 # echo | openssl s_client -servername bitbucket.org -connect bitbucket.org:443 2>/dev/null | openssl x509 -text | grep "CA Issuers" |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
101 |
5292 | 102 (2) Once we get the URL to the CA certificate, we convert it to a C |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
103 macro that can be used by libcurl: |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
104 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
105 # cd UnitTestsSources |
5292 | 106 # python2 ../Resources/RetrieveCACertificates.py BITBUCKET_CERTIFICATES http://cacerts.digicert.com/DigiCertSHA2ExtendedValidationServerCA.crt > BitbucketCACertificates.h |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
107 **/ |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
108 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
109 #include "BitbucketCACertificates.h" |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
110 |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1532
diff
changeset
|
111 TEST(HttpClient, Ssl) |
1532 | 112 { |
2140 | 113 SystemToolbox::WriteFile(BITBUCKET_CERTIFICATES, "UnitTestsResults/bitbucket.cert"); |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
114 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
115 /*{ |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
116 std::string s; |
5000
e56a6beb454e
fix unit tests HttpClient.Ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4998
diff
changeset
|
117 SystemToolbox::ReadFile(s, "/etc/ssl/certs/ca-certificates.crt"); |
2140 | 118 SystemToolbox::WriteFile(s, "UnitTestsResults/bitbucket.cert"); |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
119 }*/ |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
120 |
1532 | 121 HttpClient c; |
5000
e56a6beb454e
fix unit tests HttpClient.Ssl
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4998
diff
changeset
|
122 //c.SetVerbose(true); |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
123 c.SetHttpsVerifyPeers(true); |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
124 c.SetHttpsCACertificates("UnitTestsResults/bitbucket.cert"); |
3853 | 125 |
126 // Test file modified on 2020-04-20, in order to use a git | |
127 // repository on BitBucket instead of a Mercurial repository | |
128 // (because Mercurial support disappears on 2020-05-31) | |
129 c.SetUrl("https://bitbucket.org/osimis/orthanc-setup-samples/raw/master/docker/serve-folders/orthanc/serve-folders.json"); | |
1532 | 130 |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
131 Json::Value v; |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
132 c.Apply(v); |
3853 | 133 ASSERT_TRUE(v.isMember("ServeFolders")); |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
134 } |
1533
0011cc99443c
improving HTTPS support
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1532
diff
changeset
|
135 |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
136 TEST(HttpClient, SslNoVerification) |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
137 { |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
138 HttpClient c; |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
139 c.SetHttpsVerifyPeers(false); |
3853 | 140 c.SetUrl("https://bitbucket.org/osimis/orthanc-setup-samples/raw/master/docker/serve-folders/orthanc/serve-folders.json"); |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
141 |
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
142 Json::Value v; |
1532 | 143 c.Apply(v); |
3853 | 144 ASSERT_TRUE(v.isMember("ServeFolders")); |
1532 | 145 } |
1534
95b3b0260240
Options to validate peers against CA certificates in HTTPS requests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1533
diff
changeset
|
146 |
1532 | 147 #endif |
148 | |
149 | |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
150 TEST(ChunkedBuffer, Basic) |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
151 { |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
152 for (unsigned int i = 0; i < 2; i++) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
153 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
154 ChunkedBuffer b; |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
155 |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
156 if (i == 0) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
157 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
158 b.SetPendingBufferSize(0); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
159 ASSERT_EQ(0u, b.GetPendingBufferSize()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
160 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
161 else |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
162 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
163 ASSERT_EQ(16u * 1024u, b.GetPendingBufferSize()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
164 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
165 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
166 ASSERT_EQ(0u, b.GetNumBytes()); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
167 |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
168 b.AddChunk("hello", 5); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
169 ASSERT_EQ(5u, b.GetNumBytes()); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
170 |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
171 b.AddChunk("world", 5); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
172 ASSERT_EQ(10u, b.GetNumBytes()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
173 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
174 std::string s; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
175 b.Flatten(s); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
176 ASSERT_EQ("helloworld", s); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
177 } |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
178 } |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
632
diff
changeset
|
179 |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
180 |
330 | 181 TEST(RestApi, ParseCookies) |
182 { | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
183 HttpToolbox::Arguments headers; |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
184 HttpToolbox::Arguments cookies; |
330 | 185 |
332 | 186 headers["cookie"] = "a=b;c=d;;;e=f;;g=h;"; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1419
diff
changeset
|
187 HttpToolbox::ParseCookies(cookies, headers); |
330 | 188 ASSERT_EQ(4u, cookies.size()); |
189 ASSERT_EQ("b", cookies["a"]); | |
190 ASSERT_EQ("d", cookies["c"]); | |
191 ASSERT_EQ("f", cookies["e"]); | |
192 ASSERT_EQ("h", cookies["g"]); | |
193 | |
332 | 194 headers["cookie"] = " name = value ; name2=value2"; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1419
diff
changeset
|
195 HttpToolbox::ParseCookies(cookies, headers); |
330 | 196 ASSERT_EQ(2u, cookies.size()); |
197 ASSERT_EQ("value", cookies["name"]); | |
198 ASSERT_EQ("value2", cookies["name2"]); | |
199 | |
332 | 200 headers["cookie"] = " ;;; "; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1419
diff
changeset
|
201 HttpToolbox::ParseCookies(cookies, headers); |
330 | 202 ASSERT_EQ(0u, cookies.size()); |
203 | |
332 | 204 headers["cookie"] = " ; n=v ;; "; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1419
diff
changeset
|
205 HttpToolbox::ParseCookies(cookies, headers); |
330 | 206 ASSERT_EQ(1u, cookies.size()); |
207 ASSERT_EQ("v", cookies["n"]); | |
208 } | |
209 | |
4326 | 210 |
209 | 211 TEST(RestApi, RestApiPath) |
212 { | |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
213 HttpToolbox::Arguments args; |
209 | 214 UriComponents trail; |
215 | |
216 { | |
217 RestApiPath uri("/coucou/{abc}/d/*"); | |
218 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/e/f/g")); | |
219 ASSERT_EQ(1u, args.size()); | |
220 ASSERT_EQ(3u, trail.size()); | |
221 ASSERT_EQ("moi", args["abc"]); | |
222 ASSERT_EQ("e", trail[0]); | |
223 ASSERT_EQ("f", trail[1]); | |
224 ASSERT_EQ("g", trail[2]); | |
225 | |
226 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi/f")); | |
227 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d/")); | |
228 ASSERT_FALSE(uri.Match(args, trail, "/a/moi/d")); | |
229 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi")); | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
230 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
231 ASSERT_EQ(3u, uri.GetLevelCount()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
232 ASSERT_TRUE(uri.IsUniversalTrailing()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
233 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
234 ASSERT_EQ("coucou", uri.GetLevelName(0)); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
235 ASSERT_THROW(uri.GetWildcardName(0), OrthancException); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
236 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
237 ASSERT_EQ("abc", uri.GetWildcardName(1)); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
238 ASSERT_THROW(uri.GetLevelName(1), OrthancException); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
239 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
240 ASSERT_EQ("d", uri.GetLevelName(2)); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
241 ASSERT_THROW(uri.GetWildcardName(2), OrthancException); |
209 | 242 } |
243 | |
244 { | |
245 RestApiPath uri("/coucou/{abc}/d"); | |
246 ASSERT_FALSE(uri.Match(args, trail, "/coucou/moi/d/e/f/g")); | |
247 ASSERT_TRUE(uri.Match(args, trail, "/coucou/moi/d")); | |
248 ASSERT_EQ(1u, args.size()); | |
249 ASSERT_EQ(0u, trail.size()); | |
250 ASSERT_EQ("moi", args["abc"]); | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
251 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
252 ASSERT_EQ(3u, uri.GetLevelCount()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
253 ASSERT_FALSE(uri.IsUniversalTrailing()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
254 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
255 ASSERT_EQ("coucou", uri.GetLevelName(0)); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
256 ASSERT_THROW(uri.GetWildcardName(0), OrthancException); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
257 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
258 ASSERT_EQ("abc", uri.GetWildcardName(1)); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
259 ASSERT_THROW(uri.GetLevelName(1), OrthancException); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
260 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
261 ASSERT_EQ("d", uri.GetLevelName(2)); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
262 ASSERT_THROW(uri.GetWildcardName(2), OrthancException); |
209 | 263 } |
264 | |
265 { | |
266 RestApiPath uri("/*"); | |
267 ASSERT_TRUE(uri.Match(args, trail, "/a/b/c")); | |
268 ASSERT_EQ(0u, args.size()); | |
269 ASSERT_EQ(3u, trail.size()); | |
270 ASSERT_EQ("a", trail[0]); | |
271 ASSERT_EQ("b", trail[1]); | |
272 ASSERT_EQ("c", trail[2]); | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
273 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
274 ASSERT_EQ(0u, uri.GetLevelCount()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
275 ASSERT_TRUE(uri.IsUniversalTrailing()); |
209 | 276 } |
277 } | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
278 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
279 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
280 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
281 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
282 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
283 |
968 | 284 static int testValue; |
285 | |
286 template <int value> | |
974 | 287 static void SetValue(RestApiGetCall& get) |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
288 { |
968 | 289 testValue = value; |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
290 } |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
291 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
292 |
969 | 293 static bool GetDirectory(Json::Value& target, |
294 RestApiHierarchy& hierarchy, | |
295 const std::string& uri) | |
296 { | |
297 UriComponents p; | |
298 Toolbox::SplitUriComponents(p, uri); | |
299 return hierarchy.GetDirectory(target, p); | |
300 } | |
301 | |
302 | |
978 | 303 |
304 namespace | |
305 { | |
306 class MyVisitor : public RestApiHierarchy::IVisitor | |
307 { | |
308 public: | |
309 virtual bool Visit(const RestApiHierarchy::Resource& resource, | |
310 const UriComponents& uri, | |
4399
80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4394
diff
changeset
|
311 bool hasTrailing, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
312 const HttpToolbox::Arguments& components, |
2924
22524fd06225
macros ORTHANC_OVERRIDE and ORTHANC_FINAL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2824
diff
changeset
|
313 const UriComponents& trailing) ORTHANC_OVERRIDE |
978 | 314 { |
2543 | 315 return resource.Handle(*(RestApiGetCall*) NULL); |
978 | 316 } |
317 }; | |
318 } | |
319 | |
320 | |
969 | 321 static bool HandleGet(RestApiHierarchy& hierarchy, |
322 const std::string& uri) | |
323 { | |
324 UriComponents p; | |
325 Toolbox::SplitUriComponents(p, uri); | |
978 | 326 MyVisitor visitor; |
327 return hierarchy.LookupResource(p, visitor); | |
969 | 328 } |
329 | |
330 | |
968 | 331 TEST(RestApi, RestApiHierarchy) |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
332 { |
968 | 333 RestApiHierarchy root; |
970 | 334 root.Register("/hello/world/test", SetValue<1>); |
335 root.Register("/hello/world/test2", SetValue<2>); | |
336 root.Register("/hello/{world}/test3/test4", SetValue<3>); | |
337 root.Register("/hello2/*", SetValue<4>); | |
968 | 338 |
339 Json::Value m; | |
340 root.CreateSiteMap(m); | |
4392
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4333
diff
changeset
|
341 |
3af1d763763a
confining Json::Reader and Json::*Writer into Toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4333
diff
changeset
|
342 std::string s; |
4394
f7104e9d044c
functions to read/write JSON in OrthancPluginCppWrapper.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4392
diff
changeset
|
343 Toolbox::WriteStyledJson(s, m); |
968 | 344 |
345 Json::Value d; | |
969 | 346 ASSERT_FALSE(GetDirectory(d, root, "/hello")); |
968 | 347 |
969 | 348 ASSERT_TRUE(GetDirectory(d, root, "/hello/a")); |
968 | 349 ASSERT_EQ(1u, d.size()); |
350 ASSERT_EQ("test3", d[0].asString()); | |
351 | |
969 | 352 ASSERT_TRUE(GetDirectory(d, root, "/hello/world")); |
968 | 353 ASSERT_EQ(2u, d.size()); |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
354 |
969 | 355 ASSERT_TRUE(GetDirectory(d, root, "/hello/a/test3")); |
968 | 356 ASSERT_EQ(1u, d.size()); |
357 ASSERT_EQ("test4", d[0].asString()); | |
358 | |
1064 | 359 ASSERT_TRUE(GetDirectory(d, root, "/hello/world/test")); |
360 ASSERT_TRUE(GetDirectory(d, root, "/hello/world/test2")); | |
969 | 361 ASSERT_FALSE(GetDirectory(d, root, "/hello2")); |
968 | 362 |
363 testValue = 0; | |
969 | 364 ASSERT_TRUE(HandleGet(root, "/hello/world/test")); |
968 | 365 ASSERT_EQ(testValue, 1); |
969 | 366 ASSERT_TRUE(HandleGet(root, "/hello/world/test2")); |
968 | 367 ASSERT_EQ(testValue, 2); |
969 | 368 ASSERT_TRUE(HandleGet(root, "/hello/b/test3/test4")); |
968 | 369 ASSERT_EQ(testValue, 3); |
969 | 370 ASSERT_FALSE(HandleGet(root, "/hello/b/test3/test")); |
968 | 371 ASSERT_EQ(testValue, 3); |
969 | 372 ASSERT_TRUE(HandleGet(root, "/hello2/a/b")); |
968 | 373 ASSERT_EQ(testValue, 4); |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
374 } |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
375 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
376 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
377 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
378 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
379 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
380 namespace |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
381 { |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
382 class AcceptHandler : public HttpContentNegociation::IHandler |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
383 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
384 private: |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
385 std::string type_; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
386 std::string subtype_; |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
387 HttpContentNegociation::Dictionary parameters_; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
388 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
389 public: |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
390 AcceptHandler() |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
391 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
392 Reset(); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
393 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
394 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
395 void Reset() |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
396 { |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
397 HttpContentNegociation::Dictionary parameters; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
398 Handle("nope", "nope", parameters); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
399 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
400 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
401 const std::string& GetType() const |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
402 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
403 return type_; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
404 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
405 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
406 const std::string& GetSubType() const |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
407 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
408 return subtype_; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
409 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
410 |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
411 HttpContentNegociation::Dictionary& GetParameters() |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
412 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
413 return parameters_; |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
414 } |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
415 |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
416 virtual void Handle(const std::string& type, |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
417 const std::string& subtype, |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
418 const HttpContentNegociation::Dictionary& parameters) ORTHANC_OVERRIDE |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
419 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
420 type_ = type; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
421 subtype_ = subtype; |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
422 parameters_ = parameters; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
423 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
424 }; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
425 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
426 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
427 |
1782 | 428 TEST(RestApi, HttpContentNegociation) |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
429 { |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
430 // Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
431 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
432 AcceptHandler h; |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
433 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
434 { |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
435 HttpContentNegociation d; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
436 d.Register("audio/mp3", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
437 d.Register("audio/basic", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
438 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
439 ASSERT_TRUE(d.Apply("audio/*; q=0.2, audio/basic")); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
440 ASSERT_EQ("audio", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
441 ASSERT_EQ("basic", h.GetSubType()); |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
442 ASSERT_EQ(0u, h.GetParameters().size()); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
443 |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
444 ASSERT_TRUE(d.Apply("audio/*; q=0.2 ; type = test ; hello , audio/nope")); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
445 ASSERT_EQ("audio", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
446 ASSERT_EQ("mp3", h.GetSubType()); |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
447 ASSERT_EQ(3u, h.GetParameters().size()); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
448 ASSERT_EQ("0.2", h.GetParameters() ["q"]); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
449 ASSERT_EQ("test", h.GetParameters() ["type"]); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
450 ASSERT_EQ("", h.GetParameters() ["hello"]); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
451 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
452 ASSERT_FALSE(d.Apply("application/*; q=0.2, application/pdf")); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
453 |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
454 ASSERT_TRUE(d.Apply("*/*; hello=world, application/*; q=0.2, application/pdf")); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
455 ASSERT_EQ("audio", h.GetType()); |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
456 ASSERT_EQ(1u, h.GetParameters().size()); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
457 ASSERT_EQ("world", h.GetParameters() ["hello"]); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
458 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
459 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
460 // "This would be interpreted as "text/html and text/x-c are the |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
461 // preferred media types, but if they do not exist, then send the |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
462 // text/x-dvi entity, and if that does not exist, send the |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
463 // text/plain entity."" |
5339
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
464 const std::string T1 = "text/plain; q=0.5, text/html ; hello = \"world\" , text/x-dvi; q=0.8, text/x-c"; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
465 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
466 { |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
467 HttpContentNegociation d; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
468 d.Register("text/plain", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
469 d.Register("text/html", h); |
1782 | 470 d.Register("text/x-dvi", h); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
471 ASSERT_TRUE(d.Apply(T1)); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
472 ASSERT_EQ("text", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
473 ASSERT_EQ("html", h.GetSubType()); |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
474 ASSERT_EQ(1u, h.GetParameters().size()); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
475 ASSERT_EQ("world", h.GetParameters() ["hello"]); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
476 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
477 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
478 { |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
479 HttpContentNegociation d; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
480 d.Register("text/plain", h); |
1782 | 481 d.Register("text/x-dvi", h); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
482 d.Register("text/x-c", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
483 ASSERT_TRUE(d.Apply(T1)); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
484 ASSERT_EQ("text", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
485 ASSERT_EQ("x-c", h.GetSubType()); |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
486 ASSERT_EQ(0u, h.GetParameters().size()); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
487 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
488 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
489 { |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
490 HttpContentNegociation d; |
1782 | 491 d.Register("text/plain", h); |
492 d.Register("text/x-dvi", h); | |
493 d.Register("text/x-c", h); | |
494 d.Register("text/html", h); | |
495 ASSERT_TRUE(d.Apply(T1)); | |
496 ASSERT_EQ("text", h.GetType()); | |
497 ASSERT_TRUE(h.GetSubType() == "x-c" || h.GetSubType() == "html"); | |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
498 if (h.GetSubType() == "x-c") |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
499 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
500 ASSERT_EQ(0u, h.GetParameters().size()); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
501 } |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
502 else |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
503 { |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
504 ASSERT_EQ(1u, h.GetParameters().size()); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
505 ASSERT_EQ("world", h.GetParameters() ["hello"]); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
506 } |
1782 | 507 } |
508 | |
509 { | |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
510 HttpContentNegociation d; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
511 d.Register("text/plain", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
512 d.Register("text/x-dvi", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
513 ASSERT_TRUE(d.Apply(T1)); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
514 ASSERT_EQ("text", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
515 ASSERT_EQ("x-dvi", h.GetSubType()); |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
516 ASSERT_EQ(1u, h.GetParameters().size()); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
517 ASSERT_EQ("0.8", h.GetParameters() ["q"]); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
518 } |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
519 |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
520 { |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
521 HttpContentNegociation d; |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
522 d.Register("text/plain", h); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
523 ASSERT_TRUE(d.Apply(T1)); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
524 ASSERT_EQ("text", h.GetType()); |
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
525 ASSERT_EQ("plain", h.GetSubType()); |
5338
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
526 ASSERT_EQ(1u, h.GetParameters().size()); |
78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5292
diff
changeset
|
527 ASSERT_EQ("0.5", h.GetParameters() ["q"]); |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
528 } |
5339
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
529 |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
530 // Below are the tests from issue 216: |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5339
diff
changeset
|
531 // https://orthanc.uclouvain.be/bugs/show_bug.cgi?id=216 |
5339
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
532 |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
533 { |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
534 HttpContentNegociation d; |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
535 d.Register("application/dicom+json", h); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
536 ASSERT_TRUE(d.Apply("image/webp, */*;q=0.8, text/html, application/xhtml+xml, application/xml;q=0.9")); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
537 ASSERT_EQ("application", h.GetType()); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
538 ASSERT_EQ("dicom+json", h.GetSubType()); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
539 ASSERT_EQ(1u, h.GetParameters().size()); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
540 ASSERT_EQ("0.8", h.GetParameters() ["q"]); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
541 } |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
542 |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
543 { |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
544 HttpContentNegociation d; |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
545 d.Register("application/dicom+json", h); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
546 ASSERT_TRUE(d.Apply("image/webp, */*; q = \"0.8\" , text/html, application/xhtml+xml, application/xml;q=0.9")); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
547 ASSERT_EQ("application", h.GetType()); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
548 ASSERT_EQ("dicom+json", h.GetSubType()); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
549 ASSERT_EQ(1u, h.GetParameters().size()); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
550 ASSERT_EQ("0.8", h.GetParameters() ["q"]); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
551 } |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
552 |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
553 { |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
554 HttpContentNegociation d; |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
555 d.Register("application/dicom+json", h); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
556 ASSERT_TRUE(d.Apply("text/html, application/xhtml+xml, application/xml, image/webp, */*;q=0.8")); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
557 ASSERT_EQ("application", h.GetType()); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
558 ASSERT_EQ("dicom+json", h.GetSubType()); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
559 ASSERT_EQ(1u, h.GetParameters().size()); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
560 ASSERT_EQ("0.8", h.GetParameters() ["q"]); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
561 } |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
562 |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
563 { |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
564 HttpContentNegociation d; |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
565 d.Register("application/dicom+json", h); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
566 ASSERT_TRUE(d.Apply("text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2")); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
567 ASSERT_EQ("application", h.GetType()); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
568 ASSERT_EQ("dicom+json", h.GetSubType()); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
569 ASSERT_EQ(1u, h.GetParameters().size()); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
570 ASSERT_EQ(".2", h.GetParameters() ["q"]); |
cb11e5ced4e3
added tests from issue 216
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5338
diff
changeset
|
571 } |
1781
5ad4e4d92ecb
AcceptMediaDispatcher bootstrap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1545
diff
changeset
|
572 } |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
573 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
574 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
575 TEST(WebServiceParameters, Serialization) |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
576 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
577 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
578 Json::Value v = Json::arrayValue; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
579 v.append("http://localhost:8042/"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
580 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
581 WebServiceParameters p(v); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
582 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
583 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
584 Json::Value v2; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
585 p.Serialize(v2, false, true); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
586 ASSERT_EQ(v, v2); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
587 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
588 WebServiceParameters p2(v2); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
589 ASSERT_EQ("http://localhost:8042/", p2.GetUrl()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
590 ASSERT_TRUE(p2.GetUsername().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
591 ASSERT_TRUE(p2.GetPassword().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
592 ASSERT_TRUE(p2.GetCertificateFile().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
593 ASSERT_TRUE(p2.GetCertificateKeyFile().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
594 ASSERT_TRUE(p2.GetCertificateKeyPassword().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
595 ASSERT_FALSE(p2.IsPkcs11Enabled()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
596 } |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
597 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
598 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
599 Json::Value v = Json::arrayValue; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
600 v.append("http://localhost:8042/"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
601 v.append("user"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
602 v.append("pass"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
603 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
604 WebServiceParameters p(v); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
605 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
606 ASSERT_EQ("http://localhost:8042/", p.GetUrl()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
607 ASSERT_EQ("user", p.GetUsername()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
608 ASSERT_EQ("pass", p.GetPassword()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
609 ASSERT_TRUE(p.GetCertificateFile().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
610 ASSERT_TRUE(p.GetCertificateKeyFile().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
611 ASSERT_TRUE(p.GetCertificateKeyPassword().empty()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
612 ASSERT_FALSE(p.IsPkcs11Enabled()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
613 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
614 Json::Value v2; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
615 p.Serialize(v2, false, true); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
616 ASSERT_EQ(v, v2); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
617 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
618 p.Serialize(v2, false, false /* no password */); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
619 ASSERT_EQ(Json::arrayValue, v2.type()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
620 ASSERT_EQ(3u, v2.size()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
621 ASSERT_EQ("http://localhost:8042/", v2[0u].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
622 ASSERT_EQ("user", v2[1u].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
623 ASSERT_TRUE(v2[2u].asString().empty()); |
4204 | 624 |
625 WebServiceParameters p2(v2); // Test decoding | |
626 ASSERT_EQ("http://localhost:8042/", p2.GetUrl()); | |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
627 } |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
628 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
629 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
630 Json::Value v = Json::arrayValue; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
631 v.append("http://localhost:8042/"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
632 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
633 WebServiceParameters p(v); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
634 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
635 p.SetPkcs11Enabled(true); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
636 ASSERT_TRUE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
637 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
638 Json::Value v2; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
639 p.Serialize(v2, false, true); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
640 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
641 ASSERT_EQ(Json::objectValue, v2.type()); |
4522
017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4453
diff
changeset
|
642 ASSERT_EQ(4u, v2.size()); |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
643 ASSERT_EQ("http://localhost:8042/", v2["Url"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
644 ASSERT_TRUE(v2["Pkcs11"].asBool()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
645 ASSERT_EQ(Json::objectValue, v2["HttpHeaders"].type()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
646 ASSERT_EQ(0u, v2["HttpHeaders"].size()); |
4522
017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4453
diff
changeset
|
647 ASSERT_EQ(0, v2["Timeout"].asInt()); |
4204 | 648 |
649 WebServiceParameters p2(v2); // Test decoding | |
650 ASSERT_EQ("http://localhost:8042/", p2.GetUrl()); | |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
651 } |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
652 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
653 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
654 Json::Value v = Json::arrayValue; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
655 v.append("http://localhost:8042/"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
656 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
657 WebServiceParameters p(v); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
658 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
659 p.SetClientCertificate("a", "b", "c"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
660 ASSERT_TRUE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
661 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
662 Json::Value v2; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
663 p.Serialize(v2, false, true); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
664 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
665 ASSERT_EQ(Json::objectValue, v2.type()); |
4522
017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4453
diff
changeset
|
666 ASSERT_EQ(7u, v2.size()); |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
667 ASSERT_EQ("http://localhost:8042/", v2["Url"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
668 ASSERT_EQ("a", v2["CertificateFile"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
669 ASSERT_EQ("b", v2["CertificateKeyFile"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
670 ASSERT_EQ("c", v2["CertificateKeyPassword"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
671 ASSERT_FALSE(v2["Pkcs11"].asBool()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
672 ASSERT_EQ(Json::objectValue, v2["HttpHeaders"].type()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
673 ASSERT_EQ(0u, v2["HttpHeaders"].size()); |
4522
017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4453
diff
changeset
|
674 ASSERT_EQ(0, v2["Timeout"].asInt()); |
4204 | 675 |
676 WebServiceParameters p2(v2); // Test decoding | |
677 ASSERT_EQ("http://localhost:8042/", p2.GetUrl()); | |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
678 } |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
679 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
680 { |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
681 Json::Value v = Json::arrayValue; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
682 v.append("http://localhost:8042/"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
683 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
684 WebServiceParameters p(v); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
685 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
686 p.AddHttpHeader("a", "b"); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
687 p.AddHttpHeader("c", "d"); |
4522
017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4453
diff
changeset
|
688 p.SetTimeout(42); |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
689 ASSERT_TRUE(p.IsAdvancedFormatNeeded()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
690 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
691 Json::Value v2; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
692 p.Serialize(v2, false, true); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
693 WebServiceParameters p2(v2); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
694 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
695 ASSERT_EQ(Json::objectValue, v2.type()); |
4522
017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4453
diff
changeset
|
696 ASSERT_EQ(4u, v2.size()); |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
697 ASSERT_EQ("http://localhost:8042/", v2["Url"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
698 ASSERT_FALSE(v2["Pkcs11"].asBool()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
699 ASSERT_EQ(Json::objectValue, v2["HttpHeaders"].type()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
700 ASSERT_EQ(2u, v2["HttpHeaders"].size()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
701 ASSERT_EQ("b", v2["HttpHeaders"]["a"].asString()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
702 ASSERT_EQ("d", v2["HttpHeaders"]["c"].asString()); |
4522
017ab543e6ef
added field "Timeout" in "OrthancPeers" configuration option
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4453
diff
changeset
|
703 ASSERT_EQ(42, v2["Timeout"].asInt()); |
2800
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
704 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
705 std::set<std::string> a; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
706 p2.ListHttpHeaders(a); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
707 ASSERT_EQ(2u, a.size()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
708 ASSERT_TRUE(a.find("a") != a.end()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
709 ASSERT_TRUE(a.find("c") != a.end()); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
710 |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
711 std::string s; |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
712 ASSERT_TRUE(p2.LookupHttpHeader(s, "a")); ASSERT_EQ("b", s); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
713 ASSERT_TRUE(p2.LookupHttpHeader(s, "c")); ASSERT_EQ("d", s); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
714 ASSERT_FALSE(p2.LookupHttpHeader(s, "nope")); |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
715 } |
dc7330089736
"OrthancPeers" configuration option now allows to specify HTTP headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2543
diff
changeset
|
716 } |
2823
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
717 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
718 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
719 TEST(WebServiceParameters, UserProperties) |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
720 { |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
721 Json::Value v = Json::nullValue; |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
722 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
723 { |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
724 WebServiceParameters p; |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
725 p.SetUrl("http://localhost:8042/"); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
726 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
727 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
728 ASSERT_THROW(p.AddUserProperty("Url", "nope"), OrthancException); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
729 p.AddUserProperty("Hello", "world"); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
730 p.AddUserProperty("a", "b"); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
731 ASSERT_TRUE(p.IsAdvancedFormatNeeded()); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
732 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
733 p.Serialize(v, false, true); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
734 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
735 p.ClearUserProperties(); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
736 ASSERT_FALSE(p.IsAdvancedFormatNeeded()); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
737 } |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
738 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
739 { |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
740 WebServiceParameters p(v); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
741 ASSERT_TRUE(p.IsAdvancedFormatNeeded()); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
742 ASSERT_TRUE(p.GetHttpHeaders().empty()); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
743 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
744 std::set<std::string> tmp; |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
745 p.ListUserProperties(tmp); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
746 ASSERT_EQ(2u, tmp.size()); |
2824 | 747 ASSERT_TRUE(tmp.find("a") != tmp.end()); |
748 ASSERT_TRUE(tmp.find("Hello") != tmp.end()); | |
749 ASSERT_TRUE(tmp.find("hello") == tmp.end()); | |
2823
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
750 |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
751 std::string s; |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
752 ASSERT_TRUE(p.LookupUserProperty(s, "a")); ASSERT_TRUE(s == "b"); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
753 ASSERT_TRUE(p.LookupUserProperty(s, "Hello")); ASSERT_TRUE(s == "world"); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
754 ASSERT_FALSE(p.LookupUserProperty(s, "hello")); |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
755 } |
807169f85ba9
OrthancPluginGetPeerUserProperty()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2800
diff
changeset
|
756 } |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
757 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
758 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
759 TEST(StringMatcher, Basic) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
760 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
761 StringMatcher matcher("---"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
762 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
763 ASSERT_THROW(matcher.GetMatchBegin(), OrthancException); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
764 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
765 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
766 const std::string s = ""; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
767 ASSERT_FALSE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
768 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
769 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
770 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
771 const std::string s = "abc----def"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
772 ASSERT_TRUE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
773 ASSERT_EQ(3, std::distance(s.begin(), matcher.GetMatchBegin())); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
774 ASSERT_EQ("---", std::string(matcher.GetMatchBegin(), matcher.GetMatchEnd())); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
775 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
776 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
777 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
778 const std::string s = "abc---"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
779 ASSERT_TRUE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
780 ASSERT_EQ(3, std::distance(s.begin(), matcher.GetMatchBegin())); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
781 ASSERT_EQ(s.end(), matcher.GetMatchEnd()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
782 ASSERT_EQ("---", std::string(matcher.GetMatchBegin(), matcher.GetMatchEnd())); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
783 ASSERT_EQ("", std::string(matcher.GetMatchEnd(), s.end())); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
784 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
785 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
786 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
787 const std::string s = "abc--def"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
788 ASSERT_FALSE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
789 ASSERT_THROW(matcher.GetMatchBegin(), OrthancException); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
790 ASSERT_THROW(matcher.GetMatchEnd(), OrthancException); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
791 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
792 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
793 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
794 std::string s(10u, '\0'); // String with null values |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
795 ASSERT_EQ(10u, s.size()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
796 ASSERT_FALSE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
797 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
798 s[9] = '-'; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
799 ASSERT_FALSE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
800 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
801 s[8] = '-'; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
802 ASSERT_FALSE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
803 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
804 s[7] = '-'; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
805 ASSERT_TRUE(matcher.Apply(s)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
806 ASSERT_EQ(s.c_str() + 7, matcher.GetPointerBegin()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
807 ASSERT_EQ(s.c_str() + 10, matcher.GetPointerEnd()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
808 ASSERT_EQ(s.end() - 3, matcher.GetMatchBegin()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
809 ASSERT_EQ(s.end(), matcher.GetMatchEnd()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
810 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
811 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
812 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
813 |
4652
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
814 TEST(CStringMatcher, Basic) |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
815 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
816 CStringMatcher matcher("---"); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
817 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
818 ASSERT_THROW(matcher.GetMatchBegin(), OrthancException); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
819 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
820 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
821 ASSERT_FALSE(matcher.Apply(NULL, 0)); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
822 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
823 const std::string s = ""; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
824 ASSERT_FALSE(matcher.Apply(s)); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
825 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
826 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
827 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
828 const char* s = "abc---def"; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
829 ASSERT_TRUE(matcher.Apply(s, s + 9)); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
830 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
831 ASSERT_EQ('a', matcher.GetMatchBegin()[-3]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
832 ASSERT_EQ('b', matcher.GetMatchBegin()[-2]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
833 ASSERT_EQ('c', matcher.GetMatchBegin()[-1]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
834 ASSERT_EQ('-', matcher.GetMatchBegin()[0]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
835 ASSERT_EQ('-', matcher.GetMatchBegin()[1]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
836 ASSERT_EQ('-', matcher.GetMatchBegin()[2]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
837 ASSERT_EQ('d', matcher.GetMatchBegin()[3]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
838 ASSERT_EQ('e', matcher.GetMatchBegin()[4]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
839 ASSERT_EQ('f', matcher.GetMatchBegin()[5]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
840 ASSERT_EQ('\0', matcher.GetMatchBegin()[6]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
841 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
842 ASSERT_EQ('a', matcher.GetMatchEnd()[-6]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
843 ASSERT_EQ('b', matcher.GetMatchEnd()[-5]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
844 ASSERT_EQ('c', matcher.GetMatchEnd()[-4]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
845 ASSERT_EQ('-', matcher.GetMatchEnd()[-3]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
846 ASSERT_EQ('-', matcher.GetMatchEnd()[-2]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
847 ASSERT_EQ('-', matcher.GetMatchEnd()[-1]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
848 ASSERT_EQ('d', matcher.GetMatchEnd()[0]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
849 ASSERT_EQ('e', matcher.GetMatchEnd()[1]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
850 ASSERT_EQ('f', matcher.GetMatchEnd()[2]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
851 ASSERT_EQ('\0', matcher.GetMatchEnd()[3]); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
852 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
853 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
854 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
855 const std::string s = "abc----def"; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
856 ASSERT_TRUE(matcher.Apply(s)); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
857 ASSERT_EQ(3, std::distance(s.c_str(), matcher.GetMatchBegin())); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
858 ASSERT_EQ("---", std::string(matcher.GetMatchBegin(), matcher.GetMatchEnd())); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
859 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
860 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
861 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
862 const std::string s = "abc---"; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
863 ASSERT_TRUE(matcher.Apply(s)); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
864 ASSERT_EQ(3, std::distance(s.c_str(), matcher.GetMatchBegin())); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
865 ASSERT_EQ(s.c_str() + s.size(), matcher.GetMatchEnd()); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
866 ASSERT_EQ("---", std::string(matcher.GetMatchBegin(), matcher.GetMatchEnd())); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
867 ASSERT_EQ("", std::string(matcher.GetMatchEnd(), s.c_str() + s.size())); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
868 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
869 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
870 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
871 const std::string s = "abc--def"; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
872 ASSERT_FALSE(matcher.Apply(s)); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
873 ASSERT_THROW(matcher.GetMatchBegin(), OrthancException); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
874 ASSERT_THROW(matcher.GetMatchEnd(), OrthancException); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
875 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
876 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
877 { |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
878 std::string s(10u, '\0'); // String with null values |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
879 ASSERT_EQ(10u, s.size()); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
880 ASSERT_FALSE(matcher.Apply(s)); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
881 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
882 s[9] = '-'; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
883 ASSERT_FALSE(matcher.Apply(s)); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
884 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
885 s[8] = '-'; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
886 ASSERT_FALSE(matcher.Apply(s)); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
887 |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
888 s[7] = '-'; |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
889 ASSERT_TRUE(matcher.Apply(s)); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
890 ASSERT_EQ(s.c_str() + 7, matcher.GetMatchBegin()); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
891 ASSERT_EQ(s.c_str() + 10, matcher.GetMatchEnd()); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
892 ASSERT_EQ(s.c_str() + s.size() - 3, matcher.GetMatchBegin()); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
893 ASSERT_EQ(s.c_str() + s.size(), matcher.GetMatchEnd()); |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
894 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
895 } |
0ad5736c8d62
use plain C strings in MultipartStreamReader instead of std::string to allow further optimizations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4522
diff
changeset
|
896 |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
897 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
898 class MultipartTester : public MultipartStreamReader::IHandler |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
899 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
900 private: |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
901 struct Part |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
902 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
903 MultipartStreamReader::HttpHeaders headers_; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
904 std::string data_; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
905 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
906 Part(const MultipartStreamReader::HttpHeaders& headers, |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
907 const void* part, |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
908 size_t size) : |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
909 headers_(headers), |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
910 data_(reinterpret_cast<const char*>(part), size) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
911 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
912 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
913 }; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
914 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
915 std::vector<Part> parts_; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
916 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
917 public: |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
918 virtual void HandlePart(const MultipartStreamReader::HttpHeaders& headers, |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
919 const void* part, |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
920 size_t size) |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
921 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
922 parts_.push_back(Part(headers, part, size)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
923 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
924 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
925 unsigned int GetCount() const |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
926 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
927 return parts_.size(); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
928 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
929 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
930 MultipartStreamReader::HttpHeaders& GetHeaders(size_t i) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
931 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
932 return parts_[i].headers_; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
933 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
934 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
935 const std::string& GetData(size_t i) const |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
936 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
937 return parts_[i].data_; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
938 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
939 }; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
940 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
941 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
942 TEST(MultipartStreamReader, ParseHeaders) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
943 { |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
944 std::string ct, b, st, header; |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
945 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
946 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
947 MultipartStreamReader::HttpHeaders h; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
948 h["hello"] = "world"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
949 h["Content-Type"] = "world"; // Should be in lower-case |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
950 h["CONTENT-type"] = "world"; // Should be in lower-case |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
951 ASSERT_FALSE(MultipartStreamReader::GetMainContentType(header, h)); |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
952 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
953 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
954 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
955 MultipartStreamReader::HttpHeaders h; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
956 h["content-type"] = "world"; |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
957 ASSERT_TRUE(MultipartStreamReader::GetMainContentType(header, h)); |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
958 ASSERT_EQ(header, "world"); |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
959 ASSERT_FALSE(MultipartStreamReader::ParseMultipartContentType(ct, st, b, header)); |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
960 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
961 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
962 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
963 MultipartStreamReader::HttpHeaders h; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
964 h["content-type"] = "multipart/related; dummy=value; boundary=1234; hello=world"; |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
965 ASSERT_TRUE(MultipartStreamReader::GetMainContentType(header, h)); |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
966 ASSERT_EQ(header, h["content-type"]); |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
967 ASSERT_TRUE(MultipartStreamReader::ParseMultipartContentType(ct, st, b, header)); |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
968 ASSERT_EQ(ct, "multipart/related"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
969 ASSERT_EQ(b, "1234"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
970 ASSERT_TRUE(st.empty()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
971 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
972 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
973 { |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
974 ASSERT_FALSE(MultipartStreamReader::ParseMultipartContentType |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
975 (ct, st, b, "multipart/related; boundary=")); // Empty boundary |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
976 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
977 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
978 { |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
979 ASSERT_TRUE(MultipartStreamReader::ParseMultipartContentType |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
980 (ct, st, b, "Multipart/Related; TYPE=Application/Dicom; Boundary=heLLO")); |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
981 ASSERT_EQ(ct, "multipart/related"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
982 ASSERT_EQ(b, "heLLO"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
983 ASSERT_EQ(st, "application/dicom"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
984 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
985 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
986 { |
3399
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
987 ASSERT_TRUE(MultipartStreamReader::ParseMultipartContentType |
4e8205871967
OrthancPluginRegisterMultipartRestCallback() is working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3398
diff
changeset
|
988 (ct, st, b, "Multipart/Related; type=\"application/DICOM\"; Boundary=a")); |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
989 ASSERT_EQ(ct, "multipart/related"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
990 ASSERT_EQ(b, "a"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
991 ASSERT_EQ(st, "application/dicom"); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
992 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
993 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
994 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
995 |
4453
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
996 TEST(MultipartStreamReader, ParseHeaders2) |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
997 { |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
998 std::string main; |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
999 std::map<std::string, std::string> args; |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1000 |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1001 ASSERT_FALSE(MultipartStreamReader::ParseHeaderArguments(main, args, "")); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1002 ASSERT_FALSE(MultipartStreamReader::ParseHeaderArguments(main, args, " ")); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1003 ASSERT_FALSE(MultipartStreamReader::ParseHeaderArguments(main, args, " ; ")); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1004 |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1005 ASSERT_TRUE(MultipartStreamReader::ParseHeaderArguments(main, args, "hello")); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1006 ASSERT_EQ("hello", main); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1007 ASSERT_TRUE(args.empty()); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1008 |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1009 ASSERT_TRUE(MultipartStreamReader::ParseHeaderArguments(main, args, "hello ; a = \" b \";c=d ; e=f;")); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1010 ASSERT_EQ("hello", main); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1011 ASSERT_EQ(3u, args.size()); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1012 ASSERT_EQ(" b ", args["a"]); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1013 ASSERT_EQ("d", args["c"]); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1014 ASSERT_EQ("f", args["e"]); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1015 |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1016 ASSERT_TRUE(MultipartStreamReader::ParseHeaderArguments(main, args, " hello ;;;; ; ")); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1017 ASSERT_EQ("hello", main); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1018 ASSERT_TRUE(args.empty()); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1019 |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1020 ASSERT_FALSE(MultipartStreamReader::ParseHeaderArguments(main, args, "hello;a=b;c=d;a=f")); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1021 |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1022 ASSERT_TRUE(MultipartStreamReader::ParseHeaderArguments(main, args, "multipart/related; dummy=value; boundary=1234; hello=world")); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1023 ASSERT_EQ("multipart/related", main); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1024 ASSERT_EQ(3u, args.size()); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1025 ASSERT_EQ("value", args["dummy"]); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1026 ASSERT_EQ("1234", args["boundary"]); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1027 ASSERT_EQ("world", args["hello"]); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1028 |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1029 ASSERT_TRUE(MultipartStreamReader::ParseHeaderArguments(main, args, "multipart/related; boundary=")); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1030 ASSERT_EQ("multipart/related", main); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1031 ASSERT_EQ(1u, args.size()); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1032 ASSERT_EQ("", args["boundary"]); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1033 |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1034 ASSERT_TRUE(MultipartStreamReader::ParseHeaderArguments(main, args, "multipart/related; boundary")); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1035 ASSERT_EQ("multipart/related", main); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1036 ASSERT_EQ(1u, args.size()); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1037 ASSERT_EQ("", args["boundary"]); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1038 |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1039 ASSERT_TRUE(MultipartStreamReader::ParseHeaderArguments(main, args, "Multipart/Related; TYPE=Application/Dicom; Boundary=heLLO")); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1040 ASSERT_EQ("multipart/related", main); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1041 ASSERT_EQ(2u, args.size()); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1042 ASSERT_EQ("Application/Dicom", args["type"]); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1043 ASSERT_EQ("heLLO", args["boundary"]); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1044 |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1045 ASSERT_TRUE(MultipartStreamReader::ParseHeaderArguments(main, args, "Multipart/Related; type=\"application/DICOM\"; Boundary=a")); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1046 ASSERT_EQ("multipart/related", main); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1047 ASSERT_EQ(2u, args.size()); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1048 ASSERT_EQ("application/DICOM", args["type"]); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1049 ASSERT_EQ("a", args["boundary"]); |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1050 } |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1051 |
4f8e77c650e8
new function MultipartStreamReader::ParseHeaderArguments()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
1052 |
3398
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1053 TEST(MultipartStreamReader, BytePerByte) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1054 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1055 std::string stream = "GARBAGE"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1056 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1057 std::string boundary = "123456789123456789"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1058 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1059 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1060 for (size_t i = 0; i < 10; i++) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1061 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1062 std::string f = "hello " + boost::lexical_cast<std::string>(i); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1063 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1064 stream += "\r\n--" + boundary + "\r\n"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1065 if (i % 2 == 0) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1066 stream += "Content-Length: " + boost::lexical_cast<std::string>(f.size()) + "\r\n"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1067 stream += "Content-Type: toto " + boost::lexical_cast<std::string>(i) + "\r\n\r\n"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1068 stream += f; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1069 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1070 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1071 stream += "\r\n--" + boundary + "--"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1072 stream += "GARBAGE"; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1073 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1074 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1075 for (unsigned int k = 0; k < 2; k++) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1076 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1077 MultipartTester decoded; |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1078 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1079 MultipartStreamReader reader(boundary); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1080 reader.SetBlockSize(1); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1081 reader.SetHandler(decoded); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1082 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1083 if (k == 0) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1084 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1085 for (size_t i = 0; i < stream.size(); i++) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1086 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1087 reader.AddChunk(&stream[i], 1); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1088 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1089 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1090 else |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1091 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1092 reader.AddChunk(stream); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1093 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1094 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1095 reader.CloseStream(); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1096 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1097 ASSERT_EQ(10u, decoded.GetCount()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1098 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1099 for (size_t i = 0; i < 10; i++) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1100 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1101 ASSERT_EQ("hello " + boost::lexical_cast<std::string>(i), decoded.GetData(i)); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1102 ASSERT_EQ("toto " + boost::lexical_cast<std::string>(i), decoded.GetHeaders(i)["content-type"]); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1103 |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1104 if (i % 2 == 0) |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1105 { |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1106 ASSERT_EQ(2u, decoded.GetHeaders(i).size()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1107 ASSERT_TRUE(decoded.GetHeaders(i).find("content-length") != decoded.GetHeaders(i).end()); |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1108 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1109 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1110 } |
4acd1431e603
new classes: StringMatcher and MultipartStreamReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3060
diff
changeset
|
1111 } |
4072
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1112 |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1113 |
4333
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1114 TEST(MultipartStreamReader, Issue190) |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1115 { |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5339
diff
changeset
|
1116 // https://orthanc.uclouvain.be/bugs/show_bug.cgi?id=190 |
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5339
diff
changeset
|
1117 // https://orthanc.uclouvain.be/hg/orthanc-dicomweb/rev/6dc2f79b5579 |
4333
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1118 |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1119 std::map<std::string, std::string> headers; |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1120 headers["content-type"] = "multipart/related; type=application/dicom; boundary=0f3cf5c0-70e0-41ef-baef-c6f9f65ec3e1"; |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1121 |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1122 { |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1123 std::string tmp, contentType, subType, boundary; |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1124 ASSERT_TRUE(Orthanc::MultipartStreamReader::GetMainContentType(tmp, headers)); |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1125 ASSERT_TRUE(Orthanc::MultipartStreamReader::ParseMultipartContentType(contentType, subType, boundary, tmp)); |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1126 ASSERT_EQ("multipart/related", contentType); |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1127 ASSERT_EQ("application/dicom", subType); |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1128 ASSERT_EQ("0f3cf5c0-70e0-41ef-baef-c6f9f65ec3e1", boundary); |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1129 } |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1130 |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1131 headers["content-type"] = "multipart/related; type=\"application/dicom\"; boundary=\"0f3cf5c0-70e0-41ef-baef-c6f9f65ec3e1\""; |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1132 |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1133 { |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1134 std::string tmp, contentType, subType, boundary; |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1135 ASSERT_TRUE(Orthanc::MultipartStreamReader::GetMainContentType(tmp, headers)); |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1136 ASSERT_TRUE(Orthanc::MultipartStreamReader::ParseMultipartContentType(contentType, subType, boundary, tmp)); |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1137 ASSERT_EQ("multipart/related", contentType); |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1138 ASSERT_EQ("application/dicom", subType); |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1139 ASSERT_EQ("0f3cf5c0-70e0-41ef-baef-c6f9f65ec3e1", boundary); |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1140 } |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1141 } |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1142 |
a85e74235a78
fix parsing of multipart boundaries, to resolve issue #190 in STOW-RS of DICOMweb plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4331
diff
changeset
|
1143 |
4072
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1144 TEST(WebServiceParameters, Url) |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1145 { |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1146 WebServiceParameters w; |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1147 |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1148 ASSERT_THROW(w.SetUrl("ssh://coucou"), OrthancException); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1149 w.SetUrl("http://coucou"); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1150 w.SetUrl("https://coucou"); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1151 ASSERT_THROW(w.SetUrl("httpss://coucou"), OrthancException); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1152 ASSERT_THROW(w.SetUrl(""), OrthancException); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1153 |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1154 // New in Orthanc 1.7.2: Allow relative URLs (for DICOMweb in Stone) |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1155 w.SetUrl("coucou"); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1156 w.SetUrl("/coucou"); |
3dda0d73193c
fix doxygen, more tolerant WebServiceParameters::SetUrl()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
1157 } |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1158 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1159 |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1160 TEST(ChunkedBuffer, DISABLED_Large) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1161 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1162 const size_t LARGE = 60 * 1024 * 1024; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1163 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1164 ChunkedBuffer b; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1165 for (size_t i = 0; i < LARGE; i++) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1166 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1167 b.AddChunk(boost::lexical_cast<std::string>(i % 10)); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1168 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1169 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1170 std::string s; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1171 b.Flatten(s); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1172 ASSERT_EQ(LARGE, s.size()); |
4157
86e99e08ba52
fix compiler warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4151
diff
changeset
|
1173 ASSERT_EQ(0u, b.GetNumBytes()); |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1174 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1175 for (size_t i = 0; i < LARGE; i++) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1176 { |
4157
86e99e08ba52
fix compiler warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4151
diff
changeset
|
1177 ASSERT_EQ(static_cast<char>('0' + (i % 10)), s[i]); |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1178 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1179 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1180 b.Flatten(s); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1181 ASSERT_EQ(0u, s.size()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1182 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1183 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1184 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1185 TEST(ChunkedBuffer, Pending) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1186 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1187 ChunkedBuffer b; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1188 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1189 for (size_t pendingSize = 0; pendingSize < 16; pendingSize++) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1190 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1191 b.SetPendingBufferSize(pendingSize); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1192 ASSERT_EQ(pendingSize, b.GetPendingBufferSize()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1193 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1194 unsigned int pos = 0; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1195 unsigned int iteration = 0; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1196 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1197 while (pos < 1024) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1198 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1199 size_t chunkSize = (iteration % 17); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1200 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1201 std::string chunk; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1202 chunk.resize(chunkSize); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1203 for (size_t i = 0; i < chunkSize; i++) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1204 { |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1205 chunk[i] = '0' + (pos % 10); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1206 pos++; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1207 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1208 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1209 b.AddChunk(chunk); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1210 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1211 iteration ++; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1212 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1213 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1214 std::string s; |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1215 b.Flatten(s); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1216 ASSERT_EQ(0u, b.GetNumBytes()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1217 ASSERT_EQ(pos, s.size()); |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1218 |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1219 for (size_t i = 0; i < s.size(); i++) |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1220 { |
4157
86e99e08ba52
fix compiler warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4151
diff
changeset
|
1221 ASSERT_EQ(static_cast<char>('0' + (i % 10)), s[i]); |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1222 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1223 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1224 } |
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1225 |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1226 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1227 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
1228 #if ORTHANC_SANDBOXED != 1 |
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
1229 |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
1230 |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1231 namespace |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1232 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1233 class TotoBody : public HttpClient::IRequestBody |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1234 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1235 private: |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1236 size_t size_; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1237 size_t chunkSize_; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1238 size_t pos_; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1239 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1240 public: |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1241 TotoBody(size_t size, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1242 size_t chunkSize) : |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1243 size_(size), |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1244 chunkSize_(chunkSize), |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1245 pos_(0) |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1246 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1247 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1248 |
4204 | 1249 virtual bool ReadNextChunk(std::string& chunk) ORTHANC_OVERRIDE |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1250 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1251 if (pos_ == size_) |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1252 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1253 return false; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1254 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1255 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1256 chunk.clear(); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1257 chunk.resize(chunkSize_); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1258 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1259 size_t i = 0; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1260 while (pos_ < size_ && |
4150
b56f3a37a4a1
optimization of ChunkedBuffer if many small chunks are added
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4148
diff
changeset
|
1261 i < chunk.size()) |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1262 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1263 chunk[i] = '0' + (pos_ % 7); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1264 pos_++; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1265 i++; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1266 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1267 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1268 if (i < chunk.size()) |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1269 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1270 chunk.erase(i, chunk.size()); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1271 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1272 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1273 return true; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1274 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1275 }; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1276 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1277 class TotoServer : public IHttpHandler |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1278 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1279 public: |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1280 virtual bool CreateChunkedRequestReader(std::unique_ptr<IChunkedRequestReader>& target, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1281 RequestOrigin origin, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1282 const char* remoteIp, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1283 const char* username, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1284 HttpMethod method, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1285 const UriComponents& uri, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
1286 const HttpToolbox::Arguments& headers) ORTHANC_OVERRIDE |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1287 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1288 return false; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1289 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1290 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1291 virtual bool Handle(HttpOutput& output, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1292 RequestOrigin origin, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1293 const char* remoteIp, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1294 const char* username, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1295 HttpMethod method, |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1296 const UriComponents& uri, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
1297 const HttpToolbox::Arguments& headers, |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4327
diff
changeset
|
1298 const HttpToolbox::GetArguments& getArguments, |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1299 const void* bodyData, |
4204 | 1300 size_t bodySize) ORTHANC_OVERRIDE |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1301 { |
4158
32ac045109a6
fix compiler warnings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4157
diff
changeset
|
1302 printf("received %d\n", static_cast<int>(bodySize)); |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1303 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1304 const uint8_t* b = reinterpret_cast<const uint8_t*>(bodyData); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1305 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1306 for (size_t i = 0; i < bodySize; i++) |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1307 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1308 if (b[i] != ('0' + i % 7)) |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1309 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1310 throw; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1311 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1312 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1313 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1314 output.Answer("ok"); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1315 return true; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1316 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1317 }; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1318 } |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1319 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1320 |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
1321 |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1322 #include "../Sources/HttpServer/HttpServer.h" |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1323 |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1324 TEST(HttpClient, DISABLED_Issue156_Slow) |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1325 { |
5432
59e3b6f8c5be
migration to UCLouvain servers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5339
diff
changeset
|
1326 // https://orthanc.uclouvain.be/bugs/show_bug.cgi?id=156 |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1327 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1328 TotoServer handler; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1329 HttpServer server; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1330 server.SetPortNumber(5000); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1331 server.Register(handler); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1332 server.Start(); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1333 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1334 WebServiceParameters w; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1335 w.SetUrl("http://localhost:5000"); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1336 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1337 // This is slow in Orthanc <= 1.5.8 (issue 156) |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1338 TotoBody body(600 * 1024 * 1024, 6 * 1024 * 1024 - 17); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1339 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1340 HttpClient c(w, "toto"); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1341 c.SetMethod(HttpMethod_Post); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1342 c.AddHeader("Expect", ""); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1343 c.AddHeader("Transfer-Encoding", "chunked"); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1344 c.SetBody(body); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1345 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1346 std::string s; |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1347 ASSERT_TRUE(c.Apply(s)); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1348 ASSERT_EQ("ok", s); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1349 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1350 server.Stop(); |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1351 } |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1352 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1353 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1354 TEST(HttpClient, DISABLED_Issue156_Crash) |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1355 { |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1356 TotoServer handler; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1357 HttpServer server; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1358 server.SetPortNumber(5000); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1359 server.Register(handler); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1360 server.Start(); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1361 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1362 WebServiceParameters w; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1363 w.SetUrl("http://localhost:5000"); |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1364 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1365 // This crashes Orthanc 1.6.0 to 1.7.2 |
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1366 TotoBody body(32 * 1024, 1); |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1367 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1368 HttpClient c(w, "toto"); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1369 c.SetMethod(HttpMethod_Post); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1370 c.AddHeader("Expect", ""); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1371 c.AddHeader("Transfer-Encoding", "chunked"); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1372 c.SetBody(body); |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1373 |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1374 std::string s; |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1375 ASSERT_TRUE(c.Apply(s)); |
4151
8c559dd5034b
Fix possible crash in HttpClient if sending multipart body (can occur in STOW-RS)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4150
diff
changeset
|
1376 ASSERT_EQ("ok", s); |
4148
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1377 |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1378 server.Stop(); |
732ad6c618ba
removing ChunkedBuffer::AddChunkDestructive()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
1379 } |
4325
b96aedfa8cc1
unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4204
diff
changeset
|
1380 #endif |