#ifdef GTEST_HAS_TYPED_TEST
//! Define the types that end up being available as TypeParam in the test cases for both kinds of ArrayRefWithPadding
-typedef ::testing::Types<
- ArrayRefWithPadding<int32_t>,
- ArrayRefWithPadding<float>,
- ArrayRefWithPadding<double>
- > ArrayRefTypes;
+typedef ::testing::Types<ArrayRefWithPadding<int32_t>, ArrayRefWithPadding<float>, ArrayRefWithPadding<double>> ArrayRefTypes;
//! Helper constant used in the text fixture.
constexpr index aSize = 3;
*
* The main objective is to verify that all the different kinds of
* construction lead to the expected result. */
-template <typename TypeParam>
+template<typename TypeParam>
class ArrayRefWithPaddingTest : public ::testing::Test
{
- public:
- typedef TypeParam ArrayRefType;
- typedef typename ArrayRefType::value_type ValueType;
- typedef PaddedVector<ValueType> PaddedVectorType;
-
- ValueType a[aSize] = { ValueType(1.2), ValueType(2.4), ValueType(3.1) };
- PaddedVectorType v;
-
- //! Constructor, which prepares a padded vector to take array ref of.
- ArrayRefWithPaddingTest() : v(aSize)
+public:
+ typedef TypeParam ArrayRefType;
+ typedef typename ArrayRefType::value_type ValueType;
+ typedef PaddedVector<ValueType> PaddedVectorType;
+
+ ValueType a[aSize] = { ValueType(1.2), ValueType(2.4), ValueType(3.1) };
+ PaddedVectorType v;
+
+ //! Constructor, which prepares a padded vector to take array ref of.
+ ArrayRefWithPaddingTest() : v(aSize) { std::copy(a, a + aSize, v.begin()); }
+
+ /*! \brief Run the same tests all the time
+ *
+ * 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(ArrayRefType& arrayRefWithPadding)
+ {
+ ASSERT_LE(aSize, arrayRefWithPadding.size());
+ ASSERT_FALSE(arrayRefWithPadding.empty());
+ auto unpaddedArrayRef = arrayRefWithPadding.unpaddedArrayRef();
+ auto paddedArrayRef = arrayRefWithPadding.paddedArrayRef();
+ EXPECT_LE(unpaddedArrayRef.size(), paddedArrayRef.size());
+ for (index i = 0; i != aSize; ++i)
{
- std::copy(a, a + aSize, v.begin());
+ EXPECT_EQ(paddedArrayRef[i], unpaddedArrayRef[i]);
+ EXPECT_EQ(a[i], unpaddedArrayRef[i]);
}
- /*! \brief Run the same tests all the time
- *
- * 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(ArrayRefType &arrayRefWithPadding)
+ using ConstArrayRefWithPaddingType = ArrayRefWithPadding<const typename ArrayRefType::value_type>;
{
- ASSERT_LE(aSize, arrayRefWithPadding.size());
- ASSERT_FALSE(arrayRefWithPadding.empty());
- auto unpaddedArrayRef = arrayRefWithPadding.unpaddedArrayRef();
- auto paddedArrayRef = arrayRefWithPadding.paddedArrayRef();
- EXPECT_LE(unpaddedArrayRef.size(), paddedArrayRef.size());
+ // Check that we can make a padded view that refers to const elements
+ ConstArrayRefWithPaddingType constArrayRefWithPadding =
+ arrayRefWithPadding.constArrayRefWithPadding();
for (index i = 0; i != aSize; ++i)
{
- EXPECT_EQ(paddedArrayRef[i], unpaddedArrayRef[i]);
- EXPECT_EQ(a[i], unpaddedArrayRef[i]);
- }
-
- using ConstArrayRefWithPaddingType = ArrayRefWithPadding<const typename ArrayRefType::value_type>;
- {
- // Check that we can make a padded view that refers to const elements
- ConstArrayRefWithPaddingType constArrayRefWithPadding = arrayRefWithPadding.constArrayRefWithPadding();
- for (index i = 0; i != aSize; ++i)
- {
- EXPECT_EQ(a[i], constArrayRefWithPadding.paddedArrayRef()[i]);
- }
+ EXPECT_EQ(a[i], constArrayRefWithPadding.paddedArrayRef()[i]);
}
+ }
+ {
+ // Check that we can implicitly make a padded view that refers to const elements
+ ConstArrayRefWithPaddingType constArrayRefWithPadding = arrayRefWithPadding;
+ for (index i = 0; i != aSize; ++i)
{
- // Check that we can implicitly make a padded view that refers to const elements
- ConstArrayRefWithPaddingType constArrayRefWithPadding = arrayRefWithPadding;
- for (index i = 0; i != aSize; ++i)
- {
- EXPECT_EQ(a[i], constArrayRefWithPadding.paddedArrayRef()[i]);
- }
+ EXPECT_EQ(a[i], constArrayRefWithPadding.paddedArrayRef()[i]);
}
+ }
+ {
+ // Check that a swap works, by making an empty padded
+ // vector, and a view of it, and observing what
+ // happens when we swap with the one constructed for
+ // the test.
+ PaddedVectorType w;
+ ArrayRefType view = w.arrayRefWithPadding();
+ EXPECT_TRUE(view.empty());
+
+ view.swap(arrayRefWithPadding);
+ EXPECT_TRUE(arrayRefWithPadding.empty());
+ EXPECT_LE(aSize, view.size());
+ for (index i = 0; i != v.size(); ++i)
{
- // Check that a swap works, by making an empty padded
- // vector, and a view of it, and observing what
- // happens when we swap with the one constructed for
- // the test.
- PaddedVectorType w;
- ArrayRefType view = w.arrayRefWithPadding();
- EXPECT_TRUE(view.empty());
-
- view.swap(arrayRefWithPadding);
- EXPECT_TRUE(arrayRefWithPadding.empty());
- EXPECT_LE(aSize, view.size());
- for (index i = 0; i != v.size(); ++i)
- {
- EXPECT_EQ(v[i], view.paddedArrayRef()[i]);
- }
- // Restore arrayRefWithPadding for future test code
- view.swap(arrayRefWithPadding);
+ EXPECT_EQ(v[i], view.paddedArrayRef()[i]);
}
+ // Restore arrayRefWithPadding for future test code
+ view.swap(arrayRefWithPadding);
}
+ }
};
TYPED_TEST_CASE(ArrayRefWithPaddingTest, ArrayRefTypes);
TYPED_TEST(ArrayRefWithPaddingTest, ConstructFromPointersWorks)
{
- typename TestFixture::ArrayRefType arrayRef(this->v.data(),
- this->v.data() + this->v.size(),
+ typename TestFixture::ArrayRefType arrayRef(this->v.data(), this->v.data() + this->v.size(),
this->v.data() + this->v.paddedSize());
this->runTests(arrayRef);
}
using makeConstIf_t = std::conditional_t<c, const T, T>;
//! Helper struct for the case actually used in mdrun signalling
-template <typename T>
+template<typename T>
struct Helper
{
- public:
- T a[3];
- int size;
+public:
+ T a[3];
+ int size;
};
-#else // GTEST_HAS_TYPED_TEST
+#else // GTEST_HAS_TYPED_TEST
/* A dummy test that at least signals that something is missing if one runs the
* unit test executable itself.
*/
TEST(DISABLED_ArrayRefWithPaddingTest, GenericTests)
{
- ADD_FAILURE()
- << "Tests for generic ArrayRefWithPadding functionality require support for "
- << "Google Test typed tests, which was not available when the tests "
- << "were compiled.";
+ ADD_FAILURE() << "Tests for generic ArrayRefWithPadding functionality require support for "
+ << "Google Test typed tests, which was not available when the tests "
+ << "were compiled.";
}
#endif // GTEST_HAS_TYPED_TEST
-} // namespace
+} // namespace
-} // namespace gmx
+} // namespace gmx