annotate OrthancFramework/UnitTestsSources/FileStorageTests.cpp @ 5295:ca6df6e6c7a6 Orthanc-1.12.0

fix HttpClient.Ssl unit tests
author Alain Mazy <am@osimis.io>
date Tue, 16 May 2023 07:09:06 +0200
parents 0ea402b4d901
children 48b8dae6dc77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
1 /**
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1549
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1135
diff changeset
4 * Department, University Hospital of Liege, Belgium
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5184
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5184
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
7 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
8 * 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
9 * 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
10 * 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
11 * the License, or (at your option) any later version.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
12 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
13 * This program is distributed in the hope that it will be useful, but
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
15 * 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
16 * Lesser General Public License for more details.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
17 *
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
18 * 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
19 * 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
20 * <http://www.gnu.org/licenses/>.
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
21 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
22
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
23
4058
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
24 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1
4063
e00f3d089991 shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4062
diff changeset
25 // Must be the first to be sure to use the Orthanc framework shared library
4058
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
26 # include <OrthancFramework.h>
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
27 #endif
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
28
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4058
diff changeset
29 #include <gtest/gtest.h>
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
4058
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
31 #include "../Sources/FileStorage/FilesystemStorage.h"
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
32 #include "../Sources/FileStorage/StorageAccessor.h"
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
33 #include "../Sources/FileStorage/StorageCache.h"
4058
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
34 #include "../Sources/HttpServer/BufferHttpSender.h"
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
35 #include "../Sources/HttpServer/FilesystemHttpSender.h"
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
36 #include "../Sources/Logging.h"
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
37 #include "../Sources/OrthancException.h"
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
38 #include "../Sources/Toolbox.h"
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
4062
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4058
diff changeset
40 #include <ctype.h>
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4058
diff changeset
41
0953b3dc3261 pretty-printing
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4058
diff changeset
42
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 using namespace Orthanc;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
45
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
46 static void StringToVector(std::vector<uint8_t>& v,
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
47 const std::string& s)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
48 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
49 v.resize(s.size());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
50 for (size_t i = 0; i < s.size(); i++)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
51 v[i] = s[i];
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
52 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
53
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
54
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
55 TEST(FilesystemStorage, Basic)
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
57 FilesystemStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
2512
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
59 std::string data = Toolbox::GenerateUuid();
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
60 std::string uid = Toolbox::GenerateUuid();
1135
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
61 s.Create(uid.c_str(), &data[0], data.size(), FileContentType_Unknown);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 std::string d;
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
63 {
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
64 std::unique_ptr<IMemoryBuffer> buffer(s.Read(uid, FileContentType_Unknown));
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
65 buffer->MoveToString(d);
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
66 }
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 ASSERT_EQ(d.size(), data.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
1122
1d60316c3618 simplifications in FileStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
69 ASSERT_EQ(s.GetSize(uid), data.size());
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
70 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
71
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
72 TEST(FilesystemStorage, Basic2)
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
73 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
74 FilesystemStorage s("UnitTestsStorage");
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
75
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
76 std::vector<uint8_t> data;
2512
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
77 StringToVector(data, Toolbox::GenerateUuid());
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
78 std::string uid = Toolbox::GenerateUuid();
1135
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
79 s.Create(uid.c_str(), &data[0], data.size(), FileContentType_Unknown);
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
80 std::string d;
4484
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
81 {
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
82 std::unique_ptr<IMemoryBuffer> buffer(s.Read(uid, FileContentType_Unknown));
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
83 buffer->MoveToString(d);
64f06e7d5fc7 new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
84 }
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
85 ASSERT_EQ(d.size(), data.size());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
86 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
1122
1d60316c3618 simplifications in FileStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
87 ASSERT_EQ(s.GetSize(uid), data.size());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 }
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
90 TEST(FilesystemStorage, EndToEnd)
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
92 FilesystemStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 s.Clear();
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 std::list<std::string> u;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 for (unsigned int i = 0; i < 10; i++)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 {
2512
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
98 std::string t = Toolbox::GenerateUuid();
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
99 std::string uid = Toolbox::GenerateUuid();
1135
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
100 s.Create(uid.c_str(), &t[0], t.size(), FileContentType_Unknown);
67c3c1e4a6e0 index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1126
diff changeset
101 u.push_back(uid);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 }
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 std::set<std::string> ss;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 s.ListAllFiles(ss);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 ASSERT_EQ(10u, ss.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 unsigned int c = 0;
4203
4d42408da117 improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
109 for (std::list<std::string>::const_iterator
4d42408da117 improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
110 i = u.begin(); i != u.end(); ++i, c++)
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 ASSERT_TRUE(ss.find(*i) != ss.end());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 if (c < 5)
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
114 s.Remove(*i, FileContentType_Unknown);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 s.ListAllFiles(ss);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 ASSERT_EQ(5u, ss.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 s.Clear();
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 s.ListAllFiles(ss);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 ASSERT_EQ(0u, ss.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 }
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
126 TEST(StorageAccessor, NoCompression)
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
128 FilesystemStorage s("UnitTestsStorage");
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
129 StorageCache cache;
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5048
diff changeset
130 StorageAccessor accessor(s, cache);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 std::string data = "Hello world";
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
133 FileInfo info = accessor.Write(data, FileContentType_Dicom, CompressionType_None, true);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 std::string r;
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
136 accessor.Read(r, info);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 ASSERT_EQ(data, r);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
139 ASSERT_EQ(CompressionType_None, info.GetCompressionType());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
140 ASSERT_EQ(11u, info.GetUncompressedSize());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
141 ASSERT_EQ(11u, info.GetCompressedSize());
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
142 ASSERT_EQ(FileContentType_Dicom, info.GetContentType());
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
143 ASSERT_EQ("3e25960a79dbc69b674cd4ec67a72c62", info.GetUncompressedMD5());
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
144 ASSERT_EQ(info.GetUncompressedMD5(), info.GetCompressedMD5());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
148 TEST(StorageAccessor, Compression)
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
149 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
150 FilesystemStorage s("UnitTestsStorage");
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
151 StorageCache cache;
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5048
diff changeset
152 StorageAccessor accessor(s, cache);
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
153
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
154 std::string data = "Hello world";
4512
cff7fdfc83a4 added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
155 FileInfo info = accessor.Write(data, FileContentType_Dicom, CompressionType_ZlibWithSize, true);
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
156
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
157 std::string r;
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
158 accessor.Read(r, info);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 ASSERT_EQ(data, r);
1514
d73a2178b319 support of deflate and gzip content-types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
161 ASSERT_EQ(CompressionType_ZlibWithSize, info.GetCompressionType());
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
162 ASSERT_EQ(11u, info.GetUncompressedSize());
4512
cff7fdfc83a4 added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4484
diff changeset
163 ASSERT_EQ(FileContentType_Dicom, info.GetContentType());
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
164 ASSERT_EQ("3e25960a79dbc69b674cd4ec67a72c62", info.GetUncompressedMD5());
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
165 ASSERT_NE(info.GetUncompressedMD5(), info.GetCompressedMD5());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
169 TEST(StorageAccessor, Mix)
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
171 FilesystemStorage s("UnitTestsStorage");
4792
434843934307 Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents: 4512
diff changeset
172 StorageCache cache;
5184
dd085f7e7e71 cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5048
diff changeset
173 StorageAccessor accessor(s, cache);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 std::string r;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 std::string compressedData = "Hello";
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 std::string uncompressedData = "HelloWorld";
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
179 FileInfo compressedInfo = accessor.Write(compressedData, FileContentType_Dicom, CompressionType_ZlibWithSize, false);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
180 FileInfo uncompressedInfo = accessor.Write(uncompressedData, FileContentType_Dicom, CompressionType_None, false);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
182 accessor.Read(r, compressedInfo);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 ASSERT_EQ(compressedData, r);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
185 accessor.Read(r, uncompressedInfo);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
186 ASSERT_EQ(uncompressedData, r);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 ASSERT_NE(compressedData, r);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
188
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
189 /*
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 223
diff changeset
190 // This test is too slow on Windows
1514
d73a2178b319 support of deflate and gzip content-types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
191 accessor.SetCompressionForNextOperations(CompressionType_ZlibWithSize);
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
192 ASSERT_THROW(accessor.Read(r, uncompressedInfo.GetUuid(), FileContentType_Unknown), OrthancException);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
193 */
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 }