Mercurial > hg > orthanc
comparison OrthancFramework/UnitTestsSources/StreamTests.cpp @ 4325:b96aedfa8cc1
unit tests now running in WebAssembly
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 24 Nov 2020 16:21:29 +0100 |
parents | 318c16cfccab |
children | d9473bd5ed43 |
comparison
equal
deleted
inserted
replaced
4324:433e94d08e36 | 4325:b96aedfa8cc1 |
---|---|
25 # include <OrthancFramework.h> | 25 # include <OrthancFramework.h> |
26 #endif | 26 #endif |
27 | 27 |
28 #include <gtest/gtest.h> | 28 #include <gtest/gtest.h> |
29 | 29 |
30 #include "../Sources/SystemToolbox.h" | |
31 #include "../Sources/Toolbox.h" | 30 #include "../Sources/Toolbox.h" |
32 #include "../Sources/OrthancException.h" | 31 #include "../Sources/OrthancException.h" |
33 #include "../Sources/HttpServer/BufferHttpSender.h" | 32 #include "../Sources/HttpServer/BufferHttpSender.h" |
34 #include "../Sources/HttpServer/FilesystemHttpSender.h" | |
35 #include "../Sources/HttpServer/HttpStreamTranscoder.h" | 33 #include "../Sources/HttpServer/HttpStreamTranscoder.h" |
36 #include "../Sources/Compression/ZlibCompressor.h" | 34 #include "../Sources/Compression/ZlibCompressor.h" |
37 #include "../Sources/Compression/GzipCompressor.h" | 35 #include "../Sources/Compression/GzipCompressor.h" |
38 | 36 |
37 #if ORTHANC_SANDBOXED != 1 | |
38 # include "../Sources/HttpServer/FilesystemHttpSender.h" | |
39 # include "../Sources/SystemToolbox.h" | |
40 #endif | |
41 | |
39 | 42 |
40 using namespace Orthanc; | 43 using namespace Orthanc; |
41 | 44 |
42 | 45 |
43 TEST(Gzip, Basic) | 46 TEST(Gzip, Basic) |
169 IBufferCompressor::Uncompress(uncompressed, c, compressed); | 172 IBufferCompressor::Uncompress(uncompressed, c, compressed); |
170 ASSERT_TRUE(uncompressed.empty()); | 173 ASSERT_TRUE(uncompressed.empty()); |
171 } | 174 } |
172 | 175 |
173 | 176 |
177 #if ORTHANC_SANDBOXED != 1 | |
174 static bool ReadAllStream(std::string& result, | 178 static bool ReadAllStream(std::string& result, |
175 IHttpStreamAnswer& stream, | 179 IHttpStreamAnswer& stream, |
176 bool allowGzip = false, | 180 bool allowGzip = false, |
177 bool allowDeflate = false) | 181 bool allowDeflate = false) |
178 { | 182 { |
193 pos += s; | 197 pos += s; |
194 } | 198 } |
195 | 199 |
196 return pos == result.size(); | 200 return pos == result.size(); |
197 } | 201 } |
198 | 202 #endif |
199 | 203 |
204 | |
205 #if ORTHANC_SANDBOXED != 1 | |
200 TEST(BufferHttpSender, Basic) | 206 TEST(BufferHttpSender, Basic) |
201 { | 207 { |
202 const std::string s = "Hello world"; | 208 const std::string s = "Hello world"; |
203 std::string t; | 209 std::string t; |
204 | 210 |
216 sender.GetBuffer() = s; | 222 sender.GetBuffer() = s; |
217 ASSERT_TRUE(ReadAllStream(t, sender)); | 223 ASSERT_TRUE(ReadAllStream(t, sender)); |
218 ASSERT_EQ(s, t); | 224 ASSERT_EQ(s, t); |
219 } | 225 } |
220 } | 226 } |
221 | 227 #endif |
222 | 228 |
229 | |
230 #if ORTHANC_SANDBOXED != 1 | |
223 TEST(FilesystemHttpSender, Basic) | 231 TEST(FilesystemHttpSender, Basic) |
224 { | 232 { |
225 const std::string& path = "UnitTestsResults/stream"; | 233 const std::string& path = "UnitTestsResults/stream"; |
226 const std::string s = "Hello world"; | 234 const std::string s = "Hello world"; |
227 std::string t; | 235 std::string t; |
238 FilesystemHttpSender sender(path); | 246 FilesystemHttpSender sender(path); |
239 ASSERT_TRUE(ReadAllStream(t, sender)); | 247 ASSERT_TRUE(ReadAllStream(t, sender)); |
240 ASSERT_EQ(0u, t.size()); | 248 ASSERT_EQ(0u, t.size()); |
241 } | 249 } |
242 } | 250 } |
243 | 251 #endif |
244 | 252 |
253 | |
254 #if ORTHANC_SANDBOXED != 1 | |
245 TEST(HttpStreamTranscoder, Basic) | 255 TEST(HttpStreamTranscoder, Basic) |
246 { | 256 { |
247 ZlibCompressor compressor; | 257 ZlibCompressor compressor; |
248 | 258 |
249 const std::string s = "Hello world " + Toolbox::GenerateUuid(); | 259 const std::string s = "Hello world " + Toolbox::GenerateUuid(); |
320 ASSERT_TRUE(ReadAllStream(u, transcode, false, true)); | 330 ASSERT_TRUE(ReadAllStream(u, transcode, false, true)); |
321 | 331 |
322 ASSERT_EQ(0u, u.size()); | 332 ASSERT_EQ(0u, u.size()); |
323 } | 333 } |
324 } | 334 } |
335 #endif |