]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add another test
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 8 Jan 2016 15:51:37 +0000 (16:51 +0100)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 8 Jan 2016 15:51:37 +0000 (16:51 +0100)
tests/base/aligned_vector_04.cc [new file with mode: 0644]
tests/base/aligned_vector_04.output [new file with mode: 0644]
tests/base/table_06.cc

diff --git a/tests/base/aligned_vector_04.cc b/tests/base/aligned_vector_04.cc
new file mode 100644 (file)
index 0000000..8fb76b2
--- /dev/null
@@ -0,0 +1,80 @@
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 1998 - 2015 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 at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// check that AlignedVector::fill() does correctly call the destructor and
+// constructor on a complicated class
+
+// NOTE: The number of calls to the constructor/destructor depends on the
+// actual implementation of AlignedVector. When that is changed, this test
+// will typically fail even if the implementation in AlignedVector is
+// otherwise correct. When adjusting the output, make sure to check this test
+// with valgrind.
+
+#include "../tests.h"
+
+#include <deal.II/base/table.h>
+
+// make function virtual to ensure that the function table is correctly copied
+class FunctionBase
+{
+public:
+  ~FunctionBase() {}
+
+  virtual void do_test() = 0;
+};
+
+class Function
+{
+public:
+  Function ()
+    :
+    size_ (2)
+  {
+    deallog << "Construct object" << std::endl;
+  }
+
+  ~Function()
+  {
+    deallog << "Destruct with size " << vec.size() << std::endl;
+  }
+
+  virtual void do_test()
+  {
+    vec.resize(size_++);
+    deallog << "Resize vector to " << vec.size() << std::endl;
+  }
+
+private:
+  unsigned int size_;
+  std::vector<unsigned int> vec;
+};
+
+int main()
+{
+  initlog();
+  AlignedVector<Function> vec;
+  vec.resize(2);
+  vec[1].do_test();
+  vec[0].do_test();
+  vec[0].do_test();
+  vec.fill(Function());
+  vec.resize(1);
+  vec[0].do_test();
+  vec.resize(3);
+  vec[0].do_test();
+  vec.fill(Function());
+  vec[0].do_test();
+}
diff --git a/tests/base/aligned_vector_04.output b/tests/base/aligned_vector_04.output
new file mode 100644 (file)
index 0000000..be5adf2
--- /dev/null
@@ -0,0 +1,22 @@
+
+DEAL::Construct object
+DEAL::Destruct with size 0
+DEAL::Resize vector to 2
+DEAL::Resize vector to 2
+DEAL::Resize vector to 3
+DEAL::Construct object
+DEAL::Destruct with size 0
+DEAL::Construct object
+DEAL::Destruct with size 0
+DEAL::Destruct with size 0
+DEAL::Resize vector to 2
+DEAL::Construct object
+DEAL::Destruct with size 2
+DEAL::Destruct with size 0
+DEAL::Resize vector to 3
+DEAL::Construct object
+DEAL::Destruct with size 0
+DEAL::Resize vector to 2
+DEAL::Destruct with size 0
+DEAL::Destruct with size 0
+DEAL::Destruct with size 2
index ca1ba8c87e85c7782c93701fef1e68a3d38598f5..0903a34bb825e57f1eee99a8413b2434e1201a7f 100644 (file)
@@ -20,8 +20,8 @@
 
 // NOTE: The number of calls to the constructor/destructor depends on the
 // actual implementation of TableBase. When that is changed, this test will
-// typically fail. When adjusting the output, make sure to check this test
-// with valgrind
+// typically fail even if the implementation of TableBase is correct. When
+// adjusting the output, make sure to check this test with valgrind.
 
 #include "../tests.h"
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.