• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

IntrusivePtrTest.cc

Go to the documentation of this file.
00001 /** @file
00002 
00003     Intrusive pointer test.
00004 
00005     @section license License
00006 
00007     Licensed to the Apache Software Foundation (ASF) under one
00008     or more contributor license agreements.  See the NOTICE file
00009     distributed with this work for additional information
00010     regarding copyright ownership.  The ASF licenses this file
00011     to you under the Apache License, Version 2.0 (the
00012     "License"); you may not use this file except in compliance
00013     with the License.  You may obtain a copy of the License at
00014 
00015     http://www.apache.org/licenses/LICENSE-2.0
00016 
00017     Unless required by applicable law or agreed to in writing, software
00018     distributed under the License is distributed on an "AS IS" BASIS,
00019     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020     See the License for the specific language governing permissions and
00021     limitations under the License.
00022 */
00023 
00024 # include <ts/IntrusivePtr.h>
00025 # include <ts/IntrusiveDList.h>
00026 # include <ts/TestBox.h>
00027 
00028 namespace { // Hide our local defintions
00029 
00030 // Test class for pointers and lists.
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 // Definitions to test compilation.
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 }

Generated by  doxygen 1.7.1