- install PtrTypes test
authorMichael Andres <ma@suse.de>
Fri, 17 Feb 2006 21:10:33 +0000 (21:10 +0000)
committerMichael Andres <ma@suse.de>
Fri, 17 Feb 2006 21:10:33 +0000 (21:10 +0000)
testsuite/zypp/tests/.cvsignore [new file with mode: 0644]
testsuite/zypp/tests/Makefile.am
testsuite/zypp/tests/PtrTypes.cc [new file with mode: 0644]
testsuite/zypp/zypp.test/PtrTypes.exp [new file with mode: 0644]

diff --git a/testsuite/zypp/tests/.cvsignore b/testsuite/zypp/tests/.cvsignore
new file mode 100644 (file)
index 0000000..d69b34c
--- /dev/null
@@ -0,0 +1,12 @@
+Makefile.in
+Makefile
+.libs
+.deps
+Arch
+Capabilities
+Edition
+PtrTypes
+Url1
+Url2
+Url3
+Url4
index 4c4ee0a2557e4974545dcd4e7ee3418a60102a23..65725f0e8c9cdcd520648600c822066daea7a241 100644 (file)
@@ -3,14 +3,15 @@
 
 # Do NOT list devel.* in subdirs. It's developers playgound and
 # must not prevent anything from building.
-SUBDIRS = 
+SUBDIRS =
 
 ## ##################################################
 
 noinst_PROGRAMS = Arch Url1 Url2 Url3 Url4 Url5 \
        RWPtr \
-       Edition                 \
-       Capabilities
+       Edition         \
+       Capabilities    \
+       PtrTypes
 
 ## ##################################################
 
@@ -27,6 +28,7 @@ Url5_SOURCES = Url5.cc
 RWPtr_SOURCES = RWPtr.cc
 Edition_SOURCES = Edition.cc
 Capabilities_SOURCES = Capabilities.cc
+PtrTypes_SOURCES = PtrTypes.cc
 
 ## ##################################################
 
diff --git a/testsuite/zypp/tests/PtrTypes.cc b/testsuite/zypp/tests/PtrTypes.cc
new file mode 100644 (file)
index 0000000..49bbd4a
--- /dev/null
@@ -0,0 +1,125 @@
+#include <iostream>
+
+#include "zypp/base/Logger.h"
+#include <zypp/base/PtrTypes.h>
+#include <zypp/base/ReferenceCounted.h>
+#include <zypp/base/ProvideNumericId.h>
+
+using std::endl;
+using namespace zypp;
+using namespace zypp::base;
+
+#define TRACE_TAG DBG << this->numericId() << " " << __PRETTY_FUNCTION__ << endl
+
+/** Logs Ctor, CopyCtor, Assign and Dtor. */
+template<class _Trace>
+  struct Trace : public ProvideNumericId<_Trace>
+  {
+    Trace()                            { TRACE_TAG; }
+    Trace( const Trace & )             { TRACE_TAG; }
+    ~Trace()                           { TRACE_TAG; }
+    Trace & operator=( const Trace & ) { TRACE_TAG; return *this; }
+  };
+
+/** Data class for shared_ptr */
+struct NonIntrusive : private Trace<NonIntrusive>
+{
+  Trace<NonIntrusive>::numericId;
+};
+
+/** Data class for intrusive_ptr */
+struct Intrusive : public ReferenceCounted,
+                   private Trace<Intrusive>
+{
+  Trace<Intrusive>::numericId;
+};
+
+namespace zypp
+{
+  template<>
+    inline NonIntrusive * rwcowClone<NonIntrusive>( const NonIntrusive * rhs )
+    { return new NonIntrusive( *rhs ); }
+
+  template<>
+    inline Intrusive * rwcowClone<Intrusive>( const Intrusive * rhs )
+    { return new Intrusive( *rhs ); }
+
+}
+/******************************************************************
+**
+*/
+#define T_NULL       assert( !ptr )
+#define T_NOT_NULL   assert( ptr )
+#define T_UNIQUE     assert( ptr.unique() ); assert( ptr.use_count() < 2 )
+#define T_NOT_UNIQUE assert( !ptr.unique() ); assert( ptr.use_count() >= 2 )
+
+template<class _RW>
+  void test()
+  {
+    MIL << __PRETTY_FUNCTION__ << std::endl;
+    // typedefs that should be provided:
+    typedef typename _RW::_Ptr               _Ptr;
+    typedef typename _RW::_constPtr          _constPtr;
+    typedef typename _Ptr::element_type      _Ptr_element_type;
+    typedef typename _constPtr::element_type _constPtr_element_type;
+    // initial NULL
+    _RW ptr;
+    T_NULL;
+    T_UNIQUE;
+    // assign
+    ptr = _RW( new _Ptr_element_type );
+    T_NOT_NULL;
+    T_UNIQUE;
+    {
+      // share
+      _RW ptr2( ptr );
+      T_NOT_NULL;
+      T_NOT_UNIQUE;
+      // unshare
+      ptr2.reset();
+      T_NOT_NULL;
+      T_UNIQUE;
+    }
+    // assign
+    ptr.reset( 0 );
+    T_NULL;
+    T_UNIQUE;
+  }
+
+template<class _RW>
+  void cowt()
+  {
+    test<_RW>();
+    MIL << __PRETTY_FUNCTION__ << std::endl;
+    typedef typename _RW::_Ptr::element_type _Ptr_element_type;
+    // create
+    _RW ptr( new _Ptr_element_type );
+    unsigned long ptrid = ptr->numericId();
+    // share
+    _RW ptr2( ptr );
+    // clone aon access
+    unsigned long ptrid2 = ptr2->numericId();
+    assert( ptrid != ptrid2 );
+  }
+
+/******************************************************************
+**
+**      FUNCTION NAME : main
+**      FUNCTION TYPE : int
+*/
+int main( int argc, char * argv[] )
+{
+  MIL << "===[START]=====" << endl;
+  test<RW_pointer<NonIntrusive,          rw_pointer::Shared<NonIntrusive> > >();
+  test<RW_pointer<const NonIntrusive,    rw_pointer::Shared<NonIntrusive> > >();
+  test<RW_pointer<Intrusive,             rw_pointer::Intrusive<Intrusive> > >();
+  test<RW_pointer<const Intrusive,       rw_pointer::Intrusive<Intrusive> > >();
+
+  cowt<RWCOW_pointer<NonIntrusive,       rw_pointer::Shared<NonIntrusive> > >();
+  cowt<RWCOW_pointer<const NonIntrusive, rw_pointer::Shared<NonIntrusive> > >();
+  cowt<RWCOW_pointer<Intrusive,          rw_pointer::Intrusive<Intrusive> > >();
+  cowt<RWCOW_pointer<const Intrusive,    rw_pointer::Intrusive<Intrusive> > >();
+
+  MIL << "===[DONE]=====" << endl;
+  return 0;
+}
diff --git a/testsuite/zypp/zypp.test/PtrTypes.exp b/testsuite/zypp/zypp.test/PtrTypes.exp
new file mode 100644 (file)
index 0000000..64707c2
--- /dev/null
@@ -0,0 +1,4 @@
+# PtrTypes.exp
+# run tests for PtrTypes
+
+  shouldPass "PtrTypes"