changeset 1971:869a87c08673

fix for mingw <= 4.2
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 11 Apr 2016 13:50:44 +0200
parents a1c1c606ce98
children 38fb3f524d81
files Core/Endianness.h UnitTestsSources/FromDcmtkTests.cpp UnitTestsSources/ServerIndexTests.cpp UnitTestsSources/UnitTestsMain.cpp
diffstat 4 files changed, 73 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/Core/Endianness.h	Mon Apr 11 13:07:15 2016 +0200
+++ b/Core/Endianness.h	Mon Apr 11 13:50:44 2016 +0200
@@ -38,6 +38,7 @@
  ********************************************************************/
 
 #if defined(__linux)
+#  define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1
 #  include <endian.h>
 #endif
 
@@ -50,14 +51,23 @@
 
 #if defined(_WIN32)
 #  if defined(_MSC_VER)
-//   http://msdn.microsoft.com/en-us/library/a3140177.aspx
+//   Visual Studio - http://msdn.microsoft.com/en-us/library/a3140177.aspx
+#    define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1
 #    define be16toh(x) _byteswap_ushort(x)
 #    define be32toh(x) _byteswap_ulong(x)
 #    define be64toh(x) _byteswap_uint64(x)
-#  else   // MinGW
+#  elif (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
+//   MinGW >= 4.3 - Use builtin intrinsic for byte swapping
+#    define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1
 #    define be16toh(x) __builtin_bswap16(x)
 #    define be32toh(x) __builtin_bswap32(x)
 #    define be64toh(x) __builtin_bswap64(x)
+#  else
+//   MinGW <= 4.2, we must manually implement the byte swapping
+#    define ORTHANC_HAS_BUILTIN_BYTE_SWAP 0
+#    define be16toh(x) __orthanc_bswap16(x)
+#    define be32toh(x) __orthanc_bswap32(x)
+#    define be64toh(x) __orthanc_bswap64(x)
 #  endif
 
 #  define htobe16(x) be16toh(x)
@@ -79,6 +89,7 @@
  ********************************************************************/
 
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
+#  define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1
 #  include <arpa/inet.h>
 #endif
 
@@ -88,6 +99,7 @@
  ********************************************************************/
 
 #if defined(__APPLE__)
+#  define ORTHANC_HAS_BUILTIN_BYTE_SWAP 1
 #  include <libkern/OSByteOrder.h>
 #  define be16toh(x) OSSwapBigToHostInt16(x)
 #  define be32toh(x) OSSwapBigToHostInt32(x)
@@ -105,3 +117,41 @@
 #  define le32toh(x) OSSwapLittleToHostInt32(x)
 #  define le64toh(x) OSSwapLittleToHostInt64(x)
 #endif
+
+
+/********************************************************************
+ ** PORTABLE (BUT SLOW) IMPLEMENTATION OF BYTE-SWAPPING
+ ********************************************************************/
+
+#if ORTHANC_HAS_BUILTIN_BYTE_SWAP != 1
+
+#include <stdint.h>
+
+static inline uint16_t __orthanc_bswap16(uint16_t a)
+{
+  return (a << 8) | (a >> 8);
+}
+
+static inline uint32_t __orthanc_bswap32(uint32_t a)
+{
+  const uint8_t* p = reinterpret_cast<const uint8_t*>(&a);
+  return (static_cast<uint32_t>(p[0]) << 24 |
+          static_cast<uint32_t>(p[1]) << 16 |
+          static_cast<uint32_t>(p[2]) << 8 |
+          static_cast<uint32_t>(p[3]));
+}
+
+static inline uint64_t __orthanc_bswap64(uint64_t a)
+{
+  const uint8_t* p = reinterpret_cast<const uint8_t*>(&a);
+  return (static_cast<uint64_t>(p[0]) << 56 |
+          static_cast<uint64_t>(p[1]) << 48 |
+          static_cast<uint64_t>(p[2]) << 40 |
+          static_cast<uint64_t>(p[3]) << 32 |
+          static_cast<uint64_t>(p[4]) << 24 |
+          static_cast<uint64_t>(p[5]) << 16 |
+          static_cast<uint64_t>(p[6]) << 8 |
+          static_cast<uint64_t>(p[7]));
+}
+
+#endif
--- a/UnitTestsSources/FromDcmtkTests.cpp	Mon Apr 11 13:07:15 2016 +0200
+++ b/UnitTestsSources/FromDcmtkTests.cpp	Mon Apr 11 13:50:44 2016 +0200
@@ -541,7 +541,7 @@
   Json::Value v;
   f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0);
   ASSERT_EQ(Json::objectValue, v.type());
