annotate OrthancFramework/UnitTestsSources/FrameworkTests.cpp @ 4146:1fbe54808853

added woff2 file extension in serve folders plugin
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 17 Aug 2020 18:25:20 +0200
parents bf7b9edf6b81
children e99d1ad11cfe
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
10 * the License, or (at your option) any later version.
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * 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
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
15 * Lesser General Public License for more details.
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4063
diff changeset
19 * <http://www.gnu.org/licenses/>.
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3987
diff changeset
23 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
24 // Must be the first to be sure to use the Orthanc framework shared library
4014
27628b0f6ada merging logging code for plugins and files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3992
diff changeset
25 # include <OrthancFramework.h>
3992
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3987
diff changeset
26 #endif
f9863630ec7f working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3987
diff changeset
27
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
28 #if !defined(ORTHANC_ENABLE_PUGIXML)
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
29 # error ORTHANC_ENABLE_PUGIXML is not defined
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
30 #endif
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
31
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
32 #include "../Sources/EnumerationDictionary.h"
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
34 #include <gtest/gtest.h>
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
36 #include "../Sources/DicomFormat/DicomTag.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
37 #include "../Sources/FileBuffer.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
38 #include "../Sources/HttpServer/HttpToolbox.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
39 #include "../Sources/Logging.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
40 #include "../Sources/MetricsRegistry.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/SystemToolbox.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
43 #include "../Sources/TemporaryFile.h"
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
44 #include "../Sources/Toolbox.h"
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
46 #include <ctype.h>
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
47
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 using namespace Orthanc;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 TEST(Uuid, Generation)
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 for (int i = 0; i < 10; i++)
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 std::string s = Toolbox::GenerateUuid();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 ASSERT_TRUE(Toolbox::IsUuid(s));
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 }
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 TEST(Uuid, Test)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 ASSERT_FALSE(Toolbox::IsUuid(""));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 ASSERT_FALSE(Toolbox::IsUuid("012345678901234567890123456789012345"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 ASSERT_TRUE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-446655440000"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 ASSERT_FALSE(Toolbox::IsUuid("550e8400-e29b-41d4-a716-44665544000_"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 ASSERT_FALSE(Toolbox::IsUuid("01234567890123456789012345678901234_"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-44665544000"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ASSERT_TRUE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000 ok"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 ASSERT_FALSE(Toolbox::StartsWithUuid("550e8400-e29b-41d4-a716-446655440000ok"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 TEST(Toolbox, IsSHA1)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 ASSERT_FALSE(Toolbox::IsSHA1(""));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 ASSERT_FALSE(Toolbox::IsSHA1("01234567890123456789012345678901234567890123"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 ASSERT_FALSE(Toolbox::IsSHA1("012345678901234567890123456789012345678901234"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 ASSERT_TRUE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9"));
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 std::string sha = " b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b9 ";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 ASSERT_TRUE(Toolbox::IsSHA1(sha));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 sha[3] = '\0';
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 sha[53] = '\0';
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 ASSERT_TRUE(Toolbox::IsSHA1(sha));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 sha[40] = '\0';
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 ASSERT_FALSE(Toolbox::IsSHA1(sha));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 ASSERT_FALSE(Toolbox::IsSHA1(" "));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 ASSERT_TRUE(Toolbox::IsSHA1("16738bc3-e47ed42a-43ce044c-a3414a45-cb069bd0"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 ASSERT_TRUE(Toolbox::IsSHA1(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s);
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 ASSERT_FALSE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b_"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 TEST(ParseGetArguments, Basic)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 IHttpHandler::GetArguments b;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 HttpToolbox::ParseGetArguments(b, "aaa=baaa&bb=a&aa=c");
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 IHttpHandler::Arguments a;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 HttpToolbox::CompileGetArguments(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 ASSERT_EQ(3u, a.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 ASSERT_EQ(a["aaa"], "baaa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 ASSERT_EQ(a["bb"], "a");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 ASSERT_EQ(a["aa"], "c");
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 TEST(ParseGetArguments, BasicEmpty)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 IHttpHandler::GetArguments b;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 HttpToolbox::ParseGetArguments(b, "aaa&bb=aa&aa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 IHttpHandler::Arguments a;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 HttpToolbox::CompileGetArguments(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 ASSERT_EQ(3u, a.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 ASSERT_EQ(a["aaa"], "");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 ASSERT_EQ(a["bb"], "aa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 ASSERT_EQ(a["aa"], "");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
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 TEST(ParseGetArguments, Single)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 IHttpHandler::GetArguments b;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 HttpToolbox::ParseGetArguments(b, "aaa=baaa");
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 IHttpHandler::Arguments a;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 HttpToolbox::CompileGetArguments(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 ASSERT_EQ(1u, a.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 ASSERT_EQ(a["aaa"], "baaa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 TEST(ParseGetArguments, SingleEmpty)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 IHttpHandler::GetArguments b;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 HttpToolbox::ParseGetArguments(b, "aaa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 IHttpHandler::Arguments a;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 HttpToolbox::CompileGetArguments(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 ASSERT_EQ(1u, a.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 ASSERT_EQ(a["aaa"], "");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 TEST(ParseGetQuery, Test1)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 UriComponents uri;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 IHttpHandler::GetArguments b;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 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
158
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 IHttpHandler::Arguments a;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 HttpToolbox::CompileGetArguments(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 ASSERT_EQ(3u, uri.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 ASSERT_EQ("instances", uri[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 ASSERT_EQ("test", uri[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 ASSERT_EQ("world", uri[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 ASSERT_EQ(3u, a.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 ASSERT_EQ(a["aaa"], "baaa");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 ASSERT_EQ(a["bb"], "a");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 ASSERT_EQ(a["aa"], "c");
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 TEST(ParseGetQuery, Test2)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 UriComponents uri;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 IHttpHandler::GetArguments b;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 HttpToolbox::ParseGetQuery(uri, b, "/instances/test/world");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 IHttpHandler::Arguments a;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 HttpToolbox::CompileGetArguments(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 ASSERT_EQ(3u, uri.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 ASSERT_EQ("instances", uri[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 ASSERT_EQ("test", uri[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 ASSERT_EQ("world", uri[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 ASSERT_EQ(0u, a.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 TEST(Uri, SplitUriComponents)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 UriComponents c, d;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 Toolbox::SplitUriComponents(c, "/cou/hello/world");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 ASSERT_EQ(3u, c.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 ASSERT_EQ("cou", c[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 ASSERT_EQ("hello", c[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 ASSERT_EQ("world", c[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 Toolbox::SplitUriComponents(c, "/cou/hello/world/");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 ASSERT_EQ(3u, c.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 ASSERT_EQ("cou", c[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 ASSERT_EQ("hello", c[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 ASSERT_EQ("world", c[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 Toolbox::SplitUriComponents(c, "/cou/hello/world/a");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 ASSERT_EQ(4u, c.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 ASSERT_EQ("cou", c[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 ASSERT_EQ("hello", c[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 ASSERT_EQ("world", c[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 ASSERT_EQ("a", c[3]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 Toolbox::SplitUriComponents(c, "/");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 ASSERT_EQ(0u, c.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 Toolbox::SplitUriComponents(c, "/hello");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 ASSERT_EQ(1u, c.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 ASSERT_EQ("hello", c[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 Toolbox::SplitUriComponents(c, "/hello/");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 ASSERT_EQ(1u, c.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 ASSERT_EQ("hello", c[0]);
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 ASSERT_THROW(Toolbox::SplitUriComponents(c, ""), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 ASSERT_THROW(Toolbox::SplitUriComponents(c, "a"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 ASSERT_THROW(Toolbox::SplitUriComponents(c, "/coucou//coucou"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 c.clear();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 c.push_back("test");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 ASSERT_EQ("/", Toolbox::FlattenUri(c, 10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 TEST(Uri, Truncate)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 UriComponents c, d;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 Toolbox::SplitUriComponents(c, "/cou/hello/world");
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 Toolbox::TruncateUri(d, c, 0);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 ASSERT_EQ(3u, d.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 ASSERT_EQ("cou", d[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 ASSERT_EQ("hello", d[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 ASSERT_EQ("world", d[2]);
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 Toolbox::TruncateUri(d, c, 1);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 ASSERT_EQ(2u, d.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 ASSERT_EQ("hello", d[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 ASSERT_EQ("world", d[1]);
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, 2);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 ASSERT_EQ(1u, d.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 ASSERT_EQ("world", d[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 Toolbox::TruncateUri(d, c, 3);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 ASSERT_EQ(0u, d.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 Toolbox::TruncateUri(d, c, 4);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 ASSERT_EQ(0u, d.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 Toolbox::TruncateUri(d, c, 5);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 ASSERT_EQ(0u, d.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260
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 TEST(Uri, Child)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 UriComponents c1; Toolbox::SplitUriComponents(c1, "/hello/world");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 UriComponents c2; Toolbox::SplitUriComponents(c2, "/hello/hello");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 UriComponents c3; Toolbox::SplitUriComponents(c3, "/hello");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 UriComponents c4; Toolbox::SplitUriComponents(c4, "/world");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 UriComponents c5; Toolbox::SplitUriComponents(c5, "/");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 ASSERT_TRUE(Toolbox::IsChildUri(c1, c1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 ASSERT_FALSE(Toolbox::IsChildUri(c1, c2));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 ASSERT_FALSE(Toolbox::IsChildUri(c1, c3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 ASSERT_FALSE(Toolbox::IsChildUri(c1, c4));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 ASSERT_FALSE(Toolbox::IsChildUri(c1, c5));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 ASSERT_FALSE(Toolbox::IsChildUri(c2, c1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 ASSERT_TRUE(Toolbox::IsChildUri(c2, c2));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 ASSERT_FALSE(Toolbox::IsChildUri(c2, c3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 ASSERT_FALSE(Toolbox::IsChildUri(c2, c4));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 ASSERT_FALSE(Toolbox::IsChildUri(c2, c5));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 ASSERT_TRUE(Toolbox::IsChildUri(c3, c1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 ASSERT_TRUE(Toolbox::IsChildUri(c3, c2));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 ASSERT_TRUE(Toolbox::IsChildUri(c3, c3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 ASSERT_FALSE(Toolbox::IsChildUri(c3, c4));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 ASSERT_FALSE(Toolbox::IsChildUri(c3, c5));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 ASSERT_FALSE(Toolbox::IsChildUri(c4, c1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 ASSERT_FALSE(Toolbox::IsChildUri(c4, c2));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 ASSERT_FALSE(Toolbox::IsChildUri(c4, c3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 ASSERT_TRUE(Toolbox::IsChildUri(c4, c4));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 ASSERT_FALSE(Toolbox::IsChildUri(c4, c5));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 ASSERT_TRUE(Toolbox::IsChildUri(c5, c1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 ASSERT_TRUE(Toolbox::IsChildUri(c5, c2));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 ASSERT_TRUE(Toolbox::IsChildUri(c5, c3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 ASSERT_TRUE(Toolbox::IsChildUri(c5, c4));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 ASSERT_TRUE(Toolbox::IsChildUri(c5, c5));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 TEST(Uri, AutodetectMimeType)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("../NOTES"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType(""));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("/"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("a/a"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("..\\a\\"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 ASSERT_EQ(MimeType_Binary, SystemToolbox::AutodetectMimeType("..\\a\\a"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 ASSERT_EQ(MimeType_PlainText, SystemToolbox::AutodetectMimeType("../NOTES.txt"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 ASSERT_EQ(MimeType_PlainText, SystemToolbox::AutodetectMimeType("../coucou.xml/NOTES.txt"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("..\\coucou.\\NOTES.xml"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("../.xml"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("../.XmL"));
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_JavaScript, SystemToolbox::AutodetectMimeType("NOTES.js"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 ASSERT_EQ(MimeType_Json, SystemToolbox::AutodetectMimeType("NOTES.json"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 ASSERT_EQ(MimeType_Pdf, SystemToolbox::AutodetectMimeType("NOTES.pdf"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 ASSERT_EQ(MimeType_Css, SystemToolbox::AutodetectMimeType("NOTES.css"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 ASSERT_EQ(MimeType_Html, SystemToolbox::AutodetectMimeType("NOTES.html"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 ASSERT_EQ(MimeType_PlainText, SystemToolbox::AutodetectMimeType("NOTES.txt"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 ASSERT_EQ(MimeType_Xml, SystemToolbox::AutodetectMimeType("NOTES.xml"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 ASSERT_EQ(MimeType_Gif, SystemToolbox::AutodetectMimeType("NOTES.gif"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 ASSERT_EQ(MimeType_Jpeg, SystemToolbox::AutodetectMimeType("NOTES.jpg"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 ASSERT_EQ(MimeType_Jpeg, SystemToolbox::AutodetectMimeType("NOTES.jpeg"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 ASSERT_EQ(MimeType_Png, SystemToolbox::AutodetectMimeType("NOTES.png"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 ASSERT_EQ(MimeType_NaCl, SystemToolbox::AutodetectMimeType("NOTES.nexe"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 ASSERT_EQ(MimeType_Json, SystemToolbox::AutodetectMimeType("NOTES.nmf"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 ASSERT_EQ(MimeType_PNaCl, SystemToolbox::AutodetectMimeType("NOTES.pexe"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 ASSERT_EQ(MimeType_Svg, SystemToolbox::AutodetectMimeType("NOTES.svg"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 ASSERT_EQ(MimeType_Woff, SystemToolbox::AutodetectMimeType("NOTES.woff"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 ASSERT_EQ(MimeType_Woff2, SystemToolbox::AutodetectMimeType("NOTES.woff2"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 // Test primitives from the "RegisterDefaultExtensions()" that was
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 // present in the sample "Serve Folders plugin" of Orthanc 1.4.2
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 ASSERT_STREQ("application/javascript", EnumerationToString(SystemToolbox::AutodetectMimeType(".js")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 ASSERT_STREQ("application/json", EnumerationToString(SystemToolbox::AutodetectMimeType(".json")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 ASSERT_STREQ("application/json", EnumerationToString(SystemToolbox::AutodetectMimeType(".nmf")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 ASSERT_STREQ("application/octet-stream", EnumerationToString(SystemToolbox::AutodetectMimeType("")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 ASSERT_STREQ("application/wasm", EnumerationToString(SystemToolbox::AutodetectMimeType(".wasm")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 ASSERT_STREQ("application/x-font-woff", EnumerationToString(SystemToolbox::AutodetectMimeType(".woff")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 ASSERT_STREQ("application/x-nacl", EnumerationToString(SystemToolbox::AutodetectMimeType(".nexe")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 ASSERT_STREQ("application/x-pnacl", EnumerationToString(SystemToolbox::AutodetectMimeType(".pexe")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 ASSERT_STREQ("application/xml", EnumerationToString(SystemToolbox::AutodetectMimeType(".xml")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 ASSERT_STREQ("font/woff2", EnumerationToString(SystemToolbox::AutodetectMimeType(".woff2")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 ASSERT_STREQ("image/gif", EnumerationToString(SystemToolbox::AutodetectMimeType(".gif")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 ASSERT_STREQ("image/jpeg", EnumerationToString(SystemToolbox::AutodetectMimeType(".jpeg")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 ASSERT_STREQ("image/jpeg", EnumerationToString(SystemToolbox::AutodetectMimeType(".jpg")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 ASSERT_STREQ("image/png", EnumerationToString(SystemToolbox::AutodetectMimeType(".png")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 ASSERT_STREQ("image/svg+xml", EnumerationToString(SystemToolbox::AutodetectMimeType(".svg")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 ASSERT_STREQ("text/css", EnumerationToString(SystemToolbox::AutodetectMimeType(".css")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 ASSERT_STREQ("text/html", EnumerationToString(SystemToolbox::AutodetectMimeType(".html")));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 TEST(Toolbox, ComputeMD5)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 // # echo -n "Hello" | md5sum
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 Toolbox::ComputeMD5(s, "Hello");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 ASSERT_EQ("8b1a9953c4611296a827abf8c47804d7", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 Toolbox::ComputeMD5(s, "");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 ASSERT_EQ("d41d8cd98f00b204e9800998ecf8427e", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 TEST(Toolbox, ComputeSHA1)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 Toolbox::ComputeSHA1(s, "The quick brown fox jumps over the lazy dog");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 ASSERT_EQ("2fd4e1c6-7a2d28fc-ed849ee1-bb76e739-1b93eb12", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 Toolbox::ComputeSHA1(s, "");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 ASSERT_EQ("da39a3ee-5e6b4b0d-3255bfef-95601890-afd80709", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 }
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 TEST(Toolbox, PathToExecutable)
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 printf("[%s]\n", SystemToolbox::GetPathToExecutable().c_str());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 printf("[%s]\n", SystemToolbox::GetDirectoryOfExecutable().c_str());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 TEST(Toolbox, StripSpaces)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 ASSERT_EQ("", Toolbox::StripSpaces(" \t \r \n "));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 ASSERT_EQ("coucou", Toolbox::StripSpaces(" coucou \t \r \n "));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 ASSERT_EQ("cou cou", Toolbox::StripSpaces(" cou cou \n "));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 ASSERT_EQ("c", Toolbox::StripSpaces(" \n\t c\r \n "));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 TEST(Toolbox, Case)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 std::string s = "CoU";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 std::string ss;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 Toolbox::ToUpperCase(ss, s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 ASSERT_EQ("COU", ss);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 Toolbox::ToLowerCase(ss, s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 ASSERT_EQ("cou", ss);
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 s = "CoU";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 Toolbox::ToUpperCase(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 ASSERT_EQ("COU", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 s = "CoU";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 Toolbox::ToLowerCase(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 ASSERT_EQ("cou", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409
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 TEST(Logger, Basic)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 LOG(INFO) << "I say hello";
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 TEST(Toolbox, ConvertFromLatin1)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 // This is a Latin-1 test string
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 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
420
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 std::string s((char*) &data[0], 10);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 ASSERT_EQ("&abc", Toolbox::ConvertToAscii(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 // Open in Emacs, then save with UTF-8 encoding, then "hexdump -C"
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 std::string utf8 = Toolbox::ConvertToUtf8(s, Encoding_Latin1, false);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 ASSERT_EQ(15u, utf8.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[0]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 ASSERT_EQ(0xa0, static_cast<unsigned char>(utf8[1]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[2]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 ASSERT_EQ(0xa9, static_cast<unsigned char>(utf8[3]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[4]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 ASSERT_EQ(0xaa, static_cast<unsigned char>(utf8[5]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[6]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 ASSERT_EQ(0xa7, static_cast<unsigned char>(utf8[7]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 ASSERT_EQ(0x26, static_cast<unsigned char>(utf8[8]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 ASSERT_EQ(0xc3, static_cast<unsigned char>(utf8[9]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 ASSERT_EQ(0x86, static_cast<unsigned char>(utf8[10]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 ASSERT_EQ(0x61, static_cast<unsigned char>(utf8[11]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 ASSERT_EQ(0x62, static_cast<unsigned char>(utf8[12]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 ASSERT_EQ(0x63, static_cast<unsigned char>(utf8[13]));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 ASSERT_EQ(0x00, static_cast<unsigned char>(utf8[14])); // Null-terminated string
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 TEST(Toolbox, FixUtf8)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 // This is a Latin-1 test string: "crane" with a circumflex accent
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 const unsigned char latin1[] = { 0x63, 0x72, 0xe2, 0x6e, 0x65 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 std::string s((char*) &latin1[0], sizeof(latin1) / sizeof(char));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 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
453 ASSERT_EQ("cre", Toolbox::ConvertToUtf8(s, Encoding_Utf8, false));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 static int32_t GetUnicode(const uint8_t* data,
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 size_t size,
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 size_t expectedLength)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 std::string s((char*) &data[0], size);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 uint32_t unicode;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 size_t length;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 Toolbox::Utf8ToUnicodeCharacter(unicode, length, s, 0);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 if (length != expectedLength)
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 return -1; // Error case
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 else
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 return unicode;
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
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 TEST(Toolbox, Utf8ToUnicode)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 // https://en.wikipedia.org/wiki/UTF-8
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 ASSERT_EQ(1u, sizeof(char));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 ASSERT_EQ(1u, sizeof(uint8_t));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 const uint8_t data[] = { 0x24 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 ASSERT_EQ(0x24, GetUnicode(data, 1, 1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 ASSERT_THROW(GetUnicode(data, 0, 1), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 const uint8_t data[] = { 0xc2, 0xa2 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 ASSERT_EQ(0xa2, GetUnicode(data, 2, 2));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 ASSERT_THROW(GetUnicode(data, 1, 2), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 const uint8_t data[] = { 0xe0, 0xa4, 0xb9 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 ASSERT_EQ(0x0939, GetUnicode(data, 3, 3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 ASSERT_THROW(GetUnicode(data, 2, 3), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 }
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 const uint8_t data[] = { 0xe2, 0x82, 0xac };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 ASSERT_EQ(0x20ac, GetUnicode(data, 3, 3));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 ASSERT_THROW(GetUnicode(data, 2, 3), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506
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 const uint8_t data[] = { 0xf0, 0x90, 0x8d, 0x88 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 ASSERT_EQ(0x010348, GetUnicode(data, 4, 4));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 ASSERT_THROW(GetUnicode(data, 3, 4), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 }
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 const uint8_t data[] = { 0xe0 };
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 ASSERT_THROW(GetUnicode(data, 1, 1), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 }
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 TEST(Toolbox, UrlDecode)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 s = "Hello%20World";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 Toolbox::UrlDecode(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 ASSERT_EQ("Hello World", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 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
529 Toolbox::UrlDecode(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 std::string ss = "!#$&'()*+,/:;=?@[]";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 ss.push_back((char) 144);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 ss.push_back((char) 255);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 ASSERT_EQ(ss, s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 s = "(2000%2C00A4)+Other";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 Toolbox::UrlDecode(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 ASSERT_EQ("(2000,00A4) Other", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539
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 TEST(Toolbox, IsAsciiString)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 std::string s = "Hello 12 /";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 ASSERT_EQ(10u, s.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 ASSERT_TRUE(Toolbox::IsAsciiString(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 ASSERT_TRUE(Toolbox::IsAsciiString(s.c_str(), 10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 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
548
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 s[2] = '\0';
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 ASSERT_EQ(10u, s.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 ASSERT_FALSE(Toolbox::IsAsciiString(s));
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 ASSERT_TRUE(Toolbox::IsAsciiString("Hello\nworld"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554 ASSERT_FALSE(Toolbox::IsAsciiString("Hello\rworld"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 ASSERT_EQ("Hello\nworld", Toolbox::ConvertToAscii("Hello\nworld"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 ASSERT_EQ("Helloworld", Toolbox::ConvertToAscii("Hello\r\tworld"));
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 #if defined(__linux__)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 TEST(Toolbox, AbsoluteDirectory)
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 ASSERT_EQ("/tmp/hello", SystemToolbox::InterpretRelativePath("/tmp", "hello"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 ASSERT_EQ("/tmp", SystemToolbox::InterpretRelativePath("/tmp", "/tmp"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568
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 TEST(Toolbox, WriteFile)
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 std::string path;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573
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 TemporaryFile tmp;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 path = tmp.GetPath();
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 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 s.append("Hello");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 s.push_back('\0');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 s.append("World");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 ASSERT_EQ(11u, s.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 SystemToolbox::WriteFile(s, path.c_str());
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 std::string t;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 SystemToolbox::ReadFile(t, path.c_str());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 ASSERT_EQ(11u, t.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 ASSERT_EQ(0, t[5]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 ASSERT_EQ(0, memcmp(s.c_str(), t.c_str(), s.size()));
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 std::string h;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 ASSERT_EQ(true, SystemToolbox::ReadHeader(h, path.c_str(), 1));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 ASSERT_EQ(1u, h.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 ASSERT_EQ('H', h[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 ASSERT_TRUE(SystemToolbox::ReadHeader(h, path.c_str(), 0));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 ASSERT_EQ(0u, h.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 ASSERT_FALSE(SystemToolbox::ReadHeader(h, path.c_str(), 32));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 ASSERT_EQ(11u, h.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 ASSERT_EQ(0, memcmp(s.c_str(), h.c_str(), s.size()));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 std::string u;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 ASSERT_THROW(SystemToolbox::ReadFile(u, path.c_str()), OrthancException);
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 TEST(Toolbox, FileBuffer)
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 FileBuffer f;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 f.Append("a", 1);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 f.Append("", 0);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 f.Append("bc", 2);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 f.Read(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 ASSERT_EQ("abc", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 ASSERT_THROW(f.Append("d", 1), OrthancException); // File is closed
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 TEST(Toolbox, Wildcard)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 ASSERT_EQ("abcd", Toolbox::WildcardToRegularExpression("abcd"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 ASSERT_EQ("ab.*cd", Toolbox::WildcardToRegularExpression("ab*cd"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 ASSERT_EQ("ab..cd", Toolbox::WildcardToRegularExpression("ab??cd"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 ASSERT_EQ("a.*b.c.*d", Toolbox::WildcardToRegularExpression("a*b?c*d"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 ASSERT_EQ("a\\{b\\]", Toolbox::WildcardToRegularExpression("a{b]"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 }
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 TEST(Toolbox, Tokenize)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636 std::vector<std::string> t;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 Toolbox::TokenizeString(t, "", ',');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639 ASSERT_EQ(1u, t.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 ASSERT_EQ("", t[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 Toolbox::TokenizeString(t, "abc", ',');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 ASSERT_EQ(1u, t.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 ASSERT_EQ("abc", t[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 Toolbox::TokenizeString(t, "ab,cd,ef,", ',');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 ASSERT_EQ(4u, t.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 ASSERT_EQ("ab", t[0]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 ASSERT_EQ("cd", t[1]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 ASSERT_EQ("ef", t[2]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 ASSERT_EQ("", t[3]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 TEST(Toolbox, Enumerations)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 ASSERT_EQ(Encoding_Utf8, StringToEncoding(EnumerationToString(Encoding_Utf8)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 ASSERT_EQ(Encoding_Ascii, StringToEncoding(EnumerationToString(Encoding_Ascii)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 ASSERT_EQ(Encoding_Latin1, StringToEncoding(EnumerationToString(Encoding_Latin1)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 ASSERT_EQ(Encoding_Latin2, StringToEncoding(EnumerationToString(Encoding_Latin2)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 ASSERT_EQ(Encoding_Latin3, StringToEncoding(EnumerationToString(Encoding_Latin3)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 ASSERT_EQ(Encoding_Latin4, StringToEncoding(EnumerationToString(Encoding_Latin4)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 ASSERT_EQ(Encoding_Latin5, StringToEncoding(EnumerationToString(Encoding_Latin5)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 ASSERT_EQ(Encoding_Cyrillic, StringToEncoding(EnumerationToString(Encoding_Cyrillic)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 ASSERT_EQ(Encoding_Arabic, StringToEncoding(EnumerationToString(Encoding_Arabic)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 ASSERT_EQ(Encoding_Greek, StringToEncoding(EnumerationToString(Encoding_Greek)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 ASSERT_EQ(Encoding_Hebrew, StringToEncoding(EnumerationToString(Encoding_Hebrew)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 ASSERT_EQ(Encoding_Japanese, StringToEncoding(EnumerationToString(Encoding_Japanese)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 ASSERT_EQ(Encoding_Chinese, StringToEncoding(EnumerationToString(Encoding_Chinese)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 ASSERT_EQ(Encoding_Thai, StringToEncoding(EnumerationToString(Encoding_Thai)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 ASSERT_EQ(Encoding_Korean, StringToEncoding(EnumerationToString(Encoding_Korean)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 ASSERT_EQ(Encoding_JapaneseKanji, StringToEncoding(EnumerationToString(Encoding_JapaneseKanji)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 ASSERT_EQ(Encoding_SimplifiedChinese, StringToEncoding(EnumerationToString(Encoding_SimplifiedChinese)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 ASSERT_EQ(ResourceType_Patient, StringToResourceType(EnumerationToString(ResourceType_Patient)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 ASSERT_EQ(ResourceType_Study, StringToResourceType(EnumerationToString(ResourceType_Study)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 ASSERT_EQ(ResourceType_Series, StringToResourceType(EnumerationToString(ResourceType_Series)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 ASSERT_EQ(ResourceType_Instance, StringToResourceType(EnumerationToString(ResourceType_Instance)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 ASSERT_EQ(ImageFormat_Png, StringToImageFormat(EnumerationToString(ImageFormat_Png)));
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 ASSERT_EQ(PhotometricInterpretation_ARGB, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_ARGB)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 ASSERT_EQ(PhotometricInterpretation_CMYK, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_CMYK)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 ASSERT_EQ(PhotometricInterpretation_HSV, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_HSV)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 ASSERT_EQ(PhotometricInterpretation_Monochrome1, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Monochrome1)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685 ASSERT_EQ(PhotometricInterpretation_Monochrome2, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Monochrome2)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 ASSERT_EQ(PhotometricInterpretation_Palette, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_Palette)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 ASSERT_EQ(PhotometricInterpretation_RGB, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_RGB)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 ASSERT_EQ(PhotometricInterpretation_YBRFull, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRFull)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 ASSERT_EQ(PhotometricInterpretation_YBRFull422, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRFull422)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 ASSERT_EQ(PhotometricInterpretation_YBRPartial420, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRPartial420)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 ASSERT_EQ(PhotometricInterpretation_YBRPartial422, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBRPartial422)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 ASSERT_EQ(PhotometricInterpretation_YBR_ICT, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBR_ICT)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693 ASSERT_EQ(PhotometricInterpretation_YBR_RCT, StringToPhotometricInterpretation(EnumerationToString(PhotometricInterpretation_YBR_RCT)));
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 ASSERT_STREQ("Unknown", EnumerationToString(PhotometricInterpretation_Unknown));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 ASSERT_THROW(StringToPhotometricInterpretation("Unknown"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 ASSERT_EQ(DicomVersion_2008, StringToDicomVersion(EnumerationToString(DicomVersion_2008)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 ASSERT_EQ(DicomVersion_2017c, StringToDicomVersion(EnumerationToString(DicomVersion_2017c)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 for (int i = static_cast<int>(ValueRepresentation_ApplicationEntity);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 i < static_cast<int>(ValueRepresentation_NotSupported); i += 1)
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 ValueRepresentation vr = static_cast<ValueRepresentation>(i);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 ASSERT_EQ(vr, StringToValueRepresentation(EnumerationToString(vr), true));
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 ASSERT_THROW(StringToValueRepresentation("nope", true), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 ASSERT_EQ(JobState_Pending, StringToJobState(EnumerationToString(JobState_Pending)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 ASSERT_EQ(JobState_Running, StringToJobState(EnumerationToString(JobState_Running)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 ASSERT_EQ(JobState_Success, StringToJobState(EnumerationToString(JobState_Success)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 ASSERT_EQ(JobState_Failure, StringToJobState(EnumerationToString(JobState_Failure)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 ASSERT_EQ(JobState_Paused, StringToJobState(EnumerationToString(JobState_Paused)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 ASSERT_EQ(JobState_Retry, StringToJobState(EnumerationToString(JobState_Retry)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 ASSERT_THROW(StringToJobState("nope"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 ASSERT_EQ(MimeType_Binary, StringToMimeType(EnumerationToString(MimeType_Binary)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 ASSERT_EQ(MimeType_Css, StringToMimeType(EnumerationToString(MimeType_Css)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 ASSERT_EQ(MimeType_Dicom, StringToMimeType(EnumerationToString(MimeType_Dicom)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 ASSERT_EQ(MimeType_Gif, StringToMimeType(EnumerationToString(MimeType_Gif)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 ASSERT_EQ(MimeType_Gzip, StringToMimeType(EnumerationToString(MimeType_Gzip)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 ASSERT_EQ(MimeType_Html, StringToMimeType(EnumerationToString(MimeType_Html)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 ASSERT_EQ(MimeType_JavaScript, StringToMimeType(EnumerationToString(MimeType_JavaScript)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 ASSERT_EQ(MimeType_Jpeg, StringToMimeType(EnumerationToString(MimeType_Jpeg)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 ASSERT_EQ(MimeType_Jpeg2000, StringToMimeType(EnumerationToString(MimeType_Jpeg2000)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 ASSERT_EQ(MimeType_Json, StringToMimeType(EnumerationToString(MimeType_Json)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 ASSERT_EQ(MimeType_NaCl, StringToMimeType(EnumerationToString(MimeType_NaCl)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 ASSERT_EQ(MimeType_PNaCl, StringToMimeType(EnumerationToString(MimeType_PNaCl)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 ASSERT_EQ(MimeType_Pam, StringToMimeType(EnumerationToString(MimeType_Pam)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 ASSERT_EQ(MimeType_Pdf, StringToMimeType(EnumerationToString(MimeType_Pdf)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 ASSERT_EQ(MimeType_PlainText, StringToMimeType(EnumerationToString(MimeType_PlainText)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 ASSERT_EQ(MimeType_Png, StringToMimeType(EnumerationToString(MimeType_Png)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 ASSERT_EQ(MimeType_Svg, StringToMimeType(EnumerationToString(MimeType_Svg)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 ASSERT_EQ(MimeType_WebAssembly, StringToMimeType(EnumerationToString(MimeType_WebAssembly)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 ASSERT_EQ(MimeType_Xml, StringToMimeType("application/xml"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 ASSERT_EQ(MimeType_Xml, StringToMimeType("text/xml"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 ASSERT_EQ(MimeType_Xml, StringToMimeType(EnumerationToString(MimeType_Xml)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 ASSERT_EQ(MimeType_DicomWebJson, StringToMimeType(EnumerationToString(MimeType_DicomWebJson)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 ASSERT_EQ(MimeType_DicomWebXml, StringToMimeType(EnumerationToString(MimeType_DicomWebXml)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 ASSERT_THROW(StringToMimeType("nope"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Patient));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Study));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Series));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Patient, ResourceType_Instance));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Patient));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Study));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Series));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Study, ResourceType_Instance));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Patient));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Study));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Series));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Series, ResourceType_Instance));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Patient));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Study));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 ASSERT_FALSE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Series));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 ASSERT_TRUE(IsResourceLevelAboveOrEqual(ResourceType_Instance, ResourceType_Instance));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 #if defined(__linux__) || defined(__OpenBSD__)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 #include <endian.h>
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 #elif defined(__FreeBSD__)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 #include <machine/endian.h>
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 TEST(Toolbox, Endianness)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 // Parts of this test come from Adam Conrad
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=728822#5
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 /**
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 * Windows and OS X are assumed to always little-endian.
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 **/
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 #if defined(_WIN32) || defined(__APPLE__)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 /**
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 * FreeBSD.
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788 **/
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 #elif defined(__FreeBSD__) || defined(__OpenBSD__)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 # if _BYTE_ORDER == _BIG_ENDIAN
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 # else // _LITTLE_ENDIAN
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 # endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 /**
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799 * Linux.
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 **/
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 #elif defined(__linux__) || defined(__FreeBSD_kernel__)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 #if !defined(__BYTE_ORDER)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805 # error Support your platform here
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808 # if __BYTE_ORDER == __BIG_ENDIAN
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 ASSERT_EQ(Endianness_Big, Toolbox::DetectEndianness());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 # else // __LITTLE_ENDIAN
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 ASSERT_EQ(Endianness_Little, Toolbox::DetectEndianness());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 # endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 #error Support your platform here
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819
4045
05b8fd21089c fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
820 #include "../Sources/Endianness.h"
3987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 static void ASSERT_EQ16(uint16_t a, uint16_t b)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 #ifdef __MINGW32__
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 // This cast solves a linking problem with MinGW
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828 ASSERT_EQ(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 static void ASSERT_NE16(uint16_t a, uint16_t b)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 #ifdef __MINGW32__
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 // This cast solves a linking problem with MinGW
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 ASSERT_NE(static_cast<unsigned int>(a), static_cast<unsigned int>(b));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 ASSERT_NE(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840 }
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 static void ASSERT_EQ32(uint32_t a, uint32_t b)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 #ifdef __MINGW32__
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 // This cast solves a linking problem with MinGW
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848 ASSERT_EQ(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 static void ASSERT_NE32(uint32_t a, uint32_t b)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854 #ifdef __MINGW32__
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 // This cast solves a linking problem with MinGW
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 ASSERT_NE(static_cast<unsigned int>(a), static_cast<unsigned int>(b));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 ASSERT_NE(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 static void ASSERT_EQ64(uint64_t a, uint64_t b)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 #ifdef __MINGW32__
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 // This cast solves a linking problem with MinGW
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866 ASSERT_EQ(static_cast<unsigned int>(a), static_cast<unsigned int>(b));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 ASSERT_EQ(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 static void ASSERT_NE64(uint64_t a, uint64_t b)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 #ifdef __MINGW32__
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 // This cast solves a linking problem with MinGW
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 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
877 #else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 ASSERT_NE(a, b);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 #endif
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 TEST(Toolbox, EndiannessConversions16)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 Endianness e = Toolbox::DetectEndianness();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 for (unsigned int i = 0; i < 65536; i += 17)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 uint16_t v = static_cast<uint16_t>(i);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891 ASSERT_EQ16(v, be16toh(htobe16(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892 ASSERT_EQ16(v, le16toh(htole16(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 const uint8_t* bytes = reinterpret_cast<const uint8_t*>(&v);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 if (bytes[0] != bytes[1])
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 ASSERT_NE16(v, le16toh(htobe16(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898 ASSERT_NE16(v, be16toh(htole16(v)));
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 else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 ASSERT_EQ16(v, le16toh(htobe16(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 ASSERT_EQ16(v, be16toh(htole16(v)));
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 switch (e)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 case Endianness_Little:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 ASSERT_EQ16(v, htole16(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 if (bytes[0] != bytes[1])
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 ASSERT_NE16(v, htobe16(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914 else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 ASSERT_EQ16(v, htobe16(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 break;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920 case Endianness_Big:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 ASSERT_EQ16(v, htobe16(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922 if (bytes[0] != bytes[1])
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924 ASSERT_NE16(v, htole16(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 else
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928 ASSERT_EQ16(v, htole16(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930 break;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932 default:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 throw OrthancException(ErrorCode_ParameterOutOfRange);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 }
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 TEST(Toolbox, EndiannessConversions32)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941 const uint32_t v = 0xff010203u;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 const uint32_t r = 0x030201ffu;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 ASSERT_EQ32(v, be32toh(htobe32(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944 ASSERT_EQ32(v, le32toh(htole32(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945 ASSERT_NE32(v, be32toh(htole32(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946 ASSERT_NE32(v, le32toh(htobe32(v)));
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 switch (Toolbox::DetectEndianness())
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950 case Endianness_Little:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 ASSERT_EQ32(r, htobe32(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952 ASSERT_EQ32(v, htole32(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 ASSERT_EQ32(r, be32toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 ASSERT_EQ32(v, le32toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 break;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957 case Endianness_Big:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 ASSERT_EQ32(v, htobe32(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 ASSERT_EQ32(r, htole32(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 ASSERT_EQ32(v, be32toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 ASSERT_EQ32(r, le32toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962 break;
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 default:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 throw OrthancException(ErrorCode_ParameterOutOfRange);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970 TEST(Toolbox, EndiannessConversions64)
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 const uint64_t v = 0xff01020304050607LL;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 const uint64_t r = 0x07060504030201ffLL;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974 ASSERT_EQ64(v, be64toh(htobe64(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975 ASSERT_EQ64(v, le64toh(htole64(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 ASSERT_NE64(v, be64toh(htole64(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977 ASSERT_NE64(v, le64toh(htobe64(v)));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 switch (Toolbox::DetectEndianness())
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 case Endianness_Little:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 ASSERT_EQ64(r, htobe64(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983 ASSERT_EQ64(v, htole64(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984 ASSERT_EQ64(r, be64toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 ASSERT_EQ64(v, le64toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986 break;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
988 case Endianness_Big:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989 ASSERT_EQ64(v, htobe64(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
990 ASSERT_EQ64(r, htole64(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991 ASSERT_EQ64(v, be64toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
992 ASSERT_EQ64(r, le64toh(v));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
993 break;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
994
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
995 default:
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
996 throw OrthancException(ErrorCode_ParameterOutOfRange);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
997 }
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1001 TEST(Toolbox, Now)
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 LOG(WARNING) << "Local time: " << SystemToolbox::GetNowIsoString(false);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1004 LOG(WARNING) << "Universal time: " << SystemToolbox::GetNowIsoString(true);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1006 std::string date, time;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1007 SystemToolbox::GetNowDicom(date, time, false);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1008 LOG(WARNING) << "Local DICOM time: [" << date << "] [" << time << "]";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1009
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1010 SystemToolbox::GetNowDicom(date, time, true);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1011 LOG(WARNING) << "Universal DICOM time: [" << date << "] [" << time << "]";
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
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1016 #if ORTHANC_ENABLE_PUGIXML == 1
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1017 TEST(Toolbox, Xml)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1018 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019 Json::Value a;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020 a["hello"] = "world";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 a["42"] = 43;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022 a["b"] = Json::arrayValue;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1023 a["b"].append("test");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1024 a["b"].append("test2");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1025
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1026 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027 Toolbox::JsonToXml(s, a);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1028
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1029 std::cout << s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1030 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1031 #endif
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1034 #if !defined(_WIN32)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035 TEST(Toolbox, ExecuteSystemCommand)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1036 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1037 std::vector<std::string> args(2);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1038 args[0] = "Hello";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1039 args[1] = "World";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1040
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1041 SystemToolbox::ExecuteSystemCommand("echo", args);
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 #endif
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1046 TEST(Toolbox, IsInteger)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1047 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1048 ASSERT_TRUE(Toolbox::IsInteger("00236"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1049 ASSERT_TRUE(Toolbox::IsInteger("-0042"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1050 ASSERT_TRUE(Toolbox::IsInteger("0"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1051 ASSERT_TRUE(Toolbox::IsInteger("-0"));
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 ASSERT_FALSE(Toolbox::IsInteger(""));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1054 ASSERT_FALSE(Toolbox::IsInteger("42a"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1055 ASSERT_FALSE(Toolbox::IsInteger("42-"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1056 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1058
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1059 TEST(Toolbox, StartsWith)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1060 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1061 ASSERT_TRUE(Toolbox::StartsWith("hello world", ""));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1062 ASSERT_TRUE(Toolbox::StartsWith("hello world", "hello"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1063 ASSERT_TRUE(Toolbox::StartsWith("hello world", "h"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1064 ASSERT_FALSE(Toolbox::StartsWith("hello world", "H"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1065 ASSERT_FALSE(Toolbox::StartsWith("h", "hello"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1066 ASSERT_TRUE(Toolbox::StartsWith("h", "h"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1067 ASSERT_FALSE(Toolbox::StartsWith("", "h"));
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
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 TEST(Toolbox, UriEncode)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1072 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1073 std::string s;
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 // Unreserved characters must not be modified
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1076 std::string t = "aAzZ09.-~_";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1077 Toolbox::UriEncode(s, t);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1078 ASSERT_EQ(t, s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1079
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1080 Toolbox::UriEncode(s, "!#$&'()*+,/:;=?@[]"); ASSERT_EQ("%21%23%24%26%27%28%29%2A%2B%2C%2F%3A%3B%3D%3F%40%5B%5D", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1081 Toolbox::UriEncode(s, "%"); ASSERT_EQ("%25", s);
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 // Encode characters from UTF-8. This is the test string from the
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1084 // file "../Resources/EncodingTests.py"
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1085 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
1086 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
1087 }
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 TEST(Toolbox, AccessJson)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1092 Json::Value v = Json::arrayValue;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 ASSERT_EQ("nope", Toolbox::GetJsonStringField(v, "hello", "nope"));
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 v = Json::objectValue;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096 ASSERT_EQ("nope", Toolbox::GetJsonStringField(v, "hello", "nope"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1097 ASSERT_EQ(-10, Toolbox::GetJsonIntegerField(v, "hello", -10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098 ASSERT_EQ(10u, Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099 ASSERT_TRUE(Toolbox::GetJsonBooleanField(v, "hello", true));
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 v["hello"] = "world";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1102 ASSERT_EQ("world", Toolbox::GetJsonStringField(v, "hello", "nope"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1103 ASSERT_THROW(Toolbox::GetJsonIntegerField(v, "hello", -10), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1104 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1105 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException);
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 v["hello"] = -42;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109 ASSERT_EQ(-42, Toolbox::GetJsonIntegerField(v, "hello", -10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException);
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 v["hello"] = 42;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1114 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1115 ASSERT_EQ(42, Toolbox::GetJsonIntegerField(v, "hello", -10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1116 ASSERT_EQ(42u, Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1117 ASSERT_THROW(Toolbox::GetJsonBooleanField(v, "hello", true), OrthancException);
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 v["hello"] = false;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120 ASSERT_THROW(Toolbox::GetJsonStringField(v, "hello", "nope"), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1121 ASSERT_THROW(Toolbox::GetJsonIntegerField(v, "hello", -10), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1122 ASSERT_THROW(Toolbox::GetJsonUnsignedIntegerField(v, "hello", 10), OrthancException);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1123 ASSERT_FALSE(Toolbox::GetJsonBooleanField(v, "hello", true));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1125
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1126
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1127 TEST(Toolbox, LinesIterator)
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 std::string s;
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 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1132 std::string content;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1133 Toolbox::LinesIterator it(content);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1134 ASSERT_FALSE(it.GetLine(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1135 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1136
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 std::string content = "\n\r";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1139 Toolbox::LinesIterator it(content);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1140 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1141 ASSERT_FALSE(it.GetLine(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1142 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143
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 std::string content = "\n Hello \n\nWorld\n\n";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1146 Toolbox::LinesIterator it(content);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1147 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152 ASSERT_FALSE(it.GetLine(s)); it.Next();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153 ASSERT_FALSE(it.GetLine(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1154 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1156 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1157 std::string content = "\r Hello \r\rWorld\r\r";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158 Toolbox::LinesIterator it(content);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164 ASSERT_FALSE(it.GetLine(s)); it.Next();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165 ASSERT_FALSE(it.GetLine(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1166 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167
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 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
1170 Toolbox::LinesIterator it(content);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1171 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1173 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1174 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1175 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1176 ASSERT_FALSE(it.GetLine(s)); it.Next();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177 ASSERT_FALSE(it.GetLine(s));
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 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
1182 Toolbox::LinesIterator it(content);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1184 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ(" Hello ", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1185 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("World", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187 ASSERT_TRUE(it.GetLine(s)); it.Next(); ASSERT_EQ("", s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188 ASSERT_FALSE(it.GetLine(s)); it.Next();
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1189 ASSERT_FALSE(it.GetLine(s));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1190 }
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1193
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 TEST(Toolbox, SubstituteVariables)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1195 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1196 std::map<std::string, std::string> env;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1197 env["NOPE"] = "nope";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1198 env["WORLD"] = "world";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1199
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200 ASSERT_EQ("Hello world\r\nWorld \r\nDone world\r\n",
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 Toolbox::SubstituteVariables(
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 "Hello ${WORLD}\r\nWorld ${HELLO}\r\nDone ${WORLD}\r\n",
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1203 env));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1204
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1205 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
1206 Toolbox::SubstituteVariables(
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1207 "${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
1208 env));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1209
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1210 SystemToolbox::GetEnvironmentVariables(env);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1211 ASSERT_TRUE(env.find("NOPE") == env.end());
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 // The "PATH" environment variable should always be available on
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1214 // machines running the unit tests
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215 ASSERT_TRUE(env.find("PATH") != env.end() /* Case used by UNIX */ ||
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1216 env.find("Path") != env.end() /* Case used by Windows */);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1217
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1218 env["PATH"] = "hello";
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1219 ASSERT_EQ("AhelloB",
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1220 Toolbox::SubstituteVariables("A${PATH}B", env));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1221 }
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1224 TEST(MetricsRegistry, Basic)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1225 {
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 MetricsRegistry m;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1228 m.SetEnabled(false);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1229 m.SetValue("hello.world", 42.5f);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1232 m.ExportPrometheusText(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233 ASSERT_TRUE(s.empty());
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
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237 MetricsRegistry m;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1238 m.Register("hello.world", MetricsType_Default);
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 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1241 m.ExportPrometheusText(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1242 ASSERT_TRUE(s.empty());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1243 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1244
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1245 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1246 MetricsRegistry m;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1247 m.SetValue("hello.world", 42.5f);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248 ASSERT_EQ(MetricsType_Default, m.GetMetricsType("hello.world"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1249 ASSERT_THROW(m.GetMetricsType("nope"), OrthancException);
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 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1252 m.ExportPrometheusText(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1253
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1254 std::vector<std::string> t;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1255 Toolbox::TokenizeString(t, s, '\n');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1256 ASSERT_EQ(2u, t.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1257 ASSERT_EQ("hello.world 42.5 ", t[0].substr(0, 17));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1258 ASSERT_TRUE(t[1].empty());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1259 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1260
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1261 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1262 MetricsRegistry m;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1263 m.Register("hello.max", MetricsType_MaxOver10Seconds);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1264 m.SetValue("hello.max", 10);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1265 m.SetValue("hello.max", 20);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1266 m.SetValue("hello.max", -10);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1267 m.SetValue("hello.max", 5);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1268
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1269 m.Register("hello.min", MetricsType_MinOver10Seconds);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1270 m.SetValue("hello.min", 10);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1271 m.SetValue("hello.min", 20);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1272 m.SetValue("hello.min", -10);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1273 m.SetValue("hello.min", 5);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1274
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1275 m.Register("hello.default", MetricsType_Default);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1276 m.SetValue("hello.default", 10);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1277 m.SetValue("hello.default", 20);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1278 m.SetValue("hello.default", -10);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1279 m.SetValue("hello.default", 5);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1280
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1281 ASSERT_EQ(MetricsType_MaxOver10Seconds, m.GetMetricsType("hello.max"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1282 ASSERT_EQ(MetricsType_MinOver10Seconds, m.GetMetricsType("hello.min"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1283 ASSERT_EQ(MetricsType_Default, m.GetMetricsType("hello.default"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1284
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1285 std::string s;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1286 m.ExportPrometheusText(s);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1287
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1288 std::vector<std::string> t;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1289 Toolbox::TokenizeString(t, s, '\n');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1290 ASSERT_EQ(4u, t.size());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1291 ASSERT_TRUE(t[3].empty());
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1292
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1293 std::map<std::string, std::string> u;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1294 for (size_t i = 0; i < t.size() - 1; i++)
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1295 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1296 std::vector<std::string> v;
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1297 Toolbox::TokenizeString(v, t[i], ' ');
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1298 u[v[0]] = v[1];
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1299 }
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 ASSERT_EQ("20", u["hello.max"]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1302 ASSERT_EQ("-10", u["hello.min"]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1303 ASSERT_EQ("5", u["hello.default"]);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1304 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1305
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 MetricsRegistry m;
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 m.SetValue("a", 10);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1310 m.SetValue("b", 10, MetricsType_MinOver10Seconds);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1311
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1312 m.Register("c", MetricsType_MaxOver10Seconds);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1313 m.SetValue("c", 10, MetricsType_MinOver10Seconds);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1314
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1315 m.Register("d", MetricsType_MaxOver10Seconds);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1316 m.Register("d", MetricsType_Default);
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 ASSERT_EQ(MetricsType_Default, m.GetMetricsType("a"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1319 ASSERT_EQ(MetricsType_MinOver10Seconds, m.GetMetricsType("b"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1320 ASSERT_EQ(MetricsType_MaxOver10Seconds, m.GetMetricsType("c"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1321 ASSERT_EQ(MetricsType_Default, m.GetMetricsType("d"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1322 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1323
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 MetricsRegistry m;
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 {
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1328 MetricsRegistry::Timer t1(m, "a");
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1329 MetricsRegistry::Timer t2(m, "b", MetricsType_MinOver10Seconds);
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1330 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1331
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1332 ASSERT_EQ(MetricsType_MaxOver10Seconds, m.GetMetricsType("a"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1333 ASSERT_EQ(MetricsType_MinOver10Seconds, m.GetMetricsType("b"));
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1334 }
e12c8ac6dc82 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1335 }