Skip to content
Snippets Groups Projects
Commit f78555ef authored by Marco Biasini's avatar Marco Biasini
Browse files

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)
parent ce680562
No related branches found
No related tags found
No related merge requests found
...@@ -62,11 +62,12 @@ void DF3::SetNormalizeOnSave(bool normalize_on_save) ...@@ -62,11 +62,12 @@ void DF3::SetNormalizeOnSave(bool normalize_on_save)
Real DF3::GetMaximum() const Real DF3::GetMaximum() const
{ {
return 65535.0; return std::numeric_limits<unsigned short>::max();
} }
Real DF3::GetMinimum() const Real DF3::GetMinimum() const
{ {
return 0.0; return 0;
} }
void DF3MapIOHandler::Import(img::MapHandle& mh, const bf::path& loc, void DF3MapIOHandler::Import(img::MapHandle& mh, const bf::path& loc,
...@@ -110,7 +111,7 @@ void DF3MapIOHandler::Export(const img::MapHandle& mh2, ...@@ -110,7 +111,7 @@ void DF3MapIOHandler::Export(const img::MapHandle& mh2,
throw IOException("DF3 doesn't support complex-valued maps"); throw IOException("DF3 doesn't support complex-valued maps");
} }
img::alg::Normalizer norm=img::alg::CreateNoOpNormalizer(); img::alg::Normalizer norm=img::alg::CreateNoOpNormalizer();
if (fmt.GetNormalizeOnSave() == true) { if (fmt.GetNormalizeOnSave()) {
norm=img::alg::CreateLinearRangeNormalizer(mh2, fmt.GetMinimum(), norm=img::alg::CreateLinearRangeNormalizer(mh2, fmt.GetMinimum(),
fmt.GetMaximum()); fmt.GetMaximum());
......
...@@ -47,7 +47,10 @@ BOOST_AUTO_TEST_CASE(test_io_img) ...@@ -47,7 +47,10 @@ BOOST_AUTO_TEST_CASE(test_io_img)
//float tests //float tests
boost::test_tools::close_at_tolerance<Real> close_test(::boost::test_tools::percent_tolerance(0.001)); 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))); 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 testimage+=0.01; //if all values are > 0.0 we can use close_at_tolerance
const String fname("temp_img.tmp"); const String fname("temp_img.tmp");
std::map<String,ImageFormatBase*> float_formats; std::map<String,ImageFormatBase*> float_formats;
...@@ -82,7 +85,7 @@ BOOST_AUTO_TEST_CASE(test_io_img) ...@@ -82,7 +85,7 @@ BOOST_AUTO_TEST_CASE(test_io_img)
int_formats["DAT (16 bit)"]=new DAT(true,OST_BIT16_FORMAT); int_formats["DAT (16 bit)"]=new DAT(true,OST_BIT16_FORMAT);
int_formats["TIF (16 bit)"]=new TIF; int_formats["TIF (16 bit)"]=new TIF;
int_formats["JPK (16 bit)"]=new JPK; 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){ for(std::map<String,ImageFormatBase*>::iterator it=int_formats.begin();it!=int_formats.end();++it){
ost::io::SaveImage(testimage,fname,*(it->second)); ost::io::SaveImage(testimage,fname,*(it->second));
ost::img::ImageHandle loadedimage=ost::io::LoadImage(fname,*(it->second)); ost::img::ImageHandle loadedimage=ost::io::LoadImage(fname,*(it->second));
...@@ -97,7 +100,10 @@ BOOST_AUTO_TEST_CASE(test_io_img) ...@@ -97,7 +100,10 @@ BOOST_AUTO_TEST_CASE(test_io_img)
} }
} }
if(failed){ 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; delete it->second;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment