annotate OrthancFramework/UnitTestsSources/RestApiTests.cpp @ 4748:4336642b8cff

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