From: Michael Andres Date: Fri, 17 Feb 2006 21:10:33 +0000 (+0000) Subject: - install PtrTypes test X-Git-Tag: 6.6.0~4761 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c66453756269a9e1be725b1afbb70397105e53ef;p=platform%2Fupstream%2Flibzypp.git - install PtrTypes test --- diff --git a/testsuite/zypp/tests/.cvsignore b/testsuite/zypp/tests/.cvsignore new file mode 100644 index 000000000..d69b34c2f --- /dev/null +++ b/testsuite/zypp/tests/.cvsignore @@ -0,0 +1,12 @@ +Makefile.in +Makefile +.libs +.deps +Arch +Capabilities +Edition +PtrTypes +Url1 +Url2 +Url3 +Url4 diff --git a/testsuite/zypp/tests/Makefile.am b/testsuite/zypp/tests/Makefile.am index 4c4ee0a25..65725f0e8 100644 --- a/testsuite/zypp/tests/Makefile.am +++ b/testsuite/zypp/tests/Makefile.am @@ -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 index 000000000..49bbd4a34 --- /dev/null +++ b/testsuite/zypp/tests/PtrTypes.cc @@ -0,0 +1,125 @@ +#include + +#include "zypp/base/Logger.h" +#include +#include +#include + +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 + 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 +{ + Trace::numericId; +}; + +/** Data class for intrusive_ptr */ +struct Intrusive : public ReferenceCounted, + private Trace +{ + Trace::numericId; +}; + +namespace zypp +{ + template<> + inline NonIntrusive * rwcowClone( const NonIntrusive * rhs ) + { return new NonIntrusive( *rhs ); } + + template<> + inline Intrusive * rwcowClone( 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 + 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 + 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 > >(); + test > >(); + test > >(); + test > >(); + + cowt > >(); + cowt > >(); + cowt > >(); + cowt > >(); + + 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 index 000000000..64707c251 --- /dev/null +++ b/testsuite/zypp/zypp.test/PtrTypes.exp @@ -0,0 +1,4 @@ +# PtrTypes.exp +# run tests for PtrTypes + + shouldPass "PtrTypes"