changeset 709:6c90ce085261

zlib tests
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 13 Feb 2014 15:06:38 +0100
parents 38e2883e096f
children c87a1d529e13
files UnitTestsSources/Png.cpp
diffstat 1 files changed, 31 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/UnitTestsSources/Png.cpp	Thu Feb 13 14:57:57 2014 +0100
+++ b/UnitTestsSources/Png.cpp	Thu Feb 13 15:06:38 2014 +0100
@@ -4,6 +4,7 @@
 #include "../Core/FileFormats/PngReader.h"
 #include "../Core/FileFormats/PngWriter.h"
 #include "../Core/Toolbox.h"
+#include "../Core/Uuid.h"
 
 
 TEST(PngWriter, ColorPattern)
@@ -107,19 +108,40 @@
   std::string s;
   w.WriteToMemory(s, width, height, pitch, Orthanc::PixelFormat_Grayscale16, &image[0]);
 
-  Orthanc::PngReader r;
-  r.ReadFromMemory(s);
+  {
+    Orthanc::PngReader r;
+    r.ReadFromMemory(s);
 
-  ASSERT_EQ(r.GetWidth(), width);
-  ASSERT_EQ(r.GetHeight(), height);
+    ASSERT_EQ(r.GetWidth(), width);
+    ASSERT_EQ(r.GetHeight(), height);
 
-  v = 0;
-  for (int y = 0; y < height; y++)
+    v = 0;
+    for (int y = 0; y < height; y++)
+    {
+      uint16_t *p = reinterpret_cast<uint16_t*>((uint8_t*) r.GetBuffer() + y * r.GetPitch());
+      for (int x = 0; x < width; x++, p++, v++)
+      {
+        ASSERT_EQ(*p, v);
+      }
+    }
+  }
+
   {
-    uint16_t *p = reinterpret_cast<uint16_t*>((uint8_t*) r.GetBuffer() + y * r.GetPitch());
-    for (int x = 0; x < width; x++, p++, v++)
+    Toolbox::TemporaryFile tmp;
+    Toolbox::WriteFile(s, tmp.GetPath());
+
+    Orthanc::PngReader r2;
+    r2.ReadFromFile(tmp.GetPath());
+
+    ASSERT_EQ(r2.GetWidth(), width);
+    ASSERT_EQ(r2.GetHeight(), height);
+    for (int y = 0; y < height; y++)
     {
-      ASSERT_EQ(*p, v);
+      uint16_t *p = reinterpret_cast<uint16_t*>((uint8_t*) r2.GetBuffer() + y * r2.GetPitch());
+      for (int x = 0; x < width; x++, p++, v++)
+      {
+        ASSERT_EQ(*p, v);
+      }
     }
   }
 }