annotate UnitTestsSources/FileStorage.cpp @ 906:cbc0ea03dffe plugins

sample plugin configuration
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 19 Jun 2014 13:37:49 +0200
parents 84513f2ee1f3
children
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
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege,
3d6f9b7d0add precompiled headers in unit tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 811
diff changeset
4 * Belgium
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
234
7c1faef915a4 cleaning room
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
39 #include "../Core/FileStorage/FileStorage.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
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
51
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
52 static void StringToVector(std::vector<uint8_t>& v,
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
53 const std::string& s)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
54 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
55 v.resize(s.size());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
56 for (size_t i = 0; i < s.size(); i++)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
57 v[i] = s[i];
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
58 }
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
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 TEST(FileStorage, Basic)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
63 FileStorage 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();
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 std::string uid = s.Create(data);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 std::string d;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 s.ReadFile(d, uid);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 ASSERT_EQ(d.size(), data.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
71 ASSERT_EQ(s.GetCompressedSize(uid), data.size());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
72 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
73
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
74 TEST(FileStorage, Basic2)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
75 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
76 FileStorage s("UnitTestsStorage");
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
77
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
78 std::vector<uint8_t> data;
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
79 StringToVector(data, Toolbox::GenerateUuid());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
80 std::string uid = s.Create(data);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
81 std::string d;
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
82 s.ReadFile(d, uid);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
83 ASSERT_EQ(d.size(), data.size());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
84 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
85 ASSERT_EQ(s.GetCompressedSize(uid), data.size());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 TEST(FileStorage, EndToEnd)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
90 FileStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 s.Clear();
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 std::list<std::string> u;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 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
95 {
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 u.push_back(s.Create(Toolbox::GenerateUuid()));
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 std::set<std::string> ss;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 s.ListAllFiles(ss);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 ASSERT_EQ(10u, ss.size());
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 unsigned int c = 0;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 for (std::list<std::string>::iterator
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 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
106 {
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 ASSERT_TRUE(ss.find(*i) != ss.end());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 if (c < 5)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 s.Remove(*i);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
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 s.ListAllFiles(ss);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 ASSERT_EQ(5u, ss.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 s.Clear();
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 s.ListAllFiles(ss);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 ASSERT_EQ(0u, ss.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
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
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 TEST(FileStorageAccessor, Simple)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
123 FileStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 FileStorageAccessor accessor(s);
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 std::string data = "Hello world";
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
127 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
128
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 std::string r;
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
130 accessor.Read(r, info.GetUuid());
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 ASSERT_EQ(data, r);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
133 ASSERT_EQ(CompressionType_None, info.GetCompressionType());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
134 ASSERT_EQ(11u, info.GetUncompressedSize());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
135 ASSERT_EQ(11u, info.GetCompressedSize());
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
136 ASSERT_EQ(FileContentType_Dicom, info.GetContentType());
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
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 TEST(FileStorageAccessor, NoCompression)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
142 FileStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 CompressedFileStorageAccessor accessor(s);
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 accessor.SetCompressionForNextOperations(CompressionType_None);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 std::string data = "Hello world";
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
147 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
148
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 std::string r;
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
150 accessor.Read(r, info.GetUuid());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 ASSERT_EQ(data, r);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
153 ASSERT_EQ(CompressionType_None, info.GetCompressionType());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
154 ASSERT_EQ(11u, info.GetUncompressedSize());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
155 ASSERT_EQ(11u, info.GetCompressedSize());
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
156 ASSERT_EQ(FileContentType_Dicom, info.GetContentType());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
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
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
160 TEST(FileStorageAccessor, NoCompression2)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
161 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
162 FileStorage s("UnitTestsStorage");
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
163 CompressedFileStorageAccessor accessor(s);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
164
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
165 accessor.SetCompressionForNextOperations(CompressionType_None);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
166 std::vector<uint8_t> data;
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
167 StringToVector(data, "Hello world");
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
168 FileInfo info = accessor.Write(data, FileContentType_Dicom);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
169
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
170 std::string r;
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
171 accessor.Read(r, info.GetUuid());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
172
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
173 ASSERT_EQ(0, memcmp(&r[0], &data[0], data.size()));
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
174 ASSERT_EQ(CompressionType_None, info.GetCompressionType());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
175 ASSERT_EQ(11u, info.GetUncompressedSize());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
176 ASSERT_EQ(11u, info.GetCompressedSize());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
177 ASSERT_EQ(FileContentType_Dicom, info.GetContentType());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
178 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
179
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
180
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 TEST(FileStorageAccessor, Compression)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
183 FileStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 CompressedFileStorageAccessor accessor(s);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 accessor.SetCompressionForNextOperations(CompressionType_Zlib);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 std::string data = "Hello world";
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
188 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
189
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 std::string r;
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
191 accessor.Read(r, info.GetUuid());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 ASSERT_EQ(data, r);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
194 ASSERT_EQ(CompressionType_Zlib, info.GetCompressionType());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
195 ASSERT_EQ(11u, info.GetUncompressedSize());
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
196 ASSERT_EQ(FileContentType_Dicom, info.GetContentType());
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
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 TEST(FileStorageAccessor, Mix)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
202 FileStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 CompressedFileStorageAccessor accessor(s);
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 std::string r;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 std::string compressedData = "Hello";
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 std::string uncompressedData = "HelloWorld";
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 accessor.SetCompressionForNextOperations(CompressionType_Zlib);
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
210 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
211
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 accessor.SetCompressionForNextOperations(CompressionType_None);
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
213 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
214
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 accessor.SetCompressionForNextOperations(CompressionType_Zlib);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
216 accessor.Read(r, compressedInfo.GetUuid());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 ASSERT_EQ(compressedData, r);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 accessor.SetCompressionForNextOperations(CompressionType_None);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
220 accessor.Read(r, compressedInfo.GetUuid());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 ASSERT_NE(compressedData, r);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
222
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
223 /*
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 223
diff changeset
224 // 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
225 accessor.SetCompressionForNextOperations(CompressionType_Zlib);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
226 ASSERT_THROW(accessor.Read(r, uncompressedInfo.GetUuid()), OrthancException);
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
227 */
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 }