annotate OrthancFramework/UnitTestsSources/FileStorageTests.cpp @ 4058:2a8bf0991be0 framework

moved FileStorageTests.cpp from OrthancServer to OrthancFramework
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jun 2020 13:57:44 +0200
parents OrthancServer/UnitTestsSources/FileStorageTests.cpp@05b8fd21089c
children 0953b3dc3261
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1549
diff changeset
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
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
827
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
6 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
7 * 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
8 * 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
9 * 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
10 * License, or (at your option) any later version.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
11 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
12 * 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
13 * 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
14 * 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
15 * 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
16 * 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
17 * 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
18 * 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
19 * 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
20 * 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
21 * 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
22 * in the program, then also delete it here.
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 * 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
25 * 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
26 * 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
27 * General Public License for more details.
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
28 *
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
29 * 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
30 * 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
31 **/
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
32
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
33
4058
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
34 #if ORTHANC_UNIT_TESTS_LINK_FRAMEWORK == 1
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
35 # include <OrthancFramework.h>
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
36 #endif
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
37
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include "gtest/gtest.h"
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #include <ctype.h>
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
4058
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
42 #include "../Sources/FileStorage/FilesystemStorage.h"
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
43 #include "../Sources/FileStorage/StorageAccessor.h"
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
44 #include "../Sources/HttpServer/BufferHttpSender.h"
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
45 #include "../Sources/HttpServer/FilesystemHttpSender.h"
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
46 #include "../Sources/Logging.h"
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
47 #include "../Sources/OrthancException.h"
2a8bf0991be0 moved FileStorageTests.cpp from OrthancServer to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4045
diff changeset
48 #include "../Sources/Toolbox.h"
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 using namespace Orthanc;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
52
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
53 static void StringToVector(std::vector<uint8_t>& v,
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
54 const std::string& s)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
55 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
56 v.resize(s.size());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
57 for (size_t i = 0; i < s.size(); i++)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
58 v[i] = s[i];
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
59 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
60
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
61
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
62 TEST(FilesystemStorage, Basic)
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
64 FilesystemStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65
2512
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
66 std::string data = Toolbox::GenerateUuid();
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
67 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
68 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
69 std::string d;
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
70 s.Read(d, uid, FileContentType_Unknown);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 ASSERT_EQ(d.size(), data.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
1122
1d60316c3618 simplifications in FileStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
73 ASSERT_EQ(s.GetSize(uid), data.size());
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
74 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
75
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
76 TEST(FilesystemStorage, Basic2)
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
77 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
78 FilesystemStorage s("UnitTestsStorage");
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
79
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
80 std::vector<uint8_t> data;
2512
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
81 StringToVector(data, Toolbox::GenerateUuid());
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
82 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
83 s.Create(uid.c_str(), &data[0], data.size(), FileContentType_Unknown);
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
84 std::string d;
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
85 s.Read(d, uid, FileContentType_Unknown);
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
86 ASSERT_EQ(d.size(), data.size());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
87 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
1122
1d60316c3618 simplifications in FileStorage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 967
diff changeset
88 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
89 }
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
91 TEST(FilesystemStorage, EndToEnd)
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
93 FilesystemStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 s.Clear();
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 std::list<std::string> u;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 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
98 {
2512
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
99 std::string t = Toolbox::GenerateUuid();
4dcafa8d6633 SystemToolbox::GenerateUuid moved to Toolbox::GenerateUuid
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
100 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
101 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
102 u.push_back(uid);
222
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
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 std::set<std::string> ss;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 s.ListAllFiles(ss);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 ASSERT_EQ(10u, ss.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 unsigned int c = 0;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 for (std::list<std::string>::iterator
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 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
112 {
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 ASSERT_TRUE(ss.find(*i) != ss.end());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 if (c < 5)
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
115 s.Remove(*i, FileContentType_Unknown);
222
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
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 s.ListAllFiles(ss);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 ASSERT_EQ(5u, ss.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 s.Clear();
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 s.ListAllFiles(ss);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 ASSERT_EQ(0u, ss.size());
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
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
127 TEST(StorageAccessor, NoCompression)
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
129 FilesystemStorage s("UnitTestsStorage");
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
130 StorageAccessor accessor(s);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 std::string data = "Hello world";
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
133 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
134
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 std::string r;
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
136 accessor.Read(r, info);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 ASSERT_EQ(data, r);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
139 ASSERT_EQ(CompressionType_None, info.GetCompressionType());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
140 ASSERT_EQ(11u, info.GetUncompressedSize());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
141 ASSERT_EQ(11u, info.GetCompressedSize());
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
142 ASSERT_EQ(FileContentType_Dicom, info.GetContentType());
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
143 ASSERT_EQ("3e25960a79dbc69b674cd4ec67a72c62", info.GetUncompressedMD5());
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
144 ASSERT_EQ(info.GetUncompressedMD5(), info.GetCompressedMD5());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 }
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
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
148 TEST(StorageAccessor, Compression)
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
149 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
150 FilesystemStorage s("UnitTestsStorage");
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
151 StorageAccessor accessor(s);
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
152
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
153 std::string data = "Hello world";
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
154 FileInfo info = accessor.Write(data, FileContentType_DicomAsJson, CompressionType_ZlibWithSize, true);
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
155
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
156 std::string r;
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
157 accessor.Read(r, info);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 ASSERT_EQ(data, r);
1514
d73a2178b319 support of deflate and gzip content-types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
160 ASSERT_EQ(CompressionType_ZlibWithSize, info.GetCompressionType());
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
161 ASSERT_EQ(11u, info.GetUncompressedSize());
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
162 ASSERT_EQ(FileContentType_DicomAsJson, info.GetContentType());
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
163 ASSERT_EQ("3e25960a79dbc69b674cd4ec67a72c62", info.GetUncompressedMD5());
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
164 ASSERT_NE(info.GetUncompressedMD5(), info.GetCompressedMD5());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 }
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
168 TEST(StorageAccessor, Mix)
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 {
1123
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1122
diff changeset
170 FilesystemStorage s("UnitTestsStorage");
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
171 StorageAccessor accessor(s);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 std::string r;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 std::string compressedData = "Hello";
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 std::string uncompressedData = "HelloWorld";
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
177 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
178 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
179
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
180 accessor.Read(r, compressedInfo);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 ASSERT_EQ(compressedData, r);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
1549
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
183 accessor.Read(r, uncompressedInfo);
e5e975e9b738 refactoring and simplification of StorageAccessor
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1514
diff changeset
184 ASSERT_EQ(uncompressedData, r);
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 ASSERT_NE(compressedData, r);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
186
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
187 /*
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 223
diff changeset
188 // 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
189 accessor.SetCompressionForNextOperations(CompressionType_ZlibWithSize);
1126
bf67431a7383 handling of file content type in IStorageArea
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1124
diff changeset
190 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
191 */
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 }