aboutsummaryrefslogtreecommitdiff
path: root/test/unit/shared_ptr_test.cpp
blob: a5393de6f975b3e39b71d4f339d17c8ce89436b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <memory>

#if !defined(_STLP_NO_EXTENSIONS) && defined(_STLP_USE_BOOST_SUPPORT)

// #include <typeinfo>
#include "cppunit/cppunit_proxy.h"

#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
using namespace std;
#endif

class SharedPtrTest :
    public CPPUNIT_NS::TestCase
{
    CPPUNIT_TEST_SUITE(SharedPtrTest);
    CPPUNIT_TEST(shared_from_this);
    CPPUNIT_TEST_SUITE_END();

  protected:
    void shared_from_this();
};

CPPUNIT_TEST_SUITE_REGISTRATION(SharedPtrTest);

struct X;

struct X :
    public std::tr1::enable_shared_from_this<X>
{
};

void SharedPtrTest::shared_from_this()
{
  std::tr1::shared_ptr<X> p( new X );
  std::tr1::shared_ptr<X> q = p->shared_from_this();

  CPPUNIT_CHECK( p == q );
  CPPUNIT_CHECK( !(p < q) && !(q < p) ); // p and q share ownership
}

#endif /* !_STLP_NO_EXTENSIONS && _STLP_USE_BOOST_SUPPORT */