-  ASSERT_EQ(6, v.getMemberNames().size());
+  ASSERT_EQ(6u, v.getMemberNames().size());
   ASSERT_FALSE(v.isMember("7052,1000"));
   ASSERT_FALSE(v.isMember("7053,1000"));
   ASSERT_TRUE(v.isMember("7050,1000"));
@@ -550,7 +550,7 @@
 
   f.ToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePrivateTags | DicomToJsonFlags_ConvertBinaryToNull), 0);
   ASSERT_EQ(Json::objectValue, v.type());
-  ASSERT_EQ(7, v.getMemberNames().size());
+  ASSERT_EQ(7u, v.getMemberNames().size());
   ASSERT_FALSE(v.isMember("7052,1000"));
   ASSERT_TRUE(v.isMember("7050,1000"));
   ASSERT_TRUE(v.isMember("7053,1000"));
@@ -559,7 +559,7 @@
 
   f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludePrivateTags, 0);
   ASSERT_EQ(Json::objectValue, v.type());
-  ASSERT_EQ(7, v.getMemberNames().size());
+  ASSERT_EQ(7u, v.getMemberNames().size());
   ASSERT_FALSE(v.isMember("7052,1000"));
   ASSERT_TRUE(v.isMember("7050,1000"));
   ASSERT_TRUE(v.isMember("7053,1000"));
@@ -572,7 +572,7 @@
 
   f.ToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_ConvertBinaryToNull), 0);
   ASSERT_EQ(Json::objectValue, v.type());
-  ASSERT_EQ(7, v.getMemberNames().size());
+  ASSERT_EQ(7u, v.getMemberNames().size());
   ASSERT_TRUE(v.isMember("7050,1000"));
   ASSERT_TRUE(v.isMember("7052,1000"));
   ASSERT_FALSE(v.isMember("7053,1000"));
@@ -581,7 +581,7 @@
 
   f.ToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags), 0);
   ASSERT_EQ(Json::objectValue, v.type());
-  ASSERT_EQ(7, v.getMemberNames().size());
+  ASSERT_EQ(7u, v.getMemberNames().size());
   ASSERT_TRUE(v.isMember("7050,1000"));
   ASSERT_TRUE(v.isMember("7052,1000"));
   ASSERT_FALSE(v.isMember("7053,1000"));
@@ -593,7 +593,7 @@
 
   f.ToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludeUnknownTags | DicomToJsonFlags_IncludePrivateTags | DicomToJsonFlags_ConvertBinaryToNull), 0);
   ASSERT_EQ(Json::objectValue, v.type());
-  ASSERT_EQ(8, v.getMemberNames().size());
+  ASSERT_EQ(8u, v.getMemberNames().size());
   ASSERT_TRUE(v.isMember("7050,1000"));
   ASSERT_TRUE(v.isMember("7052,1000"));
   ASSERT_TRUE(v.isMember("7053,1000"));
@@ -611,25 +611,25 @@
   Json::Value v;
   f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0);
   ASSERT_EQ(Json::objectValue, v.type());
-  ASSERT_EQ(5, v.getMemberNames().size());
+  ASSERT_EQ(5u, v.getMemberNames().size());
   ASSERT_FALSE(v.isMember("7fe0,0010"));  
 
   f.ToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePixelData | DicomToJsonFlags_ConvertBinaryToNull), 0);
   ASSERT_EQ(Json::objectValue, v.type());
-  ASSERT_EQ(6, v.getMemberNames().size());
+  ASSERT_EQ(6u, v.getMemberNames().size());
   ASSERT_TRUE(v.isMember("7fe0,0010"));  
   ASSERT_EQ(Json::nullValue, v["7fe0,0010"].type());  
 
   f.ToJson(v, DicomToJsonFormat_Short, static_cast<DicomToJsonFlags>(DicomToJsonFlags_IncludePixelData | DicomToJsonFlags_ConvertBinaryToAscii), 0);
   ASSERT_EQ(Json::objectValue, v.type());
