Mercurial > hg > orthanc
annotate OrthancFramework/UnitTestsSources/FileStorageTests.cpp @ 5842:08e47734328e find-refactoring
StatelessDatabaseOperations: reimplementing GetAllUuids() and GetAllMetadata()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 29 Oct 2024 12:46:11 +0000 |
parents | 2fe77dfe0466 |
children | 8279eaab0d1d |
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 | 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 |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
8 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
9 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
10 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
11 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
12 * the License, or (at your option) any later version. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
13 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
14 * 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
|
15 * 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
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
17 * Lesser General Public License for more details. |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
18 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
19 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
20 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4063
diff
changeset
|
21 * <http://www.gnu.org/licenses/>. |
827
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 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
24 |
4058
2a8bf0991be0
moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
25 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1 |
4063
e00f3d089991
shared library of orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4062
diff
changeset
|
26 // Must be the first to be sure to use the Orthanc framework shared library |
4058
2a8bf0991be0
moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
27 # include <OrthancFramework.h> |
2a8bf0991be0
moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
28 #endif |
2a8bf0991be0
moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
29 |
4062 | 30 #include <gtest/gtest.h> |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
4058
2a8bf0991be0
moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
32 #include "../Sources/FileStorage/FilesystemStorage.h" |
2a8bf0991be0
moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
33 #include "../Sources/FileStorage/StorageAccessor.h" |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
34 #include "../Sources/FileStorage/StorageCache.h" |
4058
2a8bf0991be0
moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
35 #include "../Sources/HttpServer/BufferHttpSender.h" |
2a8bf0991be0
moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
36 #include "../Sources/HttpServer/FilesystemHttpSender.h" |
2a8bf0991be0
moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
37 #include "../Sources/Logging.h" |
2a8bf0991be0
moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
38 #include "../Sources/OrthancException.h" |
2a8bf0991be0
moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4045
diff
changeset
|
39 #include "../Sources/Toolbox.h" |
5737
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
40 #include "../Sources/SystemToolbox.h" |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
4062 | 42 #include <ctype.h> |
43 | |
44 | |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 using namespace Orthanc; |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 |
712 | 47 |
48 static void StringToVector(std::vector<uint8_t>& v, | |
49 const std::string& s) | |
50 { | |
51 v.resize(s.size()); | |
52 for (size_t i = 0; i < s.size(); i++) | |
53 v[i] = s[i]; | |
54 } | |
55 | |
56 | |
1123 | 57 TEST(FilesystemStorage, Basic) |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 { |
1123 | 59 FilesystemStorage s("UnitTestsStorage"); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
2512
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
61 std::string data = Toolbox::GenerateUuid(); |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
62 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
|
63 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
|
64 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
|
65 { |
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
66 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
|
67 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
|
68 } |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 ASSERT_EQ(d.size(), data.size()); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size())); |
1122
1d60316c3618
simplifications in FileStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
71 ASSERT_EQ(s.GetSize(uid), data.size()); |
712 | 72 } |
73 | |
1123 | 74 TEST(FilesystemStorage, Basic2) |
712 | 75 { |
1123 | 76 FilesystemStorage s("UnitTestsStorage"); |
712 | 77 |
78 std::vector<uint8_t> data; | |
2512
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
79 StringToVector(data, Toolbox::GenerateUuid()); |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
80 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
|
81 s.Create(uid.c_str(), &data[0], data.size(), FileContentType_Unknown); |
712 | 82 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
|
83 { |
64f06e7d5fc7
new abstraction IMemoryBuffer to avoid unnecessary copies of std::string buffers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4437
diff
changeset
|
84 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
|
85 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
|
86 } |
712 | 87 ASSERT_EQ(d.size(), data.size()); |
88 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size())); | |
1122
1d60316c3618
simplifications in FileStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
89 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
|
90 } |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 |
5737
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
92 TEST(FilesystemStorage, FileWithSameNameAsTopDirectory) |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
93 { |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
94 FilesystemStorage s("UnitTestsStorageTop"); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
95 s.Clear(); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
96 |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
97 std::vector<uint8_t> data; |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
98 StringToVector(data, Toolbox::GenerateUuid()); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
99 |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
100 SystemToolbox::WriteFile("toto", "UnitTestsStorageTop/12"); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
101 ASSERT_THROW(s.Create("12345678-1234-1234-1234-1234567890ab", &data[0], data.size(), FileContentType_Unknown), OrthancException); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
102 s.Clear(); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
103 } |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
104 |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
105 TEST(FilesystemStorage, FileWithSameNameAsChildDirectory) |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
106 { |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
107 FilesystemStorage s("UnitTestsStorageChild"); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
108 s.Clear(); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
109 |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
110 std::vector<uint8_t> data; |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
111 StringToVector(data, Toolbox::GenerateUuid()); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
112 |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
113 SystemToolbox::MakeDirectory("UnitTestsStorageChild/12"); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
114 SystemToolbox::WriteFile("toto", "UnitTestsStorageChild/12/34"); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
115 ASSERT_THROW(s.Create("12345678-1234-1234-1234-1234567890ab", &data[0], data.size(), FileContentType_Unknown), OrthancException); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
116 s.Clear(); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
117 } |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
118 |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
119 TEST(FilesystemStorage, FileAlreadyExists) |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
120 { |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
121 FilesystemStorage s("UnitTestsStorageFileAlreadyExists"); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
122 s.Clear(); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
123 |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
124 std::vector<uint8_t> data; |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
125 StringToVector(data, Toolbox::GenerateUuid()); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
126 |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
127 SystemToolbox::MakeDirectory("UnitTestsStorageFileAlreadyExists/12/34"); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
128 SystemToolbox::WriteFile("toto", "UnitTestsStorageFileAlreadyExists/12/34/12345678-1234-1234-1234-1234567890ab"); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
129 ASSERT_THROW(s.Create("12345678-1234-1234-1234-1234567890ab", &data[0], data.size(), FileContentType_Unknown), OrthancException); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
130 s.Clear(); |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
131 } |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
132 |
2fe77dfe0466
rewrote FileSystemStorage::Create knowing that we should not check the return value of boost::file_system::create_directories and that it throws on errors we were detecting manually
Alain Mazy <am@orthanc.team>
parents:
5640
diff
changeset
|
133 |
1123 | 134 TEST(FilesystemStorage, EndToEnd) |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 { |
1123 | 136 FilesystemStorage s("UnitTestsStorage"); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 s.Clear(); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 std::list<std::string> u; |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 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
|
141 { |
2512
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
142 std::string t = Toolbox::GenerateUuid(); |
4dcafa8d6633
SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
143 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
|
144 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
|
145 u.push_back(uid); |
222
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 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 std::set<std::string> ss; |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 s.ListAllFiles(ss); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 ASSERT_EQ(10u, ss.size()); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 unsigned int c = 0; |
4203
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
153 for (std::list<std::string>::const_iterator |
4d42408da117
improving const-correctness in ParsedDicomFile
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
154 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
|
155 { |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 ASSERT_TRUE(ss.find(*i) != ss.end()); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 if (c < 5) |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
158 s.Remove(*i, FileContentType_Unknown); |
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 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 s.ListAllFiles(ss); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 ASSERT_EQ(5u, ss.size()); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 s.Clear(); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 s.ListAllFiles(ss); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 ASSERT_EQ(0u, ss.size()); |
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 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
170 TEST(StorageAccessor, NoCompression) |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 { |
1123 | 172 FilesystemStorage s("UnitTestsStorage"); |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
173 StorageCache cache; |
5184
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5048
diff
changeset
|
174 StorageAccessor accessor(s, cache); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 std::string data = "Hello world"; |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
177 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
|
178 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 std::string r; |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
180 accessor.Read(r, info); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 ASSERT_EQ(data, r); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
183 ASSERT_EQ(CompressionType_None, info.GetCompressionType()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
184 ASSERT_EQ(11u, info.GetUncompressedSize()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
185 ASSERT_EQ(11u, info.GetCompressedSize()); |
233 | 186 ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
187 ASSERT_EQ("3e25960a79dbc69b674cd4ec67a72c62", info.GetUncompressedMD5()); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
188 ASSERT_EQ(info.GetUncompressedMD5(), info.GetCompressedMD5()); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 } |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
192 TEST(StorageAccessor, Compression) |
712 | 193 { |
1123 | 194 FilesystemStorage s("UnitTestsStorage"); |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
195 StorageCache cache; |
5184
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5048
diff
changeset
|
196 StorageAccessor accessor(s, cache); |
712 | 197 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
198 std::string data = "Hello world"; |
4512
cff7fdfc83a4
added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4484
diff
changeset
|
199 FileInfo info = accessor.Write(data, FileContentType_Dicom, CompressionType_ZlibWithSize, true); |
712 | 200 |
201 std::string r; | |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
202 accessor.Read(r, info); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
204 ASSERT_EQ(data, r); |
1514
d73a2178b319
support of deflate and gzip content-types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
205 ASSERT_EQ(CompressionType_ZlibWithSize, info.GetCompressionType()); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
206 ASSERT_EQ(11u, info.GetUncompressedSize()); |
4512
cff7fdfc83a4
added FileContentType_DicomUntilPixelData
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4484
diff
changeset
|
207 ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
208 ASSERT_EQ("3e25960a79dbc69b674cd4ec67a72c62", info.GetUncompressedMD5()); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
209 ASSERT_NE(info.GetUncompressedMD5(), info.GetCompressedMD5()); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 } |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
213 TEST(StorageAccessor, Mix) |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 { |
1123 | 215 FilesystemStorage s("UnitTestsStorage"); |
4792
434843934307
Added a StorageCache in the StorageAccessor
Alain Mazy <am@osimis.io>
parents:
4512
diff
changeset
|
216 StorageCache cache; |
5184
dd085f7e7e71
cleaning new constructors of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5048
diff
changeset
|
217 StorageAccessor accessor(s, cache); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 std::string r; |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 std::string compressedData = "Hello"; |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
221 std::string uncompressedData = "HelloWorld"; |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
223 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
|
224 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
|
225 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
226 accessor.Read(r, compressedInfo); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 ASSERT_EQ(compressedData, r); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
228 |
1549
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
229 accessor.Read(r, uncompressedInfo); |
e5e975e9b738
refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1514
diff
changeset
|
230 ASSERT_EQ(uncompressedData, r); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 ASSERT_NE(compressedData, r); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
232 |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
233 /* |
224
4eb0c7ce86c9
refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
223
diff
changeset
|
234 // 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
|
235 accessor.SetCompressionForNextOperations(CompressionType_ZlibWithSize); |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
236 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
|
237 */ |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
238 } |