Mercurial > hg > orthanc
annotate UnitTestsSources/FileStorageTests.cpp @ 1382:1cd2e09cb0e5
case insensitive search by default
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 29 May 2015 14:46:06 +0200 |
parents | 6e7e5ed91c2d |
children | f967bdf8534e |
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 |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1135
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1135
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
827
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
5 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
6 * This program is free software: you can redistribute it and/or |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
7 * modify it under the terms of the GNU General Public License as |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
8 * published by the Free Software Foundation, either version 3 of the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
9 * License, or (at your option) any later version. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
10 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
11 * In addition, as a special exception, the copyright holders of this |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
12 * program give permission to link the code of its release with the |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
14 * that use the same license as the "OpenSSL" library), and distribute |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
15 * the linked executables. You must obey the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
16 * in all respects for all of the code used other than "OpenSSL". If you |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
17 * modify file(s) with this exception, you may extend this exception to |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
18 * your version of the file(s), but you are not obligated to do so. If |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
19 * you do not wish to do so, delete this exception statement from your |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
20 * version. If you delete this exception statement from all source files |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
21 * in the program, then also delete it here. |
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 * 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
|
24 * 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
|
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
26 * General Public License for more details. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
27 * |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
28 * You should have received a copy of the GNU General Public License |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
30 **/ |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
31 |
3d6f9b7d0add
precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
32 |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
827
diff
changeset
|
33 #include "PrecompiledHeadersUnitTests.h" |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include "gtest/gtest.h" |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 #include <ctype.h> |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 #include <glog/logging.h> |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
1123 | 39 #include "../Core/FileStorage/FilesystemStorage.h" |
224
4eb0c7ce86c9
refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
223
diff
changeset
|
40 #include "../OrthancServer/ServerIndex.h" |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 #include "../Core/Toolbox.h" |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 #include "../Core/OrthancException.h" |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 #include "../Core/Uuid.h" |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 #include "../Core/HttpServer/FilesystemHttpSender.h" |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 #include "../Core/HttpServer/BufferHttpSender.h" |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 #include "../Core/FileStorage/FileStorageAccessor.h" |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 #include "../Core/FileStorage/CompressedFileStorageAccessor.h" |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 using namespace Orthanc; |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 |
712 | 51 |
52 static void StringToVector(std::vector<uint8_t>& v, | |
53 const std::string& s) | |
54 { | |
55 v.resize(s.size()); | |
56 for (size_t i = 0; i < s.size(); i++) | |
57 v[i] = s[i]; | |
58 } | |
59 | |
60 | |
1123 | 61 TEST(FilesystemStorage, Basic) |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 { |
1123 | 63 FilesystemStorage s("UnitTestsStorage"); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 std::string data = Toolbox::GenerateUuid(); |
1135
67c3c1e4a6e0
index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
66 std::string uid = Toolbox::GenerateUuid(); |
67c3c1e4a6e0
index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
67 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
|
68 std::string d; |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
69 s.Read(d, uid, FileContentType_Unknown); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 ASSERT_EQ(d.size(), data.size()); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size())); |
1122
1d60316c3618
simplifications in FileStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
967
diff
changeset
|
72 ASSERT_EQ(s.GetSize(uid), data.size()); |
712 | 73 } |
74 | |
1123 | 75 TEST(FilesystemStorage, Basic2) |
712 | 76 { |
1123 | 77 FilesystemStorage s("UnitTestsStorage"); |
712 | 78 |
79 std::vector<uint8_t> data; | |
80 StringToVector(data, Toolbox::GenerateUuid()); | |
1135
67c3c1e4a6e0
index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
81 std::string uid = Toolbox::GenerateUuid(); |
67c3c1e4a6e0
index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
82 s.Create(uid.c_str(), &data[0], data.size(), FileContentType_Unknown); |
712 | 83 std::string d; |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
84 s.Read(d, uid, FileContentType_Unknown); |
712 | 85 ASSERT_EQ(d.size(), data.size()); |
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 | 90 TEST(FilesystemStorage, EndToEnd) |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 { |
1123 | 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 { |
1124
790ff7a5b3bf
IStorageArea abstraction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1123
diff
changeset
|
98 std::string t = Toolbox::GenerateUuid(); |
1135
67c3c1e4a6e0
index-only mode, and custom storage area with plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1126
diff
changeset
|
99 std::string uid = Toolbox::GenerateUuid(); |
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; |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 for (std::list<std::string>::iterator |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 i = u.begin(); i != u.end(); i++, c++) |
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 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 TEST(FileStorageAccessor, Simple) |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 { |
1123 | 128 FilesystemStorage s("UnitTestsStorage"); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 FileStorageAccessor accessor(s); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 std::string data = "Hello world"; |
233 | 132 FileInfo info = accessor.Write(data, FileContentType_Dicom); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 std::string r; |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
135 accessor.Read(r, info.GetUuid(), FileContentType_Unknown); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 ASSERT_EQ(data, r); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
138 ASSERT_EQ(CompressionType_None, info.GetCompressionType()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
139 ASSERT_EQ(11u, info.GetUncompressedSize()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
140 ASSERT_EQ(11u, info.GetCompressedSize()); |
233 | 141 ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 } |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 TEST(FileStorageAccessor, NoCompression) |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 { |
1123 | 147 FilesystemStorage s("UnitTestsStorage"); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 CompressedFileStorageAccessor accessor(s); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 accessor.SetCompressionForNextOperations(CompressionType_None); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 std::string data = "Hello world"; |
233 | 152 FileInfo info = accessor.Write(data, FileContentType_Dicom); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 std::string r; |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
155 accessor.Read(r, info.GetUuid(), FileContentType_Unknown); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 ASSERT_EQ(data, r); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
158 ASSERT_EQ(CompressionType_None, info.GetCompressionType()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
159 ASSERT_EQ(11u, info.GetUncompressedSize()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
160 ASSERT_EQ(11u, info.GetCompressedSize()); |
233 | 161 ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 } |
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 |
712 | 165 TEST(FileStorageAccessor, NoCompression2) |
166 { | |
1123 | 167 FilesystemStorage s("UnitTestsStorage"); |
712 | 168 CompressedFileStorageAccessor accessor(s); |
169 | |
170 accessor.SetCompressionForNextOperations(CompressionType_None); | |
171 std::vector<uint8_t> data; | |
172 StringToVector(data, "Hello world"); | |
173 FileInfo info = accessor.Write(data, FileContentType_Dicom); | |
174 | |
175 std::string r; | |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
176 accessor.Read(r, info.GetUuid(), FileContentType_Unknown); |
712 | 177 |
178 ASSERT_EQ(0, memcmp(&r[0], &data[0], data.size())); | |
179 ASSERT_EQ(CompressionType_None, info.GetCompressionType()); | |
180 ASSERT_EQ(11u, info.GetUncompressedSize()); | |
181 ASSERT_EQ(11u, info.GetCompressedSize()); | |
182 ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); | |
183 } | |
184 | |
185 | |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 TEST(FileStorageAccessor, Compression) |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 { |
1123 | 188 FilesystemStorage s("UnitTestsStorage"); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 CompressedFileStorageAccessor accessor(s); |
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 accessor.SetCompressionForNextOperations(CompressionType_Zlib); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 std::string data = "Hello world"; |
233 | 193 FileInfo info = accessor.Write(data, FileContentType_Dicom); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 std::string r; |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
196 accessor.Read(r, info.GetUuid(), FileContentType_Unknown); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 ASSERT_EQ(data, r); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
199 ASSERT_EQ(CompressionType_Zlib, info.GetCompressionType()); |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
200 ASSERT_EQ(11u, info.GetUncompressedSize()); |
233 | 201 ASSERT_EQ(FileContentType_Dicom, info.GetContentType()); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 } |
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 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
205 TEST(FileStorageAccessor, Mix) |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
206 { |
1123 | 207 FilesystemStorage s("UnitTestsStorage"); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
208 CompressedFileStorageAccessor accessor(s); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
209 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 std::string r; |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
211 std::string compressedData = "Hello"; |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
212 std::string uncompressedData = "HelloWorld"; |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 accessor.SetCompressionForNextOperations(CompressionType_Zlib); |
233 | 215 FileInfo compressedInfo = accessor.Write(compressedData, FileContentType_Dicom); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
216 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 accessor.SetCompressionForNextOperations(CompressionType_None); |
233 | 218 FileInfo uncompressedInfo = accessor.Write(uncompressedData, FileContentType_Dicom); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 accessor.SetCompressionForNextOperations(CompressionType_Zlib); |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
221 accessor.Read(r, compressedInfo.GetUuid(), FileContentType_Unknown); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
222 ASSERT_EQ(compressedData, r); |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 |
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 accessor.SetCompressionForNextOperations(CompressionType_None); |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
225 accessor.Read(r, compressedInfo.GetUuid(), FileContentType_Unknown); |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 ASSERT_NE(compressedData, r); |
232
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
227 |
5368bbe813cf
refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
224
diff
changeset
|
228 /* |
224
4eb0c7ce86c9
refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
223
diff
changeset
|
229 // This test is too slow on Windows |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 accessor.SetCompressionForNextOperations(CompressionType_Zlib); |
1126
bf67431a7383
handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1124
diff
changeset
|
231 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
|
232 */ |
222
bd934af46ba4
unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 } |