summaryrefslogtreecommitdiff
path: root/ACE/contrib/utility/Test/ReferenceCounting/DefaultImpl/default_impl.cpp
diff options
context:
space:
mode:
authorWilliam R. Otte <wotte@dre.vanderbilt.edu>2008-03-04 14:51:23 +0000
committerWilliam R. Otte <wotte@dre.vanderbilt.edu>2008-03-04 14:51:23 +0000
commit99aa8c60282c7b8072eb35eb9ac815702f5bf586 (patch)
treebda96bf8c3a4c2875a083d7b16720533c8ffeaf4 /ACE/contrib/utility/Test/ReferenceCounting/DefaultImpl/default_impl.cpp
parentc4078c377d74290ebe4e66da0b4975da91732376 (diff)
downloadATCD-99aa8c60282c7b8072eb35eb9ac815702f5bf586.tar.gz
undoing accidental deletion
Diffstat (limited to 'ACE/contrib/utility/Test/ReferenceCounting/DefaultImpl/default_impl.cpp')
-rw-r--r--ACE/contrib/utility/Test/ReferenceCounting/DefaultImpl/default_impl.cpp132
1 files changed, 132 insertions, 0 deletions
diff --git a/ACE/contrib/utility/Test/ReferenceCounting/DefaultImpl/default_impl.cpp b/ACE/contrib/utility/Test/ReferenceCounting/DefaultImpl/default_impl.cpp
new file mode 100644
index 00000000000..428e78cd061
--- /dev/null
+++ b/ACE/contrib/utility/Test/ReferenceCounting/DefaultImpl/default_impl.cpp
@@ -0,0 +1,132 @@
+// file : Test/ReferenceCounting/DefaultImpl/default_impl.cpp
+// author : Boris Kolpackov <boris@kolpackov.net>
+// copyright : Copyright (c) 2002-2003 Boris Kolpackov
+// license : http://kolpackov.net/license.html
+
+#include "Utility/ReferenceCounting/DefaultImpl.hpp"
+
+using namespace Utility::ReferenceCounting;
+
+struct Base : public virtual Interface
+{
+ virtual
+ ~Base () throw ()
+ {
+ }
+};
+
+
+class Impl : public virtual Base,
+ public virtual DefaultImpl <>
+{
+public:
+ Impl (bool& destroyed)
+ : dummy_ (false),
+ destroyed_ (destroyed)
+ {
+ }
+
+ Impl ()
+ : dummy_ (false),
+ destroyed_ (dummy_)
+ {
+ }
+
+ virtual
+ ~Impl () throw ()
+ {
+ destroyed_ = true;
+ }
+
+public:
+ void
+ lock ()
+ {
+ lock_i ();
+ }
+
+private:
+ bool dummy_;
+ bool& destroyed_;
+};
+
+struct E {};
+
+void postcondition (bool p)
+{
+ if (!p) throw E ();
+}
+
+int main ()
+{
+ try
+ {
+ // DefaultImpl
+ //
+ {
+ Impl* a (new Impl);
+
+ postcondition (a->refcount_value () == 1);
+
+ a->remove_ref ();
+ }
+
+ // ~DefaultImpl
+ //
+ {
+ Impl* a (new Impl);
+ a->remove_ref ();
+ }
+
+ // add_ref
+ //
+ {
+ Impl* a (new Impl);
+
+ a->add_ref ();
+
+ postcondition (a->refcount_value () == 2);
+
+ a->remove_ref ();
+ a->remove_ref ();
+ }
+
+
+ // remove_ref
+ //
+ {
+ bool destroyed (false);
+ Impl* a (new Impl (destroyed));
+
+ a->add_ref ();
+ a->remove_ref ();
+
+ postcondition (destroyed == false && a->refcount_value () == 1);
+
+ a->remove_ref ();
+
+ postcondition (destroyed == true);
+ }
+
+
+ // refcount_value
+ //
+ {
+ Impl* a (new Impl);
+
+ postcondition (a->refcount_value () == 1);
+ }
+
+ // lock_i
+ //
+ {
+ Impl* a (new Impl);
+ a->lock ();
+ }
+ }
+ catch (...)
+ {
+ return -1;
+ }
+}
+//$Id$