4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief pimpl_ptr.test unit tests */
31 //#include "pimpl_ptr.test.hh"
32 //#include "pimpl_ptr.test.ih"
35 #include "pimpl_ptr.hh"
37 #include <senf/Utils/auto_unit_test.hh>
38 #include <boost/test/test_tools.hpp>
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
48 senf::pimpl_ptr<Impl> impl_;
50 explicit PimplTest(int v);
53 unsigned implConstruct (0);
54 unsigned implClone (0);
55 unsigned implDestroy (0);
57 struct PimplTest::Impl
59 Impl(int v) : value (v) { ++ implConstruct; }
60 Impl(Impl const & other) : value (other.value) { ++ implClone; }
61 ~Impl() { ++ implDestroy; }
66 prefix_ PimplTest::PimplTest(int v)
72 BOOST_AUTO_UNIT_TEST(pimpl_ptr)
79 BOOST_CHECK_EQUAL( implConstruct, 2u );
80 BOOST_CHECK_EQUAL( implClone, 1u );
81 BOOST_CHECK_EQUAL( implDestroy, 0u );
83 BOOST_CHECK( ob1.impl_.get() != ob2.impl_.get() );
84 BOOST_CHECK( ob2.impl_.get() != ob3.impl_.get() );
85 BOOST_CHECK( ob3.impl_.get() != ob1.impl_.get() );
87 BOOST_CHECK_EQUAL( ob1.impl_->value, 1 );
88 BOOST_CHECK_EQUAL( ob2.impl_->value, 1 );
89 BOOST_CHECK_EQUAL( ob3.impl_->value, 3 );
93 BOOST_CHECK_EQUAL( implConstruct, 2u );
94 BOOST_CHECK_EQUAL( implClone, 2u );
95 BOOST_CHECK_EQUAL( implDestroy, 1u );
97 BOOST_CHECK( ob3.impl_.get() != ob1.impl_.get() );
99 BOOST_CHECK_EQUAL( ob1.impl_->value, 1 );
100 BOOST_CHECK_EQUAL( ob3.impl_->value, 1 );
102 ob3.impl_->value = 3;
104 BOOST_CHECK_EQUAL( ob1.impl_->value, 1 );
105 BOOST_CHECK_EQUAL( ob3.impl_->value, 3 );
107 struct PimplTest::Impl * p1 (ob1.impl_.get());
108 struct PimplTest::Impl * p3 (ob3.impl_.get());
110 std::swap(ob3.impl_, ob1.impl_);
112 BOOST_CHECK_EQUAL( implConstruct, 2u );
113 BOOST_CHECK_EQUAL( implClone, 2u );
114 BOOST_CHECK_EQUAL( implDestroy, 1u );
116 BOOST_CHECK_EQUAL( ob1.impl_->value, 3 );
117 BOOST_CHECK_EQUAL( ob3.impl_->value, 1 );
119 BOOST_CHECK_EQUAL( ob1.impl_.get(), p3 );
120 BOOST_CHECK_EQUAL( ob3.impl_.get(), p1 );
123 BOOST_CHECK_EQUAL( implConstruct, 2u );
124 BOOST_CHECK_EQUAL( implClone, 2u );
125 BOOST_CHECK_EQUAL( implDestroy, 4u );
132 // We need this template arg to delay the constructor instantiation
133 // until within COMPILE_FAIL. Otherwise the CompileCheck builder has no
134 // way to associate the error message with the test ...
135 template <class Delay=void>
136 struct PimplTestIncomplete
139 senf::pimpl_ptr<Impl> impl_;
140 PimplTestIncomplete() : impl_ (0) {}
145 COMPILE_FAIL(pimpl_ptr_incomplete)
147 PimplTestIncomplete<> ob;
152 //-/////////////////////////////////////////////////////////////////////////////////////////////////
159 // comment-column: 40
160 // c-file-style: "senf"
161 // indent-tabs-mode: nil
162 // ispell-local-dictionary: "american"
163 // compile-command: "scons -u test"