From: Roland Schulz Date: Fri, 10 Aug 2018 22:28:12 +0000 (-0700) Subject: Remove macros in utility/tests/arrayref X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=c5ada7206211a5be56bc2b9b9dfffef095f96c00;p=alexxy%2Fgromacs.git Remove macros in utility/tests/arrayref Gave warnings in GCC 8. And were ugly anyhow. Change-Id: I63ed9c5f46baa5523349cdae4d46ed2253119ca2 --- diff --git a/src/gromacs/utility/tests/arrayref.cpp b/src/gromacs/utility/tests/arrayref.cpp index 47dddfb5a7..679b4d1353 100644 --- a/src/gromacs/utility/tests/arrayref.cpp +++ b/src/gromacs/utility/tests/arrayref.cpp @@ -99,6 +99,8 @@ typedef ::testing::Types< ArrayRef > ArrayRefTypes; +constexpr index aSize = 3; + /*! \brief Permit all the tests to run on all kinds of ArrayRefs * * The main objective is to verify that all the different kinds of @@ -116,9 +118,7 @@ class ArrayRefTest : public ::testing::Test * Note that test cases must call this->runTests(), because * that's how the derived-class templates that implement * type-parameterized tests actually work. */ - void runTests(ValueType *a, - size_t aSize, - ValueType *aData, + void runTests(ValueType *aData, ArrayRefType &arrayRef) { ASSERT_EQ(aSize, arrayRef.size()); @@ -126,78 +126,53 @@ class ArrayRefTest : public ::testing::Test EXPECT_EQ(aData, arrayRef.data()); EXPECT_EQ(a[0], arrayRef.front()); EXPECT_EQ(a[aSize-1], arrayRef.back()); - for (size_t i = 0; i != aSize; ++i) + for (index i = 0; i != aSize; ++i) { EXPECT_EQ(a[i], arrayRef[i]); } } + + ValueType a[aSize] = { ValueType(1.2), ValueType(2.4), ValueType(3.1) }; + NonConstValueType ma[aSize] = { ValueType(1.2), ValueType(2.4), ValueType(3.1) }; }; TYPED_TEST_CASE(ArrayRefTest, ArrayRefTypes); -/* Welcome back to the past. While you can declare a static array[] of - templated type in a class, in C++98, you have to define it outside - the class, and when you do, the compiler knows the declaration is - incomplete and can't match the types to actual functions. So, - declaring locals is the only choice available, so we need macros to - avoid duplication. Lovely. */ -#define DEFINE_ARRAY(a, aSize) \ - typename TestFixture::ValueType (a)[] = { \ - static_cast(1.2), \ - static_cast(2.4), \ - static_cast(3.1) \ - }; \ - size_t aSize = sizeof((a)) / sizeof(typename TestFixture::ValueType); - -#define DEFINE_NON_CONST_ARRAY(a, aSize) \ - typename TestFixture::NonConstValueType (a)[] = { \ - static_cast(1.2), \ - static_cast(2.4), \ - static_cast(3.1) \ - }; \ - size_t aSize = sizeof((a)) / sizeof(typename TestFixture::ValueType); - TYPED_TEST(ArrayRefTest, MakeWithAssignmentWorks) { - DEFINE_ARRAY(a, aSize); - typename TestFixture::ArrayRefType arrayRef = a; - this->runTests(a, aSize, a, arrayRef); + typename TestFixture::ArrayRefType arrayRef = this->a; + this->runTests(this->a, arrayRef); } TYPED_TEST(ArrayRefTest, MakeWithNonConstAssignmentWorks) { - DEFINE_NON_CONST_ARRAY(a, aSize); - typename TestFixture::ArrayRefType arrayRef = a; - this->runTests(a, aSize, a, arrayRef); + typename TestFixture::ArrayRefType arrayRef = this->ma; + this->runTests(this->ma, arrayRef); } TYPED_TEST(ArrayRefTest, ConstructWithTemplateConstructorWorks) { - DEFINE_ARRAY(a, aSize); - typename TestFixture::ArrayRefType arrayRef(a); - this->runTests(a, aSize, a, arrayRef); + typename TestFixture::ArrayRefType arrayRef(this->a); + this->runTests(this->a, arrayRef); } TYPED_TEST(ArrayRefTest, ConstructWithNonConstTemplateConstructorWorks) { - DEFINE_NON_CONST_ARRAY(a, aSize); - typename TestFixture::ArrayRefType arrayRef(a); - this->runTests(a, aSize, a, arrayRef); + typename TestFixture::ArrayRefType arrayRef(this->ma); + this->runTests(this->ma, arrayRef); } TYPED_TEST(ArrayRefTest, ConstructFromPointersWorks) { - DEFINE_ARRAY(a, aSize); - typename TestFixture::ArrayRefType arrayRef(a, a + aSize); - this->runTests(a, aSize, a, arrayRef); + typename TestFixture::ArrayRefType arrayRef(this->a, this->a + aSize); + this->runTests(this->a, arrayRef); } TYPED_TEST(ArrayRefTest, ConstructFromNonConstPointersWorks) { - DEFINE_NON_CONST_ARRAY(a, aSize); - typename TestFixture::ArrayRefType arrayRef(a, a + aSize); - this->runTests(a, aSize, a, arrayRef); + typename TestFixture::ArrayRefType arrayRef(this->ma, this->ma + aSize); + this->runTests(this->ma, arrayRef); } template @@ -205,19 +180,17 @@ using makeConstIf_t = typename std::conditional::type; TYPED_TEST(ArrayRefTest, ConstructFromVectorWorks) { - DEFINE_ARRAY(a, aSize); makeConstIf_t::value, - std::vector > v(a, a + aSize); + std::vector > v(this->a, this->a + aSize); typename TestFixture::ArrayRefType arrayRef(v); - this->runTests(a, aSize, v.data(), arrayRef); + this->runTests(v.data(), arrayRef); } TYPED_TEST(ArrayRefTest, ConstructFromNonConstVectorWorks) { - DEFINE_ARRAY(a, aSize); - std::vector v(a, a + aSize); + std::vector v(this->a, this->a + aSize); typename TestFixture::ArrayRefType arrayRef(v); - this->runTests(a, aSize, v.data(), arrayRef); + this->runTests(v.data(), arrayRef); } //! Helper struct for the case actually used in mdrun signalling @@ -240,15 +213,14 @@ struct Helper TYPED_TEST(ArrayRefTest, ConstructFromStructFieldWithTemplateConstructorWorks) { - DEFINE_ARRAY(a, aSize); Helper h; h.size = aSize; for (int i = 0; i != h.size; ++i) { - h.a[i] = a[i]; + h.a[i] = this->a[i]; } typename TestFixture::ArrayRefType arrayRef(h.a); - this->runTests(h.a, h.size, h.a, arrayRef); + this->runTests(h.a, arrayRef); } #else // GTEST_HAS_TYPED_TEST