From: bangerth Date: Mon, 13 Jun 2011 18:13:44 +0000 (+0000) Subject: New test. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe8be872c34c7d76ec933fd02f25229d62473212;p=dealii-svn.git New test. git-svn-id: https://svn.dealii.org/trunk@23813 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/tests/serialization/pointer_03.cc b/tests/serialization/pointer_03.cc new file mode 100644 index 0000000000..8f619721dc --- /dev/null +++ b/tests/serialization/pointer_03.cc @@ -0,0 +1,111 @@ +//---------------------------- pointer_03.cc --------------------------- +// $Id$ +// Version: $Name$ +// +// Copyright (C) 2010, 2011 by the deal.II authors +// +// This file is subject to QPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- pointer_03.cc --------------------------- + +// test what happens when serializing two objects that have pointers to the +// same common object. the two objects here are the members of a std::pair + +#include "serialization.h" + +#include +#include + +int object_number = 1; + +class C +{ + public: + C () + { + object_number = ::object_number++; + deallog << "Default constructor. Object number " + << object_number + << std::endl; + } + + C (const C&) + { + object_number = ::object_number++; + deallog << "copy constructor. Object number " + << object_number + << std::endl; + } + + ~C () + { + deallog << "destructor. Object number " + << object_number + << std::endl; + } + + template + void serialize (Archive &ar, const unsigned int version) + { + deallog << "Serializing object number " + << object_number + << " via " << typeid(Archive).name() + << std::endl; + } + + bool operator == (const C &) const + { + return true; + } + + private: + unsigned int object_number; +}; + + +template +bool compare (const std::pair &t1, + const std::pair &t2) +{ + return (*t1.first == *t2.first) && (*t1.second == *t2.second); +} + + +void test () +{ + { + C *p = new C(); + std::pair pair_1 = {p, p}; + std::pair pair_2; + + verify (pair_1, pair_2); + + // boost::serialize should have + // recognized that the two pointers in + // pair_1 point to the same object and + // consequently re-create only one object + // that the two components of the + // re-created pair point to + Assert (pair_2.first == pair_2.second, ExcInternalError()); + Assert (object_number == 3, ExcInternalError()); + + delete p; + } +} + + +int main () +{ + std::ofstream logfile("pointer_03/output"); + deallog << std::setprecision(3); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + test (); + + deallog << "OK" << std::endl; +} diff --git a/tests/serialization/pointer_03/cmp/generic b/tests/serialization/pointer_03/cmp/generic new file mode 100644 index 0000000000..7ab18c2c52 --- /dev/null +++ b/tests/serialization/pointer_03/cmp/generic @@ -0,0 +1,10 @@ + +DEAL::Default constructor. Object number 1 +DEAL::Serializing object number 1 via N5boost7archive13text_oarchiveE +DEAL::22 serialization::archive 9 0 0 1 1 0 +0 1 0 + +DEAL::Default constructor. Object number 2 +DEAL::Serializing object number 2 via N5boost7archive13text_iarchiveE +DEAL::destructor. Object number 1 +DEAL::OK