From 5c4ad59d5242dbf0d0c7aaa6caf08e903aafd15e Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 20 Apr 2021 09:05:41 -0600 Subject: [PATCH] Add a test for AlignedVector. --- tests/base/aligned_vector_memory_01.cc | 108 +++++++++++++++++++++ tests/base/aligned_vector_memory_01.output | 30 ++++++ 2 files changed, 138 insertions(+) create mode 100644 tests/base/aligned_vector_memory_01.cc create mode 100644 tests/base/aligned_vector_memory_01.output diff --git a/tests/base/aligned_vector_memory_01.cc b/tests/base/aligned_vector_memory_01.cc new file mode 100644 index 0000000000..c642d8c13c --- /dev/null +++ b/tests/base/aligned_vector_memory_01.cc @@ -0,0 +1,108 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2012 - 2018 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// Test AlignedVector. This class does some complex data management, +// explicitly allocating objects with placement-new expressions and +// explicitly releasing memory. Make sure this is all works as +// expected. + +#include +#include + +#include "../tests.h" + + +int object_number = 0; +int objects_destroyed = 0; + +class C +{ +public: + C() + { + object_number = ::object_number++; + deallog << "Default constructor. Object number " << object_number + << std::endl; + } + + C(const C &c) + { + object_number = ::object_number++; + deallog << "copy constructor from " << c.object_number << ". Object number " + << object_number << std::endl; + } + + C(const C &&c) + { + object_number = ::object_number++; + deallog << "move constructor from " << c.object_number << ". Object number " + << object_number << std::endl; + } + + ~C() + { + deallog << "destructor. Object number " << object_number << std::endl; + ++objects_destroyed; + } + + template + void + serialize(Archive &ar, const unsigned int) + { + ar &object_number; + } + + +private: + unsigned int object_number; +}; + + + +void +test() +{ + { + deallog << "Check 1:" << std::endl; + AlignedVector v(2); + } + + { + deallog << "Check 2:" << std::endl; + AlignedVector v(2); + v.resize(0); + } + + { + deallog << "Check 3:" << std::endl; + AlignedVector v(2); + v.resize(1); + v.resize(3); + } +} + + + +int +main(int argc, char **argv) +{ + initlog(); + + test(); + + deallog << "Objects created: " << object_number << std::endl; + deallog << "Objects destroyed: " << objects_destroyed << std::endl; +} diff --git a/tests/base/aligned_vector_memory_01.output b/tests/base/aligned_vector_memory_01.output new file mode 100644 index 0000000000..f17a9e7fa0 --- /dev/null +++ b/tests/base/aligned_vector_memory_01.output @@ -0,0 +1,30 @@ + +DEAL::Check 1: +DEAL::Default constructor. Object number 0 +DEAL::copy constructor from 0. Object number 1 +DEAL::copy constructor from 0. Object number 2 +DEAL::destructor. Object number 0 +DEAL::destructor. Object number 2 +DEAL::destructor. Object number 1 +DEAL::Check 2: +DEAL::Default constructor. Object number 3 +DEAL::copy constructor from 3. Object number 4 +DEAL::copy constructor from 3. Object number 5 +DEAL::destructor. Object number 3 +DEAL::destructor. Object number 5 +DEAL::destructor. Object number 4 +DEAL::Check 3: +DEAL::Default constructor. Object number 6 +DEAL::copy constructor from 6. Object number 7 +DEAL::copy constructor from 6. Object number 8 +DEAL::destructor. Object number 6 +DEAL::destructor. Object number 8 +DEAL::move constructor from 7. Object number 9 +DEAL::destructor. Object number 7 +DEAL::Default constructor. Object number 10 +DEAL::Default constructor. Object number 11 +DEAL::destructor. Object number 11 +DEAL::destructor. Object number 10 +DEAL::destructor. Object number 9 +DEAL::Objects created: 12 +DEAL::Objects destroyed: 12 -- 2.39.5