Mercurial > hg > orthanc
annotate UnitTestsSources/ToolboxTests.cpp @ 3634:103ee029982e storage-commitment
integration default->storage-commitment
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 29 Jan 2020 08:51:31 +0100 |
parents | 7ae553d9c366 |
children | f6a73611ec5c |
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 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
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 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
10 * License, or (at your option) any later version. |
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 * In addition, as a special exception, the copyright holders of this |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
13 * program give permission to link the code of its release with the |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
22 * in the program, then also delete it here. |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
23 * |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
24 * 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
|
25 * 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
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
27 * General Public License for more details. |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
28 * |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
31 **/ |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
32 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
33 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
34 #include "PrecompiledHeadersUnitTests.h" |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
35 #include "gtest/gtest.h" |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
36 #include "../Core/OrthancException.h" |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
37 #include "../Core/Toolbox.h" |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
38 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
39 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
|
40 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
41 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
|
42 { |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
43 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
|
44 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
|
45 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
|
46 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 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
|
51 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
52 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
|
53 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
|
54 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
55 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
|
56 } |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
57 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
58 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
|
59 { |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
64 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
|
65 { |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
72 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
|
73 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
|
74 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
75 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
|
76 } |
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 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
79 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
|
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 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
|
82 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
|
83 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
|
84 } |
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 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
87 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
|
88 { |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
89 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
|
90 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
|
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 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
|
93 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
|
94 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
99 // 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
|
100 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
|
101 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
102 // 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
|
103 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
|
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 |
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 #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
|
108 #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
|
109 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
110 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
|
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 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
|
113 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
|
114 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
|
115 |
4a8e8a96b233
Fixed CRLF to LF in various files (found through grepping the source tree)
Benjamin Golinvaux <bgo@osimis.io>
parents:
3331
diff
changeset
|
116 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
|
117 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
|
118 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
|
119 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
|
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::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
|
122 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
|
123 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
|
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 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
|
126 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
|
127 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
|
128 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
|
129 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
|
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 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
|
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 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
|
134 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
|
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 #endif |
3608
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
137 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
138 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
139 TEST(Toolbox, LargeHexadecimalToDecimal) |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
140 { |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
141 // https://stackoverflow.com/a/16967286/881731 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
142 ASSERT_EQ( |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
143 "166089946137986168535368849184301740204613753693156360462575217560130904921953976324839782808018277000296027060873747803291797869684516494894741699267674246881622658654267131250470956587908385447044319923040838072975636163137212887824248575510341104029461758594855159174329892125993844566497176102668262139513", |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
144 Toolbox::LargeHexadecimalToDecimal("EC851A69B8ACD843164E10CFF70CF9E86DC2FEE3CF6F374B43C854E3342A2F1AC3E30C741CC41E679DF6D07CE6FA3A66083EC9B8C8BF3AF05D8BDBB0AA6Cb3ef8c5baa2a5e531ba9e28592f99e0fe4f95169a6c63f635d0197e325c5ec76219b907e4ebdcd401fb1986e4e3ca661ff73e7e2b8fd9988e753b7042b2bbca76679")); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
145 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
146 ASSERT_EQ("0", Toolbox::LargeHexadecimalToDecimal("")); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
147 ASSERT_EQ("0", Toolbox::LargeHexadecimalToDecimal("0")); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
148 ASSERT_EQ("0", Toolbox::LargeHexadecimalToDecimal("0000")); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
149 ASSERT_EQ("255", Toolbox::LargeHexadecimalToDecimal("00000ff")); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
150 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
151 ASSERT_THROW(Toolbox::LargeHexadecimalToDecimal("g"), Orthanc::OrthancException); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
152 } |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
153 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
154 |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
155 TEST(Toolbox, GenerateDicomPrivateUniqueIdentifier) |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
156 { |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
157 std::string s = Toolbox::GenerateDicomPrivateUniqueIdentifier(); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
158 ASSERT_EQ("2.25.", s.substr(0, 5)); |
7ae553d9c366
created DicomUserConnection::RequestStorageCommitment()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3373
diff
changeset
|
159 } |