Mercurial > hg > orthanc
annotate OrthancFramework/UnitTestsSources/ToolboxTests.cpp @ 4393:e8e95b80194f
removing usage of deprecated JsonCpp classes
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 21 Dec 2020 18:55:32 +0100 |
parents | bf7b9edf6b81 |
children | f7104e9d044c |
rev | line source |
---|---|
3373
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
1 /** |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
3373
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
6 * |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
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. |
3373
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
11 * |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
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. |
3373
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
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/>. |
3373
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
20 **/ |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
21 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
22 |
3992
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
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:
3713
diff
changeset
|
26 #endif |
f9863630ec7f
working on the shared library for Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3713
diff
changeset
|
27 |
4062 | 28 #include <gtest/gtest.h> |
29 | |
4045 | 30 #include "../Sources/Compatibility.h" |
31 #include "../Sources/IDynamicObject.h" | |
32 #include "../Sources/OrthancException.h" | |
33 #include "../Sources/Toolbox.h" | |
3373
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
34 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
35 using namespace Orthanc; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
36 |
4393
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
37 TEST(Toolbox, Json) |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
38 { |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
39 Json::Value a = Json::objectValue; |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
40 a["hello"] = "world"; |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
41 |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
42 std::string b = "{\"hello\" : \"world\"}"; |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
43 |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
44 Json::Value c; |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
45 ASSERT_TRUE(Toolbox::ReadJson(c, b)); |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
46 |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
47 std::string d, e; |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
48 Toolbox::WriteJson(d, a, true); |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
49 Toolbox::WriteJson(e, c, true); |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
50 ASSERT_EQ(d, e); |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
51 |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
52 std::string f, g; |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
53 Toolbox::WriteJson(f, a, false); |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
54 Toolbox::WriteJson(g, c, false); |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
55 ASSERT_EQ(f, g); |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
56 |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
57 /** |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
58 * Check compatibility with the serialized string generated by |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
59 * JsonCpp 1.7.4 (Ubuntu 18.04). "StripSpaces()" removes the |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
60 * trailing end-of-line character that was not present in the |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
61 * deprecated serialization classes of JsonCpp. |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
62 **/ |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
63 ASSERT_EQ(Toolbox::StripSpaces(d), "{\"hello\":\"world\"}"); |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
64 ASSERT_EQ(Toolbox::StripSpaces(f), "{\n \"hello\" : \"world\"\n}"); |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
65 } |
e8e95b80194f
removing usage of deprecated JsonCpp classes
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
66 |
3373
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
67 TEST(Toolbox, Base64_allByteValues) |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
68 { |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
69 std::string toEncode; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
70 std::string base64Result; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
71 std::string decodedResult; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
72 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
73 size_t size = 2*256; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
74 toEncode.reserve(size); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
75 for (size_t i = 0; i < size; i++) |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
76 toEncode.push_back(i % 256); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
77 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
78 Toolbox::EncodeBase64(base64Result, toEncode); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
79 Toolbox::DecodeBase64(decodedResult, base64Result); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
80 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
81 ASSERT_EQ(toEncode, decodedResult); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
82 } |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
83 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
84 TEST(Toolbox, Base64_multipleSizes) |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
85 { |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
86 std::string toEncode; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
87 std::string base64Result; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
88 std::string decodedResult; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
89 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
90 for (size_t size = 0; size <= 5; size++) |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
91 { |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
92 printf("base64, testing size %zu\n", size); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
93 toEncode.clear(); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
94 toEncode.reserve(size); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
95 for (size_t i = 0; i < size; i++) |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
96 toEncode.push_back(i % 256); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
97 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
98 Toolbox::EncodeBase64(base64Result, toEncode); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
99 Toolbox::DecodeBase64(decodedResult, base64Result); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
100 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
101 ASSERT_EQ(toEncode, decodedResult); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
102 } |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
103 } |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
104 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
105 static std::string EncodeBase64Bis(const std::string& s) |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
106 { |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
107 std::string result; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
108 Toolbox::EncodeBase64(result, s); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
109 return result; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
110 } |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
111 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
112 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
113 TEST(Toolbox, Base64) |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
114 { |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
115 ASSERT_EQ("", EncodeBase64Bis("")); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
116 ASSERT_EQ("YQ==", EncodeBase64Bis("a")); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
117 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
118 const std::string hello = "SGVsbG8gd29ybGQ="; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
119 ASSERT_EQ(hello, EncodeBase64Bis("Hello world")); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
120 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
121 std::string decoded; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
122 Toolbox::DecodeBase64(decoded, hello); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
123 ASSERT_EQ("Hello world", decoded); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
124 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
125 // Invalid character |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
126 ASSERT_THROW(Toolbox::DecodeBase64(decoded, "?"), OrthancException); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
127 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
128 // All the allowed characters |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
129 Toolbox::DecodeBase64(decoded, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
130 } |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
131 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
132 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
133 #if 0 // enable only when compiling in Release with a C++ 11 compiler |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
134 #include <chrono> // I had troubles to link with boost::chrono ... |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
135 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
136 TEST(Toolbox, Base64_largeString) |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
137 { |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
138 std::string toEncode; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
139 std::string base64Result; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
140 std::string decodedResult; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
141 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
142 size_t size = 10 * 1024 * 1024; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
143 toEncode.reserve(size); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
144 for (size_t i = 0; i < size; i++) |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
145 toEncode.push_back(i % 256); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
146 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
147 std::chrono::high_resolution_clock::time_point start; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
148 std::chrono::high_resolution_clock::time_point afterEncoding; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
149 std::chrono::high_resolution_clock::time_point afterDecoding; |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
150 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
151 start = std::chrono::high_resolution_clock::now(); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
152 Orthanc::Toolbox::EncodeBase64(base64Result, toEncode); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
153 afterEncoding = std::chrono::high_resolution_clock::now(); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
154 Orthanc::Toolbox::DecodeBase64(decodedResult, base64Result); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
155 afterDecoding = std::chrono::high_resolution_clock::now(); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
156 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
157 ASSERT_EQ(toEncode, decodedResult); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
158 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
159 printf("encoding took %zu ms\n", (std::chrono::duration_cast<std::chrono::milliseconds>(afterEncoding - start))); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
160 printf("decoding took %zu ms\n", (std::chrono::duration_cast<std::chrono::milliseconds>(afterDecoding - afterEncoding))); |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
161 } |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
162 #endif |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
163 |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
164 |
3608
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
165 TEST(Toolbox, LargeHexadecimalToDecimal) |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
166 { |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
167 // https://stackoverflow.com/a/16967286/881731 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
168 ASSERT_EQ( |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
169 "166089946137986168535368849184301740204613753693156360462575217560130904921953976324839782808018277000296027060873747803291797869684516494894741699267674246881622658654267131250470956587908385447044319923040838072975636163137212887824248575510341104029461758594855159174329892125993844566497176102668262139513", |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
170 Toolbox::LargeHexadecimalToDecimal("EC851A69B8ACD843164E10CFF70CF9E86DC2FEE3CF6F374B43C854E3342A2F1AC3E30C741CC41E679DF6D07CE6FA3A66083EC9B8C8BF3AF05D8BDBB0AA6Cb3ef8c5baa2a5e531ba9e28592f99e0fe4f95169a6c63f635d0197e325c5ec76219b907e4ebdcd401fb1986e4e3ca661ff73e7e2b8fd9988e753b7042b2bbca76679")); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
171 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
172 ASSERT_EQ("0", Toolbox::LargeHexadecimalToDecimal("")); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
173 ASSERT_EQ("0", Toolbox::LargeHexadecimalToDecimal("0")); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
174 ASSERT_EQ("0", Toolbox::LargeHexadecimalToDecimal("0000")); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
175 ASSERT_EQ("255", Toolbox::LargeHexadecimalToDecimal("00000ff")); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
176 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
177 ASSERT_THROW(Toolbox::LargeHexadecimalToDecimal("g"), Orthanc::OrthancException); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
178 } |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
179 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
180 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
181 TEST(Toolbox, GenerateDicomPrivateUniqueIdentifier) |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
182 { |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
183 std::string s = Toolbox::GenerateDicomPrivateUniqueIdentifier(); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
184 ASSERT_EQ("2.25.", s.substr(0, 5)); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
185 } |
3711
14b363d972a8
experimenting boost::movelib::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3641
diff
changeset
|
186 |
14b363d972a8
experimenting boost::movelib::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3641
diff
changeset
|
187 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
188 TEST(Toolbox, UniquePtr) |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
189 { |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
190 std::unique_ptr<int> i(new int(42)); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
191 ASSERT_EQ(42, *i); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
192 |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
193 std::unique_ptr<SingleValueObject<int> > j(new SingleValueObject<int>(42)); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
194 ASSERT_EQ(42, j->GetValue()); |
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
195 } |