comparison OrthancFramework/UnitTestsSources/FileStorageTests.cpp @ 5807:8279eaab0d1d attach-custom-data

merged default -> attach-custom-data
author Alain Mazy <am@orthanc.team>
date Tue, 24 Sep 2024 11:39:52 +0200
parents d7274e43ea7c 2fe77dfe0466
children
comparison
equal deleted inserted replaced
5085:79f98ee4f04b 5807:8279eaab0d1d
1 /** 1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store 2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium 4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium 5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium 6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 * 8 *
8 * This program is free software: you can redistribute it and/or 9 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License 10 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation, either version 3 of 11 * as published by the Free Software Foundation, either version 3 of
11 * the License, or (at your option) any later version. 12 * the License, or (at your option) any later version.
34 #include "../Sources/HttpServer/BufferHttpSender.h" 35 #include "../Sources/HttpServer/BufferHttpSender.h"
35 #include "../Sources/HttpServer/FilesystemHttpSender.h" 36 #include "../Sources/HttpServer/FilesystemHttpSender.h"
36 #include "../Sources/Logging.h" 37 #include "../Sources/Logging.h"
37 #include "../Sources/OrthancException.h" 38 #include "../Sources/OrthancException.h"
38 #include "../Sources/Toolbox.h" 39 #include "../Sources/Toolbox.h"
40 #include "../Sources/SystemToolbox.h"
39 41
40 #include <ctype.h> 42 #include <ctype.h>
41 43
42 44
43 using namespace Orthanc; 45 using namespace Orthanc;
84 } 86 }
85 ASSERT_EQ(d.size(), data.size()); 87 ASSERT_EQ(d.size(), data.size());
86 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size())); 88 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
87 ASSERT_EQ(s.GetSize(uid), data.size()); 89 ASSERT_EQ(s.GetSize(uid), data.size());
88 } 90 }
91
92 TEST(FilesystemStorage, FileWithSameNameAsTopDirectory)
93 {
94 FilesystemStorage s("UnitTestsStorageTop");
95 s.Clear();
96
97 std::vector<uint8_t> data;
98 StringToVector(data, Toolbox::GenerateUuid());
99
100 SystemToolbox::WriteFile("toto", "UnitTestsStorageTop/12");
101 ASSERT_THROW(s.Create("12345678-1234-1234-1234-1234567890ab", &data[0], data.size(), FileContentType_Unknown), OrthancException);
102 s.Clear();
103 }
104
105 TEST(FilesystemStorage, FileWithSameNameAsChildDirectory)
106 {
107 FilesystemStorage s("UnitTestsStorageChild");
108 s.Clear();
109
110 std::vector<uint8_t> data;
111 StringToVector(data, Toolbox::GenerateUuid());
112
113 SystemToolbox::MakeDirectory("UnitTestsStorageChild/12");
114 SystemToolbox::WriteFile("toto", "UnitTestsStorageChild/12/34");
115 ASSERT_THROW(s.Create("12345678-1234-1234-1234-1234567890ab", &data[0], data.size(), FileContentType_Unknown), OrthancException);
116 s.Clear();
117 }
118
119 TEST(FilesystemStorage, FileAlreadyExists)
120 {
121 FilesystemStorage s("UnitTestsStorageFileAlreadyExists");
122 s.Clear();
123
124 std::vector<uint8_t> data;
125 StringToVector(data, Toolbox::GenerateUuid());
126
127 SystemToolbox::MakeDirectory("UnitTestsStorageFileAlreadyExists/12/34");
128 SystemToolbox::WriteFile("toto", "UnitTestsStorageFileAlreadyExists/12/34/12345678-1234-1234-1234-1234567890ab");
129 ASSERT_THROW(s.Create("12345678-1234-1234-1234-1234567890ab", &data[0], data.size(), FileContentType_Unknown), OrthancException);
130 s.Clear();
131 }
132
89 133
90 TEST(FilesystemStorage, EndToEnd) 134 TEST(FilesystemStorage, EndToEnd)
91 { 135 {
92 FilesystemStorage s("UnitTestsStorage"); 136 FilesystemStorage s("UnitTestsStorage");
93 s.Clear(); 137 s.Clear();
125 169
126 TEST(StorageAccessor, NoCompression) 170 TEST(StorageAccessor, NoCompression)
127 { 171 {
128 FilesystemStorage s("UnitTestsStorage"); 172 FilesystemStorage s("UnitTestsStorage");
129 StorageCache cache; 173 StorageCache cache;
130 StorageAccessor accessor(s, &cache); 174 StorageAccessor accessor(s, cache);
131 175
132 std::string data = "Hello world"; 176 std::string data = "Hello world";
133 std::string uuid = Toolbox::GenerateUuid(); 177 std::string uuid = Toolbox::GenerateUuid();
134 FileInfo info = accessor.WriteAttachment(data, "", ResourceType_Instance, data.c_str(), data.size(), FileContentType_Dicom, CompressionType_None, true, uuid); 178 FileInfo info = accessor.WriteAttachment(data, "", ResourceType_Instance, data.c_str(), data.size(), FileContentType_Dicom, CompressionType_None, true, uuid);
135 179
148 192
149 TEST(StorageAccessor, Compression) 193 TEST(StorageAccessor, Compression)
150 { 194 {
151 FilesystemStorage s("UnitTestsStorage"); 195 FilesystemStorage s("UnitTestsStorage");
152 StorageCache cache; 196 StorageCache cache;
153 StorageAccessor accessor(s, &cache); 197 StorageAccessor accessor(s, cache);
154 198
155 std::string data = "Hello world"; 199 std::string data = "Hello world";
156 std::string uuid = Toolbox::GenerateUuid(); 200 std::string uuid = Toolbox::GenerateUuid();
157 FileInfo info = accessor.WriteAttachment(data, "", ResourceType_Instance, data.c_str(), data.size(), FileContentType_Dicom, CompressionType_ZlibWithSize, true, uuid); 201 FileInfo info = accessor.WriteAttachment(data, "", ResourceType_Instance, data.c_str(), data.size(), FileContentType_Dicom, CompressionType_ZlibWithSize, true, uuid);
158 202
171 215
172 TEST(StorageAccessor, Mix) 216 TEST(StorageAccessor, Mix)
173 { 217 {
174 FilesystemStorage s("UnitTestsStorage"); 218 FilesystemStorage s("UnitTestsStorage");
175 StorageCache cache; 219 StorageCache cache;
176 StorageAccessor accessor(s, &cache); 220 StorageAccessor accessor(s, cache);
177 221
178 std::string r; 222 std::string r;
179 std::string compressedData = "Hello"; 223 std::string compressedData = "Hello";
180 std::string uncompressedData = "HelloWorld"; 224 std::string uncompressedData = "HelloWorld";
181 225