annotate OrthancFramework/UnitTestsSources/FrameworkTests.cpp @ 5657:dedbf019a707

Improved parsing of multiple numerical values in DICOM tags
author Alain Mazy <am@orthanc.team>
date Thu, 06 Jun 2024 17:55:13 +0200
parents f7adfb22e20e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5575
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5575
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5377
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 *
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
12 * the License, or (at your option) any later version.
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
17 * Lesser General Public License for more details.
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
20 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
21 * <http://www.gnu.org/licenses/>.
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3987
diff changeset
25 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
26 // Must be the first to be sure to use the Orthanc framework shared library
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
27 # include <OrthancFramework.h>
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3987
diff changeset
28 #endif
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3987
diff changeset
29
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
30 #if !defined(ORTHANC_ENABLE_PUGIXML)
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
31 # error ORTHANC_ENABLE_PUGIXML is not defined
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
32 #endif
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
33
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
34 #include "../Sources/EnumerationDictionary.h"
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
36 #include <gtest/gtest.h>
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
38 #include "../Sources/DicomFormat/DicomTag.h"
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
39 #include "../Sources/HttpServer/HttpToolbox.h"
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
40 #include "../Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
41 #include "../Sources/OrthancException.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
42 #include "../Sources/Toolbox.h"
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
44 #if ORTHANC_SANDBOXED != 1
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
45 # include "../Sources/FileBuffer.h"
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
46 # include "../Sources/MetricsRegistry.h"
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
47 # include "../Sources/SystemToolbox.h"
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
48 # include "../Sources/TemporaryFile.h"
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
49 #endif
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
50
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
51 #include <ctype.h>
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
52
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 using namespace Orthanc;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 TEST(Uuid, Generation)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 for (int i = 0; i < 10; i++)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 std::string s = Toolbox::GenerateUuid();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 ASSERT_TRUE(Toolbox::IsUuid(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 TEST(Uuid, Test)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 ASSERT_FALSE(Toolbox::IsUuid(""));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 ASSERT_FALSE(Toolbox::IsUuid("012345678901234567890123456789012345"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ASSERT_TRUE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-446655440000"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 ASSERT_FALSE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-44665544000_"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 ASSERT_FALSE(Toolbox::IsUuid("01234567890123456789012345678901234_"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-44665544000"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000 ok"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000ok"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 TEST(Toolbox, IsSHA1)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 ASSERT_FALSE(Toolbox::IsSHA1(""));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 ASSERT_FALSE(Toolbox::IsSHA1("01234567890123456789012345678901234567890123"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 ASSERT_FALSE(Toolbox::IsSHA1("012345678901234567890123456789012345678901234"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 ASSERT_TRUE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 std::string sha = " b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9 ";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 ASSERT_TRUE(Toolbox::IsSHA1(sha));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 sha[3] = '\0';
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 sha[53] = '\0';
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 ASSERT_TRUE(Toolbox::IsSHA1(sha));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 sha[40] = '\0';
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 ASSERT_FALSE(Toolbox::IsSHA1(sha));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 ASSERT_FALSE(Toolbox::IsSHA1(" "));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 ASSERT_TRUE(Toolbox::IsSHA1("16738bc3-e47ed42a-43ce044c-a3414a45-cb069bd0"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 ASSERT_TRUE(Toolbox::IsSHA1(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 ASSERT_FALSE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b_"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 TEST(ParseGetArguments, Basic)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 {
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
108 HttpToolbox::GetArguments b;
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 HttpToolbox::ParseGetArguments(b, "aaa=baaa&bb=a&aa=c");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
111 HttpToolbox::Arguments a;
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 HttpToolbox::CompileGetArguments(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 ASSERT_EQ(3u, a.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 ASSERT_EQ(a["aaa"], "baaa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 ASSERT_EQ(a["bb"], "a");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 ASSERT_EQ(a["aa"], "c");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
120
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 TEST(ParseGetArguments, BasicEmpty)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
123 HttpToolbox::GetArguments b;
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 HttpToolbox::ParseGetArguments(b, "aaa&bb=aa&aa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
126 HttpToolbox::Arguments a;
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 HttpToolbox::CompileGetArguments(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 ASSERT_EQ(3u, a.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 ASSERT_EQ(a["aaa"], "");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 ASSERT_EQ(a["bb"], "aa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 ASSERT_EQ(a["aa"], "");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
135
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 TEST(ParseGetArguments, Single)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 {
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
138 HttpToolbox::GetArguments b;
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 HttpToolbox::ParseGetArguments(b, "aaa=baaa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
141 HttpToolbox::Arguments a;
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 HttpToolbox::CompileGetArguments(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 ASSERT_EQ(1u, a.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 ASSERT_EQ(a["aaa"], "baaa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
148
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 TEST(ParseGetArguments, SingleEmpty)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 {
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
151 HttpToolbox::GetArguments b;
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 HttpToolbox::ParseGetArguments(b, "aaa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
154 HttpToolbox::Arguments a;
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 HttpToolbox::CompileGetArguments(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 ASSERT_EQ(1u, a.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 ASSERT_EQ(a["aaa"], "");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
161
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 TEST(ParseGetQuery, Test1)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 UriComponents uri;
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
165 HttpToolbox::GetArguments b;
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world?aaa=baaa&bb=a&aa=c");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
168 HttpToolbox::Arguments a;
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 HttpToolbox::CompileGetArguments(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 ASSERT_EQ(3u, uri.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 ASSERT_EQ("instances", uri[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 ASSERT_EQ("test", uri[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 ASSERT_EQ("world", uri[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 ASSERT_EQ(3u, a.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 ASSERT_EQ(a["aaa"], "baaa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 ASSERT_EQ(a["bb"], "a");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 ASSERT_EQ(a["aa"], "c");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
181
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 TEST(ParseGetQuery, Test2)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 UriComponents uri;
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
185 HttpToolbox::GetArguments b;
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
188 HttpToolbox::Arguments a;
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 HttpToolbox::CompileGetArguments(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 ASSERT_EQ(3u, uri.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 ASSERT_EQ("instances", uri[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 ASSERT_EQ("test", uri[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 ASSERT_EQ("world", uri[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 ASSERT_EQ(0u, a.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4327
diff changeset
197
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 TEST(Uri, SplitUriComponents)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 UriComponents c, d;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 Toolbox::SplitUriComponents(c, "/cou/hello/world");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 ASSERT_EQ(3u, c.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 ASSERT_EQ("cou", c[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 ASSERT_EQ("hello", c[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 ASSERT_EQ("world", c[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 Toolbox::SplitUriComponents(c, "/cou/hello/world/");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 ASSERT_EQ(3u, c.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 ASSERT_EQ("cou", c[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 ASSERT_EQ("hello", c[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 ASSERT_EQ("world", c[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 Toolbox::SplitUriComponents(c, "/cou/hello/world/a");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 ASSERT_EQ(4u, c.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 ASSERT_EQ("cou", c[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 ASSERT_EQ("hello", c[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 ASSERT_EQ("world", c[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 ASSERT_EQ("a", c[3]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 Toolbox::SplitUriComponents(c, "/");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 ASSERT_EQ(0u, c.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 Toolbox::SplitUriComponents(c, "/hello");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 ASSERT_EQ(1u, c.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 ASSERT_EQ("hello", c[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 Toolbox::SplitUriComponents(c, "/hello/");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 ASSERT_EQ(1u, c.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 ASSERT_EQ("hello", c[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 ASSERT_THROW(Toolbox::SplitUriComponents(c, ""), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 ASSERT_THROW(Toolbox::SplitUriComponents(c, "a"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 ASSERT_THROW(Toolbox::SplitUriComponents(c, "/coucou//coucou"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 c.clear();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 c.push_back("test");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 ASSERT_EQ("/", Toolbox::FlattenUri(c, 10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 TEST(Uri, Truncate)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 UriComponents c, d;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 Toolbox::SplitUriComponents(c, "/cou/hello/world");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 Toolbox::TruncateUri(d, c, 0);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 ASSERT_EQ(3u, d.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 ASSERT_EQ("cou", d[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 ASSERT_EQ("hello", d[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 ASSERT_EQ("world", d[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 Toolbox::TruncateUri(d, c, 1);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 ASSERT_EQ(2u, d.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 ASSERT_EQ("hello", d[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 ASSERT_EQ("world", d[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 Toolbox::TruncateUri(d, c, 2);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 ASSERT_EQ(1u, d.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 ASSERT_EQ("world", d[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 Toolbox::TruncateUri(d, c, 3);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 ASSERT_EQ(0u, d.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 Toolbox::TruncateUri(d, c, 4);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 ASSERT_EQ(0u, d.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 Toolbox::TruncateUri(d, c, 5);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 ASSERT_EQ(0u, d.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 TEST(Uri, Child)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 UriComponents c1; Toolbox::SplitUriComponents(c1, "/hello/world");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 UriComponents c2; Toolbox::SplitUriComponents(c2, "/hello/hello");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 UriComponents c3; Toolbox::SplitUriComponents(c3, "/hello");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 UriComponents c4; Toolbox::SplitUriComponents(c4, "/world");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 UriComponents c5; Toolbox::SplitUriComponents(c5, "/");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 ASSERT_TRUE(Toolbox::IsChildUri(c1, c1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 ASSERT_FALSE(Toolbox::IsChildUri(c1, c2));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 ASSERT_FALSE(Toolbox::IsChildUri(c1, c3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 ASSERT_FALSE(Toolbox::IsChildUri(c1, c4));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 ASSERT_FALSE(Toolbox::IsChildUri(c1, c5));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 ASSERT_FALSE(Toolbox::IsChildUri(c2, c1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 ASSERT_TRUE(Toolbox::IsChildUri(c2, c2));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 ASSERT_FALSE(Toolbox::IsChildUri(c2, c3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 ASSERT_FALSE(Toolbox::IsChildUri(c2, c4));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 ASSERT_FALSE(Toolbox::IsChildUri(c2, c5));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 ASSERT_TRUE(Toolbox::IsChildUri(c3, c1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 ASSERT_TRUE(Toolbox::IsChildUri(c3, c2));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 ASSERT_TRUE(Toolbox::IsChildUri(c3, c3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 ASSERT_FALSE(Toolbox::IsChildUri(c3, c4));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 ASSERT_FALSE(Toolbox::IsChildUri(c3, c5));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 ASSERT_FALSE(Toolbox::IsChildUri(c4, c1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 ASSERT_FALSE(Toolbox::IsChildUri(c4, c2));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 ASSERT_FALSE(Toolbox::IsChildUri(c4, c3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 ASSERT_TRUE(Toolbox::IsChildUri(c4, c4));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 ASSERT_FALSE(Toolbox::IsChildUri(c4, c5));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 ASSERT_TRUE(Toolbox::IsChildUri(c5, c1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 ASSERT_TRUE(Toolbox::IsChildUri(c5, c2));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 ASSERT_TRUE(Toolbox::IsChildUri(c5, c3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 ASSERT_TRUE(Toolbox::IsChildUri(c5, c4));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 ASSERT_TRUE(Toolbox::IsChildUri(c5, c5));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
312
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
313 #if ORTHANC_SANDBOXED != 1
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 TEST(Uri, AutodetectMimeType)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("../NOTES"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType(""));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("/"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("a/a"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("..\\a\\"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("..\\a\\a"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 ASSERT_EQ(MimeType_PlainText, SystemToolbox::AutodetectMimeType("../NOTES.txt"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 ASSERT_EQ(MimeType_PlainText, SystemToolbox::AutodetectMimeType("../coucou.xml/NOTES.txt"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("..\\coucou.\\NOTES.xml"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("../.xml"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("../.XmL"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 ASSERT_EQ(MimeType_JavaScript, SystemToolbox::AutodetectMimeType("NOTES.js"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 ASSERT_EQ(MimeType_Json, SystemToolbox::AutodetectMimeType("NOTES.json"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 ASSERT_EQ(MimeType_Pdf, SystemToolbox::AutodetectMimeType("NOTES.pdf"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 ASSERT_EQ(MimeType_Css, SystemToolbox::AutodetectMimeType("NOTES.css"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 ASSERT_EQ(MimeType_Html, SystemToolbox::AutodetectMimeType("NOTES.html"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 ASSERT_EQ(MimeType_PlainText, SystemToolbox::AutodetectMimeType("NOTES.txt"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("NOTES.xml"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 ASSERT_EQ(MimeType_Gif, SystemToolbox::AutodetectMimeType("NOTES.gif"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 ASSERT_EQ(MimeType_Jpeg, SystemToolbox::AutodetectMimeType("NOTES.jpg"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 ASSERT_EQ(MimeType_Jpeg, SystemToolbox::AutodetectMimeType("NOTES.jpeg"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 ASSERT_EQ(MimeType_Png, SystemToolbox::AutodetectMimeType("NOTES.png"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 ASSERT_EQ(MimeType_NaCl, SystemToolbox::AutodetectMimeType("NOTES.nexe"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 ASSERT_EQ(MimeType_Json, SystemToolbox::AutodetectMimeType("NOTES.nmf"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 ASSERT_EQ(MimeType_PNaCl, SystemToolbox::AutodetectMimeType("NOTES.pexe"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 ASSERT_EQ(MimeType_Svg, SystemToolbox::AutodetectMimeType("NOTES.svg"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 ASSERT_EQ(MimeType_Woff, SystemToolbox::AutodetectMimeType("NOTES.woff"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 ASSERT_EQ(MimeType_Woff2, SystemToolbox::AutodetectMimeType("NOTES.woff2"));
4887
a29a6bdba9dd mime type for .ico
Alain Mazy <am@osimis.io>
parents: 4870
diff changeset
346 ASSERT_EQ(MimeType_Ico, SystemToolbox::AutodetectMimeType("NOTES.ico"));
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 // Test primitives from the "RegisterDefaultExtensions()" that was
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 // present in the sample "Serve Folders plugin" of Orthanc 1.4.2
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 ASSERT_STREQ("application/javascript", EnumerationToString(SystemToolbox::AutodetectMimeType(".js")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 ASSERT_STREQ("application/json", EnumerationToString(SystemToolbox::AutodetectMimeType(".json")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 ASSERT_STREQ("application/json", EnumerationToString(SystemToolbox::AutodetectMimeType(".nmf")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 ASSERT_STREQ("application/octet-stream", EnumerationToString(SystemToolbox::AutodetectMimeType("")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 ASSERT_STREQ("application/wasm", EnumerationToString(SystemToolbox::AutodetectMimeType(".wasm")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 ASSERT_STREQ("application/x-font-woff", EnumerationToString(SystemToolbox::AutodetectMimeType(".woff")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 ASSERT_STREQ("application/x-nacl", EnumerationToString(SystemToolbox::AutodetectMimeType(".nexe")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 ASSERT_STREQ("application/x-pnacl", EnumerationToString(SystemToolbox::AutodetectMimeType(".pexe")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 ASSERT_STREQ("application/xml", EnumerationToString(SystemToolbox::AutodetectMimeType(".xml")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 ASSERT_STREQ("font/woff2", EnumerationToString(SystemToolbox::AutodetectMimeType(".woff2")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 ASSERT_STREQ("image/gif", EnumerationToString(SystemToolbox::AutodetectMimeType(".gif")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 ASSERT_STREQ("image/jpeg", EnumerationToString(SystemToolbox::AutodetectMimeType(".jpeg")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 ASSERT_STREQ("image/jpeg", EnumerationToString(SystemToolbox::AutodetectMimeType(".jpg")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 ASSERT_STREQ("image/png", EnumerationToString(SystemToolbox::AutodetectMimeType(".png")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 ASSERT_STREQ("image/svg+xml", EnumerationToString(SystemToolbox::AutodetectMimeType(".svg")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 ASSERT_STREQ("text/css", EnumerationToString(SystemToolbox::AutodetectMimeType(".css")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 ASSERT_STREQ("text/html", EnumerationToString(SystemToolbox::AutodetectMimeType(".html")));
5348
303e930fff0f "/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5337
diff changeset
367
303e930fff0f "/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5337
diff changeset
368 ASSERT_STREQ("model/obj", EnumerationToString(SystemToolbox::AutodetectMimeType(".obj")));
303e930fff0f "/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5337
diff changeset
369 ASSERT_STREQ("model/mtl", EnumerationToString(SystemToolbox::AutodetectMimeType(".mtl")));
303e930fff0f "/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5337
diff changeset
370 ASSERT_STREQ("model/stl", EnumerationToString(SystemToolbox::AutodetectMimeType(".stl")));
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 }
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
372 #endif
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
373
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 TEST(Toolbox, ComputeMD5)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 // # echo -n "Hello" | md5sum
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 Toolbox::ComputeMD5(s, "Hello");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 ASSERT_EQ("8b1a9953c4611296a827abf8c47804d7", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 Toolbox::ComputeMD5(s, "");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 ASSERT_EQ("d41d8cd98f00b204e9800998ecf8427e", s);
5377
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
385
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
386 Toolbox::ComputeMD5(s, "aaabbbccc");
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
387 ASSERT_EQ("d1aaf4767a3c10a473407a4e47b02da6", s);
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
388
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
389 std::set<std::string> set;
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
390
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
391 Toolbox::ComputeMD5(s, set);
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
392 ASSERT_EQ("d41d8cd98f00b204e9800998ecf8427e", s); // empty set same as empty string
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
393
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
394 set.insert("bbb");
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
395 set.insert("ccc");
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
396 set.insert("aaa");
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
397
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
398 Toolbox::ComputeMD5(s, set);
daf4807631c5 ComputeMD5 for std::set
Alain Mazy <am@osimis.io>
parents: 5373
diff changeset
399 ASSERT_EQ("d1aaf4767a3c10a473407a4e47b02da6", s); // set md5 same as string with the values sorted
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 TEST(Toolbox, ComputeSHA1)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 Toolbox::ComputeSHA1(s, "");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
412 #if ORTHANC_SANDBOXED != 1
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 TEST(Toolbox, PathToExecutable)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 printf("[%s]\n", SystemToolbox::GetPathToExecutable().c_str());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 printf("[%s]\n", SystemToolbox::GetDirectoryOfExecutable().c_str());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 }
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
418 #endif
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 TEST(Toolbox, StripSpaces)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 ASSERT_EQ("", Toolbox::StripSpaces(" \t \r \n "));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 ASSERT_EQ("coucou", Toolbox::StripSpaces(" coucou \t \r \n "));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 ASSERT_EQ("cou cou", Toolbox::StripSpaces(" cou cou \n "));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 ASSERT_EQ("c", Toolbox::StripSpaces(" \n\t c\r \n "));
4622
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
426
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
427 std::string s = "\" abd \"";
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
428 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ(" abd ", s);
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
429
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
430 s = " \" abd \" ";
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
431 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ(" \" abd \" ", s);
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
432
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
433 s = Toolbox::StripSpaces(s);
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
434 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ(" abd ", s);
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
435
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
436 s = "\"";
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
437 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ("", s);
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
438
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
439 s = "\"\"";
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
440 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ("", s);
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
441
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
442 s = "\"_\"";
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
443 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ("_", s);
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
444
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
445 s = "\"\"\"";
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4538
diff changeset
446 Toolbox::RemoveSurroundingQuotes(s); ASSERT_EQ("\"", s);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 TEST(Toolbox, Case)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 std::string s = "CoU";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 std::string ss;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 Toolbox::ToUpperCase(ss, s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 ASSERT_EQ("COU", ss);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 Toolbox::ToLowerCase(ss, s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 ASSERT_EQ("cou", ss);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 s = "CoU";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 Toolbox::ToUpperCase(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 ASSERT_EQ("COU", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 s = "CoU";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 Toolbox::ToLowerCase(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 ASSERT_EQ("cou", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 TEST(Logger, Basic)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 LOG(INFO) << "I say hello";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 TEST(Toolbox, ConvertFromLatin1)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 // This is a Latin-1 test string
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 const unsigned char data[10] = { 0xe0, 0xe9, 0xea, 0xe7, 0x26, 0xc6, 0x61, 0x62, 0x63, 0x00 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 std::string s((char*) &data[0], 10);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 ASSERT_EQ("&abc", Toolbox::ConvertToAscii(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 // Open in Emacs, then save with UTF-8 encoding, then "hexdump -C"
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 std::string utf8 = Toolbox::ConvertToUtf8(s, Encoding_Latin1, false);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 ASSERT_EQ(15u, utf8.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[0]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 ASSERT_EQ(0xa0, static_cast<unsigned char>(utf8[1]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[2]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 ASSERT_EQ(0xa9, static_cast<unsigned char>(utf8[3]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[4]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 ASSERT_EQ(0xaa, static_cast<unsigned char>(utf8[5]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[6]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 ASSERT_EQ(0xa7, static_cast<unsigned char>(utf8[7]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 ASSERT_EQ(0x26, static_cast<unsigned char>(utf8[8]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[9]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 ASSERT_EQ(0x86, static_cast<unsigned char>(utf8[10]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 ASSERT_EQ(0x61, static_cast<unsigned char>(utf8[11]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 ASSERT_EQ(0x62, static_cast<unsigned char>(utf8[12]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 ASSERT_EQ(0x63, static_cast<unsigned char>(utf8[13]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 ASSERT_EQ(0x00, static_cast<unsigned char>(utf8[14])); // Null-terminated string
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 TEST(Toolbox, FixUtf8)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 // This is a Latin-1 test string: "crane" with a circumflex accent
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 const unsigned char latin1[] = { 0x63, 0x72, 0xe2, 0x6e, 0x65 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 std::string s((char*) &latin1[0], sizeof(latin1) / sizeof(char));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 ASSERT_EQ(s, Toolbox::ConvertFromUtf8(Toolbox::ConvertToUtf8(s, Encoding_Latin1, false), Encoding_Latin1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 ASSERT_EQ("cre", Toolbox::ConvertToUtf8(s, Encoding_Utf8, false));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 static int32_t GetUnicode(const uint8_t* data,
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 size_t size,
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 size_t expectedLength)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 std::string s((char*) &data[0], size);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 uint32_t unicode;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 size_t length;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 Toolbox::Utf8ToUnicodeCharacter(unicode, length, s, 0);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 if (length != expectedLength)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 return -1; // Error case
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 return unicode;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 TEST(Toolbox, Utf8ToUnicode)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 // https://en.wikipedia.org/wiki/UTF-8
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 ASSERT_EQ(1u, sizeof(char));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 ASSERT_EQ(1u, sizeof(uint8_t));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 const uint8_t data[] = { 0x24 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 ASSERT_EQ(0x24, GetUnicode(data, 1, 1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 ASSERT_THROW(GetUnicode(data, 0, 1), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 const uint8_t data[] = { 0xc2, 0xa2 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 ASSERT_EQ(0xa2, GetUnicode(data, 2, 2));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 ASSERT_THROW(GetUnicode(data, 1, 2), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 const uint8_t data[] = { 0xe0, 0xa4, 0xb9 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 ASSERT_EQ(0x0939, GetUnicode(data, 3, 3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 ASSERT_THROW(GetUnicode(data, 2, 3), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 const uint8_t data[] = { 0xe2, 0x82, 0xac };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 ASSERT_EQ(0x20ac, GetUnicode(data, 3, 3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 ASSERT_THROW(GetUnicode(data, 2, 3), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 const uint8_t data[] = { 0xf0, 0x90, 0x8d, 0x88 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 ASSERT_EQ(0x010348, GetUnicode(data, 4, 4));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 ASSERT_THROW(GetUnicode(data, 3, 4), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 const uint8_t data[] = { 0xe0 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 ASSERT_THROW(GetUnicode(data, 1, 1), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 TEST(Toolbox, UrlDecode)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 s = "Hello%20World";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 Toolbox::UrlDecode(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 ASSERT_EQ("Hello World", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 s = "%21%23%24%26%27%28%29%2A%2B%2c%2f%3A%3b%3d%3f%40%5B%5D%90%ff";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 Toolbox::UrlDecode(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 std::string ss = "!#$&'()*+,/:;=?@[]";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 ss.push_back((char) 144);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 ss.push_back((char) 255);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 ASSERT_EQ(ss, s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 s = "(2000%2C00A4)+Other";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 Toolbox::UrlDecode(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 ASSERT_EQ("(2000,00A4) Other", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 TEST(Toolbox, IsAsciiString)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 std::string s = "Hello 12 /";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 ASSERT_EQ(10u, s.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 ASSERT_TRUE(Toolbox::IsAsciiString(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 ASSERT_TRUE(Toolbox::IsAsciiString(s.c_str(), 10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 ASSERT_FALSE(Toolbox::IsAsciiString(s.c_str(), 11)); // Taking the trailing hidden '\0'
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 s[2] = '\0';
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 ASSERT_EQ(10u, s.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 ASSERT_FALSE(Toolbox::IsAsciiString(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 ASSERT_TRUE(Toolbox::IsAsciiString("Hello\nworld"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 ASSERT_FALSE(Toolbox::IsAsciiString("Hello\rworld"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 ASSERT_EQ("Hello\nworld", Toolbox::ConvertToAscii("Hello\nworld"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 ASSERT_EQ("Helloworld", Toolbox::ConvertToAscii("Hello\r\tworld"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 #if defined(__linux__)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 TEST(Toolbox, AbsoluteDirectory)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 ASSERT_EQ("/tmp/hello", SystemToolbox::InterpretRelativePath("/tmp", "hello"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 ASSERT_EQ("/tmp", SystemToolbox::InterpretRelativePath("/tmp", "/tmp"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
628 #if ORTHANC_SANDBOXED != 1
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 TEST(Toolbox, WriteFile)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 std::string path;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 TemporaryFile tmp;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 path = tmp.GetPath();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 s.append("Hello");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 s.push_back('\0');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 s.append("World");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 ASSERT_EQ(11u, s.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 SystemToolbox::WriteFile(s, path.c_str());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 std::string t;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 SystemToolbox::ReadFile(t, path.c_str());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 ASSERT_EQ(11u, t.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 ASSERT_EQ(0, t[5]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size()));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 std::string h;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 ASSERT_EQ(true, SystemToolbox::ReadHeader(h, path.c_str(), 1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 ASSERT_EQ(1u, h.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 ASSERT_EQ('H', h[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 ASSERT_TRUE(SystemToolbox::ReadHeader(h, path.c_str(), 0));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 ASSERT_EQ(0u, h.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 ASSERT_FALSE(SystemToolbox::ReadHeader(h, path.c_str(), 32));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 ASSERT_EQ(11u, h.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 ASSERT_EQ(0, memcmp(s.c_str(), h.c_str(), s.size()));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 std::string u;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 ASSERT_THROW(SystemToolbox::ReadFile(u, path.c_str()), OrthancException);
4186
e99d1ad11cfe fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
665
e99d1ad11cfe fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
666 {
e99d1ad11cfe fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
667 TemporaryFile tmp;
e99d1ad11cfe fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
668 std::string s = "Hello";
e99d1ad11cfe fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
669 SystemToolbox::WriteFile(s, tmp.GetPath(), true /* call fsync() */);
e99d1ad11cfe fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
670 std::string t;
e99d1ad11cfe fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
671 SystemToolbox::ReadFile(t, tmp.GetPath());
e99d1ad11cfe fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
672 ASSERT_EQ(s, t);
e99d1ad11cfe fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
673 }
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 }
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
675 #endif
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
678 #if ORTHANC_SANDBOXED != 1
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 TEST(Toolbox, FileBuffer)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 FileBuffer f;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 f.Append("a", 1);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 f.Append("", 0);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 f.Append("bc", 2);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 f.Read(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 ASSERT_EQ("abc", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 ASSERT_THROW(f.Append("d", 1), OrthancException); // File is closed
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 }
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
692 #endif
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 TEST(Toolbox, Wildcard)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 ASSERT_EQ("abcd", Toolbox::WildcardToRegularExpression("abcd"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 ASSERT_EQ("ab.*cd", Toolbox::WildcardToRegularExpression("ab*cd"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 ASSERT_EQ("ab..cd", Toolbox::WildcardToRegularExpression("ab??cd"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 ASSERT_EQ("a.*b.c.*d", Toolbox::WildcardToRegularExpression("a*b?c*d"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 ASSERT_EQ("a\\{b\\]", Toolbox::WildcardToRegularExpression("a{b]"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 TEST(Toolbox, Tokenize)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 std::vector<std::string> t;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 Toolbox::TokenizeString(t, "", ',');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 ASSERT_EQ(1u, t.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 ASSERT_EQ("", t[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 Toolbox::TokenizeString(t, "abc", ',');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 ASSERT_EQ(1u, t.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 ASSERT_EQ("abc", t[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 Toolbox::TokenizeString(t, "ab,cd,ef,", ',');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 ASSERT_EQ(4u, t.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 ASSERT_EQ("ab", t[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 ASSERT_EQ("cd", t[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 ASSERT_EQ("ef", t[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 ASSERT_EQ("", t[3]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724
5373
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
725 TEST(Toolbox, SplitString)
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
726 {
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
727 {
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
728 std::set<std::string> result;
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
729 Toolbox::SplitString(result, "", ';');
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
730 ASSERT_EQ(0u, result.size());
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
731 }
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
732
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
733 {
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
734 std::set<std::string> result;
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
735 Toolbox::SplitString(result, "a", ';');
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
736 ASSERT_EQ(1u, result.size());
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
737 ASSERT_TRUE(result.end() != result.find("a"));
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
738 }
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
739
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
740 {
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
741 std::set<std::string> result;
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
742 Toolbox::SplitString(result, "a;b", ';');
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
743 ASSERT_EQ(2u, result.size());
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
744 ASSERT_TRUE(result.end() != result.find("a"));
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
745 ASSERT_TRUE(result.end() != result.find("b"));
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
746 }
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
747
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
748 {
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
749 std::set<std::string> result;
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
750 Toolbox::SplitString(result, "a;b;", ';');
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
751 ASSERT_EQ(2u, result.size());
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
752 ASSERT_TRUE(result.end() != result.find("a"));
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
753 ASSERT_TRUE(result.end() != result.find("b"));
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
754 }
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
755
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
756 {
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
757 std::set<std::string> result;
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
758 Toolbox::SplitString(result, "a;a", ';');
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
759 ASSERT_EQ(1u, result.size());
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
760 ASSERT_TRUE(result.end() != result.find("a"));
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
761 }
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
762
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
763 {
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
764 std::vector<std::string> result;
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
765 Toolbox::SplitString(result, "", ';');
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
766 ASSERT_EQ(0u, result.size());
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
767 }
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
768
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
769 {
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
770 std::vector<std::string> result;
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
771 Toolbox::SplitString(result, "a", ';');
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
772 ASSERT_EQ(1u, result.size());
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
773 ASSERT_EQ("a", result[0]);
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
774 }
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
775
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
776 {
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
777 std::vector<std::string> result;
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
778 Toolbox::SplitString(result, "a;b", ';');
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
779 ASSERT_EQ(2u, result.size());
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
780 ASSERT_EQ("a", result[0]);
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
781 ASSERT_EQ("b", result[1]);
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
782 }
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
783
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
784 {
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
785 std::vector<std::string> result;
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
786 Toolbox::SplitString(result, "a;b;", ';');
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
787 ASSERT_EQ(2u, result.size());
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
788 ASSERT_EQ("a", result[0]);
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
789 ASSERT_EQ("b", result[1]);
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
790 }
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
791
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
792 {
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
793 std::vector<std::string> result;
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
794 Toolbox::TokenizeString(result, "a;a", ';');
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
795 ASSERT_EQ(2u, result.size());
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
796 ASSERT_EQ("a", result[0]);
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
797 ASSERT_EQ("a", result[1]);
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
798 }
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
799 }
123a94dd57df Toolbox::SplitString
Alain Mazy <am@osimis.io>
parents: 5348
diff changeset
800
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801 TEST(Toolbox, Enumerations)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803 ASSERT_EQ(Encoding_Utf8, StringToEncoding(EnumerationToString(Encoding_Utf8)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 ASSERT_EQ(Encoding_Ascii, StringToEncoding(EnumerationToString(Encoding_Ascii)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805 ASSERT_EQ(Encoding_Latin1, StringToEncoding(EnumerationToString(Encoding_Latin1)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806 ASSERT_EQ(Encoding_Latin2, StringToEncoding(EnumerationToString(Encoding_Latin2)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 ASSERT_EQ(Encoding_Latin3, StringToEncoding(EnumerationToString(Encoding_Latin3)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 ASSERT_EQ(Encoding_Latin4, StringToEncoding(EnumerationToString(Encoding_Latin4)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 ASSERT_EQ(Encoding_Latin5, StringToEncoding(EnumerationToString(Encoding_Latin5)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 ASSERT_EQ(Encoding_Cyrillic, StringToEncoding(EnumerationToString(Encoding_Cyrillic)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 ASSERT_EQ(Encoding_Arabic, StringToEncoding(EnumerationToString(Encoding_Arabic)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 ASSERT_EQ(Encoding_Greek, StringToEncoding(EnumerationToString(Encoding_Greek)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 ASSERT_EQ(Encoding_Hebrew, StringToEncoding(EnumerationToString(Encoding_Hebrew)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 ASSERT_EQ(Encoding_Japanese, StringToEncoding(EnumerationToString(Encoding_Japanese)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 ASSERT_EQ(Encoding_Chinese, StringToEncoding(EnumerationToString(Encoding_Chinese)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 ASSERT_EQ(Encoding_Thai, StringToEncoding(EnumerationToString(Encoding_Thai)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 ASSERT_EQ(Encoding_Korean, StringToEncoding(EnumerationToString(Encoding_Korean)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818 ASSERT_EQ(Encoding_JapaneseKanji, StringToEncoding(EnumerationToString(Encoding_JapaneseKanji)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819 ASSERT_EQ(Encoding_SimplifiedChinese, StringToEncoding(EnumerationToString(Encoding_SimplifiedChinese)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 ASSERT_EQ(ResourceType_Patient, StringToResourceType(EnumerationToString(ResourceType_Patient)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 ASSERT_EQ(ResourceType_Study, StringToResourceType(EnumerationToString(ResourceType_Study)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823 ASSERT_EQ(ResourceType_Series, StringToResourceType(EnumerationToString(ResourceType_Series)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 ASSERT_EQ(ResourceType_Instance, StringToResourceType(EnumerationToString(ResourceType_Instance)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 ASSERT_EQ(ImageFormat_Png, StringToImageFormat(EnumerationToString(ImageFormat_Png)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828 ASSERT_EQ(PhotometricInterpretation_ARGB, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_ARGB)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 ASSERT_EQ(PhotometricInterpretation_CMYK, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_CMYK)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 ASSERT_EQ(PhotometricInterpretation_HSV, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_HSV)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 ASSERT_EQ(PhotometricInterpretation_Monochrome1, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Monochrome1)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 ASSERT_EQ(PhotometricInterpretation_Monochrome2, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Monochrome2)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833 ASSERT_EQ(PhotometricInterpretation_Palette, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Palette)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 ASSERT_EQ(PhotometricInterpretation_RGB, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_RGB)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 ASSERT_EQ(PhotometricInterpretation_YBRFull, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRFull)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 ASSERT_EQ(PhotometricInterpretation_YBRFull422, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRFull422)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837 ASSERT_EQ(PhotometricInterpretation_YBRPartial420, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRPartial420)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 ASSERT_EQ(PhotometricInterpretation_YBRPartial422, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRPartial422)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 ASSERT_EQ(PhotometricInterpretation_YBR_ICT, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBR_ICT)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840 ASSERT_EQ(PhotometricInterpretation_YBR_RCT, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBR_RCT)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 ASSERT_STREQ("Unknown", EnumerationToString(PhotometricInterpretation_Unknown));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 ASSERT_THROW(StringToPhotometricInterpretation("Unknown"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 ASSERT_EQ(DicomVersion_2008, StringToDicomVersion(EnumerationToString(DicomVersion_2008)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 ASSERT_EQ(DicomVersion_2017c, StringToDicomVersion(EnumerationToString(DicomVersion_2017c)));
4677
521e39b3f2c0 Fix issue #146 (Update Anonyization to 2019c) - was actually updated to 2021b
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4668
diff changeset
847 ASSERT_EQ(DicomVersion_2021b, StringToDicomVersion(EnumerationToString(DicomVersion_2021b)));
5334
5b2a5cc64cb1 upgraded anonymization to Basic Profile of PS 3.15-2023b Table E.1-1
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5326
diff changeset
848 ASSERT_EQ(DicomVersion_2023b, StringToDicomVersion(EnumerationToString(DicomVersion_2023b)));
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 for (int i = static_cast<int>(ValueRepresentation_ApplicationEntity);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 i < static_cast<int>(ValueRepresentation_NotSupported); i += 1)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 ValueRepresentation vr = static_cast<ValueRepresentation>(i);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 ASSERT_EQ(vr, StringToValueRepresentation(EnumerationToString(vr), true));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 ASSERT_THROW(StringToValueRepresentation("nope", true), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 ASSERT_EQ(JobState_Pending, StringToJobState(EnumerationToString(JobState_Pending)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 ASSERT_EQ(JobState_Running, StringToJobState(EnumerationToString(JobState_Running)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861 ASSERT_EQ(JobState_Success, StringToJobState(EnumerationToString(JobState_Success)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 ASSERT_EQ(JobState_Failure, StringToJobState(EnumerationToString(JobState_Failure)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 ASSERT_EQ(JobState_Paused, StringToJobState(EnumerationToString(JobState_Paused)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 ASSERT_EQ(JobState_Retry, StringToJobState(EnumerationToString(JobState_Retry)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 ASSERT_THROW(StringToJobState("nope"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867 ASSERT_EQ(MimeType_Binary, StringToMimeType(EnumerationToString(MimeType_Binary)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 ASSERT_EQ(MimeType_Css, StringToMimeType(EnumerationToString(MimeType_Css)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 ASSERT_EQ(MimeType_Dicom, StringToMimeType(EnumerationToString(MimeType_Dicom)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870 ASSERT_EQ(MimeType_Gif, StringToMimeType(EnumerationToString(MimeType_Gif)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871 ASSERT_EQ(MimeType_Gzip, StringToMimeType(EnumerationToString(MimeType_Gzip)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 ASSERT_EQ(MimeType_Html, StringToMimeType(EnumerationToString(MimeType_Html)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873 ASSERT_EQ(MimeType_JavaScript, StringToMimeType(EnumerationToString(MimeType_JavaScript)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 ASSERT_EQ(MimeType_Jpeg, StringToMimeType(EnumerationToString(MimeType_Jpeg)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 ASSERT_EQ(MimeType_Jpeg2000, StringToMimeType(EnumerationToString(MimeType_Jpeg2000)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 ASSERT_EQ(MimeType_Json, StringToMimeType(EnumerationToString(MimeType_Json)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 ASSERT_EQ(MimeType_NaCl, StringToMimeType(EnumerationToString(MimeType_NaCl)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 ASSERT_EQ(MimeType_PNaCl, StringToMimeType(EnumerationToString(MimeType_PNaCl)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 ASSERT_EQ(MimeType_Pam, StringToMimeType(EnumerationToString(MimeType_Pam)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880 ASSERT_EQ(MimeType_Pdf, StringToMimeType(EnumerationToString(MimeType_Pdf)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881 ASSERT_EQ(MimeType_PlainText, StringToMimeType(EnumerationToString(MimeType_PlainText)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882 ASSERT_EQ(MimeType_Png, StringToMimeType(EnumerationToString(MimeType_Png)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 ASSERT_EQ(MimeType_Svg, StringToMimeType(EnumerationToString(MimeType_Svg)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 ASSERT_EQ(MimeType_WebAssembly, StringToMimeType(EnumerationToString(MimeType_WebAssembly)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 ASSERT_EQ(MimeType_Xml, StringToMimeType("application/xml"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 ASSERT_EQ(MimeType_Xml, StringToMimeType("text/xml"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 ASSERT_EQ(MimeType_Xml, StringToMimeType(EnumerationToString(MimeType_Xml)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 ASSERT_EQ(MimeType_DicomWebJson, StringToMimeType(EnumerationToString(MimeType_DicomWebJson)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 ASSERT_EQ(MimeType_DicomWebXml, StringToMimeType(EnumerationToString(MimeType_DicomWebXml)));
5348
303e930fff0f "/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5337
diff changeset
890 ASSERT_EQ(MimeType_Mtl, StringToMimeType(EnumerationToString(MimeType_Mtl)));
303e930fff0f "/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5337
diff changeset
891 ASSERT_EQ(MimeType_Obj, StringToMimeType(EnumerationToString(MimeType_Obj)));
303e930fff0f "/tools/create-dicom" can now be used to create Encapsulated 3D Manufacturing Model IODs (MTL, OBJ, or STL)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5337
diff changeset
892 ASSERT_EQ(MimeType_Stl, StringToMimeType(EnumerationToString(MimeType_Stl)));
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 ASSERT_THROW(StringToMimeType("nope"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Patient));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Study));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Series));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Instance));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Patient));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Study));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Series));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Instance));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Patient));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Study));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Series));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Instance));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Patient));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Study));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Series));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Instance));
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
914
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
915 ASSERT_STREQ("Patients", GetResourceTypeText(ResourceType_Patient, true /* plural */, true /* upper case */));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
916 ASSERT_STREQ("patients", GetResourceTypeText(ResourceType_Patient, true, false));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
917 ASSERT_STREQ("Patient", GetResourceTypeText(ResourceType_Patient, false, true));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
918 ASSERT_STREQ("patient", GetResourceTypeText(ResourceType_Patient, false, false));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
919 ASSERT_STREQ("Studies", GetResourceTypeText(ResourceType_Study, true, true));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
920 ASSERT_STREQ("studies", GetResourceTypeText(ResourceType_Study, true, false));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
921 ASSERT_STREQ("Study", GetResourceTypeText(ResourceType_Study, false, true));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
922 ASSERT_STREQ("study", GetResourceTypeText(ResourceType_Study, false, false));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
923 ASSERT_STREQ("Series", GetResourceTypeText(ResourceType_Series, true, true));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
924 ASSERT_STREQ("series", GetResourceTypeText(ResourceType_Series, true, false));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
925 ASSERT_STREQ("Series", GetResourceTypeText(ResourceType_Series, false, true));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
926 ASSERT_STREQ("series", GetResourceTypeText(ResourceType_Series, false, false));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
927 ASSERT_STREQ("Instances", GetResourceTypeText(ResourceType_Instance, true, true));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
928 ASSERT_STREQ("instances", GetResourceTypeText(ResourceType_Instance, true, false));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
929 ASSERT_STREQ("Instance", GetResourceTypeText(ResourceType_Instance, false, true));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4342
diff changeset
930 ASSERT_STREQ("instance", GetResourceTypeText(ResourceType_Instance, false, false));
4668
9210e196cd98 unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4622
diff changeset
931
9210e196cd98 unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4622
diff changeset
932 DicomTransferSyntax ts;
9210e196cd98 unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4622
diff changeset
933 ASSERT_FALSE(LookupTransferSyntax(ts, "nope"));
9210e196cd98 unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4622
diff changeset
934 ASSERT_TRUE(LookupTransferSyntax(ts, "1.2.840.10008.1.2")); ASSERT_EQ(DicomTransferSyntax_LittleEndianImplicit, ts);
9210e196cd98 unit test for transfer syntax
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4622
diff changeset
935 ASSERT_STREQ("1.2.840.10008.1.2", GetTransferSyntaxUid(ts));
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 #if defined(__linux__) || defined(__OpenBSD__)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 #include <endian.h>
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941 #elif defined(__FreeBSD__)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 #include <machine/endian.h>
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 TEST(Toolbox, Endianness)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948 // Parts of this test come from Adam Conrad
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949 // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728822#5
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952 /**
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 * Windows and OS X are assumed to always little-endian.
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 **/
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 #if defined(_WIN32) || defined(__APPLE__)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 /**
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 * FreeBSD.
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962 **/
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 # if _BYTE_ORDER == _BIG_ENDIAN
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 # else // _LITTLE_ENDIAN
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 # endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972 /**
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 * Linux.
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 **/
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 #elif defined(__linux__) || defined(__FreeBSD_kernel__)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 #if !defined(__BYTE_ORDER)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 # error Support your platform here
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 # if __BYTE_ORDER == __BIG_ENDIAN
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984 # else // __LITTLE_ENDIAN
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986 # endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
988
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
989 /**
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
990 * WebAssembly is always little-endian.
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
991 **/
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
992
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
993 #elif defined(__EMSCRIPTEN__)
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
994 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
995 #else
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
996 # error Support your platform here
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
997 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
999
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1000
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
1001 #include "../Sources/Endianness.h"
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1002
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1003 static void ASSERT_EQ16(uint16_t a, uint16_t b)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1004 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005 #ifdef __MINGW32__
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1006 // This cast solves a linking problem with MinGW
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1007 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1008 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1009 ASSERT_EQ(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1010 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1011 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1012
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1013 static void ASSERT_NE16(uint16_t a, uint16_t b)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1014 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1015 #ifdef __MINGW32__
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1016 // This cast solves a linking problem with MinGW
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1017 ASSERT_NE(static_cast<unsigned int>(a), static_cast<unsigned int>(b));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1018 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019 ASSERT_NE(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1023 static void ASSERT_EQ32(uint32_t a, uint32_t b)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1024 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1025 #ifdef __MINGW32__
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1026 // This cast solves a linking problem with MinGW
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1028 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1029 ASSERT_EQ(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1030 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1031 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1032
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1033 static void ASSERT_NE32(uint32_t a, uint32_t b)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1034 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035 #ifdef __MINGW32__
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1036 // This cast solves a linking problem with MinGW
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1037 ASSERT_NE(static_cast<unsigned int>(a), static_cast<unsigned int>(b));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1038 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1039 ASSERT_NE(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1040 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1041 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1042
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1043 static void ASSERT_EQ64(uint64_t a, uint64_t b)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1044 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1045 #ifdef __MINGW32__
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1046 // This cast solves a linking problem with MinGW
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1047 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1048 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1049 ASSERT_EQ(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1050 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1051 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1052
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1053 static void ASSERT_NE64(uint64_t a, uint64_t b)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1054 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1055 #ifdef __MINGW32__
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1056 // This cast solves a linking problem with MinGW
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057 ASSERT_NE(static_cast<unsigned long long>(a), static_cast<unsigned long long>(b));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1058 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1059 ASSERT_NE(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1060 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1061 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1062
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1063
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1064
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1065 TEST(Toolbox, EndiannessConversions16)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1066 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1067 Endianness e = Toolbox::DetectEndianness();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1068
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1069 for (unsigned int i = 0; i < 65536; i += 17)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1070 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1071 uint16_t v = static_cast<uint16_t>(i);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1072 ASSERT_EQ16(v, be16toh(htobe16(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1073 ASSERT_EQ16(v, le16toh(htole16(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1074
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1075 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&v);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1076 if (bytes[0] != bytes[1])
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1077 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1078 ASSERT_NE16(v, le16toh(htobe16(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1079 ASSERT_NE16(v, be16toh(htole16(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1080 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1081 else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1082 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1083 ASSERT_EQ16(v, le16toh(htobe16(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1084 ASSERT_EQ16(v, be16toh(htole16(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1085 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1086
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1087 switch (e)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1088 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1089 case Endianness_Little:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 ASSERT_EQ16(v, htole16(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091 if (bytes[0] != bytes[1])
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1092 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 ASSERT_NE16(v, htobe16(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1094 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1097 ASSERT_EQ16(v, htobe16(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099 break;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1100
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1101 case Endianness_Big:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1102 ASSERT_EQ16(v, htobe16(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1103 if (bytes[0] != bytes[1])
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1104 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1105 ASSERT_NE16(v, htole16(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1106 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1107 else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109 ASSERT_EQ16(v, htole16(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111 break;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1112
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1113 default:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1114 throw OrthancException(ErrorCode_ParameterOutOfRange);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1115 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1116 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1117 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1118
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1119
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120 TEST(Toolbox, EndiannessConversions32)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1121 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1122 const uint32_t v = 0xff010203u;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1123 const uint32_t r = 0x030201ffu;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124 ASSERT_EQ32(v, be32toh(htobe32(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1125 ASSERT_EQ32(v, le32toh(htole32(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1126 ASSERT_NE32(v, be32toh(htole32(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1127 ASSERT_NE32(v, le32toh(htobe32(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1128
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1129 switch (Toolbox::DetectEndianness())
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1130 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1131 case Endianness_Little:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1132 ASSERT_EQ32(r, htobe32(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1133 ASSERT_EQ32(v, htole32(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1134 ASSERT_EQ32(r, be32toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1135 ASSERT_EQ32(v, le32toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1136 break;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1137
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1138 case Endianness_Big:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1139 ASSERT_EQ32(v, htobe32(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1140 ASSERT_EQ32(r, htole32(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1141 ASSERT_EQ32(v, be32toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1142 ASSERT_EQ32(r, le32toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143 break;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1144
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1145 default:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1146 throw OrthancException(ErrorCode_ParameterOutOfRange);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1147 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151 TEST(Toolbox, EndiannessConversions64)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153 const uint64_t v = 0xff01020304050607LL;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1154 const uint64_t r = 0x07060504030201ffLL;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155 ASSERT_EQ64(v, be64toh(htobe64(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1156 ASSERT_EQ64(v, le64toh(htole64(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1157 ASSERT_NE64(v, be64toh(htole64(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 ASSERT_NE64(v, le64toh(htobe64(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160 switch (Toolbox::DetectEndianness())
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162 case Endianness_Little:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163 ASSERT_EQ64(r, htobe64(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164 ASSERT_EQ64(v, htole64(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165 ASSERT_EQ64(r, be64toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1166 ASSERT_EQ64(v, le64toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167 break;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1169 case Endianness_Big:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1170 ASSERT_EQ64(v, htobe64(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1171 ASSERT_EQ64(r, htole64(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 ASSERT_EQ64(v, be64toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1173 ASSERT_EQ64(r, le64toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1174 break;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1175
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1176 default:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177 throw OrthancException(ErrorCode_ParameterOutOfRange);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1178 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1179 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1180
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1181
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
1182 #if ORTHANC_SANDBOXED != 1
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183 TEST(Toolbox, Now)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1184 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1185 LOG(WARNING) << "Local time: " << SystemToolbox::GetNowIsoString(false);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186 LOG(WARNING) << "Universal time: " << SystemToolbox::GetNowIsoString(true);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188 std::string date, time;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1189 SystemToolbox::GetNowDicom(date, time, false);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1190 LOG(WARNING) << "Local DICOM time: [" << date << "] [" << time << "]";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1191
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1192 SystemToolbox::GetNowDicom(date, time, true);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1193 LOG(WARNING) << "Universal DICOM time: [" << date << "] [" << time << "]";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 }
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
1195 #endif
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1196
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1197
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1198 #if ORTHANC_ENABLE_PUGIXML == 1
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1199 TEST(Toolbox, Xml)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 Json::Value a;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 a["hello"] = "world";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1203 a["42"] = 43;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1204 a["b"] = Json::arrayValue;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1205 a["b"].append("test");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1206 a["b"].append("test2");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1207
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1208 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1209 Toolbox::JsonToXml(s, a);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1210
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1211 std::cout << s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1212 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1213 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1214
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
1216 #if !defined(_WIN32) && (ORTHANC_SANDBOXED != 1)
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1217 TEST(Toolbox, ExecuteSystemCommand)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1218 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1219 std::vector<std::string> args(2);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1220 args[0] = "Hello";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1221 args[1] = "World";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1222
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1223 SystemToolbox::ExecuteSystemCommand("echo", args);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1224 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1225 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1226
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1227
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1228 TEST(Toolbox, IsInteger)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1229 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230 ASSERT_TRUE(Toolbox::IsInteger("00236"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231 ASSERT_TRUE(Toolbox::IsInteger("-0042"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1232 ASSERT_TRUE(Toolbox::IsInteger("0"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233 ASSERT_TRUE(Toolbox::IsInteger("-0"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1234
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1235 ASSERT_FALSE(Toolbox::IsInteger(""));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 ASSERT_FALSE(Toolbox::IsInteger("42a"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237 ASSERT_FALSE(Toolbox::IsInteger("42-"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1238 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1240
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1241 TEST(Toolbox, StartsWith)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1242 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1243 ASSERT_TRUE(Toolbox::StartsWith("hello world", ""));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1244 ASSERT_TRUE(Toolbox::StartsWith("hello world", "hello"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1245 ASSERT_TRUE(Toolbox::StartsWith("hello world", "h"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1246 ASSERT_FALSE(Toolbox::StartsWith("hello world", "H"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1247 ASSERT_FALSE(Toolbox::StartsWith("h", "hello"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248 ASSERT_TRUE(Toolbox::StartsWith("h", "h"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1249 ASSERT_FALSE(Toolbox::StartsWith("", "h"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1250 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1251
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1252
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1253 TEST(Toolbox, UriEncode)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1254 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1255 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1256
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1257 // Unreserved characters must not be modified
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1258 std::string t = "aAzZ09.-~_";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1259 Toolbox::UriEncode(s, t);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1260 ASSERT_EQ(t, s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1261
4234
a38376b80cd1 WebDAV: by-studies and by-patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4186
diff changeset
1262 Toolbox::UriEncode(s, "!#$&'()*+,/:;=?@[]"); ASSERT_EQ("%21%23%24%26%27%28%29%2A%2B%2C/%3A%3B%3D%3F%40%5B%5D", s);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1263 Toolbox::UriEncode(s, "%"); ASSERT_EQ("%25", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1264
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1265 // Encode characters from UTF-8. This is the test string from the
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1266 // file "../Resources/EncodingTests.py"
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1267 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");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1268 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);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1269 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1270
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1271
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1272 TEST(Toolbox, AccessJson)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1273 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1274 Json::Value v = Json::arrayValue;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1275 ASSERT_EQ("nope", Toolbox::GetJsonStringField(v, "hello", "nope"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1276
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1277 v = Json::objectValue;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1278 ASSERT_EQ("nope", Toolbox::GetJsonStringField(v, "hello", "nope"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1279 ASSERT_EQ(-10, Toolbox::GetJsonIntegerField(v, "hello", -10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1280 ASSERT_EQ(10u, Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1281 ASSERT_TRUE(Toolbox::GetJsonBooleanField(v, "hello", true));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1282
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1283 v["hello"] = "world";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1284 ASSERT_EQ("world", Toolbox::GetJsonStringField(v, "hello", "nope"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1285 ASSERT_THROW(Toolbox::GetJsonIntegerField(v, "hello", -10), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1286 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1287 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1288
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1289 v["hello"] = -42;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1290 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1291 ASSERT_EQ(-42, Toolbox::GetJsonIntegerField(v, "hello", -10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1292 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1293 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1294
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1295 v["hello"] = 42;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1296 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1297 ASSERT_EQ(42, Toolbox::GetJsonIntegerField(v, "hello", -10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1298 ASSERT_EQ(42u, Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1299 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1300
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1301 v["hello"] = false;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1302 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1303 ASSERT_THROW(Toolbox::GetJsonIntegerField(v, "hello", -10), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1304 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1305 ASSERT_FALSE(Toolbox::GetJsonBooleanField(v, "hello", true));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1306 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1307
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1308
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1309 TEST(Toolbox, LinesIterator)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1310 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1311 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1312
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1313 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1314 std::string content;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1315 Toolbox::LinesIterator it(content);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1316 ASSERT_FALSE(it.GetLine(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1317 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1318
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1319 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1320 std::string content = "\n\r";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1321 Toolbox::LinesIterator it(content);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1322 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1323 ASSERT_FALSE(it.GetLine(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1324 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1325
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1326 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1327 std::string content = "\n Hello \n\nWorld\n\n";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1328 Toolbox::LinesIterator it(content);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1329 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1330 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1331 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1332 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1333 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1334 ASSERT_FALSE(it.GetLine(s)); it.Next();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1335 ASSERT_FALSE(it.GetLine(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1336 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1337
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1338 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1339 std::string content = "\r Hello \r\rWorld\r\r";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1340 Toolbox::LinesIterator it(content);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1341 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1342 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1343 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1344 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1345 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1346 ASSERT_FALSE(it.GetLine(s)); it.Next();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1347 ASSERT_FALSE(it.GetLine(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1348 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1349
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1350 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1351 std::string content = "\n\r Hello \n\r\n\rWorld\n\r\n\r";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1352 Toolbox::LinesIterator it(content);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1353 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1354 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1355 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1356 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1357 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1358 ASSERT_FALSE(it.GetLine(s)); it.Next();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1359 ASSERT_FALSE(it.GetLine(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1360 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1361
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1362 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1363 std::string content = "\r\n Hello \r\n\r\nWorld\r\n\r\n";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1364 Toolbox::LinesIterator it(content);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1365 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1366 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1367 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1368 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1369 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1370 ASSERT_FALSE(it.GetLine(s)); it.Next();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1371 ASSERT_FALSE(it.GetLine(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1372 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1373 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1374
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1375
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
1376 #if ORTHANC_SANDBOXED != 1
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1377 TEST(Toolbox, SubstituteVariables)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1378 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1379 std::map<std::string, std::string> env;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1380 env["NOPE"] = "nope";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1381 env["WORLD"] = "world";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1382
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1383 ASSERT_EQ("Hello world\r\nWorld \r\nDone world\r\n",
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1384 Toolbox::SubstituteVariables(
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1385 "Hello ${WORLD}\r\nWorld ${HELLO}\r\nDone ${WORLD}\r\n",
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1386 env));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1387
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1388 ASSERT_EQ("world A a B world C 'c' D {\"a\":\"b\"} E ",
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1389 Toolbox::SubstituteVariables(
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1390 "${WORLD} A ${WORLD2:-a} B ${WORLD:-b} C ${WORLD2:-\"'c'\"} D ${WORLD2:-'{\"a\":\"b\"}'} E ${WORLD2:-}",
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1391 env));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1392
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1393 SystemToolbox::GetEnvironmentVariables(env);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1394 ASSERT_TRUE(env.find("NOPE") == env.end());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1395
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1396 // The "PATH" environment variable should always be available on
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1397 // machines running the unit tests
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1398 ASSERT_TRUE(env.find("PATH") != env.end() /* Case used by UNIX */ ||
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1399 env.find("Path") != env.end() /* Case used by Windows */);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1400
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1401 env["PATH"] = "hello";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1402 ASSERT_EQ("AhelloB",
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1403 Toolbox::SubstituteVariables("A${PATH}B", env));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1404 }
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
1405 #endif
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1406
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1407
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
1408 #if ORTHANC_SANDBOXED != 1
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1409 TEST(MetricsRegistry, Basic)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1410 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1411 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1412 MetricsRegistry m;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1413 m.SetEnabled(false);
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1414 m.SetIntegerValue("hello.world", 42);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1415
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1416 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1417 m.ExportPrometheusText(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1418 ASSERT_TRUE(s.empty());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1419 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1420
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1421 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1422 MetricsRegistry m;
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1423 m.Register("hello.world", MetricsUpdatePolicy_Directly, MetricsDataType_Integer);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1424
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1425 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1426 m.ExportPrometheusText(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1427 ASSERT_TRUE(s.empty());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1428 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1429
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1430 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1431 MetricsRegistry m;
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1432 m.SetIntegerValue("hello.world", -42);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1433 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("hello.world"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1434 ASSERT_THROW(m.GetUpdatePolicy("nope"), OrthancException);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1435
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1436 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1437 m.ExportPrometheusText(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1438
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1439 std::vector<std::string> t;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1440 Toolbox::TokenizeString(t, s, '\n');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1441 ASSERT_EQ(2u, t.size());
5326
fbe857e942cd store metrics as integers instead of floats to avoid precision loss in increments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
1442 ASSERT_EQ("hello.world -42 ", t[0].substr(0, 16));
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1443 ASSERT_TRUE(t[1].empty());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1444 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1445
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1446 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1447 MetricsRegistry m;
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1448 m.Register("hello.max", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Integer);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1449 m.SetIntegerValue("hello.max", 10);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1450 m.SetIntegerValue("hello.max", 20);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1451 m.SetIntegerValue("hello.max", -10);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1452 m.SetIntegerValue("hello.max", 5);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1453
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1454 m.Register("hello.min", MetricsUpdatePolicy_MinOver10Seconds, MetricsDataType_Integer);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1455 m.SetIntegerValue("hello.min", 10);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1456 m.SetIntegerValue("hello.min", 20);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1457 m.SetIntegerValue("hello.min", -10);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1458 m.SetIntegerValue("hello.min", 5);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1459
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1460 m.Register("hello.directly", MetricsUpdatePolicy_Directly, MetricsDataType_Integer);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1461 m.SetIntegerValue("hello.directly", 10);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1462 m.SetIntegerValue("hello.directly", 20);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1463 m.SetIntegerValue("hello.directly", -10);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1464 m.SetIntegerValue("hello.directly", 5);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1465
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1466 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("hello.max"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1467 ASSERT_EQ(MetricsUpdatePolicy_MinOver10Seconds, m.GetUpdatePolicy("hello.min"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1468 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("hello.directly"));
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1469
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1470 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1471 m.ExportPrometheusText(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1472
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1473 std::vector<std::string> t;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1474 Toolbox::TokenizeString(t, s, '\n');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1475 ASSERT_EQ(4u, t.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1476 ASSERT_TRUE(t[3].empty());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1477
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1478 std::map<std::string, std::string> u;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1479 for (size_t i = 0; i < t.size() - 1; i++)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1480 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1481 std::vector<std::string> v;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1482 Toolbox::TokenizeString(v, t[i], ' ');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1483 u[v[0]] = v[1];
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1484 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1485
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1486 ASSERT_EQ("20", u["hello.max"]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1487 ASSERT_EQ("-10", u["hello.min"]);
5336
dd9795dc380d renamed MetricsType as MetricsUpdate to clarify
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5334
diff changeset
1488 ASSERT_EQ("5", u["hello.directly"]);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1489 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1490
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1491 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1492 MetricsRegistry m;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1493
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1494 m.SetIntegerValue("a", 10);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1495 m.SetIntegerValue("b", 10, MetricsUpdatePolicy_MinOver10Seconds);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1496
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1497 m.Register("c", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Integer);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1498 m.SetIntegerValue("c", 10, MetricsUpdatePolicy_MinOver10Seconds);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1499
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1500 m.Register("d", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Integer);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1501 ASSERT_THROW(m.Register("d", MetricsUpdatePolicy_Directly, MetricsDataType_Integer), OrthancException);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1502
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1503 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("a"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1504 ASSERT_EQ(MetricsUpdatePolicy_MinOver10Seconds, m.GetUpdatePolicy("b"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1505 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("c"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1506 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("d"));
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1507 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1508
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1509 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1510 MetricsRegistry m;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1511
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1512 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1513 MetricsRegistry::Timer t1(m, "a");
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1514 MetricsRegistry::Timer t2(m, "b", MetricsUpdatePolicy_MinOver10Seconds);
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1515 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1516
5337
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1517 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("a"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1518 ASSERT_EQ(MetricsUpdatePolicy_MinOver10Seconds, m.GetUpdatePolicy("b"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1519 }
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1520
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1521 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1522 MetricsRegistry m;
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1523 m.Register("c", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Integer);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1524 m.SetFloatValue("c", 100, MetricsUpdatePolicy_MinOver10Seconds);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1525
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1526 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("c"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1527 ASSERT_EQ(MetricsDataType_Integer, m.GetDataType("c"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1528 }
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1529
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1530 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1531 MetricsRegistry m;
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1532 m.Register("c", MetricsUpdatePolicy_MaxOver10Seconds, MetricsDataType_Float);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1533 m.SetIntegerValue("c", 100, MetricsUpdatePolicy_MinOver10Seconds);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1534
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1535 ASSERT_EQ(MetricsUpdatePolicy_MaxOver10Seconds, m.GetUpdatePolicy("c"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1536 ASSERT_EQ(MetricsDataType_Float, m.GetDataType("c"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1537 }
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1538
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1539 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1540 MetricsRegistry m;
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1541 m.SetIntegerValue("c", 100, MetricsUpdatePolicy_MinOver10Seconds);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1542 m.SetFloatValue("c", 101, MetricsUpdatePolicy_MaxOver10Seconds);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1543
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1544 ASSERT_EQ(MetricsUpdatePolicy_MinOver10Seconds, m.GetUpdatePolicy("c"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1545 ASSERT_EQ(MetricsDataType_Integer, m.GetDataType("c"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1546 }
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1547
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1548 {
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1549 MetricsRegistry m;
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1550 m.SetIntegerValue("c", 100);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1551 m.SetFloatValue("c", 101, MetricsUpdatePolicy_MaxOver10Seconds);
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1552
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1553 ASSERT_EQ(MetricsUpdatePolicy_Directly, m.GetUpdatePolicy("c"));
b376abae664a Metrics can be stored either as floating-point numbers, or as integers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5336
diff changeset
1554 ASSERT_EQ(MetricsDataType_Integer, m.GetDataType("c"));
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1555 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1556 }
4325
b96aedfa8cc1 unit tests now running in WebAssembly
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4234
diff changeset
1557 #endif
4342
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1558
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1559
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1560 #if ORTHANC_SANDBOXED != 1
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1561 TEST(Toolbox, ReadFileRange)
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1562 {
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1563 TemporaryFile tmp;
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1564 std::string s;
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1565
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1566 tmp.Write("");
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1567 tmp.Read(s); ASSERT_TRUE(s.empty());
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1568 tmp.ReadRange(s, 0, 0, true); ASSERT_TRUE(s.empty());
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1569 tmp.ReadRange(s, 0, 10, false); ASSERT_TRUE(s.empty());
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1570
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1571 ASSERT_THROW(tmp.ReadRange(s, 0, 1, true), OrthancException);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1572
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1573 tmp.Write("Hello");
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1574 tmp.Read(s); ASSERT_EQ("Hello", s);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1575 tmp.ReadRange(s, 0, 5, true); ASSERT_EQ("Hello", s);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1576 tmp.ReadRange(s, 0, 1, true); ASSERT_EQ("H", s);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1577 tmp.ReadRange(s, 1, 2, true); ASSERT_EQ("e", s);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1578 tmp.ReadRange(s, 2, 3, true); ASSERT_EQ("l", s);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1579 tmp.ReadRange(s, 3, 4, true); ASSERT_EQ("l", s);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1580 tmp.ReadRange(s, 4, 5, true); ASSERT_EQ("o", s);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1581 tmp.ReadRange(s, 2, 5, true); ASSERT_EQ("llo", s);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1582 tmp.ReadRange(s, 2, 50, false); ASSERT_EQ("llo", s);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1583 tmp.ReadRange(s, 2, 2, false); ASSERT_TRUE(s.empty());
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1584 tmp.ReadRange(s, 10, 50, false); ASSERT_TRUE(s.empty());
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1585
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1586 ASSERT_THROW(tmp.ReadRange(s, 5, 10, true), OrthancException);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1587 ASSERT_THROW(tmp.ReadRange(s, 10, 50, true), OrthancException);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1588 ASSERT_THROW(tmp.ReadRange(s, 50, 10, true), OrthancException);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1589 ASSERT_THROW(tmp.ReadRange(s, 2, 1, true), OrthancException);
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1590 }
52166629239f SystemToolbox::ReadFileRange()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
1591 #endif
4538
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1592
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1593
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1594 #if ORTHANC_SANDBOXED != 1
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1595 TEST(Toolbox, GetMacAddressess)
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1596 {
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1597 std::set<std::string> mac;
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1598 SystemToolbox::GetMacAddresses(mac);
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1599
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1600 for (std::set<std::string>::const_iterator it = mac.begin(); it != mac.end(); ++it)
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1601 {
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1602 printf("MAC address: [%s]\n", it->c_str());
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1603 }
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1604 }
8a7523da6a9b added SystemToolbox::GetMacAddresses()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
1605 #endif
5575
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1606
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1607
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1608 TEST(Toolbox, IsVersionAbove)
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1609 {
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1610 unsigned int a, b, c;
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1611 ASSERT_FALSE(Toolbox::ParseVersion(a, b, c, "nope"));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1612 ASSERT_FALSE(Toolbox::ParseVersion(a, b, c, "mainline"));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1613 ASSERT_FALSE(Toolbox::ParseVersion(a, b, c, ""));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1614 ASSERT_FALSE(Toolbox::ParseVersion(a, b, c, "-1"));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1615 ASSERT_FALSE(Toolbox::ParseVersion(a, b, c, "1.-1"));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1616 ASSERT_FALSE(Toolbox::ParseVersion(a, b, c, "1.1.-1"));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1617
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1618 ASSERT_TRUE(Toolbox::ParseVersion(a, b, c, "14.17.20"));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1619 ASSERT_EQ(14u, a);
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1620 ASSERT_EQ(17u, b);
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1621 ASSERT_EQ(20u, c);
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1622
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1623 ASSERT_TRUE(Toolbox::ParseVersion(a, b, c, "18.19"));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1624 ASSERT_EQ(18u, a);
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1625 ASSERT_EQ(19u, b);
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1626 ASSERT_EQ(0u, c);
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1627
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1628 ASSERT_TRUE(Toolbox::ParseVersion(a, b, c, "78"));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1629 ASSERT_EQ(78u, a);
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1630 ASSERT_EQ(0u, b);
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1631 ASSERT_EQ(0u, c);
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1632
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1633 ASSERT_TRUE(Toolbox::IsVersionAbove("mainline", 99, 99, 99));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1634
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1635 ASSERT_TRUE(Toolbox::IsVersionAbove("18", 17, 99, 99));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1636 ASSERT_TRUE(Toolbox::IsVersionAbove("18", 18, 0, 0));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1637 ASSERT_FALSE(Toolbox::IsVersionAbove("18", 18, 0, 1));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1638 ASSERT_FALSE(Toolbox::IsVersionAbove("18", 18, 1, 0));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1639 ASSERT_FALSE(Toolbox::IsVersionAbove("18", 19, 0, 0));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1640
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1641 ASSERT_TRUE(Toolbox::IsVersionAbove("18.19", 17, 99, 99));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1642 ASSERT_TRUE(Toolbox::IsVersionAbove("18.19", 18, 18, 99));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1643 ASSERT_TRUE(Toolbox::IsVersionAbove("18.19", 18, 19, 0));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1644 ASSERT_FALSE(Toolbox::IsVersionAbove("18.19", 18, 19, 1));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1645 ASSERT_FALSE(Toolbox::IsVersionAbove("18.19", 18, 20, 0));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1646 ASSERT_FALSE(Toolbox::IsVersionAbove("18.19", 19, 0, 0));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1647
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1648 ASSERT_TRUE(Toolbox::IsVersionAbove("18.19.20", 17, 99, 99));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1649 ASSERT_TRUE(Toolbox::IsVersionAbove("18.19.20", 18, 18, 99));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1650 ASSERT_TRUE(Toolbox::IsVersionAbove("18.19.20", 18, 19, 19));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1651 ASSERT_TRUE(Toolbox::IsVersionAbove("18.19.20", 18, 19, 20));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1652 ASSERT_FALSE(Toolbox::IsVersionAbove("18.19.20", 18, 19, 21));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1653 ASSERT_FALSE(Toolbox::IsVersionAbove("18.19.20", 18, 20, 0));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1654 ASSERT_FALSE(Toolbox::IsVersionAbove("18.19.20", 19, 0, 0));
d7eaa568da15 Orthanc::Logging automatically detects whether the Orthanc core supports OrthancPluginLogMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
1655 }