Remove macros in utility/tests/arrayref
authorRoland Schulz <roland.schulz@intel.com>
Fri, 10 Aug 2018 22:28:12 +0000 (15:28 -0700)
committerBerk Hess <hess@kth.se>
Mon, 20 Aug 2018 08:21:50 +0000 (10:21 +0200)
Gave warnings in GCC 8. And were ugly anyhow.

Change-Id: I63ed9c5f46baa5523349cdae4d46ed2253119ca2

src/gromacs/utility/tests/arrayref.cpp

index 47dddfb5a7d8abc778a63676c673a12651a835a7..679b4d135312263d3c195ef1c2f6683f5d074d9f 100644 (file)
@@ -99,6 +99,8 @@ typedef ::testing::Types<
         ArrayRef<const double>
         > 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<typename TestFixture::ValueType>(1.2),      \
-        static_cast<typename TestFixture::ValueType>(2.4),      \
-        static_cast<typename TestFixture::ValueType>(3.1)       \
-    };                                                          \
-    size_t aSize = sizeof((a)) / sizeof(typename TestFixture::ValueType);
-
-#define DEFINE_NON_CONST_ARRAY(a, aSize)                        \
-    typename TestFixture::NonConstValueType (a)[] = {           \
-        static_cast<typename TestFixture::ValueType>(1.2),      \
-        static_cast<typename TestFixture::ValueType>(2.4),      \
-        static_cast<typename TestFixture::ValueType>(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<bool c, typename T>
@@ -205,19 +180,17 @@ using makeConstIf_t = typename std::conditional<c, const T, T>::type;
 
 TYPED_TEST(ArrayRefTest, ConstructFromVectorWorks)
 {
-    DEFINE_ARRAY(a, aSize);
     makeConstIf_t<std::is_const<typename TestFixture::ValueType>::value,
-                  std::vector<typename TestFixture::NonConstValueType> > v(a, a + aSize);
+                  std::vector<typename TestFixture::NonConstValueType> > 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<typename TestFixture::NonConstValueType> v(a, a + aSize);
+    std::vector<typename TestFixture::NonConstValueType> 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<typename TestFixture::NonConstValueType> 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