From 00d93b42b020ed50885e82f5b4f630d0e1ebd004 Mon Sep 17 00:00:00 2001 From: bangerth Date: Mon, 13 Jun 2011 18:06:08 +0000 Subject: [PATCH] Rename one test. Create another. git-svn-id: https://svn.dealii.org/trunk@23812 0785d39b-7218-0410-832d-ea1e28bc413d --- .../{pointer => pointer_01}/cmp/generic | 5 ++- .../{pointer.cc => pointer_02.cc} | 40 +++++++++++++++---- tests/serialization/pointer_02/cmp/generic | 12 ++++++ 3 files changed, 49 insertions(+), 8 deletions(-) rename tests/serialization/{pointer => pointer_01}/cmp/generic (55%) rename tests/serialization/{pointer.cc => pointer_02.cc} (55%) create mode 100644 tests/serialization/pointer_02/cmp/generic diff --git a/tests/serialization/pointer/cmp/generic b/tests/serialization/pointer_01/cmp/generic similarity index 55% rename from tests/serialization/pointer/cmp/generic rename to tests/serialization/pointer_01/cmp/generic index 6170116d66..bd245666b2 100644 --- a/tests/serialization/pointer/cmp/generic +++ b/tests/serialization/pointer_01/cmp/generic @@ -1,6 +1,9 @@ -JobId unknown Mon Jun 13 12:54:54 2011 + DEAL::Default constructor. Object number 1 DEAL::Serializing object number 1 via N5boost7archive13text_oarchiveE DEAL::22 serialization::archive 9 0 1 0 0 +DEAL::Default constructor. Object number 2 +DEAL::Serializing object number 2 via N5boost7archive13text_iarchiveE +DEAL::OK diff --git a/tests/serialization/pointer.cc b/tests/serialization/pointer_02.cc similarity index 55% rename from tests/serialization/pointer.cc rename to tests/serialization/pointer_02.cc index 9a19703341..830a9d15e7 100644 --- a/tests/serialization/pointer.cc +++ b/tests/serialization/pointer_02.cc @@ -1,4 +1,4 @@ -//---------------------------- pointer.cc --------------------------- +//---------------------------- pointer_02.cc --------------------------- // $Id$ // Version: $Name$ // @@ -9,16 +9,21 @@ // to the file deal.II/doc/license.html for the text and // further information on this license. // -//---------------------------- pointer.cc --------------------------- +//---------------------------- pointer_02.cc --------------------------- // test what happens when serializing a pointer. is a new object created when -// loading into another pointer that is NULL? this is in fact what happens +// loading into another pointer that is non-NULL and the old pointer +// destroyed? Or is the old object pointed to being co-opted? the former is in +// fact what happens, and to make things just ever so slightly more awkward, +// the previous object pointed to isn't freed but is left dangling, creating +// the potential for a memory leak #include "serialization.h" #include int object_number = 1; +int objects_destroyed = 0; class C { @@ -39,6 +44,14 @@ class C << std::endl; } + ~C () + { + deallog << "destructor. Object number " + << object_number + << std::endl; + ++objects_destroyed; + } + template void serialize (Archive &ar, const unsigned int version) { @@ -60,16 +73,29 @@ class C void test () { - C *p1 = new C(); - C *p2; + { + C *p1 = new C(); + C *p2 = new C(); - verify (p1, p2); + verify (p1, p2); + + Assert (p1 != p2, ExcInternalError()); + + delete p1; + delete p2; + } + + // as mentioned above, p2 is overwritten by + // a pointer to a new object, leaving the + // original object pointed to as a memory + // leak. assert that this behavior persists + Assert (objects_destroyed == 2, ExcInternalError()); } int main () { - std::ofstream logfile("pointer/output"); + std::ofstream logfile("pointer_02/output"); deallog << std::setprecision(3); deallog.attach(logfile); deallog.depth_console(0); diff --git a/tests/serialization/pointer_02/cmp/generic b/tests/serialization/pointer_02/cmp/generic new file mode 100644 index 0000000000..0077e32973 --- /dev/null +++ b/tests/serialization/pointer_02/cmp/generic @@ -0,0 +1,12 @@ + +DEAL::Default constructor. Object number 1 +DEAL::Default constructor. Object number 2 +DEAL::Serializing object number 1 via N5boost7archive13text_oarchiveE +DEAL::22 serialization::archive 9 0 1 0 +0 + +DEAL::Default constructor. Object number 3 +DEAL::Serializing object number 3 via N5boost7archive13text_iarchiveE +DEAL::destructor. Object number 1 +DEAL::destructor. Object number 3 +DEAL::OK -- 2.39.5