-  ASSERT_EQ(6, v.getMemberNames().size());
+  ASSERT_EQ(6u, v.getMemberNames().size());
   ASSERT_TRUE(v.isMember("7fe0,0010"));  
   ASSERT_EQ(Json::stringValue, v["7fe0,0010"].type());  
   ASSERT_EQ("Pixels", v["7fe0,0010"].asString());  
 
   f.ToJson(v, DicomToJsonFormat_Short, DicomToJsonFlags_IncludePixelData, 0);
   ASSERT_EQ(Json::objectValue, v.type());
-  ASSERT_EQ(6, v.getMemberNames().size());
+  ASSERT_EQ(6u, v.getMemberNames().size());
   ASSERT_TRUE(v.isMember("7fe0,0010"));  
   ASSERT_EQ(Json::stringValue, v["7fe0,0010"].type());
   std::string mime, content;
@@ -807,8 +807,8 @@
     Orthanc::ParsedDicomFile f(s);
     
     std::auto_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0));
-    ASSERT_EQ(256, decoded->GetWidth());
-    ASSERT_EQ(256, decoded->GetHeight());
+    ASSERT_EQ(256u, decoded->GetWidth());
+    ASSERT_EQ(256u, decoded->GetHeight());
     ASSERT_EQ(Orthanc::PixelFormat_Grayscale8, decoded->GetFormat());
 
     for (int y = 0; y < 256; y++)
@@ -869,8 +869,8 @@
     Orthanc::ParsedDicomFile f(s);
     
     std::auto_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0));
-    ASSERT_EQ(384, decoded->GetWidth());
-    ASSERT_EQ(256, decoded->GetHeight());
+    ASSERT_EQ(384u, decoded->GetWidth());
+    ASSERT_EQ(256u, decoded->GetHeight());
     ASSERT_EQ(Orthanc::PixelFormat_RGB24, decoded->GetFormat());
 
     for (int y = 0; y < 256; y++)
@@ -923,8 +923,8 @@
     Orthanc::ParsedDicomFile f(s);
     
     std::auto_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0));
-    ASSERT_EQ(256, decoded->GetWidth());
-    ASSERT_EQ(256, decoded->GetHeight());
+    ASSERT_EQ(256u, decoded->GetWidth());
+    ASSERT_EQ(256u, decoded->GetHeight());
     ASSERT_EQ(Orthanc::PixelFormat_Grayscale16, decoded->GetFormat());
 
     for (int y = 0; y < 256; y++)
@@ -977,8 +977,8 @@
     Orthanc::ParsedDicomFile f(s);
     
     std::auto_ptr<Orthanc::ImageAccessor> decoded(Orthanc::DicomImageDecoder::Decode(f, 0));
-    ASSERT_EQ(256, decoded->GetWidth());
-    ASSERT_EQ(256, decoded->GetHeight());
+    ASSERT_EQ(256u, decoded->GetWidth());
+    ASSERT_EQ(256u, decoded->GetHeight());
     ASSERT_EQ(Orthanc::PixelFormat_SignedGrayscale16, decoded->GetFormat());
 
     for (int y = 0; y < 256; y++)
--- a/UnitTestsSources/ServerIndexTests.cpp	Mon Apr 11 13:07:15 2016 +0200
+++ b/UnitTestsSources/ServerIndexTests.cpp	Mon Apr 11 13:50:44 2016 +0200
@@ -824,7 +824,7 @@
   }
 
   // Because the DB is in memory, the SQLite index must not have been created
-  ASSERT_THROW(Toolbox::GetFileSize(path + "/index"), OrthancException);  
+  ASSERT_FALSE(Toolbox::IsRegularFile(path + "/index"));
 
   context.Stop();
   db.Close();
--- a/UnitTestsSources/UnitTestsMain.cpp	Mon Apr 11 13:07:15 2016 +0200
+++ b/UnitTestsSources/UnitTestsMain.cpp	Mon Apr 11 13:50:44 2016 +0200
@@ -561,10 +561,10 @@
 
     std::string h;
     ASSERT_EQ(true, Toolbox::ReadHeader(h, path.c_str(), 1));
-    ASSERT_EQ(1, h.size());
+    ASSERT_EQ(1u, h.size());
     ASSERT_EQ('H', h[0]);
     ASSERT_TRUE(Toolbox::ReadHeader(h, path.c_str(), 0));
-    ASSERT_EQ(0, h.size());
+    ASSERT_EQ(0u, h.size());
     ASSERT_FALSE(Toolbox::ReadHeader(h, path.c_str(), 32));
     ASSERT_EQ(11u, h.size());
     ASSERT_EQ(0, memcmp(s.c_str(), h.c_str(), s.size()));