From 6ef8b98bbf79fb950ade5858876653be8b05605c Mon Sep 17 00:00:00 2001 From: Zack Moratto Date: Wed, 2 May 2012 21:33:44 -0700 Subject: [PATCH] test: Fix compile error for clang in unit tests value_diff functions must be defined before they are used in the macros. --- src/test/Helpers.h | 90 ++++++++++--------- src/vw/Core/tests/TestExceptions.cxx | 2 - src/vw/Core/tests/TestSettings.cxx | 1 - src/vw/Core/tests/TestTypeDeduction.cxx | 2 - src/vw/Image/tests/TestBlockRasterize.cxx | 2 - src/vw/Image/tests/TestImageView.cxx | 2 - src/vw/Image/tests/TestImageViewMemory.cxx | 2 - src/vw/Image/tests/TestMaskViews.cxx | 10 +-- src/vw/Image/tests/TestPixelMath.cxx | 24 ++--- src/vw/Image/tests/TestTransform.cxx | 2 - src/vw/Math/tests/TestEuler.cxx | 1 - src/vw/Math/tests/TestGeometry.cxx | 2 - src/vw/Math/tests/TestLevenbergMarquardt.cxx | 2 - src/vw/Math/tests/TestLinearAlgebra.cxx | 2 - .../tests/TestParticleSwarmOptimization.cxx | 2 - src/vw/Math/tests/TestVector.cxx | 1 - 16 files changed, 62 insertions(+), 85 deletions(-) diff --git a/src/test/Helpers.h b/src/test/Helpers.h index ca96296d8..8592c6305 100644 --- a/src/test/Helpers.h +++ b/src/test/Helpers.h @@ -88,6 +88,52 @@ void mismatch_queue(InputIterator1 first1, InputIterator1 last1, InputIterator2 } } +// Difference calculators +template +double value_diff(const vw::PixelMathBase& a, const vw::PixelMathBase& b) { + BOOST_STATIC_ASSERT((boost::is_same::value)); + typedef typename CompoundChannelType::type channel_type; + double acc = 0.0; + for( size_t c=0; c < PixelNumChannels::value; ++c ) { + channel_type const& a_x = compound_select_channel(a.impl(),c); + channel_type const& b_x = compound_select_channel(b.impl(),c); + double diff = double(a_x) - double(b_x); + acc += diff*diff; + } + return ::sqrt(acc); +} + +template +double value_diff(const vw::VectorBase& a, const vw::VectorBase& b) { + BOOST_STATIC_ASSERT((boost::is_same::value)); + double acc = 0.0; + typename Vec2T::const_iterator it2 = b.impl().begin(); + for (typename Vec1T::const_iterator it1 = a.impl().begin(); + it1 != a.impl().end(); it1++ ) { + double diff = double(*it1) - double(*it2); + acc += diff*diff; + it2++; + } + return ::sqrt(acc); +} + +template +double value_diff(const std::complex& a, const std::complex& b) { + return std::abs(std::complex(a) - std::complex(b)); +} + +template +struct both_are_arithmetic : boost::mpl::and_, boost::is_arithmetic > {}; + +template +typename boost::enable_if, double>::type +value_diff(const T1& a, const T2& b) { + BOOST_STATIC_ASSERT(boost::is_arithmetic::value); + BOOST_STATIC_ASSERT(boost::is_arithmetic::value); + return ::fabs(double(a) - double(b)); +} + +// Comparison classes template class CmpWorker { public: @@ -416,50 +462,6 @@ _CheckNDRange check_nd_range(const CmpT& cmp) { #define EXPECT_MATRIX_NEAR(e, a, delta) EXPECT_SEQ_NEAR(e,a,delta) #define ASSERT_MATRIX_NEAR(e, a, delta) ASSERT_SEQ_NEAR(e,a,delta) -template -double value_diff(const vw::PixelMathBase& a, const vw::PixelMathBase& b) { - BOOST_STATIC_ASSERT((boost::is_same::value)); - typedef typename CompoundChannelType::type channel_type; - double acc = 0.0; - for( size_t c=0; c < PixelNumChannels::value; ++c ) { - channel_type const& a_x = compound_select_channel(a.impl(),c); - channel_type const& b_x = compound_select_channel(b.impl(),c); - double diff = double(a_x) - double(b_x); - acc += diff*diff; - } - return ::sqrt(acc); -} - -template -double value_diff(const vw::VectorBase& a, const vw::VectorBase& b) { - BOOST_STATIC_ASSERT((boost::is_same::value)); - double acc = 0.0; - typename Vec2T::const_iterator it2 = b.impl().begin(); - for (typename Vec1T::const_iterator it1 = a.impl().begin(); - it1 != a.impl().end(); it1++ ) { - double diff = double(*it1) - double(*it2); - acc += diff*diff; - it2++; - } - return ::sqrt(acc); -} - -template -double value_diff(const std::complex& a, const std::complex& b) { - return std::abs(std::complex(a) - std::complex(b)); -} - -template -struct both_are_arithmetic : boost::mpl::and_, boost::is_arithmetic > {}; - -template -typename boost::enable_if, double>::type -value_diff(const T1& a, const T2& b) { - BOOST_STATIC_ASSERT(boost::is_arithmetic::value); - BOOST_STATIC_ASSERT(boost::is_arithmetic::value); - return ::fabs(double(a) - double(b)); -} - }} // namespace t #endif diff --git a/src/vw/Core/tests/TestExceptions.cxx b/src/vw/Core/tests/TestExceptions.cxx index b7e3dd9cf..4ec036ae8 100644 --- a/src/vw/Core/tests/TestExceptions.cxx +++ b/src/vw/Core/tests/TestExceptions.cxx @@ -5,8 +5,6 @@ // __END_LICENSE__ -#include - #include #include diff --git a/src/vw/Core/tests/TestSettings.cxx b/src/vw/Core/tests/TestSettings.cxx index 232e07e46..e71a14fd7 100644 --- a/src/vw/Core/tests/TestSettings.cxx +++ b/src/vw/Core/tests/TestSettings.cxx @@ -9,7 +9,6 @@ #include #include -#include #include #include #include diff --git a/src/vw/Core/tests/TestTypeDeduction.cxx b/src/vw/Core/tests/TestTypeDeduction.cxx index 8fecc6c93..6fd5d9384 100644 --- a/src/vw/Core/tests/TestTypeDeduction.cxx +++ b/src/vw/Core/tests/TestTypeDeduction.cxx @@ -4,8 +4,6 @@ // All Rights Reserved. // __END_LICENSE__ - -#include #include #include diff --git a/src/vw/Image/tests/TestBlockRasterize.cxx b/src/vw/Image/tests/TestBlockRasterize.cxx index 85981c2dc..37dc5771a 100644 --- a/src/vw/Image/tests/TestBlockRasterize.cxx +++ b/src/vw/Image/tests/TestBlockRasterize.cxx @@ -4,8 +4,6 @@ // All Rights Reserved. // __END_LICENSE__ - -#include #include #include diff --git a/src/vw/Image/tests/TestImageView.cxx b/src/vw/Image/tests/TestImageView.cxx index 759f7797d..53de71090 100644 --- a/src/vw/Image/tests/TestImageView.cxx +++ b/src/vw/Image/tests/TestImageView.cxx @@ -4,8 +4,6 @@ // All Rights Reserved. // __END_LICENSE__ - -#include #include #include diff --git a/src/vw/Image/tests/TestImageViewMemory.cxx b/src/vw/Image/tests/TestImageViewMemory.cxx index 237f1436c..c4c5e40a4 100644 --- a/src/vw/Image/tests/TestImageViewMemory.cxx +++ b/src/vw/Image/tests/TestImageViewMemory.cxx @@ -4,8 +4,6 @@ // All Rights Reserved. // __END_LICENSE__ - -#include #include #include diff --git a/src/vw/Image/tests/TestMaskViews.cxx b/src/vw/Image/tests/TestMaskViews.cxx index c154909ac..2910e5616 100644 --- a/src/vw/Image/tests/TestMaskViews.cxx +++ b/src/vw/Image/tests/TestMaskViews.cxx @@ -98,10 +98,9 @@ TYPED_TEST( MaskedViewTest, copy_mask ) { // Test a copy mask where the input is a different channel type ImageView< PixelRGB > in_rgbu8(2,2); - in(0,0) = PixelRGB(9); in(1,0) = PixelRGB(8); - in(0,1) = PixelRGB(1); in(1,1) = PixelRGB(4); - ImageView > > out_rgbu8 = - copy_mask( in_rgbu8, this->a ); + in_rgbu8(0,0) = PixelRGB(9); in_rgbu8(1,0) = PixelRGB(8); + in_rgbu8(0,1) = PixelRGB(1); in_rgbu8(1,1) = PixelRGB(4); + ImageView > > out_rgbu8 = copy_mask( in_rgbu8, this->a ); EXPECT_EQ( 2, out_rgbu8.cols() ); EXPECT_EQ( 2, out_rgbu8.rows() ); EXPECT_TRUE( is_valid(out_rgbu8(0,0)) ); EXPECT_TRUE( is_valid(out_rgbu8(1,0)) ); @@ -115,7 +114,7 @@ TYPED_TEST( MaskedViewTest, copy_mask ) { mask(0,1) = PixelMask(255); mask(1,1) = PixelMask(); c = copy_mask(in, mask); EXPECT_EQ( 2, c.cols() ); EXPECT_EQ( 2, c.rows() ); - EXPECT_FALSE is_valid(c(0,0)) ); + EXPECT_FALSE( is_valid(c(0,0)) ); EXPECT_TRUE( is_valid(c(1,0)) ); EXPECT_TRUE( is_valid(c(0,1)) ); EXPECT_FALSE(is_valid(c(1,1)) ); @@ -253,5 +252,4 @@ TYPED_TEST( MaskedViewTest, create_apply_mask ) { EXPECT_EQ( typename TestFixture::Px(2), e(1,0) ); EXPECT_EQ( typename TestFixture::Px(3), e(0,1) ); EXPECT_EQ( typename TestFixture::Px(4), e(1,1) ); - } diff --git a/src/vw/Image/tests/TestPixelMath.cxx b/src/vw/Image/tests/TestPixelMath.cxx index e6a515548..616db47d0 100644 --- a/src/vw/Image/tests/TestPixelMath.cxx +++ b/src/vw/Image/tests/TestPixelMath.cxx @@ -125,29 +125,29 @@ TEST( PixelMath, SelfAssignment ) { typedef PixelRGB Px; Px a(1,2,3), b(2,3,4); a += 2; - ASSERT_PIXEL_EQ( a, Px(3,4,5) ); + EXPECT_VW_EQ( a, Px(3,4,5) ); a -= 2; - ASSERT_PIXEL_EQ( a, Px(1,2,3) ); + EXPECT_VW_EQ( a, Px(1,2,3) ); a *= 2; - ASSERT_PIXEL_EQ( a, Px(2,4,6) ); + EXPECT_VW_EQ( a, Px(2,4,6) ); a /= 2; - ASSERT_PIXEL_EQ( a, Px(1,2,3) ); + EXPECT_VW_EQ( a, Px(1,2,3) ); a += b; - ASSERT_PIXEL_EQ( a, Px(3,5,7) ); + EXPECT_VW_EQ( a, Px(3,5,7) ); a -= b; - ASSERT_PIXEL_EQ( a, Px(1,2,3) ); + EXPECT_VW_EQ( a, Px(1,2,3) ); a *= b; - ASSERT_PIXEL_EQ( a, Px(2,6,12) ); + EXPECT_VW_EQ( a, Px(2,6,12) ); a /= b; - ASSERT_PIXEL_EQ( a, Px(1,2,3) ); + EXPECT_VW_EQ( a, Px(1,2,3) ); (a += 2) += 2; - ASSERT_PIXEL_EQ( a, Px(5,6,7) ); + EXPECT_VW_EQ( a, Px(5,6,7) ); (a -= 2) -= 2; - ASSERT_PIXEL_EQ( a, Px(1,2,3) ); + EXPECT_VW_EQ( a, Px(1,2,3) ); (a *= 2) *= 2; - ASSERT_PIXEL_EQ( a, Px(4,8,12) ); + EXPECT_VW_EQ( a, Px(4,8,12) ); (a /= 2) /= 2; - ASSERT_PIXEL_EQ( a, Px(1,2,3) ); + EXPECT_VW_EQ( a, Px(1,2,3) ); } TEST( PixelMath, ACOS ) { TEST_UNARY_MATH_FUNCTION(acos,0.5,1.0472); } diff --git a/src/vw/Image/tests/TestTransform.cxx b/src/vw/Image/tests/TestTransform.cxx index 54d05bd31..0d530a65c 100644 --- a/src/vw/Image/tests/TestTransform.cxx +++ b/src/vw/Image/tests/TestTransform.cxx @@ -4,8 +4,6 @@ // All Rights Reserved. // __END_LICENSE__ - -#include #include #include diff --git a/src/vw/Math/tests/TestEuler.cxx b/src/vw/Math/tests/TestEuler.cxx index 42a88f4e3..4b6c630dd 100644 --- a/src/vw/Math/tests/TestEuler.cxx +++ b/src/vw/Math/tests/TestEuler.cxx @@ -6,7 +6,6 @@ #include -#include #include #include diff --git a/src/vw/Math/tests/TestGeometry.cxx b/src/vw/Math/tests/TestGeometry.cxx index c6b0fe25c..52c4a5fe7 100644 --- a/src/vw/Math/tests/TestGeometry.cxx +++ b/src/vw/Math/tests/TestGeometry.cxx @@ -4,8 +4,6 @@ // All Rights Reserved. // __END_LICENSE__ - -#include #include #include #include diff --git a/src/vw/Math/tests/TestLevenbergMarquardt.cxx b/src/vw/Math/tests/TestLevenbergMarquardt.cxx index 27a427ea8..9d16d33a8 100644 --- a/src/vw/Math/tests/TestLevenbergMarquardt.cxx +++ b/src/vw/Math/tests/TestLevenbergMarquardt.cxx @@ -4,8 +4,6 @@ // All Rights Reserved. // __END_LICENSE__ - -#include #include #include #include diff --git a/src/vw/Math/tests/TestLinearAlgebra.cxx b/src/vw/Math/tests/TestLinearAlgebra.cxx index 09bdff603..fbbcd7b69 100644 --- a/src/vw/Math/tests/TestLinearAlgebra.cxx +++ b/src/vw/Math/tests/TestLinearAlgebra.cxx @@ -4,8 +4,6 @@ // All Rights Reserved. // __END_LICENSE__ - -#include #include #include #include diff --git a/src/vw/Math/tests/TestParticleSwarmOptimization.cxx b/src/vw/Math/tests/TestParticleSwarmOptimization.cxx index 95a9afdb3..2f38b546a 100644 --- a/src/vw/Math/tests/TestParticleSwarmOptimization.cxx +++ b/src/vw/Math/tests/TestParticleSwarmOptimization.cxx @@ -4,8 +4,6 @@ // All Rights Reserved. // __END_LICENSE__ - -#include #include #include diff --git a/src/vw/Math/tests/TestVector.cxx b/src/vw/Math/tests/TestVector.cxx index ce50fc2a6..67d10d3b4 100644 --- a/src/vw/Math/tests/TestVector.cxx +++ b/src/vw/Math/tests/TestVector.cxx @@ -6,7 +6,6 @@ // TestVector.h -#include #include #include