annotate UnitTestsSources/FileStorage.cpp @ 815:5dcfdd3bfca9

endianness
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 08 May 2014 15:52:37 +0200
parents 78b9f64b6b7b
children 3d6f9b7d0add
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #include "gtest/gtest.h"
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 #include <ctype.h>
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 #include <glog/logging.h>
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
234
7c1faef915a4 cleaning room
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 233
diff changeset
6 #include "../Core/FileStorage/FileStorage.h"
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 223
diff changeset
7 #include "../OrthancServer/ServerIndex.h"
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 #include "../Core/Toolbox.h"
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 #include "../Core/OrthancException.h"
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 #include "../Core/Uuid.h"
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 #include "../Core/HttpServer/FilesystemHttpSender.h"
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 #include "../Core/HttpServer/BufferHttpSender.h"
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 #include "../Core/FileStorage/FileStorageAccessor.h"
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 #include "../Core/FileStorage/CompressedFileStorageAccessor.h"
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 using namespace Orthanc;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
18
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
19 static void StringToVector(std::vector<uint8_t>& v,
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
20 const std::string& s)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
21 {
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
22 v.resize(s.size());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
23 for (size_t i = 0; i < s.size(); i++)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
24 v[i] = s[i];
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
25 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
26
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
27
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 TEST(FileStorage, Basic)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
30 FileStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 std::string data = Toolbox::GenerateUuid();
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 std::string uid = s.Create(data);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 std::string d;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 s.ReadFile(d, uid);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 ASSERT_EQ(d.size(), data.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
38 ASSERT_EQ(s.GetCompressedSize(uid), data.size());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
39 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
40
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
41 TEST(FileStorage, Basic2)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
42 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
43 FileStorage s("UnitTestsStorage");
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
44
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
45 std::vector<uint8_t> data;
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
46 StringToVector(data, Toolbox::GenerateUuid());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
47 std::string uid = s.Create(data);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
48 std::string d;
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
49 s.ReadFile(d, uid);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
50 ASSERT_EQ(d.size(), data.size());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
51 ASSERT_FALSE(memcmp(&d[0], &data[0], data.size()));
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
52 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
53 }
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 TEST(FileStorage, EndToEnd)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
57 FileStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 s.Clear();
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 std::list<std::string> u;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 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
62 {
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 u.push_back(s.Create(Toolbox::GenerateUuid()));
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
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 std::set<std::string> ss;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 s.ListAllFiles(ss);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 ASSERT_EQ(10u, ss.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 unsigned int c = 0;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 for (std::list<std::string>::iterator
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 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
73 {
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 ASSERT_TRUE(ss.find(*i) != ss.end());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 if (c < 5)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 s.Remove(*i);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 s.ListAllFiles(ss);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 ASSERT_EQ(5u, ss.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 s.Clear();
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 s.ListAllFiles(ss);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 ASSERT_EQ(0u, ss.size());
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 }
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(FileStorageAccessor, Simple)
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 FileStorageAccessor accessor(s);
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::string data = "Hello world";
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
94 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
95
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 std::string r;
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
97 accessor.Read(r, info.GetUuid());
222
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 ASSERT_EQ(data, r);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
100 ASSERT_EQ(CompressionType_None, info.GetCompressionType());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
101 ASSERT_EQ(11u, info.GetUncompressedSize());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
102 ASSERT_EQ(11u, info.GetCompressedSize());
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
103 ASSERT_EQ(FileContentType_Dicom, info.GetContentType());
222
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
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 TEST(FileStorageAccessor, NoCompression)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
109 FileStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 CompressedFileStorageAccessor accessor(s);
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 accessor.SetCompressionForNextOperations(CompressionType_None);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 std::string data = "Hello world";
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
114 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
115
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 std::string r;
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
117 accessor.Read(r, info.GetUuid());
222
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 ASSERT_EQ(data, r);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
120 ASSERT_EQ(CompressionType_None, info.GetCompressionType());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
121 ASSERT_EQ(11u, info.GetUncompressedSize());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
122 ASSERT_EQ(11u, info.GetCompressedSize());
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
123 ASSERT_EQ(FileContentType_Dicom, info.GetContentType());
222
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
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
127 TEST(FileStorageAccessor, NoCompression2)
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
128 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
129 FileStorage s("UnitTestsStorage");
712
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
130 CompressedFileStorageAccessor accessor(s);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
131
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
132 accessor.SetCompressionForNextOperations(CompressionType_None);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
133 std::vector<uint8_t> data;
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
134 StringToVector(data, "Hello world");
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
135 FileInfo info = accessor.Write(data, FileContentType_Dicom);
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
136
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
137 std::string r;
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
138 accessor.Read(r, info.GetUuid());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
139
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
140 ASSERT_EQ(0, memcmp(&r[0], &data[0], data.size()));
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
141 ASSERT_EQ(CompressionType_None, info.GetCompressionType());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
142 ASSERT_EQ(11u, info.GetUncompressedSize());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
143 ASSERT_EQ(11u, info.GetCompressedSize());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
144 ASSERT_EQ(FileContentType_Dicom, info.GetContentType());
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
145 }
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
146
9e3f21441903 lua tests
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 632
diff changeset
147
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 TEST(FileStorageAccessor, Compression)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
150 FileStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 CompressedFileStorageAccessor accessor(s);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 accessor.SetCompressionForNextOperations(CompressionType_Zlib);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 std::string data = "Hello world";
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
155 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
156
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 std::string r;
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
158 accessor.Read(r, info.GetUuid());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 ASSERT_EQ(data, r);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
161 ASSERT_EQ(CompressionType_Zlib, info.GetCompressionType());
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
162 ASSERT_EQ(11u, info.GetUncompressedSize());
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
163 ASSERT_EQ(FileContentType_Dicom, info.GetContentType());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
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 TEST(FileStorageAccessor, Mix)
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 {
811
78b9f64b6b7b fix path
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 712
diff changeset
169 FileStorage s("UnitTestsStorage");
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 CompressedFileStorageAccessor accessor(s);
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 std::string r;
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 std::string compressedData = "Hello";
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 std::string uncompressedData = "HelloWorld";
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 accessor.SetCompressionForNextOperations(CompressionType_Zlib);
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
177 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
178
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 accessor.SetCompressionForNextOperations(CompressionType_None);
233
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 232
diff changeset
180 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
181
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182 accessor.SetCompressionForNextOperations(CompressionType_Zlib);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
183 accessor.Read(r, compressedInfo.GetUuid());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 ASSERT_EQ(compressedData, r);
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_None);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
187 accessor.Read(r, compressedInfo.GetUuid());
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 ASSERT_NE(compressedData, r);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
189
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
190 /*
224
4eb0c7ce86c9 refactoring for store
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 223
diff changeset
191 // 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
192 accessor.SetCompressionForNextOperations(CompressionType_Zlib);
232
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
193 ASSERT_THROW(accessor.Read(r, uncompressedInfo.GetUuid()), OrthancException);
5368bbe813cf refactoring of attachments
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 224
diff changeset
194 */
222
bd934af46ba4 unit test of storagearea in separate file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }