From 8d24e6bb67a43733bcd8ed50cfbebcbac993c199 Mon Sep 17 00:00:00 2001 From: Hans-Christian Ebke Date: Thu, 19 Nov 2015 16:44:14 +0100 Subject: [PATCH] C++11: Moved C++11 specific unit test into #ifdef. --- src/Unittests/unittests_vector_type.cc | 88 +++++++++++++------------- 1 file changed, 45 insertions(+), 43 deletions(-) diff --git a/src/Unittests/unittests_vector_type.cc b/src/Unittests/unittests_vector_type.cc index 941c0f46..eca9d6ec 100644 --- a/src/Unittests/unittests_vector_type.cc +++ b/src/Unittests/unittests_vector_type.cc @@ -127,7 +127,51 @@ TEST_F(OpenMeshVectorTest, cpp11_htmlColorLiteral) { ::value, "Bad type deduced from _htmlColor literal."); EXPECT_EQ(light_blue, light_blue_2); } -#endif + + +namespace { +class C { + public: + C() {} + C(const C &rhs) { ADD_FAILURE() << "Copy constructor used."; } + C(C &&rhs) { ++copy_con; } + C &operator= (const C &rhs) { + ADD_FAILURE() << "Copy assignemnt used."; + return *this; + } + C &operator= (C &&rhs) { ++copy_ass; return *this; } + + static int copy_con; + static int copy_ass; +}; + +int C::copy_con = 0; +int C::copy_ass = 0; +} + +/** + * Checks two things: + * 1) Whether VectorT works with a non-arithmetic type. + * 2) Whether move construction and assignment works. + */ +TEST_F(OpenMeshVectorTest, move_constructor_assignment) { + + C::copy_con = 0; + C::copy_ass = 0; + + // Test move assigning. + OpenMesh::VectorT x, y; + x = std::move(y); + EXPECT_EQ(3, C::copy_ass); + EXPECT_EQ(0, C::copy_con); + + // Test move constructing. + OpenMesh::VectorT z(std::move(x)); + EXPECT_EQ(3, C::copy_ass); + EXPECT_EQ(3, C::copy_con); +} + +#endif // C++11 TEST_F(OpenMeshVectorTest, BasicLinearAlgebra) { @@ -178,46 +222,4 @@ TEST_F(OpenMeshVectorTest, size_dim) { EXPECT_EQ(2, v2i.dim()); } -namespace { -class C { - public: - C() {} - C(const C &rhs) { ADD_FAILURE() << "Copy constructor used."; } - C(C &&rhs) { ++copy_con; } - C &operator= (const C &rhs) { - ADD_FAILURE() << "Copy assignemnt used."; - return *this; - } - C &operator= (C &&rhs) { ++copy_ass; return *this; } - - static int copy_con; - static int copy_ass; -}; - -int C::copy_con = 0; -int C::copy_ass = 0; -} - -/** - * Checks two things: - * 1) Whether VectorT works with a non-arithmetic type. - * 2) Whether move construction and assignment works. - */ -TEST_F(OpenMeshVectorTest, move_constructor_assignment) { - - C::copy_con = 0; - C::copy_ass = 0; - - // Test move assigning. - OpenMesh::VectorT x, y; - x = std::move(y); - EXPECT_EQ(3, C::copy_ass); - EXPECT_EQ(0, C::copy_con); - - // Test move constructing. - OpenMesh::VectorT z(std::move(x)); - EXPECT_EQ(3, C::copy_ass); - EXPECT_EQ(3, C::copy_con); -} - }