diff OrthancFramework/UnitTestsSources/ZipTests.cpp @ 4355:460a71988208

new class: ZipReader
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 08 Dec 2020 12:38:59 +0100
parents bcfb53d1bc56
children d9473bd5ed43
line wrap: on
line diff
--- a/OrthancFramework/UnitTestsSources/ZipTests.cpp	Mon Dec 07 20:38:31 2020 +0100
+++ b/OrthancFramework/UnitTestsSources/ZipTests.cpp	Tue Dec 08 12:38:59 2020 +0100
@@ -27,9 +27,10 @@
 
 #include <gtest/gtest.h>
 
+#include "../Sources/Compression/HierarchicalZipWriter.h"
+#include "../Sources/Compression/ZipReader.h"
 #include "../Sources/OrthancException.h"
-#include "../Sources/Compression/ZipWriter.h"
-#include "../Sources/Compression/HierarchicalZipWriter.h"
+#include "../Sources/TemporaryFile.h"
 #include "../Sources/Toolbox.h"
 
 
@@ -182,59 +183,28 @@
 }
 
 
-
-
-
-#include "../Resources/ThirdParty/minizip/unzip.h"
-
-TEST(ZipReader, DISABLED_Basic)
+TEST(ZipReader, Basic)
 {
-  unzFile zip = unzOpen("/home/jodogne/DICOM/Demo/BRAINIX.zip");
-  printf(">> %d\n", zip);
-
-  unz_global_info info;
-  printf(">> %d\n", unzGetGlobalInfo(zip, &info));
-  printf("%d %d\n", info.number_entry, info.size_comment);
-
-  unsigned int count = 0;
-  printf(">> %d\n", unzGoToFirstFile(zip));
-  for (;;)
+  TemporaryFile f;
+  
   {
-    char f[1024];
-    unz_file_info64_s j;
-    unzGetCurrentFileInfo64(zip, &j, f, sizeof(f) - 1, NULL, 0, NULL, 0);
-    printf("[%s] %d %d\n", f, j.uncompressed_size, j.size_filename);
-
-
-    printf("%d\n", unzOpenCurrentFile(zip));
-
-    std::string content;
-    content.resize(j.uncompressed_size);
-    if (!content.empty())
-    {
-      printf("%d\n", unzReadCurrentFile(zip, &content[0], content.size()));
-
-      char g[1024];
-      sprintf(g, "/tmp/i/zip-%06d.dcm", count);
-      FILE* h = fopen(g, "wb");
-      fwrite(content.c_str(), content.size(), 1, h);
-      fclose(h);
-    }
-    
-    printf("%d\n", unzCloseCurrentFile(zip));
-  
-    
-    count += 1;
-    int i = unzGoToNextFile(zip);
-    if (i != 0)
-    {
-      printf("done\n");
-      break;
-    }
+    Orthanc::ZipWriter w;
+    w.SetOutputPath(f.GetPath().c_str());
+    w.Open();
+    w.OpenFile("world/hello");
+    w.Write("Hello world");
   }
 
-  printf("count: %d\n", count);    
+  ASSERT_TRUE(ZipReader::IsZipFile(f.GetPath()));
+
+  std::unique_ptr<ZipReader> reader(ZipReader::CreateFromFile(f.GetPath()));
+
+  ASSERT_EQ(1u, reader->GetFilesCount());
   
-  unzClose(zip);
+  std::string filename, content;
+  ASSERT_TRUE(reader->ReadNextFile(filename, content));
+  ASSERT_EQ("world/hello", filename);
+  ASSERT_EQ("Hello world", content);
+  ASSERT_FALSE(reader->ReadNextFile(filename, content));
 }