Mercurial > hg > orthanc
annotate UnitTestsSources/UnitTestsMain.cpp @ 3750:0ba17d2bcdc9
fix for boost 1.71 - cf. Debian Bug#953884
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Mar 2020 11:19:37 +0100 |
parents | 94f4a18a79cc |
children | e12c8ac6dc82 |
rev | line source |
---|---|
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
1 /** |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1102
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3581
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
6 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
10 * License, or (at your option) any later version. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
11 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
13 * program give permission to link the code of its release with the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
22 * in the program, then also delete it here. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
23 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
24 * 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:
810
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
27 * General Public License for more details. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
28 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
31 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
32 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
33 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
827
diff
changeset
|
34 #include "PrecompiledHeadersUnitTests.h" |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
35 #include "../Core/EnumerationDictionary.h" |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
36 |
0 | 37 #include "gtest/gtest.h" |
38 | |
39 #include <ctype.h> | |
40 | |
41 #include "../Core/DicomFormat/DicomTag.h" | |
3357
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
42 #include "../Core/FileBuffer.h" |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
43 #include "../Core/HttpServer/HttpToolbox.h" |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
44 #include "../Core/Logging.h" |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
45 #include "../Core/MetricsRegistry.h" |
63 | 46 #include "../Core/OrthancException.h" |
2142 | 47 #include "../Core/TemporaryFile.h" |
0 | 48 #include "../Core/Toolbox.h" |
63 | 49 #include "../OrthancServer/OrthancInitialization.h" |
0 | 50 |
1337 | 51 |
63 | 52 using namespace Orthanc; |
0 | 53 |
54 | |
55 TEST(Uuid, Generation) | |
56 { | |
57 for (int i = 0; i < 10; i++) | |
58 { | |
2512
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2499
diff
changeset
|
59 std::string s = Toolbox::GenerateUuid(); |
0 | 60 ASSERT_TRUE(Toolbox::IsUuid(s)); |
61 } | |
62 } | |
63 | |
64 TEST(Uuid, Test) | |
65 { | |
66 ASSERT_FALSE(Toolbox::IsUuid("")); | |
67 ASSERT_FALSE(Toolbox::IsUuid("012345678901234567890123456789012345")); | |
68 ASSERT_TRUE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-446655440000")); | |
708 | 69 ASSERT_FALSE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-44665544000_")); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
70 ASSERT_FALSE(Toolbox::IsUuid("01234567890123456789012345678901234_")); |
402 | 71 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-44665544000")); |
72 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000")); | |
73 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000 ok")); | |
74 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000ok")); | |
75 } | |
76 | |
77 TEST(Toolbox, IsSHA1) | |
78 { | |
79 ASSERT_FALSE(Toolbox::IsSHA1("")); | |
80 ASSERT_FALSE(Toolbox::IsSHA1("01234567890123456789012345678901234567890123")); | |
81 ASSERT_FALSE(Toolbox::IsSHA1("012345678901234567890123456789012345678901234")); | |
82 ASSERT_TRUE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9")); | |
83 | |
1428 | 84 std::string sha = " b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9 "; |
85 ASSERT_TRUE(Toolbox::IsSHA1(sha)); | |
86 sha[3] = '\0'; | |
87 sha[53] = '\0'; | |
88 ASSERT_TRUE(Toolbox::IsSHA1(sha)); | |
89 sha[40] = '\0'; | |
90 ASSERT_FALSE(Toolbox::IsSHA1(sha)); | |
91 ASSERT_FALSE(Toolbox::IsSHA1(" ")); | |
92 | |
93 ASSERT_TRUE(Toolbox::IsSHA1("16738bc3-e47ed42a-43ce044c-a3414a45-cb069bd0")); | |
94 | |
402 | 95 std::string s; |
96 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog"); | |
97 ASSERT_TRUE(Toolbox::IsSHA1(s)); | |
98 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); | |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
99 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
100 ASSERT_FALSE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b_")); |
0 | 101 } |
102 | |
708 | 103 |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
104 TEST(ParseGetArguments, Basic) |
0 | 105 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
106 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
107 HttpToolbox::ParseGetArguments(b, "aaa=baaa&bb=a&aa=c"); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
108 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
109 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
110 HttpToolbox::CompileGetArguments(a, b); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
111 |
0 | 112 ASSERT_EQ(3u, a.size()); |
113 ASSERT_EQ(a["aaa"], "baaa"); | |
114 ASSERT_EQ(a["bb"], "a"); | |
115 ASSERT_EQ(a["aa"], "c"); | |
116 } | |
117 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
118 TEST(ParseGetArguments, BasicEmpty) |
0 | 119 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
120 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
121 HttpToolbox::ParseGetArguments(b, "aaa&bb=aa&aa"); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
122 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
123 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
124 HttpToolbox::CompileGetArguments(a, b); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
125 |
0 | 126 ASSERT_EQ(3u, a.size()); |
127 ASSERT_EQ(a["aaa"], ""); | |
128 ASSERT_EQ(a["bb"], "aa"); | |
129 ASSERT_EQ(a["aa"], ""); | |
130 } | |
131 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
132 TEST(ParseGetArguments, Single) |
0 | 133 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
134 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
135 HttpToolbox::ParseGetArguments(b, "aaa=baaa"); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
136 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
137 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
138 HttpToolbox::CompileGetArguments(a, b); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
139 |
0 | 140 ASSERT_EQ(1u, a.size()); |
141 ASSERT_EQ(a["aaa"], "baaa"); | |
142 } | |
143 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
144 TEST(ParseGetArguments, SingleEmpty) |
0 | 145 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
146 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
147 HttpToolbox::ParseGetArguments(b, "aaa"); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
148 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
149 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
150 HttpToolbox::CompileGetArguments(a, b); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
151 |
0 | 152 ASSERT_EQ(1u, a.size()); |
153 ASSERT_EQ(a["aaa"], ""); | |
154 } | |
155 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
156 TEST(ParseGetQuery, Test1) |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
157 { |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
158 UriComponents uri; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
159 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
160 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world?aaa=baaa&bb=a&aa=c"); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
161 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
162 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
163 HttpToolbox::CompileGetArguments(a, b); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
164 |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
165 ASSERT_EQ(3u, uri.size()); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
166 ASSERT_EQ("instances", uri[0]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
167 ASSERT_EQ("test", uri[1]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
168 ASSERT_EQ("world", uri[2]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
169 ASSERT_EQ(3u, a.size()); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
170 ASSERT_EQ(a["aaa"], "baaa"); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
171 ASSERT_EQ(a["bb"], "a"); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
172 ASSERT_EQ(a["aa"], "c"); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
173 } |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
174 |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
175 TEST(ParseGetQuery, Test2) |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
176 { |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
177 UriComponents uri; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
178 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
179 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world"); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
180 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
181 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
182 HttpToolbox::CompileGetArguments(a, b); |
1363
feaf2840917c
Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1337
diff
changeset
|
183 |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
184 ASSERT_EQ(3u, uri.size()); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
185 ASSERT_EQ("instances", uri[0]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
186 ASSERT_EQ("test", uri[1]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
187 ASSERT_EQ("world", uri[2]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
188 ASSERT_EQ(0u, a.size()); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
189 } |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
190 |
0 | 191 TEST(Uri, SplitUriComponents) |
192 { | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
193 UriComponents c, d; |
0 | 194 Toolbox::SplitUriComponents(c, "/cou/hello/world"); |
195 ASSERT_EQ(3u, c.size()); | |
196 ASSERT_EQ("cou", c[0]); | |
197 ASSERT_EQ("hello", c[1]); | |
198 ASSERT_EQ("world", c[2]); | |
199 | |
200 Toolbox::SplitUriComponents(c, "/cou/hello/world/"); | |
201 ASSERT_EQ(3u, c.size()); | |
202 ASSERT_EQ("cou", c[0]); | |
203 ASSERT_EQ("hello", c[1]); | |
204 ASSERT_EQ("world", c[2]); | |
205 | |
206 Toolbox::SplitUriComponents(c, "/cou/hello/world/a"); | |
207 ASSERT_EQ(4u, c.size()); | |
208 ASSERT_EQ("cou", c[0]); | |
209 ASSERT_EQ("hello", c[1]); | |
210 ASSERT_EQ("world", c[2]); | |
211 ASSERT_EQ("a", c[3]); | |
212 | |
213 Toolbox::SplitUriComponents(c, "/"); | |
214 ASSERT_EQ(0u, c.size()); | |
215 | |
216 Toolbox::SplitUriComponents(c, "/hello"); | |
217 ASSERT_EQ(1u, c.size()); | |
218 ASSERT_EQ("hello", c[0]); | |
219 | |
220 Toolbox::SplitUriComponents(c, "/hello/"); | |
221 ASSERT_EQ(1u, c.size()); | |
222 ASSERT_EQ("hello", c[0]); | |
223 | |
63 | 224 ASSERT_THROW(Toolbox::SplitUriComponents(c, ""), OrthancException); |
225 ASSERT_THROW(Toolbox::SplitUriComponents(c, "a"), OrthancException); | |
207 | 226 ASSERT_THROW(Toolbox::SplitUriComponents(c, "/coucou//coucou"), OrthancException); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
227 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
228 c.clear(); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
229 c.push_back("test"); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
230 ASSERT_EQ("/", Toolbox::FlattenUri(c, 10)); |
0 | 231 } |
232 | |
233 | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
234 TEST(Uri, Truncate) |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
235 { |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
236 UriComponents c, d; |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
237 Toolbox::SplitUriComponents(c, "/cou/hello/world"); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
238 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
239 Toolbox::TruncateUri(d, c, 0); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
240 ASSERT_EQ(3u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
241 ASSERT_EQ("cou", d[0]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
242 ASSERT_EQ("hello", d[1]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
243 ASSERT_EQ("world", d[2]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
244 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
245 Toolbox::TruncateUri(d, c, 1); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
246 ASSERT_EQ(2u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
247 ASSERT_EQ("hello", d[0]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
248 ASSERT_EQ("world", d[1]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
249 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
250 Toolbox::TruncateUri(d, c, 2); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
251 ASSERT_EQ(1u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
252 ASSERT_EQ("world", d[0]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
253 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
254 Toolbox::TruncateUri(d, c, 3); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
255 ASSERT_EQ(0u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
256 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
257 Toolbox::TruncateUri(d, c, 4); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
258 ASSERT_EQ(0u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
259 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
260 Toolbox::TruncateUri(d, c, 5); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
261 ASSERT_EQ(0u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
262 } |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
263 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
264 |
0 | 265 TEST(Uri, Child) |
266 { | |
267 UriComponents c1; Toolbox::SplitUriComponents(c1, "/hello/world"); | |
268 UriComponents c2; Toolbox::SplitUriComponents(c2, "/hello/hello"); | |
269 UriComponents c3; Toolbox::SplitUriComponents(c3, "/hello"); | |
270 UriComponents c4; Toolbox::SplitUriComponents(c4, "/world"); | |
271 UriComponents c5; Toolbox::SplitUriComponents(c5, "/"); | |
272 | |
273 ASSERT_TRUE(Toolbox::IsChildUri(c1, c1)); | |
274 ASSERT_FALSE(Toolbox::IsChildUri(c1, c2)); | |
275 ASSERT_FALSE(Toolbox::IsChildUri(c1, c3)); | |
276 ASSERT_FALSE(Toolbox::IsChildUri(c1, c4)); | |
277 ASSERT_FALSE(Toolbox::IsChildUri(c1, c5)); | |
278 | |
279 ASSERT_FALSE(Toolbox::IsChildUri(c2, c1)); | |
280 ASSERT_TRUE(Toolbox::IsChildUri(c2, c2)); | |
281 ASSERT_FALSE(Toolbox::IsChildUri(c2, c3)); | |
282 ASSERT_FALSE(Toolbox::IsChildUri(c2, c4)); | |
283 ASSERT_FALSE(Toolbox::IsChildUri(c2, c5)); | |
284 | |
285 ASSERT_TRUE(Toolbox::IsChildUri(c3, c1)); | |
286 ASSERT_TRUE(Toolbox::IsChildUri(c3, c2)); | |
287 ASSERT_TRUE(Toolbox::IsChildUri(c3, c3)); | |
288 ASSERT_FALSE(Toolbox::IsChildUri(c3, c4)); | |
289 ASSERT_FALSE(Toolbox::IsChildUri(c3, c5)); | |
290 | |
291 ASSERT_FALSE(Toolbox::IsChildUri(c4, c1)); | |
292 ASSERT_FALSE(Toolbox::IsChildUri(c4, c2)); | |
293 ASSERT_FALSE(Toolbox::IsChildUri(c4, c3)); | |
294 ASSERT_TRUE(Toolbox::IsChildUri(c4, c4)); | |
295 ASSERT_FALSE(Toolbox::IsChildUri(c4, c5)); | |
296 | |
297 ASSERT_TRUE(Toolbox::IsChildUri(c5, c1)); | |
298 ASSERT_TRUE(Toolbox::IsChildUri(c5, c2)); | |
299 ASSERT_TRUE(Toolbox::IsChildUri(c5, c3)); | |
300 ASSERT_TRUE(Toolbox::IsChildUri(c5, c4)); | |
301 ASSERT_TRUE(Toolbox::IsChildUri(c5, c5)); | |
302 } | |
303 | |
304 TEST(Uri, AutodetectMimeType) | |
305 { | |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
306 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("../NOTES")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
307 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
308 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("/")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
309 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("a/a")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
310 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("..\\a\\")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
311 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("..\\a\\a")); |
0 | 312 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
313 ASSERT_EQ(MimeType_PlainText, SystemToolbox::AutodetectMimeType("../NOTES.txt")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
314 ASSERT_EQ(MimeType_PlainText, SystemToolbox::AutodetectMimeType("../coucou.xml/NOTES.txt")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
315 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("..\\coucou.\\NOTES.xml")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
316 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("../.xml")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
317 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("../.XmL")); |
2906
2a504fef4ed7
AutodetectMimeType() now using boost::filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2905
diff
changeset
|
318 |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
319 ASSERT_EQ(MimeType_JavaScript, SystemToolbox::AutodetectMimeType("NOTES.js")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
320 ASSERT_EQ(MimeType_Json, SystemToolbox::AutodetectMimeType("NOTES.json")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
321 ASSERT_EQ(MimeType_Pdf, SystemToolbox::AutodetectMimeType("NOTES.pdf")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
322 ASSERT_EQ(MimeType_Css, SystemToolbox::AutodetectMimeType("NOTES.css")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
323 ASSERT_EQ(MimeType_Html, SystemToolbox::AutodetectMimeType("NOTES.html")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
324 ASSERT_EQ(MimeType_PlainText, SystemToolbox::AutodetectMimeType("NOTES.txt")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
325 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("NOTES.xml")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
326 ASSERT_EQ(MimeType_Gif, SystemToolbox::AutodetectMimeType("NOTES.gif")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
327 ASSERT_EQ(MimeType_Jpeg, SystemToolbox::AutodetectMimeType("NOTES.jpg")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
328 ASSERT_EQ(MimeType_Jpeg, SystemToolbox::AutodetectMimeType("NOTES.jpeg")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
329 ASSERT_EQ(MimeType_Png, SystemToolbox::AutodetectMimeType("NOTES.png")); |
2984
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
330 ASSERT_EQ(MimeType_NaCl, SystemToolbox::AutodetectMimeType("NOTES.nexe")); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
331 ASSERT_EQ(MimeType_Json, SystemToolbox::AutodetectMimeType("NOTES.nmf")); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
332 ASSERT_EQ(MimeType_PNaCl, SystemToolbox::AutodetectMimeType("NOTES.pexe")); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
333 ASSERT_EQ(MimeType_Svg, SystemToolbox::AutodetectMimeType("NOTES.svg")); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
334 ASSERT_EQ(MimeType_Woff, SystemToolbox::AutodetectMimeType("NOTES.woff")); |
3435
c08bb6ac3b7f
new mime type: font/woff2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
335 ASSERT_EQ(MimeType_Woff2, SystemToolbox::AutodetectMimeType("NOTES.woff2")); |
2984
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
336 |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
337 // Test primitives from the "RegisterDefaultExtensions()" that was |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
338 // present in the sample "Serve Folders plugin" of Orthanc 1.4.2 |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
339 ASSERT_STREQ("application/javascript", EnumerationToString(SystemToolbox::AutodetectMimeType(".js"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
340 ASSERT_STREQ("application/json", EnumerationToString(SystemToolbox::AutodetectMimeType(".json"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
341 ASSERT_STREQ("application/json", EnumerationToString(SystemToolbox::AutodetectMimeType(".nmf"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
342 ASSERT_STREQ("application/octet-stream", EnumerationToString(SystemToolbox::AutodetectMimeType(""))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
343 ASSERT_STREQ("application/wasm", EnumerationToString(SystemToolbox::AutodetectMimeType(".wasm"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
344 ASSERT_STREQ("application/x-font-woff", EnumerationToString(SystemToolbox::AutodetectMimeType(".woff"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
345 ASSERT_STREQ("application/x-nacl", EnumerationToString(SystemToolbox::AutodetectMimeType(".nexe"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
346 ASSERT_STREQ("application/x-pnacl", EnumerationToString(SystemToolbox::AutodetectMimeType(".pexe"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
347 ASSERT_STREQ("application/xml", EnumerationToString(SystemToolbox::AutodetectMimeType(".xml"))); |
3435
c08bb6ac3b7f
new mime type: font/woff2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3357
diff
changeset
|
348 ASSERT_STREQ("font/woff2", EnumerationToString(SystemToolbox::AutodetectMimeType(".woff2"))); |
2984
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
349 ASSERT_STREQ("image/gif", EnumerationToString(SystemToolbox::AutodetectMimeType(".gif"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
350 ASSERT_STREQ("image/jpeg", EnumerationToString(SystemToolbox::AutodetectMimeType(".jpeg"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
351 ASSERT_STREQ("image/jpeg", EnumerationToString(SystemToolbox::AutodetectMimeType(".jpg"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
352 ASSERT_STREQ("image/png", EnumerationToString(SystemToolbox::AutodetectMimeType(".png"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
353 ASSERT_STREQ("image/svg+xml", EnumerationToString(SystemToolbox::AutodetectMimeType(".svg"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
354 ASSERT_STREQ("text/css", EnumerationToString(SystemToolbox::AutodetectMimeType(".css"))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
355 ASSERT_STREQ("text/html", EnumerationToString(SystemToolbox::AutodetectMimeType(".html"))); |
0 | 356 } |
357 | |
22 | 358 TEST(Toolbox, ComputeMD5) |
359 { | |
360 std::string s; | |
361 | |
362 // # echo -n "Hello" | md5sum | |
363 | |
364 Toolbox::ComputeMD5(s, "Hello"); | |
365 ASSERT_EQ("8b1a9953c4611296a827abf8c47804d7", s); | |
366 Toolbox::ComputeMD5(s, ""); | |
367 ASSERT_EQ("d41d8cd98f00b204e9800998ecf8427e", s); | |
368 } | |
369 | |
177 | 370 TEST(Toolbox, ComputeSHA1) |
371 { | |
372 std::string s; | |
373 | |
374 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog"); | |
375 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); | |
376 Toolbox::ComputeSHA1(s, ""); | |
377 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s); | |
378 } | |
379 | |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
380 TEST(Toolbox, PathToExecutable) |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
381 { |
2140 | 382 printf("[%s]\n", SystemToolbox::GetPathToExecutable().c_str()); |
383 printf("[%s]\n", SystemToolbox::GetDirectoryOfExecutable().c_str()); | |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
384 } |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
385 |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
386 TEST(Toolbox, StripSpaces) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
387 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
388 ASSERT_EQ("", Toolbox::StripSpaces(" \t \r \n ")); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
389 ASSERT_EQ("coucou", Toolbox::StripSpaces(" coucou \t \r \n ")); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
390 ASSERT_EQ("cou cou", Toolbox::StripSpaces(" cou cou \n ")); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
391 ASSERT_EQ("c", Toolbox::StripSpaces(" \n\t c\r \n ")); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
392 } |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
393 |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
394 TEST(Toolbox, Case) |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
395 { |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
396 std::string s = "CoU"; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
397 std::string ss; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
398 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
399 Toolbox::ToUpperCase(ss, s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
400 ASSERT_EQ("COU", ss); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
401 Toolbox::ToLowerCase(ss, s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
402 ASSERT_EQ("cou", ss); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
403 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
404 s = "CoU"; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
405 Toolbox::ToUpperCase(s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
406 ASSERT_EQ("COU", s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
407 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
408 s = "CoU"; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
409 Toolbox::ToLowerCase(s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
410 ASSERT_EQ("cou", s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
411 } |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
412 |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
413 |
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
414 TEST(Logger, Basic) |
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
415 { |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
416 LOG(INFO) << "I say hello"; |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
417 } |
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
418 |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
419 TEST(Toolbox, ConvertFromLatin1) |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
420 { |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
421 // This is a Latin-1 test string |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
422 const unsigned char data[10] = { 0xe0, 0xe9, 0xea, 0xe7, 0x26, 0xc6, 0x61, 0x62, 0x63, 0x00 }; |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
423 |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
424 std::string s((char*) &data[0], 10); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
425 ASSERT_EQ("&abc", Toolbox::ConvertToAscii(s)); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
426 |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
427 // Open in Emacs, then save with UTF-8 encoding, then "hexdump -C" |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
428 std::string utf8 = Toolbox::ConvertToUtf8(s, Encoding_Latin1, false); |
235 | 429 ASSERT_EQ(15u, utf8.size()); |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
430 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[0])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
431 ASSERT_EQ(0xa0, static_cast<unsigned char>(utf8[1])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
432 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[2])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
433 ASSERT_EQ(0xa9, static_cast<unsigned char>(utf8[3])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
434 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[4])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
435 ASSERT_EQ(0xaa, static_cast<unsigned char>(utf8[5])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
436 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[6])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
437 ASSERT_EQ(0xa7, static_cast<unsigned char>(utf8[7])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
438 ASSERT_EQ(0x26, static_cast<unsigned char>(utf8[8])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
439 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[9])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
440 ASSERT_EQ(0x86, static_cast<unsigned char>(utf8[10])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
441 ASSERT_EQ(0x61, static_cast<unsigned char>(utf8[11])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
442 ASSERT_EQ(0x62, static_cast<unsigned char>(utf8[12])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
443 ASSERT_EQ(0x63, static_cast<unsigned char>(utf8[13])); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
444 ASSERT_EQ(0x00, static_cast<unsigned char>(utf8[14])); // Null-terminated string |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
445 } |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
446 |
2907
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
447 |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
448 TEST(Toolbox, FixUtf8) |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
449 { |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
450 // This is a Latin-1 test string: "crane" with a circumflex accent |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
451 const unsigned char latin1[] = { 0x63, 0x72, 0xe2, 0x6e, 0x65 }; |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
452 |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
453 std::string s((char*) &latin1[0], sizeof(latin1) / sizeof(char)); |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
454 |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
455 ASSERT_EQ(s, Toolbox::ConvertFromUtf8(Toolbox::ConvertToUtf8(s, Encoding_Latin1, false), Encoding_Latin1)); |
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
456 ASSERT_EQ("cre", Toolbox::ConvertToUtf8(s, Encoding_Utf8, false)); |
2907
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
457 } |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
458 |
0204af4ece6a
Remove invalid characters from badly-encoded UTF-8 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2906
diff
changeset
|
459 |
3322
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
460 static int32_t GetUnicode(const uint8_t* data, |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
461 size_t size, |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
462 size_t expectedLength) |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
463 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
464 std::string s((char*) &data[0], size); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
465 uint32_t unicode; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
466 size_t length; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
467 Toolbox::Utf8ToUnicodeCharacter(unicode, length, s, 0); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
468 if (length != expectedLength) |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
469 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
470 return -1; // Error case |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
471 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
472 else |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
473 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
474 return unicode; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
475 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
476 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
477 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
478 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
479 TEST(Toolbox, Utf8ToUnicode) |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
480 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
481 // https://en.wikipedia.org/wiki/UTF-8 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
482 |
3497
db71bd11affc
fix unit tests if dcmtk != 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3435
diff
changeset
|
483 ASSERT_EQ(1u, sizeof(char)); |
db71bd11affc
fix unit tests if dcmtk != 3.6.1
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3435
diff
changeset
|
484 ASSERT_EQ(1u, sizeof(uint8_t)); |
3322
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
485 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
486 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
487 const uint8_t data[] = { 0x24 }; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
488 ASSERT_EQ(0x24, GetUnicode(data, 1, 1)); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
489 ASSERT_THROW(GetUnicode(data, 0, 1), OrthancException); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
490 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
491 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
492 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
493 const uint8_t data[] = { 0xc2, 0xa2 }; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
494 ASSERT_EQ(0xa2, GetUnicode(data, 2, 2)); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
495 ASSERT_THROW(GetUnicode(data, 1, 2), OrthancException); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
496 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
497 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
498 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
499 const uint8_t data[] = { 0xe0, 0xa4, 0xb9 }; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
500 ASSERT_EQ(0x0939, GetUnicode(data, 3, 3)); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
501 ASSERT_THROW(GetUnicode(data, 2, 3), OrthancException); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
502 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
503 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
504 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
505 const uint8_t data[] = { 0xe2, 0x82, 0xac }; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
506 ASSERT_EQ(0x20ac, GetUnicode(data, 3, 3)); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
507 ASSERT_THROW(GetUnicode(data, 2, 3), OrthancException); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
508 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
509 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
510 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
511 const uint8_t data[] = { 0xf0, 0x90, 0x8d, 0x88 }; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
512 ASSERT_EQ(0x010348, GetUnicode(data, 4, 4)); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
513 ASSERT_THROW(GetUnicode(data, 3, 4), OrthancException); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
514 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
515 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
516 { |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
517 const uint8_t data[] = { 0xe0 }; |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
518 ASSERT_THROW(GetUnicode(data, 1, 1), OrthancException); |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
519 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
520 } |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
521 |
b32b7c44a223
Toolbox::Utf8ToUnicodeCharacter()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3259
diff
changeset
|
522 |
336 | 523 TEST(Toolbox, UrlDecode) |
524 { | |
525 std::string s; | |
526 | |
527 s = "Hello%20World"; | |
528 Toolbox::UrlDecode(s); | |
529 ASSERT_EQ("Hello World", s); | |
530 | |
337 | 531 s = "%21%23%24%26%27%28%29%2A%2B%2c%2f%3A%3b%3d%3f%40%5B%5D%90%ff"; |
336 | 532 Toolbox::UrlDecode(s); |
337 | 533 std::string ss = "!#$&'()*+,/:;=?@[]"; |
534 ss.push_back((char) 144); | |
535 ss.push_back((char) 255); | |
536 ASSERT_EQ(ss, s); | |
336 | 537 |
538 s = "(2000%2C00A4)+Other"; | |
539 Toolbox::UrlDecode(s); | |
540 ASSERT_EQ("(2000,00A4) Other", s); | |
541 } | |
542 | |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
543 |
2442
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
544 TEST(Toolbox, IsAsciiString) |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
545 { |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
546 std::string s = "Hello 12 /"; |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
547 ASSERT_EQ(10u, s.size()); |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
548 ASSERT_TRUE(Toolbox::IsAsciiString(s)); |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
549 ASSERT_TRUE(Toolbox::IsAsciiString(s.c_str(), 10)); |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
550 ASSERT_FALSE(Toolbox::IsAsciiString(s.c_str(), 11)); // Taking the trailing hidden '\0' |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
551 |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
552 s[2] = '\0'; |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
553 ASSERT_EQ(10u, s.size()); |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
554 ASSERT_FALSE(Toolbox::IsAsciiString(s)); |
2900 | 555 |
556 ASSERT_TRUE(Toolbox::IsAsciiString("Hello\nworld")); | |
557 ASSERT_FALSE(Toolbox::IsAsciiString("Hello\rworld")); | |
558 | |
559 ASSERT_EQ("Hello\nworld", Toolbox::ConvertToAscii("Hello\nworld")); | |
560 ASSERT_EQ("Helloworld", Toolbox::ConvertToAscii("Hello\r\tworld")); | |
2442
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
561 } |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
562 |
330349d712f9
fix Toolbox::IsAsciiString
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2411
diff
changeset
|
563 |
1976
325772dadcd6
Macro "__linux" (now obsolete) replaced by macro "__linux__"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1971
diff
changeset
|
564 #if defined(__linux__) |
2933
4a38d7d4f0e0
new class: OrthancConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2921
diff
changeset
|
565 TEST(Toolbox, AbsoluteDirectory) |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
566 { |
2933
4a38d7d4f0e0
new class: OrthancConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2921
diff
changeset
|
567 ASSERT_EQ("/tmp/hello", SystemToolbox::InterpretRelativePath("/tmp", "hello")); |
4a38d7d4f0e0
new class: OrthancConfiguration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2921
diff
changeset
|
568 ASSERT_EQ("/tmp", SystemToolbox::InterpretRelativePath("/tmp", "/tmp")); |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
569 } |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
570 #endif |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
571 |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
572 |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
573 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
574 #include "../OrthancServer/ServerEnumerations.h" |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
575 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
576 TEST(EnumerationDictionary, Simple) |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
577 { |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
578 Toolbox::EnumerationDictionary<MetadataType> d; |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
579 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
580 ASSERT_THROW(d.Translate("ReceptionDate"), OrthancException); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
581 ASSERT_EQ(MetadataType_ModifiedFrom, d.Translate("5")); |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
582 ASSERT_EQ(256, d.Translate("256")); |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
583 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
584 d.Add(MetadataType_Instance_ReceptionDate, "ReceptionDate"); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
585 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
586 ASSERT_EQ(MetadataType_Instance_ReceptionDate, d.Translate("ReceptionDate")); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
587 ASSERT_EQ(MetadataType_Instance_ReceptionDate, d.Translate("2")); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
588 ASSERT_EQ("ReceptionDate", d.Translate(MetadataType_Instance_ReceptionDate)); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
589 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
590 ASSERT_THROW(d.Add(MetadataType_Instance_ReceptionDate, "Hello"), OrthancException); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
591 ASSERT_THROW(d.Add(MetadataType_ModifiedFrom, "ReceptionDate"), OrthancException); // already used |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
592 ASSERT_THROW(d.Add(MetadataType_ModifiedFrom, "1024"), OrthancException); // cannot register numbers |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
593 d.Add(MetadataType_ModifiedFrom, "ModifiedFrom"); // ok |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
594 } |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
595 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
596 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
597 TEST(EnumerationDictionary, ServerEnumerations) |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
598 { |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
599 ASSERT_STREQ("Patient", EnumerationToString(ResourceType_Patient)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
600 ASSERT_STREQ("Study", EnumerationToString(ResourceType_Study)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
601 ASSERT_STREQ("Series", EnumerationToString(ResourceType_Series)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
602 ASSERT_STREQ("Instance", EnumerationToString(ResourceType_Instance)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
603 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
604 ASSERT_STREQ("ModifiedSeries", EnumerationToString(ChangeType_ModifiedSeries)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
605 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
606 ASSERT_STREQ("Failure", EnumerationToString(StoreStatus_Failure)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
607 ASSERT_STREQ("Success", EnumerationToString(StoreStatus_Success)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
608 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
609 ASSERT_STREQ("CompletedSeries", EnumerationToString(ChangeType_CompletedSeries)); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
610 |
437 | 611 ASSERT_EQ("IndexInSeries", EnumerationToString(MetadataType_Instance_IndexInSeries)); |
612 ASSERT_EQ("LastUpdate", EnumerationToString(MetadataType_LastUpdate)); | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
613 |
559 | 614 ASSERT_EQ(ResourceType_Patient, StringToResourceType("PATienT")); |
615 ASSERT_EQ(ResourceType_Study, StringToResourceType("STudy")); | |
616 ASSERT_EQ(ResourceType_Series, StringToResourceType("SeRiEs")); | |
617 ASSERT_EQ(ResourceType_Instance, StringToResourceType("INStance")); | |
618 ASSERT_EQ(ResourceType_Instance, StringToResourceType("IMagE")); | |
619 ASSERT_THROW(StringToResourceType("heLLo"), OrthancException); | |
620 | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
621 ASSERT_EQ(2047, StringToMetadata("2047")); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
622 ASSERT_THROW(StringToMetadata("Ceci est un test"), OrthancException); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
623 ASSERT_THROW(RegisterUserMetadata(128, ""), OrthancException); // too low (< 1024) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
624 ASSERT_THROW(RegisterUserMetadata(128000, ""), OrthancException); // too high (> 65535) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
625 RegisterUserMetadata(2047, "Ceci est un test"); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
626 ASSERT_EQ(2047, StringToMetadata("2047")); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
627 ASSERT_EQ(2047, StringToMetadata("Ceci est un test")); |
1429
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
628 |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
629 ASSERT_STREQ("Generic", EnumerationToString(StringToModalityManufacturer("Generic"))); |
2319
ae6245053bcf
made some manufacturer obsolete: MedInria (that was not used), Syngovia & AgfaImpax (replaced by GenericNoWildcardInDates) + added 'GenericNoWildcards'
amazy
parents:
2313
diff
changeset
|
630 ASSERT_STREQ("GenericNoWildcardInDates", EnumerationToString(StringToModalityManufacturer("GenericNoWildcardInDates"))); |
2352
3ab96768d144
Fix issue 52 (DICOM level security association problems)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2319
diff
changeset
|
631 ASSERT_STREQ("GenericNoUniversalWildcard", EnumerationToString(StringToModalityManufacturer("GenericNoUniversalWildcard"))); |
1429
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
632 ASSERT_STREQ("StoreScp", EnumerationToString(StringToModalityManufacturer("StoreScp"))); |
1852
efbc3afd6cd3
Efilm and Vitrea manufacturers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1846
diff
changeset
|
633 ASSERT_STREQ("Vitrea", EnumerationToString(StringToModalityManufacturer("Vitrea"))); |
2888
61a5667f37d9
New modality manufacturer: "GE" for GE Healthcare EA and AW
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2841
diff
changeset
|
634 ASSERT_STREQ("GE", EnumerationToString(StringToModalityManufacturer("GE"))); |
2319
ae6245053bcf
made some manufacturer obsolete: MedInria (that was not used), Syngovia & AgfaImpax (replaced by GenericNoWildcardInDates) + added 'GenericNoWildcards'
amazy
parents:
2313
diff
changeset
|
635 // backward compatibility tests (to remove once we make these manufacturer really obsolete) |
ae6245053bcf
made some manufacturer obsolete: MedInria (that was not used), Syngovia & AgfaImpax (replaced by GenericNoWildcardInDates) + added 'GenericNoWildcards'
amazy
parents:
2313
diff
changeset
|
636 ASSERT_STREQ("Generic", EnumerationToString(StringToModalityManufacturer("MedInria"))); |
ae6245053bcf
made some manufacturer obsolete: MedInria (that was not used), Syngovia & AgfaImpax (replaced by GenericNoWildcardInDates) + added 'GenericNoWildcards'
amazy
parents:
2313
diff
changeset
|
637 ASSERT_STREQ("Generic", EnumerationToString(StringToModalityManufacturer("EFilm2"))); |
3561
bdafff1ce443
C-Find SCU at Instance level now sets the 0008,0052 tag to IMAGE per default (was INSTANCE). Source: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/orthanc-users/FYxHXzlaQ0M/rn6d0SowAAAJ
Alain Mazy <alain@mazy.be>
parents:
3497
diff
changeset
|
638 ASSERT_STREQ("Generic", EnumerationToString(StringToModalityManufacturer("ClearCanvas"))); |
bdafff1ce443
C-Find SCU at Instance level now sets the 0008,0052 tag to IMAGE per default (was INSTANCE). Source: https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/orthanc-users/FYxHXzlaQ0M/rn6d0SowAAAJ
Alain Mazy <alain@mazy.be>
parents:
3497
diff
changeset
|
639 ASSERT_STREQ("Generic", EnumerationToString(StringToModalityManufacturer("Dcm4Chee"))); |
2319
ae6245053bcf
made some manufacturer obsolete: MedInria (that was not used), Syngovia & AgfaImpax (replaced by GenericNoWildcardInDates) + added 'GenericNoWildcards'
amazy
parents:
2313
diff
changeset
|
640 ASSERT_STREQ("GenericNoWildcardInDates", EnumerationToString(StringToModalityManufacturer("SyngoVia"))); |
ae6245053bcf
made some manufacturer obsolete: MedInria (that was not used), Syngovia & AgfaImpax (replaced by GenericNoWildcardInDates) + added 'GenericNoWildcards'
amazy
parents:
2313
diff
changeset
|
641 ASSERT_STREQ("GenericNoWildcardInDates", EnumerationToString(StringToModalityManufacturer("AgfaImpax"))); |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
642 } |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
643 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
644 |
450 | 645 |
483
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
646 TEST(Toolbox, WriteFile) |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
647 { |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
648 std::string path; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
649 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
650 { |
2140 | 651 TemporaryFile tmp; |
483
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
652 path = tmp.GetPath(); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
653 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
654 std::string s; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
655 s.append("Hello"); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
656 s.push_back('\0'); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
657 s.append("World"); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
658 ASSERT_EQ(11u, s.size()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
659 |
2140 | 660 SystemToolbox::WriteFile(s, path.c_str()); |
483
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
661 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
662 std::string t; |
2140 | 663 SystemToolbox::ReadFile(t, path.c_str()); |
483
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
664 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
665 ASSERT_EQ(11u, t.size()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
666 ASSERT_EQ(0, t[5]); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
667 ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size())); |
1933
ff11ba08e5d0
Toolbox::ReadHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
668 |
ff11ba08e5d0
Toolbox::ReadHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
669 std::string h; |
2140 | 670 ASSERT_EQ(true, SystemToolbox::ReadHeader(h, path.c_str(), 1)); |
1971
869a87c08673
fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1969
diff
changeset
|
671 ASSERT_EQ(1u, h.size()); |
1933
ff11ba08e5d0
Toolbox::ReadHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
672 ASSERT_EQ('H', h[0]); |
2140 | 673 ASSERT_TRUE(SystemToolbox::ReadHeader(h, path.c_str(), 0)); |
1971
869a87c08673
fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1969
diff
changeset
|
674 ASSERT_EQ(0u, h.size()); |
2140 | 675 ASSERT_FALSE(SystemToolbox::ReadHeader(h, path.c_str(), 32)); |
1933
ff11ba08e5d0
Toolbox::ReadHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
676 ASSERT_EQ(11u, h.size()); |
ff11ba08e5d0
Toolbox::ReadHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
677 ASSERT_EQ(0, memcmp(s.c_str(), h.c_str(), s.size())); |
483
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
678 } |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
679 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
680 std::string u; |
2140 | 681 ASSERT_THROW(SystemToolbox::ReadFile(u, path.c_str()), OrthancException); |
483
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
682 } |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
683 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
684 |
3357
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
685 TEST(Toolbox, FileBuffer) |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
686 { |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
687 FileBuffer f; |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
688 f.Append("a", 1); |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
689 f.Append("", 0); |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
690 f.Append("bc", 2); |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
691 |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
692 std::string s; |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
693 f.Read(s); |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
694 ASSERT_EQ("abc", s); |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
695 |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
696 ASSERT_THROW(f.Append("d", 1), OrthancException); // File is closed |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
697 } |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
698 |
c0aa5f1cf2f5
new class: FileBuffer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3326
diff
changeset
|
699 |
608 | 700 TEST(Toolbox, Wildcard) |
701 { | |
702 ASSERT_EQ("abcd", Toolbox::WildcardToRegularExpression("abcd")); | |
703 ASSERT_EQ("ab.*cd", Toolbox::WildcardToRegularExpression("ab*cd")); | |
704 ASSERT_EQ("ab..cd", Toolbox::WildcardToRegularExpression("ab??cd")); | |
705 ASSERT_EQ("a.*b.c.*d", Toolbox::WildcardToRegularExpression("a*b?c*d")); | |
706 ASSERT_EQ("a\\{b\\]", Toolbox::WildcardToRegularExpression("a{b]")); | |
707 } | |
708 | |
709 | |
710 TEST(Toolbox, Tokenize) | |
711 { | |
712 std::vector<std::string> t; | |
713 | |
714 Toolbox::TokenizeString(t, "", ','); | |
1492 | 715 ASSERT_EQ(1u, t.size()); |
608 | 716 ASSERT_EQ("", t[0]); |
717 | |
718 Toolbox::TokenizeString(t, "abc", ','); | |
1492 | 719 ASSERT_EQ(1u, t.size()); |
608 | 720 ASSERT_EQ("abc", t[0]); |
721 | |
722 Toolbox::TokenizeString(t, "ab,cd,ef,", ','); | |
1492 | 723 ASSERT_EQ(4u, t.size()); |
608 | 724 ASSERT_EQ("ab", t[0]); |
725 ASSERT_EQ("cd", t[1]); | |
726 ASSERT_EQ("ef", t[2]); | |
727 ASSERT_EQ("", t[3]); | |
728 } | |
729 | |
1086
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
730 TEST(Toolbox, Enumerations) |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
731 { |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
732 ASSERT_EQ(Encoding_Utf8, StringToEncoding(EnumerationToString(Encoding_Utf8))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
733 ASSERT_EQ(Encoding_Ascii, StringToEncoding(EnumerationToString(Encoding_Ascii))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
734 ASSERT_EQ(Encoding_Latin1, StringToEncoding(EnumerationToString(Encoding_Latin1))); |
1087 | 735 ASSERT_EQ(Encoding_Latin2, StringToEncoding(EnumerationToString(Encoding_Latin2))); |
736 ASSERT_EQ(Encoding_Latin3, StringToEncoding(EnumerationToString(Encoding_Latin3))); | |
737 ASSERT_EQ(Encoding_Latin4, StringToEncoding(EnumerationToString(Encoding_Latin4))); | |
738 ASSERT_EQ(Encoding_Latin5, StringToEncoding(EnumerationToString(Encoding_Latin5))); | |
739 ASSERT_EQ(Encoding_Cyrillic, StringToEncoding(EnumerationToString(Encoding_Cyrillic))); | |
740 ASSERT_EQ(Encoding_Arabic, StringToEncoding(EnumerationToString(Encoding_Arabic))); | |
741 ASSERT_EQ(Encoding_Greek, StringToEncoding(EnumerationToString(Encoding_Greek))); | |
742 ASSERT_EQ(Encoding_Hebrew, StringToEncoding(EnumerationToString(Encoding_Hebrew))); | |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
743 ASSERT_EQ(Encoding_Japanese, StringToEncoding(EnumerationToString(Encoding_Japanese))); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
744 ASSERT_EQ(Encoding_Chinese, StringToEncoding(EnumerationToString(Encoding_Chinese))); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
745 ASSERT_EQ(Encoding_Thai, StringToEncoding(EnumerationToString(Encoding_Thai))); |
3217
cf8cbeb35f33
preliminary support of Korean character set
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3203
diff
changeset
|
746 ASSERT_EQ(Encoding_Korean, StringToEncoding(EnumerationToString(Encoding_Korean))); |
3218 | 747 ASSERT_EQ(Encoding_JapaneseKanji, StringToEncoding(EnumerationToString(Encoding_JapaneseKanji))); |
3226
45e1631febbb
support of simplified chinese
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3218
diff
changeset
|
748 ASSERT_EQ(Encoding_SimplifiedChinese, StringToEncoding(EnumerationToString(Encoding_SimplifiedChinese))); |
1086
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
749 |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
750 ASSERT_EQ(ResourceType_Patient, StringToResourceType(EnumerationToString(ResourceType_Patient))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
751 ASSERT_EQ(ResourceType_Study, StringToResourceType(EnumerationToString(ResourceType_Study))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
752 ASSERT_EQ(ResourceType_Series, StringToResourceType(EnumerationToString(ResourceType_Series))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
753 ASSERT_EQ(ResourceType_Instance, StringToResourceType(EnumerationToString(ResourceType_Instance))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
754 |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
755 ASSERT_EQ(ImageFormat_Png, StringToImageFormat(EnumerationToString(ImageFormat_Png))); |
2281
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
756 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
757 ASSERT_EQ(PhotometricInterpretation_ARGB, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_ARGB))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
758 ASSERT_EQ(PhotometricInterpretation_CMYK, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_CMYK))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
759 ASSERT_EQ(PhotometricInterpretation_HSV, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_HSV))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
760 ASSERT_EQ(PhotometricInterpretation_Monochrome1, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Monochrome1))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
761 ASSERT_EQ(PhotometricInterpretation_Monochrome2, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Monochrome2))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
762 ASSERT_EQ(PhotometricInterpretation_Palette, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Palette))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
763 ASSERT_EQ(PhotometricInterpretation_RGB, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_RGB))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
764 ASSERT_EQ(PhotometricInterpretation_YBRFull, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRFull))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
765 ASSERT_EQ(PhotometricInterpretation_YBRFull422, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRFull422))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
766 ASSERT_EQ(PhotometricInterpretation_YBRPartial420, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRPartial420))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
767 ASSERT_EQ(PhotometricInterpretation_YBRPartial422, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRPartial422))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
768 ASSERT_EQ(PhotometricInterpretation_YBR_ICT, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBR_ICT))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
769 ASSERT_EQ(PhotometricInterpretation_YBR_RCT, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBR_RCT))); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
770 |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
771 ASSERT_STREQ("Unknown", EnumerationToString(PhotometricInterpretation_Unknown)); |
e002430baa41
Fix issue #44 (Bad interpretation of photometric interpretation MONOCHROME1)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2244
diff
changeset
|
772 ASSERT_THROW(StringToPhotometricInterpretation("Unknown"), OrthancException); |
2309
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
773 |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
774 ASSERT_EQ(DicomVersion_2008, StringToDicomVersion(EnumerationToString(DicomVersion_2008))); |
4dc313b9a20a
Argument "DicomVersion" in URIs "/{...}/{...}/anonymization"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2281
diff
changeset
|
775 ASSERT_EQ(DicomVersion_2017c, StringToDicomVersion(EnumerationToString(DicomVersion_2017c))); |
2499
83b8b6743531
ITagVisitor - for anonymization relationships
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2475
diff
changeset
|
776 |
83b8b6743531
ITagVisitor - for anonymization relationships
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2475
diff
changeset
|
777 for (int i = static_cast<int>(ValueRepresentation_ApplicationEntity); |
83b8b6743531
ITagVisitor - for anonymization relationships
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2475
diff
changeset
|
778 i < static_cast<int>(ValueRepresentation_NotSupported); i += 1) |
83b8b6743531
ITagVisitor - for anonymization relationships
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2475
diff
changeset
|
779 { |
83b8b6743531
ITagVisitor - for anonymization relationships
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2475
diff
changeset
|
780 ValueRepresentation vr = static_cast<ValueRepresentation>(i); |
83b8b6743531
ITagVisitor - for anonymization relationships
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2475
diff
changeset
|
781 ASSERT_EQ(vr, StringToValueRepresentation(EnumerationToString(vr), true)); |
83b8b6743531
ITagVisitor - for anonymization relationships
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2475
diff
changeset
|
782 } |
83b8b6743531
ITagVisitor - for anonymization relationships
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2475
diff
changeset
|
783 |
83b8b6743531
ITagVisitor - for anonymization relationships
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2475
diff
changeset
|
784 ASSERT_THROW(StringToValueRepresentation("nope", true), OrthancException); |
2646 | 785 |
786 ASSERT_EQ(JobState_Pending, StringToJobState(EnumerationToString(JobState_Pending))); | |
787 ASSERT_EQ(JobState_Running, StringToJobState(EnumerationToString(JobState_Running))); | |
788 ASSERT_EQ(JobState_Success, StringToJobState(EnumerationToString(JobState_Success))); | |
789 ASSERT_EQ(JobState_Failure, StringToJobState(EnumerationToString(JobState_Failure))); | |
790 ASSERT_EQ(JobState_Paused, StringToJobState(EnumerationToString(JobState_Paused))); | |
791 ASSERT_EQ(JobState_Retry, StringToJobState(EnumerationToString(JobState_Retry))); | |
792 ASSERT_THROW(StringToJobState("nope"), OrthancException); | |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
793 |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
794 ASSERT_EQ(MimeType_Binary, StringToMimeType(EnumerationToString(MimeType_Binary))); |
2984
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
795 ASSERT_EQ(MimeType_Css, StringToMimeType(EnumerationToString(MimeType_Css))); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
796 ASSERT_EQ(MimeType_Dicom, StringToMimeType(EnumerationToString(MimeType_Dicom))); |
2984
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
797 ASSERT_EQ(MimeType_Gif, StringToMimeType(EnumerationToString(MimeType_Gif))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
798 ASSERT_EQ(MimeType_Gzip, StringToMimeType(EnumerationToString(MimeType_Gzip))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
799 ASSERT_EQ(MimeType_Html, StringToMimeType(EnumerationToString(MimeType_Html))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
800 ASSERT_EQ(MimeType_JavaScript, StringToMimeType(EnumerationToString(MimeType_JavaScript))); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
801 ASSERT_EQ(MimeType_Jpeg, StringToMimeType(EnumerationToString(MimeType_Jpeg))); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
802 ASSERT_EQ(MimeType_Jpeg2000, StringToMimeType(EnumerationToString(MimeType_Jpeg2000))); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
803 ASSERT_EQ(MimeType_Json, StringToMimeType(EnumerationToString(MimeType_Json))); |
2984
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
804 ASSERT_EQ(MimeType_NaCl, StringToMimeType(EnumerationToString(MimeType_NaCl))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
805 ASSERT_EQ(MimeType_PNaCl, StringToMimeType(EnumerationToString(MimeType_PNaCl))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
806 ASSERT_EQ(MimeType_Pam, StringToMimeType(EnumerationToString(MimeType_Pam))); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
807 ASSERT_EQ(MimeType_Pdf, StringToMimeType(EnumerationToString(MimeType_Pdf))); |
2984
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
808 ASSERT_EQ(MimeType_PlainText, StringToMimeType(EnumerationToString(MimeType_PlainText))); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
809 ASSERT_EQ(MimeType_Png, StringToMimeType(EnumerationToString(MimeType_Png))); |
2984
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
810 ASSERT_EQ(MimeType_Svg, StringToMimeType(EnumerationToString(MimeType_Svg))); |
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
811 ASSERT_EQ(MimeType_WebAssembly, StringToMimeType(EnumerationToString(MimeType_WebAssembly))); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
812 ASSERT_EQ(MimeType_Xml, StringToMimeType("application/xml")); |
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
813 ASSERT_EQ(MimeType_Xml, StringToMimeType("text/xml")); |
2984
db8f360fcb41
OrthancPluginAutodetectMimeType()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2933
diff
changeset
|
814 ASSERT_EQ(MimeType_Xml, StringToMimeType(EnumerationToString(MimeType_Xml))); |
3203
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
815 ASSERT_EQ(MimeType_DicomWebJson, StringToMimeType(EnumerationToString(MimeType_DicomWebJson))); |
810772486249
URI "/instances/.../file" can return DICOMweb JSON or XML, depending on Accept header
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3174
diff
changeset
|
816 ASSERT_EQ(MimeType_DicomWebXml, StringToMimeType(EnumerationToString(MimeType_DicomWebXml))); |
2908
9d277f8ad698
new enumeration: MimeType
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2907
diff
changeset
|
817 ASSERT_THROW(StringToMimeType("nope"), OrthancException); |
3027 | 818 |
819 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Patient)); | |
820 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Study)); | |
821 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Series)); | |
822 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Instance)); | |
823 | |
824 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Patient)); | |
825 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Study)); | |
826 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Series)); | |
827 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Instance)); | |
828 | |
829 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Patient)); | |
830 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Study)); | |
831 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Series)); | |
832 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Instance)); | |
833 | |
834 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Patient)); | |
835 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Study)); | |
836 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Series)); | |
837 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Instance)); | |
1086
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
838 } |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
839 |
608 | 840 |
2364 | 841 #if defined(__linux__) || defined(__OpenBSD__) |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
842 #include <endian.h> |
1337 | 843 #elif defined(__FreeBSD__) |
844 #include <machine/endian.h> | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
845 #endif |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
846 |
1337 | 847 |
637 | 848 TEST(Toolbox, Endianness) |
849 { | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
850 // Parts of this test come from Adam Conrad |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
851 // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728822#5 |
637 | 852 |
1337 | 853 |
854 /** | |
855 * Windows and OS X are assumed to always little-endian. | |
856 **/ | |
857 | |
858 #if defined(_WIN32) || defined(__APPLE__) | |
637 | 859 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
860 |
2545 | 861 |
862 /** | |
863 * FreeBSD. | |
864 **/ | |
865 | |
866 #elif defined(__FreeBSD__) || defined(__OpenBSD__) | |
867 # if _BYTE_ORDER == _BIG_ENDIAN | |
868 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness()); | |
869 # else // _LITTLE_ENDIAN | |
870 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); | |
871 # endif | |
872 | |
918 | 873 |
1337 | 874 /** |
875 * Linux. | |
876 **/ | |
877 | |
1976
325772dadcd6
Macro "__linux" (now obsolete) replaced by macro "__linux__"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1971
diff
changeset
|
878 #elif defined(__linux__) || defined(__FreeBSD_kernel__) |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
879 |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
880 #if !defined(__BYTE_ORDER) |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
881 # error Support your platform here |
637 | 882 #endif |
883 | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
884 # if __BYTE_ORDER == __BIG_ENDIAN |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
885 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness()); |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
886 # else // __LITTLE_ENDIAN |
637 | 887 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
888 # endif |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
889 |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
890 #else |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
891 #error Support your platform here |
637 | 892 #endif |
893 } | |
894 | |
895 | |
1938 | 896 #include "../Core/Endianness.h" |
897 | |
898 static void ASSERT_EQ16(uint16_t a, uint16_t b) | |
899 { | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
900 #ifdef __MINGW32__ |
1938 | 901 // This cast solves a linking problem with MinGW |
902 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
903 #else |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
904 ASSERT_EQ(a, b); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
905 #endif |
1938 | 906 } |
907 | |
908 static void ASSERT_NE16(uint16_t a, uint16_t b) | |
909 { | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
910 #ifdef __MINGW32__ |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
911 // This cast solves a linking problem with MinGW |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
912 ASSERT_NE(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
913 #else |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
914 ASSERT_NE(a, b); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
915 #endif |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
916 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
917 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
918 static void ASSERT_EQ32(uint32_t a, uint32_t b) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
919 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
920 #ifdef __MINGW32__ |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
921 // This cast solves a linking problem with MinGW |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
922 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
923 #else |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
924 ASSERT_EQ(a, b); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
925 #endif |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
926 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
927 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
928 static void ASSERT_NE32(uint32_t a, uint32_t b) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
929 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
930 #ifdef __MINGW32__ |
1938 | 931 // This cast solves a linking problem with MinGW |
932 ASSERT_NE(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
933 #else |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
934 ASSERT_NE(a, b); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
935 #endif |
1938 | 936 } |
937 | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
938 static void ASSERT_EQ64(uint64_t a, uint64_t b) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
939 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
940 #ifdef __MINGW32__ |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
941 // This cast solves a linking problem with MinGW |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
942 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
943 #else |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
944 ASSERT_EQ(a, b); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
945 #endif |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
946 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
947 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
948 static void ASSERT_NE64(uint64_t a, uint64_t b) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
949 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
950 #ifdef __MINGW32__ |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
951 // This cast solves a linking problem with MinGW |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
952 ASSERT_NE(static_cast<unsigned long long>(a), static_cast<unsigned long long>(b)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
953 #else |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
954 ASSERT_NE(a, b); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
955 #endif |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
956 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
957 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
958 |
1938 | 959 |
960 TEST(Toolbox, EndiannessConversions16) | |
961 { | |
962 Endianness e = Toolbox::DetectEndianness(); | |
963 | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
964 for (unsigned int i = 0; i < 65536; i += 17) |
1938 | 965 { |
966 uint16_t v = static_cast<uint16_t>(i); | |
967 ASSERT_EQ16(v, be16toh(htobe16(v))); | |
968 ASSERT_EQ16(v, le16toh(htole16(v))); | |
969 | |
970 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&v); | |
971 if (bytes[0] != bytes[1]) | |
972 { | |
973 ASSERT_NE16(v, le16toh(htobe16(v))); | |
974 ASSERT_NE16(v, be16toh(htole16(v))); | |
975 } | |
976 else | |
977 { | |
978 ASSERT_EQ16(v, le16toh(htobe16(v))); | |
979 ASSERT_EQ16(v, be16toh(htole16(v))); | |
980 } | |
981 | |
982 switch (e) | |
983 { | |
984 case Endianness_Little: | |
985 ASSERT_EQ16(v, htole16(v)); | |
986 if (bytes[0] != bytes[1]) | |
987 { | |
988 ASSERT_NE16(v, htobe16(v)); | |
989 } | |
990 else | |
991 { | |
992 ASSERT_EQ16(v, htobe16(v)); | |
993 } | |
994 break; | |
995 | |
996 case Endianness_Big: | |
997 ASSERT_EQ16(v, htobe16(v)); | |
998 if (bytes[0] != bytes[1]) | |
999 { | |
1000 ASSERT_NE16(v, htole16(v)); | |
1001 } | |
1002 else | |
1003 { | |
1004 ASSERT_EQ16(v, htole16(v)); | |
1005 } | |
1006 break; | |
1007 | |
1008 default: | |
1009 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1010 } | |
1011 } | |
1012 } | |
1013 | |
1014 | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1015 TEST(Toolbox, EndiannessConversions32) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1016 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1017 const uint32_t v = 0xff010203u; |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1018 const uint32_t r = 0x030201ffu; |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1019 ASSERT_EQ32(v, be32toh(htobe32(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1020 ASSERT_EQ32(v, le32toh(htole32(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1021 ASSERT_NE32(v, be32toh(htole32(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1022 ASSERT_NE32(v, le32toh(htobe32(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1023 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1024 switch (Toolbox::DetectEndianness()) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1025 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1026 case Endianness_Little: |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1027 ASSERT_EQ32(r, htobe32(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1028 ASSERT_EQ32(v, htole32(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1029 ASSERT_EQ32(r, be32toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1030 ASSERT_EQ32(v, le32toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1031 break; |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1032 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1033 case Endianness_Big: |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1034 ASSERT_EQ32(v, htobe32(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1035 ASSERT_EQ32(r, htole32(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1036 ASSERT_EQ32(v, be32toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1037 ASSERT_EQ32(r, le32toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1038 break; |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1039 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1040 default: |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1041 throw OrthancException(ErrorCode_ParameterOutOfRange); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1042 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1043 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1044 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1045 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1046 TEST(Toolbox, EndiannessConversions64) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1047 { |
1942 | 1048 const uint64_t v = 0xff01020304050607LL; |
1049 const uint64_t r = 0x07060504030201ffLL; | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1050 ASSERT_EQ64(v, be64toh(htobe64(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1051 ASSERT_EQ64(v, le64toh(htole64(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1052 ASSERT_NE64(v, be64toh(htole64(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1053 ASSERT_NE64(v, le64toh(htobe64(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1054 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1055 switch (Toolbox::DetectEndianness()) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1056 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1057 case Endianness_Little: |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1058 ASSERT_EQ64(r, htobe64(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1059 ASSERT_EQ64(v, htole64(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1060 ASSERT_EQ64(r, be64toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1061 ASSERT_EQ64(v, le64toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1062 break; |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1063 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1064 case Endianness_Big: |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1065 ASSERT_EQ64(v, htobe64(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1066 ASSERT_EQ64(r, htole64(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1067 ASSERT_EQ64(v, be64toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1068 ASSERT_EQ64(r, le64toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1069 break; |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1070 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1071 default: |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1072 throw OrthancException(ErrorCode_ParameterOutOfRange); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1073 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
1074 } |
1938 | 1075 |
1076 | |
2475
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1077 TEST(Toolbox, Now) |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1078 { |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1079 LOG(WARNING) << "Local time: " << SystemToolbox::GetNowIsoString(false); |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1080 LOG(WARNING) << "Universal time: " << SystemToolbox::GetNowIsoString(true); |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1081 |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1082 std::string date, time; |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1083 SystemToolbox::GetNowDicom(date, time, false); |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1084 LOG(WARNING) << "Local DICOM time: [" << date << "] [" << time << "]"; |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1085 |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1086 SystemToolbox::GetNowDicom(date, time, true); |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1087 LOG(WARNING) << "Universal DICOM time: [" << date << "] [" << time << "]"; |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1088 } |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1089 |
8cc3ca64a534
Orthanc now uses UTC (universal time) instead of local time in its database
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
1090 |
1938 | 1091 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2071
diff
changeset
|
1092 #if ORTHANC_ENABLE_PUGIXML == 1 |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1093 TEST(Toolbox, Xml) |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1094 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1095 Json::Value a; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1096 a["hello"] = "world"; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1097 a["42"] = 43; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1098 a["b"] = Json::arrayValue; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1099 a["b"].append("test"); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1100 a["b"].append("test2"); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1101 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1102 std::string s; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1103 Toolbox::JsonToXml(s, a); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1104 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1105 std::cout << s; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1106 } |
1050
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
1107 #endif |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1108 |
1050
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
1109 |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
1110 #if !defined(_WIN32) |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
1111 TEST(Toolbox, ExecuteSystemCommand) |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
1112 { |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
1113 std::vector<std::string> args(2); |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
1114 args[0] = "Hello"; |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
1115 args[1] = "World"; |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
1116 |
2140 | 1117 SystemToolbox::ExecuteSystemCommand("echo", args); |
1050
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
1118 } |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1119 #endif |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1120 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
1121 |
1102
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1122 TEST(Toolbox, IsInteger) |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1123 { |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1124 ASSERT_TRUE(Toolbox::IsInteger("00236")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1125 ASSERT_TRUE(Toolbox::IsInteger("-0042")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1126 ASSERT_TRUE(Toolbox::IsInteger("0")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1127 ASSERT_TRUE(Toolbox::IsInteger("-0")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1128 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1129 ASSERT_FALSE(Toolbox::IsInteger("")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1130 ASSERT_FALSE(Toolbox::IsInteger("42a")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1131 ASSERT_FALSE(Toolbox::IsInteger("42-")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1132 } |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1133 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
1134 |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
1135 TEST(Toolbox, StartsWith) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
1136 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
1137 ASSERT_TRUE(Toolbox::StartsWith("hello world", "")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
1138 ASSERT_TRUE(Toolbox::StartsWith("hello world", "hello")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
1139 ASSERT_TRUE(Toolbox::StartsWith("hello world", "h")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
1140 ASSERT_FALSE(Toolbox::StartsWith("hello world", "H")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
1141 ASSERT_FALSE(Toolbox::StartsWith("h", "hello")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
1142 ASSERT_TRUE(Toolbox::StartsWith("h", "h")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
1143 ASSERT_FALSE(Toolbox::StartsWith("", "h")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
1144 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
1145 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
1146 |
2043
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1147 TEST(Toolbox, UriEncode) |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1148 { |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1149 std::string s; |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1150 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1151 // Unreserved characters must not be modified |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1152 std::string t = "aAzZ09.-~_"; |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1153 Toolbox::UriEncode(s, t); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1154 ASSERT_EQ(t, s); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1155 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1156 Toolbox::UriEncode(s, "!#$&'()*+,/:;=?@[]"); ASSERT_EQ("%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D", s); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1157 Toolbox::UriEncode(s, "%"); ASSERT_EQ("%25", s); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1158 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1159 // Encode characters from UTF-8. This is the test string from the |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1160 // file "../Resources/EncodingTests.py" |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1161 Toolbox::UriEncode(s, "\x54\x65\x73\x74\xc3\xa9\xc3\xa4\xc3\xb6\xc3\xb2\xd0\x94\xce\x98\xc4\x9d\xd7\x93\xd8\xb5\xc4\xb7\xd1\x9b\xe0\xb9\x9b\xef\xbe\x88\xc4\xb0"); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1162 ASSERT_EQ("Test%C3%A9%C3%A4%C3%B6%C3%B2%D0%94%CE%98%C4%9D%D7%93%D8%B5%C4%B7%D1%9B%E0%B9%9B%EF%BE%88%C4%B0", s); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1163 } |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1164 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
1165 |
2071 | 1166 TEST(Toolbox, AccessJson) |
1167 { | |
1168 Json::Value v = Json::arrayValue; | |
1169 ASSERT_EQ("nope", Toolbox::GetJsonStringField(v, "hello", "nope")); | |
1170 | |
1171 v = Json::objectValue; | |
1172 ASSERT_EQ("nope", Toolbox::GetJsonStringField(v, "hello", "nope")); | |
1173 ASSERT_EQ(-10, Toolbox::GetJsonIntegerField(v, "hello", -10)); | |
2411
82d5e305fbd9
fix gcc warnings in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2364
diff
changeset
|
1174 ASSERT_EQ(10u, Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10)); |
2071 | 1175 ASSERT_TRUE(Toolbox::GetJsonBooleanField(v, "hello", true)); |
1176 | |
1177 v["hello"] = "world"; | |
1178 ASSERT_EQ("world", Toolbox::GetJsonStringField(v, "hello", "nope")); | |
1179 ASSERT_THROW(Toolbox::GetJsonIntegerField(v, "hello", -10), OrthancException); | |
1180 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException); | |
1181 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException); | |
1182 | |
1183 v["hello"] = -42; | |
1184 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException); | |
1185 ASSERT_EQ(-42, Toolbox::GetJsonIntegerField(v, "hello", -10)); | |
1186 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException); | |
1187 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException); | |
1188 | |
1189 v["hello"] = 42; | |
1190 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException); | |
1191 ASSERT_EQ(42, Toolbox::GetJsonIntegerField(v, "hello", -10)); | |
2411
82d5e305fbd9
fix gcc warnings in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2364
diff
changeset
|
1192 ASSERT_EQ(42u, Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10)); |
2071 | 1193 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException); |
1194 | |
1195 v["hello"] = false; | |
1196 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException); | |
1197 ASSERT_THROW(Toolbox::GetJsonIntegerField(v, "hello", -10), OrthancException); | |
1198 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException); | |
1199 ASSERT_FALSE(Toolbox::GetJsonBooleanField(v, "hello", true)); | |
1200 } | |
1201 | |
1202 | |
2513
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1203 TEST(Toolbox, LinesIterator) |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1204 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1205 std::string s; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1206 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1207 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1208 std::string content; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1209 Toolbox::LinesIterator it(content); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1210 ASSERT_FALSE(it.GetLine(s)); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1211 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1212 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1213 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1214 std::string content = "\n\r"; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1215 Toolbox::LinesIterator it(content); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1216 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1217 ASSERT_FALSE(it.GetLine(s)); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1218 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1219 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1220 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1221 std::string content = "\n Hello \n\nWorld\n\n"; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1222 Toolbox::LinesIterator it(content); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1223 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1224 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1225 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1226 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1227 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1228 ASSERT_FALSE(it.GetLine(s)); it.Next(); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1229 ASSERT_FALSE(it.GetLine(s)); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1230 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1231 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1232 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1233 std::string content = "\r Hello \r\rWorld\r\r"; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1234 Toolbox::LinesIterator it(content); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1235 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1236 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1237 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1238 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1239 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1240 ASSERT_FALSE(it.GetLine(s)); it.Next(); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1241 ASSERT_FALSE(it.GetLine(s)); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1242 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1243 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1244 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1245 std::string content = "\n\r Hello \n\r\n\rWorld\n\r\n\r"; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1246 Toolbox::LinesIterator it(content); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1247 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1248 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1249 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1250 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1251 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1252 ASSERT_FALSE(it.GetLine(s)); it.Next(); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1253 ASSERT_FALSE(it.GetLine(s)); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1254 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1255 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1256 { |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1257 std::string content = "\r\n Hello \r\n\r\nWorld\r\n\r\n"; |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1258 Toolbox::LinesIterator it(content); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1259 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1260 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1261 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1262 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1263 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1264 ASSERT_FALSE(it.GetLine(s)); it.Next(); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1265 ASSERT_FALSE(it.GetLine(s)); |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1266 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1267 } |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1268 |
97a74f0eac7a
loading DICOM dictionaries in sandboxed environments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2512
diff
changeset
|
1269 |
2920
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1270 TEST(Toolbox, SubstituteVariables) |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1271 { |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1272 std::map<std::string, std::string> env; |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1273 env["NOPE"] = "nope"; |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1274 env["WORLD"] = "world"; |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1275 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1276 ASSERT_EQ("Hello world\r\nWorld \r\nDone world\r\n", |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1277 Toolbox::SubstituteVariables( |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1278 "Hello ${WORLD}\r\nWorld ${HELLO}\r\nDone ${WORLD}\r\n", |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1279 env)); |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1280 |
2921
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1281 ASSERT_EQ("world A a B world C 'c' D {\"a\":\"b\"} E ", |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1282 Toolbox::SubstituteVariables( |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1283 "${WORLD} A ${WORLD2:-a} B ${WORLD:-b} C ${WORLD2:-\"'c'\"} D ${WORLD2:-'{\"a\":\"b\"}'} E ${WORLD2:-}", |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1284 env)); |
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1285 |
2920
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1286 SystemToolbox::GetEnvironmentVariables(env); |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1287 ASSERT_TRUE(env.find("NOPE") == env.end()); |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1288 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1289 // The "PATH" environment variable should always be available on |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1290 // machines running the unit tests |
3259
6f9398eb902d
unit test Toolbox.SubstituteVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3226
diff
changeset
|
1291 ASSERT_TRUE(env.find("PATH") != env.end() /* Case used by UNIX */ || |
6f9398eb902d
unit test Toolbox.SubstituteVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3226
diff
changeset
|
1292 env.find("Path") != env.end() /* Case used by Windows */); |
2921
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1293 |
3259
6f9398eb902d
unit test Toolbox.SubstituteVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3226
diff
changeset
|
1294 env["PATH"] = "hello"; |
6f9398eb902d
unit test Toolbox.SubstituteVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3226
diff
changeset
|
1295 ASSERT_EQ("AhelloB", |
2921
0a4428aad512
variable substitution with default value
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2920
diff
changeset
|
1296 Toolbox::SubstituteVariables("A${PATH}B", env)); |
2920
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1297 } |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1298 |
ad0e7def3338
Toolbox::SubstituteVariables and SystemToolbox::GetEnvironmentVariables
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2908
diff
changeset
|
1299 |
3174
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1300 TEST(MetricsRegistry, Basic) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1301 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1302 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1303 MetricsRegistry m; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1304 m.SetEnabled(false); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1305 m.SetValue("hello.world", 42.5f); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1306 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1307 std::string s; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1308 m.ExportPrometheusText(s); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1309 ASSERT_TRUE(s.empty()); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1310 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1311 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1312 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1313 MetricsRegistry m; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1314 m.Register("hello.world", MetricsType_Default); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1315 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1316 std::string s; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1317 m.ExportPrometheusText(s); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1318 ASSERT_TRUE(s.empty()); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1319 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1320 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1321 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1322 MetricsRegistry m; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1323 m.SetValue("hello.world", 42.5f); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1324 ASSERT_EQ(MetricsType_Default, m.GetMetricsType("hello.world")); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1325 ASSERT_THROW(m.GetMetricsType("nope"), OrthancException); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1326 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1327 std::string s; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1328 m.ExportPrometheusText(s); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1329 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1330 std::vector<std::string> t; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1331 Toolbox::TokenizeString(t, s, '\n'); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1332 ASSERT_EQ(2u, t.size()); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1333 ASSERT_EQ("hello.world 42.5 ", t[0].substr(0, 17)); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1334 ASSERT_TRUE(t[1].empty()); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1335 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1336 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1337 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1338 MetricsRegistry m; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1339 m.Register("hello.max", MetricsType_MaxOver10Seconds); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1340 m.SetValue("hello.max", 10); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1341 m.SetValue("hello.max", 20); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1342 m.SetValue("hello.max", -10); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1343 m.SetValue("hello.max", 5); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1344 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1345 m.Register("hello.min", MetricsType_MinOver10Seconds); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1346 m.SetValue("hello.min", 10); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1347 m.SetValue("hello.min", 20); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1348 m.SetValue("hello.min", -10); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1349 m.SetValue("hello.min", 5); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1350 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1351 m.Register("hello.default", MetricsType_Default); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1352 m.SetValue("hello.default", 10); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1353 m.SetValue("hello.default", 20); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1354 m.SetValue("hello.default", -10); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1355 m.SetValue("hello.default", 5); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1356 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1357 ASSERT_EQ(MetricsType_MaxOver10Seconds, m.GetMetricsType("hello.max")); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1358 ASSERT_EQ(MetricsType_MinOver10Seconds, m.GetMetricsType("hello.min")); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1359 ASSERT_EQ(MetricsType_Default, m.GetMetricsType("hello.default")); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1360 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1361 std::string s; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1362 m.ExportPrometheusText(s); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1363 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1364 std::vector<std::string> t; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1365 Toolbox::TokenizeString(t, s, '\n'); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1366 ASSERT_EQ(4u, t.size()); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1367 ASSERT_TRUE(t[3].empty()); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1368 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1369 std::map<std::string, std::string> u; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1370 for (size_t i = 0; i < t.size() - 1; i++) |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1371 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1372 std::vector<std::string> v; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1373 Toolbox::TokenizeString(v, t[i], ' '); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1374 u[v[0]] = v[1]; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1375 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1376 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1377 ASSERT_EQ("20", u["hello.max"]); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1378 ASSERT_EQ("-10", u["hello.min"]); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1379 ASSERT_EQ("5", u["hello.default"]); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1380 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1381 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1382 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1383 MetricsRegistry m; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1384 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1385 m.SetValue("a", 10); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1386 m.SetValue("b", 10, MetricsType_MinOver10Seconds); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1387 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1388 m.Register("c", MetricsType_MaxOver10Seconds); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1389 m.SetValue("c", 10, MetricsType_MinOver10Seconds); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1390 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1391 m.Register("d", MetricsType_MaxOver10Seconds); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1392 m.Register("d", MetricsType_Default); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1393 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1394 ASSERT_EQ(MetricsType_Default, m.GetMetricsType("a")); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1395 ASSERT_EQ(MetricsType_MinOver10Seconds, m.GetMetricsType("b")); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1396 ASSERT_EQ(MetricsType_MaxOver10Seconds, m.GetMetricsType("c")); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1397 ASSERT_EQ(MetricsType_Default, m.GetMetricsType("d")); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1398 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1399 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1400 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1401 MetricsRegistry m; |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1402 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1403 { |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1404 MetricsRegistry::Timer t1(m, "a"); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1405 MetricsRegistry::Timer t2(m, "b", MetricsType_MinOver10Seconds); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1406 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1407 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1408 ASSERT_EQ(MetricsType_MaxOver10Seconds, m.GetMetricsType("a")); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1409 ASSERT_EQ(MetricsType_MinOver10Seconds, m.GetMetricsType("b")); |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1410 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1411 } |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1412 |
8ea7c4546c3a
primitives to collect metrics in Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3061
diff
changeset
|
1413 |
0 | 1414 int main(int argc, char **argv) |
1415 { | |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1416 Logging::Initialize(); |
3581
4de1b019ca71
unit test DicomWebJson.PixelSpacing
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3561
diff
changeset
|
1417 Toolbox::InitializeGlobalLocale(NULL); |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1418 Logging::EnableInfoLevel(true); |
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1419 Toolbox::DetectEndianness(); |
2140 | 1420 SystemToolbox::MakeDirectory("UnitTestsResults"); |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1421 OrthancInitialize(); |
159
c08fbad40ddd
less verbosity in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
1422 |
0 | 1423 ::testing::InitGoogleTest(&argc, argv); |
1424 int result = RUN_ALL_TESTS(); | |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1425 |
63 | 1426 OrthancFinalize(); |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1427 Logging::Finalize(); |
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
1428 |
0 | 1429 return result; |
1430 } |