Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 # include <ts/IntrusivePtr.h>
00025 # include <ts/IntrusiveDList.h>
00026 # include <ts/TestBox.h>
00027
00028 namespace {
00029
00030
00031 class A : public IntrusivePtrCounter {
00032 public:
00033 A() : _data(0) {}
00034 static A*& nextPtr(A* a) { return a->_next; }
00035 static A*& prevPtr(A* a) { return a->_prev; }
00036 int _data;
00037 A* _next;
00038 A* _prev;
00039 };
00040
00041
00042 typedef IntrusivePtrQueue<
00043 A,
00044 IntrusivePtrLinkFunction<A, &A::nextPtr, &A::prevPtr>
00045 > AList;
00046
00047 }
00048
00049 REGRESSION_TEST(IntrusivePtr_Test_Basic)(RegressionTest* t, int atype, int* pstatus) {
00050 IntrusivePtr<A> ptr1;
00051 IntrusivePtr<A> ptr2(new A);
00052
00053 TestBox tb(t, pstatus);
00054
00055 tb = REGRESSION_TEST_PASSED;
00056
00057 tb.check(!ptr1, "Default construct pointer is not empty.");
00058 tb.check(ptr2, "Construction from pointer was empty.");
00059
00060 AList alist1;
00061
00062 tb.check(ptr2->useCount() == 1, "Bad use count: expected 1 got %d", ptr2->useCount());
00063 alist1.append(ptr2);
00064 tb.check(ptr2->useCount() == 2, "Bad use count: expected 2 got %d", ptr2->useCount());
00065 alist1.remove(ptr2);
00066 tb.check(ptr2->useCount() == 1, "Bad use count: expected 1 got %d", ptr2->useCount());
00067 alist1.prepend(ptr2);
00068 tb.check(ptr2->useCount() == 2, "Bad use count: expected 2 got %d", ptr2->useCount());
00069 for ( AList::iterator spot = alist1.begin(), limit = alist1.end()
00070 ; spot != limit
00071 ; ++spot
00072 ) {
00073 if (spot->_data) break;
00074 }
00075 }