comparison OrthancFramework/UnitTestsSources/FileStorageTests.cpp @ 5747:796cb17db15c find-refactoring

merged default -> find-refactoring
author Alain Mazy <am@orthanc.team>
date Mon, 02 Sep 2024 17:17:22 +0200
parents 2fe77dfe0466
children
comparison
equal deleted inserted replaced
5725:95a3802ad133 5747:796cb17db15c
35 #include "../Sources/HttpServer/BufferHttpSender.h" 35 #include "../Sources/HttpServer/BufferHttpSender.h"
36 #include "../Sources/HttpServer/FilesystemHttpSender.h" 36 #include "../Sources/HttpServer/FilesystemHttpSender.h"
37 #include "../Sources/Logging.h" 37 #include "../Sources/Logging.h"
38 #include "../Sources/OrthancException.h" 38 #include "../Sources/OrthancException.h"
39 #include "../Sources/Toolbox.h" 39 #include "../Sources/Toolbox.h"
40 #include "../Sources/SystemToolbox.h"
40 41
41 #include <ctype.h> 42 #include <ctype.h>
42 43
43 44
44 using namespace Orthanc; 45 using namespace Orthanc;
85 } 86 }
86 ASSERT_EQ(d.size(), data.size()); 87 ASSERT_EQ(d.size(), data.size());
87 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size())); 88 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
88 ASSERT_EQ(s.GetSize(uid), data.size()); 89 ASSERT_EQ(s.GetSize(uid), data.size());
89 } 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
90 133
91 TEST(FilesystemStorage, EndToEnd) 134 TEST(FilesystemStorage, EndToEnd)
92 { 135 {
93 FilesystemStorage s("UnitTestsStorage"); 136 FilesystemStorage s("UnitTestsStorage");
94 s.Clear(); 137 s.Clear();