diff OrthancFramework/UnitTestsSources/ZipTests.cpp @ 4672:d9942d48fea7

ZipWriter::CancelStream(), ZipWriter::GetArchiveSize() and HttpOutput::AnswerWithoutBuffering()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 02 Jun 2021 17:35:39 +0200
parents b12faca76a52
children 863383e7e582
line wrap: on
line diff
--- a/OrthancFramework/UnitTestsSources/ZipTests.cpp	Fri May 28 18:44:00 2021 +0200
+++ b/OrthancFramework/UnitTestsSources/ZipTests.cpp	Wed Jun 02 17:35:39 2021 +0200
@@ -30,6 +30,7 @@
 #include "../Sources/Compression/HierarchicalZipWriter.h"
 #include "../Sources/Compression/ZipReader.h"
 #include "../Sources/OrthancException.h"
+#include "../Sources/SystemToolbox.h"
 #include "../Sources/TemporaryFile.h"
 #include "../Sources/Toolbox.h"
 
@@ -189,10 +190,14 @@
   
   {
     Orthanc::ZipWriter w;
+    ASSERT_EQ(0, w.GetArchiveSize());
+
     w.SetOutputPath(f.GetPath().c_str());
     w.Open();
     w.OpenFile("world/hello");
     w.Write("Hello world");
+
+    ASSERT_EQ(w.GetArchiveSize(), SystemToolbox::GetFileSize(f.GetPath()));
   }
 
   ASSERT_TRUE(ZipReader::IsZipFile(f.GetPath()));
@@ -225,11 +230,29 @@
   {
     {
       Orthanc::ZipWriter w;
-      w.SetZip64(i == 0);
-      w.SetMemoryOutput(memory);
+      w.SetMemoryOutput(memory, (i == 0) /* ZIP64? */);
       w.Open();
 
       w.OpenFile("world/hello");
+      w.Write("Hello");
+      w.CancelStream();
+    }
+
+    ASSERT_THROW(ZipReader::CreateFromMemory(memory), Orthanc::OrthancException);
+
+    memory.clear();
+    uint64_t archiveSize;
+    
+    {
+      Orthanc::ZipWriter w;
+      ASSERT_EQ(0, w.GetArchiveSize());
+      
+      w.SetMemoryOutput(memory, (i == 0) /* ZIP64? */);
+      w.Open();
+
+      ASSERT_EQ(0, w.GetArchiveSize());
+      
+      w.OpenFile("world/hello");
       w.Write(large);
       w.OpenFile("world/hello2");
       w.Write(large);
@@ -237,8 +260,21 @@
       w.Write("Hello world");
       w.OpenFile("world/hello4");
       w.Write(large);
+
+      ASSERT_TRUE(memory.empty());
+
+      uint64_t s1 = w.GetArchiveSize();      
+      ASSERT_NE(0, s1);
+
+      w.Close();
+      archiveSize = w.GetArchiveSize();
+
+      ASSERT_NE(archiveSize, s1);
+      ASSERT_EQ(archiveSize, w.GetArchiveSize());
     }
 
+    ASSERT_EQ(archiveSize, memory.size());
+    
     std::unique_ptr<ZipReader> reader(ZipReader::CreateFromMemory(memory));
 
     ASSERT_EQ(4u, reader->GetFilesCount());