Mercurial > hg > orthanc
comparison OrthancFramework/UnitTestsSources/FileStorageTests.cpp @ 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
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Thu, 01 Aug 2024 19:44:48 +0200 |
parents | f7adfb22e20e |
children |
comparison
equal
deleted
inserted
replaced
5736:264d84c1936a | 5737:2fe77dfe0466 |
---|---|
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(); |