From f78555ef9f88ac054ddc135b73e0e7d2a6c8d688 Mon Sep 17 00:00:00 2001
From: Marco Biasini <marco.biasini@unibas.ch>
Date: Sun, 8 May 2011 14:46:25 +0200
Subject: [PATCH] robustify img unit tests

Don't use alg.Randomize() to create test image. This may lead
to failures for the situs format, as some of the digits get
lost. Also, don't test DF3 format. We can't import DF3 files
(see BZDNG-247)
---
 modules/io/src/img/map_io_df3_handler.cc |  7 ++++---
 modules/io/tests/test_io_img.cc          | 12 +++++++++---
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/modules/io/src/img/map_io_df3_handler.cc b/modules/io/src/img/map_io_df3_handler.cc
index dba2d957f..f035b5ccc 100644
--- a/modules/io/src/img/map_io_df3_handler.cc
+++ b/modules/io/src/img/map_io_df3_handler.cc
@@ -62,11 +62,12 @@ void DF3::SetNormalizeOnSave(bool normalize_on_save)
 
 Real DF3::GetMaximum() const
 {
-  return 65535.0;
+  return std::numeric_limits<unsigned short>::max();
 }
+
 Real DF3::GetMinimum() const
 {
-  return 0.0;
+  return 0;
 }
 
 void DF3MapIOHandler::Import(img::MapHandle& mh, const bf::path& loc,
@@ -110,7 +111,7 @@ void DF3MapIOHandler::Export(const img::MapHandle& mh2,
     throw IOException("DF3 doesn't support complex-valued maps");
   }
   img::alg::Normalizer norm=img::alg::CreateNoOpNormalizer();
-  if (fmt.GetNormalizeOnSave() == true) {
+  if (fmt.GetNormalizeOnSave()) {
     
     norm=img::alg::CreateLinearRangeNormalizer(mh2, fmt.GetMinimum(),
                                                fmt.GetMaximum());
diff --git a/modules/io/tests/test_io_img.cc b/modules/io/tests/test_io_img.cc
index 5c17b353b..d8165dd76 100644
--- a/modules/io/tests/test_io_img.cc
+++ b/modules/io/tests/test_io_img.cc
@@ -47,7 +47,10 @@ BOOST_AUTO_TEST_CASE(test_io_img)
   //float tests
   boost::test_tools::close_at_tolerance<Real> close_test(::boost::test_tools::percent_tolerance(0.001));
   ost::img::ImageHandle testimage=ost::img::CreateImage(ost::img::Extent(ost::img::Point(0,0),ost::img::Point(3,3)));
-  testimage.ApplyIP(ost::img::alg::Randomize());
+  int counter=0;
+  for (img::ExtentIterator i(testimage.GetExtent()); !i.AtEnd(); ++i, ++counter) {
+   testimage.SetReal(i, counter);
+  }
   testimage+=0.01; //if all values are > 0.0 we can use close_at_tolerance
   const String fname("temp_img.tmp");
   std::map<String,ImageFormatBase*> float_formats;
@@ -82,7 +85,7 @@ BOOST_AUTO_TEST_CASE(test_io_img)
   int_formats["DAT (16 bit)"]=new DAT(true,OST_BIT16_FORMAT);
   int_formats["TIF (16 bit)"]=new TIF;
   int_formats["JPK (16 bit)"]=new JPK;
-  int_formats["DF3"]=new DF3;
+  // int_formats["DF3"]=new DF3(true);
   for(std::map<String,ImageFormatBase*>::iterator it=int_formats.begin();it!=int_formats.end();++it){
     ost::io::SaveImage(testimage,fname,*(it->second));
     ost::img::ImageHandle loadedimage=ost::io::LoadImage(fname,*(it->second));
@@ -97,7 +100,10 @@ BOOST_AUTO_TEST_CASE(test_io_img)
       }
     }
     if(failed){
-      BOOST_ERROR("Image IO failed for plugin " << it->first << " at point " << ost::img::Point(eit)<< ". The values are: " << static_cast<int>(scaled_image.GetReal(eit))<< ","<< static_cast<int>(loadedimage.GetReal(eit)) );
+      BOOST_ERROR("Image IO failed for plugin " << it->first << " at point " 
+                  << ost::img::Point(eit)<< ". Should be " 
+                  << static_cast<int>(scaled_image.GetReal(eit)) << ", but "
+                  << static_cast<int>(loadedimage.GetReal(eit)) << " found.");
     }
     delete it->second;
   }
-- 
GitLab