Mercurial > hg > orthanc
annotate UnitTestsSources/UnitTestsMain.cpp @ 2071:27fd34970c52
refactoring
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 14 Jul 2016 14:21:29 +0200 |
parents | 35ccba7adae9 |
children | dd609a99d39a |
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 |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
5 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
6 * This program is free software: you can redistribute it and/or |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
7 * modify it under the terms of the GNU General Public License as |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
9 * License, or (at your option) any later version. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
10 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
11 * In addition, as a special exception, the copyright holders of this |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
12 * program give permission to link the code of its release with the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
14 * that use the same license as the "OpenSSL" library), and distribute |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
15 * the linked executables. You must obey the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
16 * in all respects for all of the code used other than "OpenSSL". If you |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
17 * modify file(s) with this exception, you may extend this exception to |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
18 * your version of the file(s), but you are not obligated to do so. If |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
19 * you do not wish to do so, delete this exception statement from your |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
20 * version. If you delete this exception statement from all source files |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
21 * in the program, then also delete it here. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
22 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
23 * This program is distributed in the hope that it will be useful, but |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
24 * WITHOUT ANY WARRANTY; without even the implied warranty of |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
26 * General Public License for more details. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
27 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
28 * You should have received a copy of the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
810
diff
changeset
|
30 **/ |
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 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
827
diff
changeset
|
33 #include "PrecompiledHeadersUnitTests.h" |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
34 #include "../Core/EnumerationDictionary.h" |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
35 |
0 | 36 #include "gtest/gtest.h" |
37 | |
38 #include <ctype.h> | |
39 | |
40 #include "../Core/DicomFormat/DicomTag.h" | |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
41 #include "../Core/HttpServer/HttpToolbox.h" |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
42 #include "../Core/Logging.h" |
63 | 43 #include "../Core/OrthancException.h" |
0 | 44 #include "../Core/Toolbox.h" |
45 #include "../Core/Uuid.h" | |
63 | 46 #include "../OrthancServer/OrthancInitialization.h" |
0 | 47 |
1337 | 48 |
63 | 49 using namespace Orthanc; |
0 | 50 |
51 | |
52 TEST(Uuid, Generation) | |
53 { | |
54 for (int i = 0; i < 10; i++) | |
55 { | |
56 std::string s = Toolbox::GenerateUuid(); | |
57 ASSERT_TRUE(Toolbox::IsUuid(s)); | |
58 } | |
59 } | |
60 | |
61 TEST(Uuid, Test) | |
62 { | |
63 ASSERT_FALSE(Toolbox::IsUuid("")); | |
64 ASSERT_FALSE(Toolbox::IsUuid("012345678901234567890123456789012345")); | |
65 ASSERT_TRUE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-446655440000")); | |
708 | 66 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
|
67 ASSERT_FALSE(Toolbox::IsUuid("01234567890123456789012345678901234_")); |
402 | 68 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-44665544000")); |
69 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000")); | |
70 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000 ok")); | |
71 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000ok")); | |
72 } | |
73 | |
74 TEST(Toolbox, IsSHA1) | |
75 { | |
76 ASSERT_FALSE(Toolbox::IsSHA1("")); | |
77 ASSERT_FALSE(Toolbox::IsSHA1("01234567890123456789012345678901234567890123")); | |
78 ASSERT_FALSE(Toolbox::IsSHA1("012345678901234567890123456789012345678901234")); | |
79 ASSERT_TRUE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9")); | |
80 | |
1428 | 81 std::string sha = " b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9 "; |
82 ASSERT_TRUE(Toolbox::IsSHA1(sha)); | |
83 sha[3] = '\0'; | |
84 sha[53] = '\0'; | |
85 ASSERT_TRUE(Toolbox::IsSHA1(sha)); | |
86 sha[40] = '\0'; | |
87 ASSERT_FALSE(Toolbox::IsSHA1(sha)); | |
88 ASSERT_FALSE(Toolbox::IsSHA1(" ")); | |
89 | |
90 ASSERT_TRUE(Toolbox::IsSHA1("16738bc3-e47ed42a-43ce044c-a3414a45-cb069bd0")); | |
91 | |
402 | 92 std::string s; |
93 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog"); | |
94 ASSERT_TRUE(Toolbox::IsSHA1(s)); | |
95 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); | |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
96 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
97 ASSERT_FALSE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b_")); |
0 | 98 } |
99 | |
708 | 100 |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
101 TEST(ParseGetArguments, Basic) |
0 | 102 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
103 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
104 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
|
105 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
106 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
107 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
|
108 |
0 | 109 ASSERT_EQ(3u, a.size()); |
110 ASSERT_EQ(a["aaa"], "baaa"); | |
111 ASSERT_EQ(a["bb"], "a"); | |
112 ASSERT_EQ(a["aa"], "c"); | |
113 } | |
114 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
115 TEST(ParseGetArguments, BasicEmpty) |
0 | 116 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
117 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
118 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
|
119 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
120 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
121 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
|
122 |
0 | 123 ASSERT_EQ(3u, a.size()); |
124 ASSERT_EQ(a["aaa"], ""); | |
125 ASSERT_EQ(a["bb"], "aa"); | |
126 ASSERT_EQ(a["aa"], ""); | |
127 } | |
128 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
129 TEST(ParseGetArguments, Single) |
0 | 130 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
131 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
132 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
|
133 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
134 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
135 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
|
136 |
0 | 137 ASSERT_EQ(1u, a.size()); |
138 ASSERT_EQ(a["aaa"], "baaa"); | |
139 } | |
140 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
141 TEST(ParseGetArguments, SingleEmpty) |
0 | 142 { |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
143 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
144 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
|
145 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
146 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
147 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
|
148 |
0 | 149 ASSERT_EQ(1u, a.size()); |
150 ASSERT_EQ(a["aaa"], ""); | |
151 } | |
152 | |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
153 TEST(ParseGetQuery, Test1) |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
154 { |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
155 UriComponents uri; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
156 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
157 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
|
158 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
159 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
160 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
|
161 |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
162 ASSERT_EQ(3u, uri.size()); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
163 ASSERT_EQ("instances", uri[0]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
164 ASSERT_EQ("test", uri[1]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
165 ASSERT_EQ("world", uri[2]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
166 ASSERT_EQ(3u, a.size()); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
167 ASSERT_EQ(a["aaa"], "baaa"); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
168 ASSERT_EQ(a["bb"], "a"); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
169 ASSERT_EQ(a["aa"], "c"); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
170 } |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
171 |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
172 TEST(ParseGetQuery, Test2) |
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 UriComponents uri; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
175 IHttpHandler::GetArguments b; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
176 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
|
177 |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
178 IHttpHandler::Arguments a; |
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1430
diff
changeset
|
179 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
|
180 |
912
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
181 ASSERT_EQ(3u, uri.size()); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
182 ASSERT_EQ("instances", uri[0]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
183 ASSERT_EQ("test", uri[1]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
184 ASSERT_EQ("world", uri[2]); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
185 ASSERT_EQ(0u, a.size()); |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
186 } |
dcb2469f00f4
PluginsHttpHandler::RestApiGet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
890
diff
changeset
|
187 |
0 | 188 TEST(Uri, SplitUriComponents) |
189 { | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
190 UriComponents c, d; |
0 | 191 Toolbox::SplitUriComponents(c, "/cou/hello/world"); |
192 ASSERT_EQ(3u, c.size()); | |
193 ASSERT_EQ("cou", c[0]); | |
194 ASSERT_EQ("hello", c[1]); | |
195 ASSERT_EQ("world", c[2]); | |
196 | |
197 Toolbox::SplitUriComponents(c, "/cou/hello/world/"); | |
198 ASSERT_EQ(3u, c.size()); | |
199 ASSERT_EQ("cou", c[0]); | |
200 ASSERT_EQ("hello", c[1]); | |
201 ASSERT_EQ("world", c[2]); | |
202 | |
203 Toolbox::SplitUriComponents(c, "/cou/hello/world/a"); | |
204 ASSERT_EQ(4u, c.size()); | |
205 ASSERT_EQ("cou", c[0]); | |
206 ASSERT_EQ("hello", c[1]); | |
207 ASSERT_EQ("world", c[2]); | |
208 ASSERT_EQ("a", c[3]); | |
209 | |
210 Toolbox::SplitUriComponents(c, "/"); | |
211 ASSERT_EQ(0u, c.size()); | |
212 | |
213 Toolbox::SplitUriComponents(c, "/hello"); | |
214 ASSERT_EQ(1u, c.size()); | |
215 ASSERT_EQ("hello", c[0]); | |
216 | |
217 Toolbox::SplitUriComponents(c, "/hello/"); | |
218 ASSERT_EQ(1u, c.size()); | |
219 ASSERT_EQ("hello", c[0]); | |
220 | |
63 | 221 ASSERT_THROW(Toolbox::SplitUriComponents(c, ""), OrthancException); |
222 ASSERT_THROW(Toolbox::SplitUriComponents(c, "a"), OrthancException); | |
207 | 223 ASSERT_THROW(Toolbox::SplitUriComponents(c, "/coucou//coucou"), OrthancException); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
224 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
225 c.clear(); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
226 c.push_back("test"); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
227 ASSERT_EQ("/", Toolbox::FlattenUri(c, 10)); |
0 | 228 } |
229 | |
230 | |
966
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
231 TEST(Uri, Truncate) |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
232 { |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
233 UriComponents c, d; |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
234 Toolbox::SplitUriComponents(c, "/cou/hello/world"); |
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 Toolbox::TruncateUri(d, c, 0); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
237 ASSERT_EQ(3u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
238 ASSERT_EQ("cou", d[0]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
239 ASSERT_EQ("hello", d[1]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
240 ASSERT_EQ("world", d[2]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
241 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
242 Toolbox::TruncateUri(d, c, 1); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
243 ASSERT_EQ(2u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
244 ASSERT_EQ("hello", d[0]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
245 ASSERT_EQ("world", d[1]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
246 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
247 Toolbox::TruncateUri(d, c, 2); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
248 ASSERT_EQ(1u, d.size()); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
249 ASSERT_EQ("world", d[0]); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
250 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
251 Toolbox::TruncateUri(d, c, 3); |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
252 ASSERT_EQ(0u, d.size()); |
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, 4); |
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, 5); |
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 |
886652370ff2
accelerating REST API matching
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
949
diff
changeset
|
261 |
0 | 262 TEST(Uri, Child) |
263 { | |
264 UriComponents c1; Toolbox::SplitUriComponents(c1, "/hello/world"); | |
265 UriComponents c2; Toolbox::SplitUriComponents(c2, "/hello/hello"); | |
266 UriComponents c3; Toolbox::SplitUriComponents(c3, "/hello"); | |
267 UriComponents c4; Toolbox::SplitUriComponents(c4, "/world"); | |
268 UriComponents c5; Toolbox::SplitUriComponents(c5, "/"); | |
269 | |
270 ASSERT_TRUE(Toolbox::IsChildUri(c1, c1)); | |
271 ASSERT_FALSE(Toolbox::IsChildUri(c1, c2)); | |
272 ASSERT_FALSE(Toolbox::IsChildUri(c1, c3)); | |
273 ASSERT_FALSE(Toolbox::IsChildUri(c1, c4)); | |
274 ASSERT_FALSE(Toolbox::IsChildUri(c1, c5)); | |
275 | |
276 ASSERT_FALSE(Toolbox::IsChildUri(c2, c1)); | |
277 ASSERT_TRUE(Toolbox::IsChildUri(c2, c2)); | |
278 ASSERT_FALSE(Toolbox::IsChildUri(c2, c3)); | |
279 ASSERT_FALSE(Toolbox::IsChildUri(c2, c4)); | |
280 ASSERT_FALSE(Toolbox::IsChildUri(c2, c5)); | |
281 | |
282 ASSERT_TRUE(Toolbox::IsChildUri(c3, c1)); | |
283 ASSERT_TRUE(Toolbox::IsChildUri(c3, c2)); | |
284 ASSERT_TRUE(Toolbox::IsChildUri(c3, c3)); | |
285 ASSERT_FALSE(Toolbox::IsChildUri(c3, c4)); | |
286 ASSERT_FALSE(Toolbox::IsChildUri(c3, c5)); | |
287 | |
288 ASSERT_FALSE(Toolbox::IsChildUri(c4, c1)); | |
289 ASSERT_FALSE(Toolbox::IsChildUri(c4, c2)); | |
290 ASSERT_FALSE(Toolbox::IsChildUri(c4, c3)); | |
291 ASSERT_TRUE(Toolbox::IsChildUri(c4, c4)); | |
292 ASSERT_FALSE(Toolbox::IsChildUri(c4, c5)); | |
293 | |
294 ASSERT_TRUE(Toolbox::IsChildUri(c5, c1)); | |
295 ASSERT_TRUE(Toolbox::IsChildUri(c5, c2)); | |
296 ASSERT_TRUE(Toolbox::IsChildUri(c5, c3)); | |
297 ASSERT_TRUE(Toolbox::IsChildUri(c5, c4)); | |
298 ASSERT_TRUE(Toolbox::IsChildUri(c5, c5)); | |
299 } | |
300 | |
301 TEST(Uri, AutodetectMimeType) | |
302 { | |
303 ASSERT_EQ("", Toolbox::AutodetectMimeType("../NOTES")); | |
304 ASSERT_EQ("", Toolbox::AutodetectMimeType("")); | |
305 ASSERT_EQ("", Toolbox::AutodetectMimeType("/")); | |
306 ASSERT_EQ("", Toolbox::AutodetectMimeType("a/a")); | |
307 | |
308 ASSERT_EQ("text/plain", Toolbox::AutodetectMimeType("../NOTES.txt")); | |
309 ASSERT_EQ("text/plain", Toolbox::AutodetectMimeType("../coucou.xml/NOTES.txt")); | |
310 ASSERT_EQ("text/xml", Toolbox::AutodetectMimeType("../.xml")); | |
311 | |
312 ASSERT_EQ("application/javascript", Toolbox::AutodetectMimeType("NOTES.js")); | |
313 ASSERT_EQ("application/json", Toolbox::AutodetectMimeType("NOTES.json")); | |
314 ASSERT_EQ("application/pdf", Toolbox::AutodetectMimeType("NOTES.pdf")); | |
315 ASSERT_EQ("text/css", Toolbox::AutodetectMimeType("NOTES.css")); | |
316 ASSERT_EQ("text/html", Toolbox::AutodetectMimeType("NOTES.html")); | |
317 ASSERT_EQ("text/plain", Toolbox::AutodetectMimeType("NOTES.txt")); | |
318 ASSERT_EQ("text/xml", Toolbox::AutodetectMimeType("NOTES.xml")); | |
319 ASSERT_EQ("image/gif", Toolbox::AutodetectMimeType("NOTES.gif")); | |
320 ASSERT_EQ("image/jpeg", Toolbox::AutodetectMimeType("NOTES.jpg")); | |
321 ASSERT_EQ("image/jpeg", Toolbox::AutodetectMimeType("NOTES.jpeg")); | |
322 ASSERT_EQ("image/png", Toolbox::AutodetectMimeType("NOTES.png")); | |
323 } | |
324 | |
22 | 325 TEST(Toolbox, ComputeMD5) |
326 { | |
327 std::string s; | |
328 | |
329 // # echo -n "Hello" | md5sum | |
330 | |
331 Toolbox::ComputeMD5(s, "Hello"); | |
332 ASSERT_EQ("8b1a9953c4611296a827abf8c47804d7", s); | |
333 Toolbox::ComputeMD5(s, ""); | |
334 ASSERT_EQ("d41d8cd98f00b204e9800998ecf8427e", s); | |
335 } | |
336 | |
177 | 337 TEST(Toolbox, ComputeSHA1) |
338 { | |
339 std::string s; | |
340 | |
341 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog"); | |
342 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s); | |
343 Toolbox::ComputeSHA1(s, ""); | |
344 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s); | |
345 } | |
346 | |
347 | |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
348 static std::string EncodeBase64Bis(const std::string& s) |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
349 { |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
350 std::string result; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
351 Toolbox::EncodeBase64(result, s); |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
352 return result; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
353 } |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
354 |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
355 |
24 | 356 TEST(Toolbox, Base64) |
357 { | |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
358 ASSERT_EQ("", EncodeBase64Bis("")); |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
359 ASSERT_EQ("YQ==", EncodeBase64Bis("a")); |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
360 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
361 const std::string hello = "SGVsbG8gd29ybGQ="; |
809
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
362 ASSERT_EQ(hello, EncodeBase64Bis("Hello world")); |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
363 |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
364 std::string decoded; |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
365 Toolbox::DecodeBase64(decoded, hello); |
8ce2f69436ca
do not return strings with base64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
803
diff
changeset
|
366 ASSERT_EQ("Hello world", decoded); |
1988
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1976
diff
changeset
|
367 |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1976
diff
changeset
|
368 // Invalid character |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1976
diff
changeset
|
369 ASSERT_THROW(Toolbox::DecodeBase64(decoded, "?"), OrthancException); |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1976
diff
changeset
|
370 |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1976
diff
changeset
|
371 // All the allowed characters |
e29aea2349b9
test validity of base64 strings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1976
diff
changeset
|
372 Toolbox::DecodeBase64(decoded, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="); |
24 | 373 } |
374 | |
87
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
375 TEST(Toolbox, PathToExecutable) |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
376 { |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
377 printf("[%s]\n", Toolbox::GetPathToExecutable().c_str()); |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
378 printf("[%s]\n", Toolbox::GetDirectoryOfExecutable().c_str()); |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
379 } |
8517e2c44283
path to configuration
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
63
diff
changeset
|
380 |
247
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
381 TEST(Toolbox, StripSpaces) |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
382 { |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
383 ASSERT_EQ("", Toolbox::StripSpaces(" \t \r \n ")); |
c9b3ba0fd140
path management in zip files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
235
diff
changeset
|
384 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
|
385 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
|
386 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
|
387 } |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
388 |
707
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
389 TEST(Toolbox, Case) |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
390 { |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
391 std::string s = "CoU"; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
392 std::string ss; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
393 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
394 Toolbox::ToUpperCase(ss, s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
395 ASSERT_EQ("COU", ss); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
396 Toolbox::ToLowerCase(ss, s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
397 ASSERT_EQ("cou", 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 s = "CoU"; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
400 Toolbox::ToUpperCase(s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
401 ASSERT_EQ("COU", s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
402 |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
403 s = "CoU"; |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
404 Toolbox::ToLowerCase(s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
405 ASSERT_EQ("cou", s); |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
406 } |
203157cb4fde
unit tests of httpclient
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
674
diff
changeset
|
407 |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
408 |
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
409 TEST(Logger, Basic) |
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
410 { |
102
7593b57dc1bf
switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
101
diff
changeset
|
411 LOG(INFO) << "I say hello"; |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
412 } |
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
413 |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
414 TEST(Toolbox, ConvertFromLatin1) |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
415 { |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
416 // 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
|
417 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
|
418 |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
419 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
|
420 ASSERT_EQ("&abc", Toolbox::ConvertToAscii(s)); |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
421 |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
422 // Open in Emacs, then save with UTF-8 encoding, then "hexdump -C" |
949
766a57997121
enumeration for encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
930
diff
changeset
|
423 std::string utf8 = Toolbox::ConvertToUtf8(s, Encoding_Latin1); |
235 | 424 ASSERT_EQ(15u, utf8.size()); |
107
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
425 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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 } |
3b45473c0a73
replace boost::locale with iconv for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
102
diff
changeset
|
441 |
336 | 442 TEST(Toolbox, UrlDecode) |
443 { | |
444 std::string s; | |
445 | |
446 s = "Hello%20World"; | |
447 Toolbox::UrlDecode(s); | |
448 ASSERT_EQ("Hello World", s); | |
449 | |
337 | 450 s = "%21%23%24%26%27%28%29%2A%2B%2c%2f%3A%3b%3d%3f%40%5B%5D%90%ff"; |
336 | 451 Toolbox::UrlDecode(s); |
337 | 452 std::string ss = "!#$&'()*+,/:;=?@[]"; |
453 ss.push_back((char) 144); | |
454 ss.push_back((char) 255); | |
455 ASSERT_EQ(ss, s); | |
336 | 456 |
457 s = "(2000%2C00A4)+Other"; | |
458 Toolbox::UrlDecode(s); | |
459 ASSERT_EQ("(2000,00A4) Other", s); | |
460 } | |
461 | |
100
27dc762e3dc8
getting rid of static dcmtk for debian
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
87
diff
changeset
|
462 |
1976
325772dadcd6
Macro "__linux" (now obsolete) replaced by macro "__linux__"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1971
diff
changeset
|
463 #if defined(__linux__) |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
464 TEST(OrthancInitialization, AbsoluteDirectory) |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
465 { |
810
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
466 ASSERT_EQ("/tmp/hello", Configuration::InterpretRelativePath("/tmp", "hello")); |
401a9633e492
configuration into a namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
809
diff
changeset
|
467 ASSERT_EQ("/tmp", Configuration::InterpretRelativePath("/tmp", "/tmp")); |
429
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
468 } |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
469 #endif |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
470 |
09b3c6265a94
unit test for fedora 18 problem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
402
diff
changeset
|
471 |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
472 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
473 #include "../OrthancServer/ServerEnumerations.h" |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
474 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
475 TEST(EnumerationDictionary, Simple) |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
476 { |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
477 Toolbox::EnumerationDictionary<MetadataType> d; |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
478 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
479 ASSERT_THROW(d.Translate("ReceptionDate"), OrthancException); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
480 ASSERT_EQ(MetadataType_ModifiedFrom, d.Translate("5")); |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
435
diff
changeset
|
481 ASSERT_EQ(256, d.Translate("256")); |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
482 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
483 d.Add(MetadataType_Instance_ReceptionDate, "ReceptionDate"); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
484 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
485 ASSERT_EQ(MetadataType_Instance_ReceptionDate, d.Translate("ReceptionDate")); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
486 ASSERT_EQ(MetadataType_Instance_ReceptionDate, d.Translate("2")); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
487 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
|
488 |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
489 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
|
490 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
|
491 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
|
492 d.Add(MetadataType_ModifiedFrom, "ModifiedFrom"); // ok |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
493 } |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
494 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
495 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
496 TEST(EnumerationDictionary, ServerEnumerations) |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
497 { |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
498 ASSERT_STREQ("Patient", EnumerationToString(ResourceType_Patient)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
499 ASSERT_STREQ("Study", EnumerationToString(ResourceType_Study)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
500 ASSERT_STREQ("Series", EnumerationToString(ResourceType_Series)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
501 ASSERT_STREQ("Instance", EnumerationToString(ResourceType_Instance)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
502 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
503 ASSERT_STREQ("ModifiedSeries", EnumerationToString(ChangeType_ModifiedSeries)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
504 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
505 ASSERT_STREQ("Failure", EnumerationToString(StoreStatus_Failure)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
506 ASSERT_STREQ("Success", EnumerationToString(StoreStatus_Success)); |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
507 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
508 ASSERT_STREQ("CompletedSeries", EnumerationToString(ChangeType_CompletedSeries)); |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
509 |
437 | 510 ASSERT_EQ("IndexInSeries", EnumerationToString(MetadataType_Instance_IndexInSeries)); |
511 ASSERT_EQ("LastUpdate", EnumerationToString(MetadataType_LastUpdate)); | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
512 |
559 | 513 ASSERT_EQ(ResourceType_Patient, StringToResourceType("PATienT")); |
514 ASSERT_EQ(ResourceType_Study, StringToResourceType("STudy")); | |
515 ASSERT_EQ(ResourceType_Series, StringToResourceType("SeRiEs")); | |
516 ASSERT_EQ(ResourceType_Instance, StringToResourceType("INStance")); | |
517 ASSERT_EQ(ResourceType_Instance, StringToResourceType("IMagE")); | |
518 ASSERT_THROW(StringToResourceType("heLLo"), OrthancException); | |
519 | |
435
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
520 ASSERT_EQ(2047, StringToMetadata("2047")); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
521 ASSERT_THROW(StringToMetadata("Ceci est un test"), OrthancException); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
522 ASSERT_THROW(RegisterUserMetadata(128, ""), OrthancException); // too low (< 1024) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
523 ASSERT_THROW(RegisterUserMetadata(128000, ""), OrthancException); // too high (> 65535) |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
524 RegisterUserMetadata(2047, "Ceci est un test"); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
525 ASSERT_EQ(2047, StringToMetadata("2047")); |
28ba73274919
registration of user-defined metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
434
diff
changeset
|
526 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
|
527 |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
528 ASSERT_STREQ("Generic", EnumerationToString(StringToModalityManufacturer("Generic"))); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
529 ASSERT_STREQ("StoreScp", EnumerationToString(StringToModalityManufacturer("StoreScp"))); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
530 ASSERT_STREQ("ClearCanvas", EnumerationToString(StringToModalityManufacturer("ClearCanvas"))); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
531 ASSERT_STREQ("MedInria", EnumerationToString(StringToModalityManufacturer("MedInria"))); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
532 ASSERT_STREQ("Dcm4Chee", EnumerationToString(StringToModalityManufacturer("Dcm4Chee"))); |
7366a0bdda6a
attempt of fix for Syngo.Via
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1428
diff
changeset
|
533 ASSERT_STREQ("SyngoVia", EnumerationToString(StringToModalityManufacturer("SyngoVia"))); |
1846
3dcf5c0734c9
New "AgfaImpax" modality manufacturer for AGFA Impax
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1525
diff
changeset
|
534 ASSERT_STREQ("AgfaImpax", EnumerationToString(StringToModalityManufacturer("AgfaImpax"))); |
1856
36ab170733d6
Made eFilm version explicit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1852
diff
changeset
|
535 ASSERT_STREQ("EFilm2", EnumerationToString(StringToModalityManufacturer("EFilm2"))); |
1852
efbc3afd6cd3
Efilm and Vitrea manufacturers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1846
diff
changeset
|
536 ASSERT_STREQ("Vitrea", EnumerationToString(StringToModalityManufacturer("Vitrea"))); |
434
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
537 } |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
538 |
ccf3a0a43dac
EnumerationDictionary
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
430
diff
changeset
|
539 |
450 | 540 |
483
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
541 TEST(Toolbox, WriteFile) |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
542 { |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
543 std::string path; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
544 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
545 { |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
546 Toolbox::TemporaryFile tmp; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
547 path = tmp.GetPath(); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
548 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
549 std::string s; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
550 s.append("Hello"); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
551 s.push_back('\0'); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
552 s.append("World"); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
553 ASSERT_EQ(11u, s.size()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
554 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
555 Toolbox::WriteFile(s, path.c_str()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
556 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
557 std::string t; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
558 Toolbox::ReadFile(t, path.c_str()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
559 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
560 ASSERT_EQ(11u, t.size()); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
561 ASSERT_EQ(0, t[5]); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
562 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
|
563 |
ff11ba08e5d0
Toolbox::ReadHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
564 std::string h; |
ff11ba08e5d0
Toolbox::ReadHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
565 ASSERT_EQ(true, Toolbox::ReadHeader(h, path.c_str(), 1)); |
1971
869a87c08673
fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1969
diff
changeset
|
566 ASSERT_EQ(1u, h.size()); |
1933
ff11ba08e5d0
Toolbox::ReadHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
567 ASSERT_EQ('H', h[0]); |
1969
5e40f88f4eba
fix for old versions of mingw
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1942
diff
changeset
|
568 ASSERT_TRUE(Toolbox::ReadHeader(h, path.c_str(), 0)); |
1971
869a87c08673
fix for mingw <= 4.2
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1969
diff
changeset
|
569 ASSERT_EQ(0u, h.size()); |
1969
5e40f88f4eba
fix for old versions of mingw
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1942
diff
changeset
|
570 ASSERT_FALSE(Toolbox::ReadHeader(h, path.c_str(), 32)); |
1933
ff11ba08e5d0
Toolbox::ReadHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
571 ASSERT_EQ(11u, h.size()); |
ff11ba08e5d0
Toolbox::ReadHeader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
572 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
|
573 } |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
574 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
575 std::string u; |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
576 ASSERT_THROW(Toolbox::ReadFile(u, path.c_str()), OrthancException); |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
577 } |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
578 |
8c3573d28868
export dicom instances to the filesystem
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
476
diff
changeset
|
579 |
608 | 580 TEST(Toolbox, Wildcard) |
581 { | |
582 ASSERT_EQ("abcd", Toolbox::WildcardToRegularExpression("abcd")); | |
583 ASSERT_EQ("ab.*cd", Toolbox::WildcardToRegularExpression("ab*cd")); | |
584 ASSERT_EQ("ab..cd", Toolbox::WildcardToRegularExpression("ab??cd")); | |
585 ASSERT_EQ("a.*b.c.*d", Toolbox::WildcardToRegularExpression("a*b?c*d")); | |
586 ASSERT_EQ("a\\{b\\]", Toolbox::WildcardToRegularExpression("a{b]")); | |
587 } | |
588 | |
589 | |
590 TEST(Toolbox, Tokenize) | |
591 { | |
592 std::vector<std::string> t; | |
593 | |
594 Toolbox::TokenizeString(t, "", ','); | |
1492 | 595 ASSERT_EQ(1u, t.size()); |
608 | 596 ASSERT_EQ("", t[0]); |
597 | |
598 Toolbox::TokenizeString(t, "abc", ','); | |
1492 | 599 ASSERT_EQ(1u, t.size()); |
608 | 600 ASSERT_EQ("abc", t[0]); |
601 | |
602 Toolbox::TokenizeString(t, "ab,cd,ef,", ','); | |
1492 | 603 ASSERT_EQ(4u, t.size()); |
608 | 604 ASSERT_EQ("ab", t[0]); |
605 ASSERT_EQ("cd", t[1]); | |
606 ASSERT_EQ("ef", t[2]); | |
607 ASSERT_EQ("", t[3]); | |
608 } | |
609 | |
1086
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
610 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
|
611 { |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
612 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
|
613 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
|
614 ASSERT_EQ(Encoding_Latin1, StringToEncoding(EnumerationToString(Encoding_Latin1))); |
1087 | 615 ASSERT_EQ(Encoding_Latin2, StringToEncoding(EnumerationToString(Encoding_Latin2))); |
616 ASSERT_EQ(Encoding_Latin3, StringToEncoding(EnumerationToString(Encoding_Latin3))); | |
617 ASSERT_EQ(Encoding_Latin4, StringToEncoding(EnumerationToString(Encoding_Latin4))); | |
618 ASSERT_EQ(Encoding_Latin5, StringToEncoding(EnumerationToString(Encoding_Latin5))); | |
619 ASSERT_EQ(Encoding_Cyrillic, StringToEncoding(EnumerationToString(Encoding_Cyrillic))); | |
620 ASSERT_EQ(Encoding_Arabic, StringToEncoding(EnumerationToString(Encoding_Arabic))); | |
621 ASSERT_EQ(Encoding_Greek, StringToEncoding(EnumerationToString(Encoding_Greek))); | |
622 ASSERT_EQ(Encoding_Hebrew, StringToEncoding(EnumerationToString(Encoding_Hebrew))); | |
1090
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
623 ASSERT_EQ(Encoding_Japanese, StringToEncoding(EnumerationToString(Encoding_Japanese))); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
624 ASSERT_EQ(Encoding_Chinese, StringToEncoding(EnumerationToString(Encoding_Chinese))); |
e494ceb8d763
support more encodings
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1087
diff
changeset
|
625 ASSERT_EQ(Encoding_Thai, StringToEncoding(EnumerationToString(Encoding_Thai))); |
1086
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
626 |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
627 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
|
628 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
|
629 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
|
630 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
|
631 |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
632 ASSERT_EQ(ImageFormat_Png, StringToImageFormat(EnumerationToString(ImageFormat_Png))); |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
633 } |
e56c3ed8d738
Parameter to set the default encoding for DICOM files without SpecificCharacterSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1050
diff
changeset
|
634 |
608 | 635 |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
636 |
1976
325772dadcd6
Macro "__linux" (now obsolete) replaced by macro "__linux__"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1971
diff
changeset
|
637 #if defined(__linux__) |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
638 #include <endian.h> |
1337 | 639 #elif defined(__FreeBSD__) |
640 #include <machine/endian.h> | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
641 #endif |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
642 |
1337 | 643 |
637 | 644 TEST(Toolbox, Endianness) |
645 { | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
646 // Parts of this test come from Adam Conrad |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
647 // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728822#5 |
637 | 648 |
1337 | 649 |
650 /** | |
651 * Windows and OS X are assumed to always little-endian. | |
652 **/ | |
653 | |
654 #if defined(_WIN32) || defined(__APPLE__) | |
637 | 655 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
656 |
918 | 657 |
1337 | 658 /** |
659 * Linux. | |
660 **/ | |
661 | |
1976
325772dadcd6
Macro "__linux" (now obsolete) replaced by macro "__linux__"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1971
diff
changeset
|
662 #elif defined(__linux__) || defined(__FreeBSD_kernel__) |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
663 |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
664 #if !defined(__BYTE_ORDER) |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
665 # error Support your platform here |
637 | 666 #endif |
667 | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
668 # if __BYTE_ORDER == __BIG_ENDIAN |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
669 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness()); |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
670 # else // __LITTLE_ENDIAN |
637 | 671 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
672 # endif |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
673 |
1337 | 674 |
675 /** | |
676 * FreeBSD. | |
677 **/ | |
678 | |
679 #elif defined(__FreeBSD__) | |
680 # if _BYTE_ORDER == _BIG_ENDIAN | |
681 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness()); | |
682 # else // _LITTLE_ENDIAN | |
683 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness()); | |
684 # endif | |
685 | |
674
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
686 #else |
d76b747aec1b
improved check for big endianness
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
637
diff
changeset
|
687 #error Support your platform here |
637 | 688 #endif |
689 } | |
690 | |
691 | |
1938 | 692 #include "../Core/Endianness.h" |
693 | |
694 static void ASSERT_EQ16(uint16_t a, uint16_t b) | |
695 { | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
696 #ifdef __MINGW32__ |
1938 | 697 // This cast solves a linking problem with MinGW |
698 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
|
699 #else |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
700 ASSERT_EQ(a, b); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
701 #endif |
1938 | 702 } |
703 | |
704 static void ASSERT_NE16(uint16_t a, uint16_t b) | |
705 { | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
706 #ifdef __MINGW32__ |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
707 // This cast solves a linking problem with MinGW |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
708 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
|
709 #else |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
710 ASSERT_NE(a, b); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
711 #endif |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
712 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
713 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
714 static void ASSERT_EQ32(uint32_t a, uint32_t b) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
715 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
716 #ifdef __MINGW32__ |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
717 // This cast solves a linking problem with MinGW |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
718 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
|
719 #else |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
720 ASSERT_EQ(a, b); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
721 #endif |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
722 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
723 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
724 static void ASSERT_NE32(uint32_t a, uint32_t b) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
725 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
726 #ifdef __MINGW32__ |
1938 | 727 // This cast solves a linking problem with MinGW |
728 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
|
729 #else |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
730 ASSERT_NE(a, b); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
731 #endif |
1938 | 732 } |
733 | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
734 static void ASSERT_EQ64(uint64_t a, uint64_t b) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
735 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
736 #ifdef __MINGW32__ |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
737 // This cast solves a linking problem with MinGW |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
738 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
|
739 #else |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
740 ASSERT_EQ(a, b); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
741 #endif |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
742 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
743 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
744 static void ASSERT_NE64(uint64_t a, uint64_t b) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
745 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
746 #ifdef __MINGW32__ |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
747 // This cast solves a linking problem with MinGW |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
748 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
|
749 #else |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
750 ASSERT_NE(a, b); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
751 #endif |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
752 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
753 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
754 |
1938 | 755 |
756 TEST(Toolbox, EndiannessConversions16) | |
757 { | |
758 Endianness e = Toolbox::DetectEndianness(); | |
759 | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
760 for (unsigned int i = 0; i < 65536; i += 17) |
1938 | 761 { |
762 uint16_t v = static_cast<uint16_t>(i); | |
763 ASSERT_EQ16(v, be16toh(htobe16(v))); | |
764 ASSERT_EQ16(v, le16toh(htole16(v))); | |
765 | |
766 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&v); | |
767 if (bytes[0] != bytes[1]) | |
768 { | |
769 ASSERT_NE16(v, le16toh(htobe16(v))); | |
770 ASSERT_NE16(v, be16toh(htole16(v))); | |
771 } | |
772 else | |
773 { | |
774 ASSERT_EQ16(v, le16toh(htobe16(v))); | |
775 ASSERT_EQ16(v, be16toh(htole16(v))); | |
776 } | |
777 | |
778 switch (e) | |
779 { | |
780 case Endianness_Little: | |
781 ASSERT_EQ16(v, htole16(v)); | |
782 if (bytes[0] != bytes[1]) | |
783 { | |
784 ASSERT_NE16(v, htobe16(v)); | |
785 } | |
786 else | |
787 { | |
788 ASSERT_EQ16(v, htobe16(v)); | |
789 } | |
790 break; | |
791 | |
792 case Endianness_Big: | |
793 ASSERT_EQ16(v, htobe16(v)); | |
794 if (bytes[0] != bytes[1]) | |
795 { | |
796 ASSERT_NE16(v, htole16(v)); | |
797 } | |
798 else | |
799 { | |
800 ASSERT_EQ16(v, htole16(v)); | |
801 } | |
802 break; | |
803 | |
804 default: | |
805 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
806 } | |
807 } | |
808 } | |
809 | |
810 | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
811 TEST(Toolbox, EndiannessConversions32) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
812 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
813 const uint32_t v = 0xff010203u; |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
814 const uint32_t r = 0x030201ffu; |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
815 ASSERT_EQ32(v, be32toh(htobe32(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
816 ASSERT_EQ32(v, le32toh(htole32(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
817 ASSERT_NE32(v, be32toh(htole32(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
818 ASSERT_NE32(v, le32toh(htobe32(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
819 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
820 switch (Toolbox::DetectEndianness()) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
821 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
822 case Endianness_Little: |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
823 ASSERT_EQ32(r, htobe32(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
824 ASSERT_EQ32(v, htole32(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
825 ASSERT_EQ32(r, be32toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
826 ASSERT_EQ32(v, le32toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
827 break; |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
828 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
829 case Endianness_Big: |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
830 ASSERT_EQ32(v, htobe32(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
831 ASSERT_EQ32(r, htole32(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
832 ASSERT_EQ32(v, be32toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
833 ASSERT_EQ32(r, le32toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
834 break; |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
835 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
836 default: |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
837 throw OrthancException(ErrorCode_ParameterOutOfRange); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
838 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
839 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
840 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
841 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
842 TEST(Toolbox, EndiannessConversions64) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
843 { |
1942 | 844 const uint64_t v = 0xff01020304050607LL; |
845 const uint64_t r = 0x07060504030201ffLL; | |
1939
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
846 ASSERT_EQ64(v, be64toh(htobe64(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
847 ASSERT_EQ64(v, le64toh(htole64(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
848 ASSERT_NE64(v, be64toh(htole64(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
849 ASSERT_NE64(v, le64toh(htobe64(v))); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
850 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
851 switch (Toolbox::DetectEndianness()) |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
852 { |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
853 case Endianness_Little: |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
854 ASSERT_EQ64(r, htobe64(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
855 ASSERT_EQ64(v, htole64(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
856 ASSERT_EQ64(r, be64toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
857 ASSERT_EQ64(v, le64toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
858 break; |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
859 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
860 case Endianness_Big: |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
861 ASSERT_EQ64(v, htobe64(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
862 ASSERT_EQ64(r, htole64(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
863 ASSERT_EQ64(v, be64toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
864 ASSERT_EQ64(r, le64toh(v)); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
865 break; |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
866 |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
867 default: |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
868 throw OrthancException(ErrorCode_ParameterOutOfRange); |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
869 } |
d80a4fe8ffcc
tests EndiannessConversions32/64
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1938
diff
changeset
|
870 } |
1938 | 871 |
872 | |
873 | |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
874 #if ORTHANC_PUGIXML_ENABLED == 1 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
875 TEST(Toolbox, Xml) |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
876 { |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
877 Json::Value a; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
878 a["hello"] = "world"; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
879 a["42"] = 43; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
880 a["b"] = Json::arrayValue; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
881 a["b"].append("test"); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
882 a["b"].append("test2"); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
883 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
884 std::string s; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
885 Toolbox::JsonToXml(s, a); |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
886 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
887 std::cout << s; |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
888 } |
1050
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
889 #endif |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
890 |
1050
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
891 |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
892 #if !defined(_WIN32) |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
893 TEST(Toolbox, ExecuteSystemCommand) |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
894 { |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
895 std::vector<std::string> args(2); |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
896 args[0] = "Hello"; |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
897 args[1] = "World"; |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
898 |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
899 Toolbox::ExecuteSystemCommand("echo", args); |
64f1842aae2e
Toolbox::ExecuteSystemCommand
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1045
diff
changeset
|
900 } |
1045
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
901 #endif |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
902 |
0bfeeb6d340f
json to xml conversion with pugixml
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
971
diff
changeset
|
903 |
1102
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
904 TEST(Toolbox, IsInteger) |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
905 { |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
906 ASSERT_TRUE(Toolbox::IsInteger("00236")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
907 ASSERT_TRUE(Toolbox::IsInteger("-0042")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
908 ASSERT_TRUE(Toolbox::IsInteger("0")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
909 ASSERT_TRUE(Toolbox::IsInteger("-0")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
910 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
911 ASSERT_FALSE(Toolbox::IsInteger("")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
912 ASSERT_FALSE(Toolbox::IsInteger("42a")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
913 ASSERT_FALSE(Toolbox::IsInteger("42-")); |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
914 } |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
915 |
ce6386b37afd
avoid unnecessary exceptions on Orthanc startup
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1090
diff
changeset
|
916 |
1430
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
917 TEST(Toolbox, StartsWith) |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
918 { |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
919 ASSERT_TRUE(Toolbox::StartsWith("hello world", "")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
920 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
|
921 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
|
922 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
|
923 ASSERT_FALSE(Toolbox::StartsWith("h", "hello")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
924 ASSERT_TRUE(Toolbox::StartsWith("h", "h")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
925 ASSERT_FALSE(Toolbox::StartsWith("", "h")); |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
926 } |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
927 |
ad94a3583b07
Plugins can send answers as multipart messages
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1429
diff
changeset
|
928 |
2043
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
929 TEST(Toolbox, UriEncode) |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
930 { |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
931 std::string s; |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
932 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
933 // Unreserved characters must not be modified |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
934 std::string t = "aAzZ09.-~_"; |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
935 Toolbox::UriEncode(s, t); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
936 ASSERT_EQ(t, s); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
937 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
938 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
|
939 Toolbox::UriEncode(s, "%"); ASSERT_EQ("%25", s); |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
940 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
941 // 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
|
942 // file "../Resources/EncodingTests.py" |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
943 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
|
944 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
|
945 } |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
946 |
35ccba7adae9
Toolbox::UriEncode
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2017
diff
changeset
|
947 |
2071 | 948 TEST(Toolbox, AccessJson) |
949 { | |
950 Json::Value v = Json::arrayValue; | |
951 ASSERT_EQ("nope", Toolbox::GetJsonStringField(v, "hello", "nope")); | |
952 | |
953 v = Json::objectValue; | |
954 ASSERT_EQ("nope", Toolbox::GetJsonStringField(v, "hello", "nope")); | |
955 ASSERT_EQ(-10, Toolbox::GetJsonIntegerField(v, "hello", -10)); | |
956 ASSERT_EQ(10, Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10)); | |
957 ASSERT_TRUE(Toolbox::GetJsonBooleanField(v, "hello", true)); | |
958 | |
959 v["hello"] = "world"; | |
960 ASSERT_EQ("world", Toolbox::GetJsonStringField(v, "hello", "nope")); | |
961 ASSERT_THROW(Toolbox::GetJsonIntegerField(v, "hello", -10), OrthancException); | |
962 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException); | |
963 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException); | |
964 | |
965 v["hello"] = -42; | |
966 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException); | |
967 ASSERT_EQ(-42, Toolbox::GetJsonIntegerField(v, "hello", -10)); | |
968 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException); | |
969 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException); | |
970 | |
971 v["hello"] = 42; | |
972 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException); | |
973 ASSERT_EQ(42, Toolbox::GetJsonIntegerField(v, "hello", -10)); | |
974 ASSERT_EQ(42, Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10)); | |
975 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException); | |
976 | |
977 v["hello"] = false; | |
978 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException); | |
979 ASSERT_THROW(Toolbox::GetJsonIntegerField(v, "hello", -10), OrthancException); | |
980 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException); | |
981 ASSERT_FALSE(Toolbox::GetJsonBooleanField(v, "hello", true)); | |
982 } | |
983 | |
984 | |
0 | 985 int main(int argc, char **argv) |
986 { | |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
987 Logging::Initialize(); |
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
988 Logging::EnableInfoLevel(true); |
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
989 Toolbox::DetectEndianness(); |
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
990 Toolbox::MakeDirectory("UnitTestsResults"); |
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
991 OrthancInitialize(); |
159
c08fbad40ddd
less verbosity in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
992 |
0 | 993 ::testing::InitGoogleTest(&argc, argv); |
994 int result = RUN_ALL_TESTS(); | |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
995 |
63 | 996 OrthancFinalize(); |
1485
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
997 Logging::Finalize(); |
27661b33f624
Creation of Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1441
diff
changeset
|
998 |
0 | 999 return result; |
1000 } |