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
* 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());
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>
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
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