Mercurial > hg > orthanc
comparison UnitTestsSources/UnitTestsMain.cpp @ 1513:fe07f82d83d3
gzip compression
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 10 Aug 2015 16:01:37 +0200 |
parents | 52dc56bcec7d |
children | f09f5d3225a7 |
comparison
equal
deleted
inserted
replaced
1512:52dc56bcec7d | 1513:fe07f82d83d3 |
---|---|
36 #include "gtest/gtest.h" | 36 #include "gtest/gtest.h" |
37 | 37 |
38 #include <ctype.h> | 38 #include <ctype.h> |
39 | 39 |
40 #include "../Core/Compression/ZlibCompressor.h" | 40 #include "../Core/Compression/ZlibCompressor.h" |
41 #include "../Core/Compression/GzipCompressor.h" | |
41 #include "../Core/DicomFormat/DicomTag.h" | 42 #include "../Core/DicomFormat/DicomTag.h" |
42 #include "../Core/HttpServer/HttpToolbox.h" | 43 #include "../Core/HttpServer/HttpToolbox.h" |
43 #include "../Core/Logging.h" | 44 #include "../Core/Logging.h" |
44 #include "../Core/OrthancException.h" | 45 #include "../Core/OrthancException.h" |
45 #include "../Core/Toolbox.h" | 46 #include "../Core/Toolbox.h" |
97 | 98 |
98 ASSERT_FALSE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b_")); | 99 ASSERT_FALSE(Toolbox::IsSHA1("b5ed549f-956400ce-69a8c063-bf5b78be-2732a4b_")); |
99 } | 100 } |
100 | 101 |
101 | 102 |
103 TEST(Gzip, Basic) | |
104 { | |
105 std::string s = "Hello world"; | |
106 | |
107 std::string compressed; | |
108 GzipCompressor c; | |
109 ASSERT_FALSE(c.HasPrefixWithUncompressedSize()); | |
110 IBufferCompressor::Compress(compressed, c, s); | |
111 | |
112 std::string uncompressed; | |
113 IBufferCompressor::Uncompress(uncompressed, c, compressed); | |
114 ASSERT_EQ(s.size(), uncompressed.size()); | |
115 ASSERT_EQ(0, memcmp(&s[0], &uncompressed[0], s.size())); | |
116 } | |
117 | |
118 | |
119 TEST(Gzip, Empty) | |
120 { | |
121 std::string s; | |
122 | |
123 std::string compressed; | |
124 GzipCompressor c; | |
125 ASSERT_FALSE(c.HasPrefixWithUncompressedSize()); | |
126 c.SetPrefixWithUncompressedSize(false); | |
127 IBufferCompressor::Compress(compressed, c, s); | |
128 | |
129 Toolbox::WriteFile(compressed, "/tmp/toto.gz"); | |
130 | |
131 std::string uncompressed; | |
132 IBufferCompressor::Uncompress(uncompressed, c, compressed); | |
133 ASSERT_EQ(0, uncompressed.size()); | |
134 } | |
135 | |
136 | |
137 TEST(Gzip, BasicWithPrefix) | |
138 { | |
139 std::string s = "Hello world"; | |
140 | |
141 std::string compressed; | |
142 GzipCompressor c; | |
143 c.SetPrefixWithUncompressedSize(true); | |
144 ASSERT_TRUE(c.HasPrefixWithUncompressedSize()); | |
145 IBufferCompressor::Compress(compressed, c, s); | |
146 | |
147 std::string uncompressed; | |
148 IBufferCompressor::Uncompress(uncompressed, c, compressed); | |
149 ASSERT_EQ(s.size(), uncompressed.size()); | |
150 ASSERT_EQ(0, memcmp(&s[0], &uncompressed[0], s.size())); | |
151 } | |
152 | |
153 | |
154 TEST(Gzip, EmptyWithPrefix) | |
155 { | |
156 std::string s; | |
157 | |
158 std::string compressed; | |
159 GzipCompressor c; | |
160 c.SetPrefixWithUncompressedSize(true); | |
161 ASSERT_TRUE(c.HasPrefixWithUncompressedSize()); | |
162 IBufferCompressor::Compress(compressed, c, s); | |
163 | |
164 std::string uncompressed; | |
165 IBufferCompressor::Uncompress(uncompressed, c, compressed); | |
166 ASSERT_EQ(0, uncompressed.size()); | |
167 } | |
168 | |
169 | |
102 TEST(Zlib, Basic) | 170 TEST(Zlib, Basic) |
103 { | 171 { |
104 std::string s = Toolbox::GenerateUuid(); | 172 std::string s = Toolbox::GenerateUuid(); |
105 s = s + s + s + s; | 173 s = s + s + s + s; |
106 | 174 |
107 std::string compressed, compressed2; | 175 std::string compressed, compressed2; |
108 ZlibCompressor c; | 176 ZlibCompressor c; |
177 ASSERT_TRUE(c.HasPrefixWithUncompressedSize()); | |
109 IBufferCompressor::Compress(compressed, c, s); | 178 IBufferCompressor::Compress(compressed, c, s); |
110 | 179 |
111 std::string uncompressed; | 180 std::string uncompressed; |
112 IBufferCompressor::Uncompress(uncompressed, c, compressed); | 181 IBufferCompressor::Uncompress(uncompressed, c, compressed); |
113 ASSERT_EQ(s.size(), uncompressed.size()); | 182 ASSERT_EQ(s.size(), uncompressed.size()); |