~ubuntu-branches/ubuntu/wily/trafficserver/wily

« back to all changes in this revision

Viewing changes to lib/ts/IntrusivePtrTest.cc

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2012-12-17 22:28:16 UTC
  • mfrom: (5.1.8 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121217222816-7xwjsx5k76zkb63d
Tags: 3.2.0-1ubuntu1
* Revert FreeBSD strerror_r() fixes that give errors with glibc 2.16.
* Apply patch from Konstantinos Margaritis to define barriers on ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
 
 
3
    Intrusive pointer test.
 
4
 
 
5
    @section license License
 
6
 
 
7
    Licensed to the Apache Software Foundation (ASF) under one
 
8
    or more contributor license agreements.  See the NOTICE file
 
9
    distributed with this work for additional information
 
10
    regarding copyright ownership.  The ASF licenses this file
 
11
    to you under the Apache License, Version 2.0 (the
 
12
    "License"); you may not use this file except in compliance
 
13
    with the License.  You may obtain a copy of the License at
 
14
 
 
15
    http://www.apache.org/licenses/LICENSE-2.0
 
16
 
 
17
    Unless required by applicable law or agreed to in writing, software
 
18
    distributed under the License is distributed on an "AS IS" BASIS,
 
19
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
20
    See the License for the specific language governing permissions and
 
21
    limitations under the License.
 
22
*/
 
23
 
 
24
# include <ts/IntrusivePtr.h>
 
25
# include <ts/IntrusiveDList.h>
 
26
# include <ts/TestBox.h>
 
27
 
 
28
namespace { // Hide our local defintions
 
29
 
 
30
// Test class for pointers and lists.
 
31
class A : public IntrusivePtrCounter {
 
32
public:
 
33
  A() : _data(0) {}
 
34
  static A*& nextPtr(A* a) { return a->_next; }
 
35
  static A*& prevPtr(A* a) { return a->_prev; }
 
36
  int _data;
 
37
  A* _next;
 
38
  A* _prev;
 
39
};
 
40
 
 
41
// Definitions to test compilation.
 
42
typedef IntrusivePtrQueue<
 
43
  A,
 
44
  IntrusivePtrLinkFunction<A, &A::nextPtr, &A::prevPtr>
 
45
> AList;
 
46
 
 
47
}
 
48
 
 
49
REGRESSION_TEST(IntrusivePtr_Test_Basic)(RegressionTest* t, int atype, int* pstatus) {
 
50
  IntrusivePtr<A> ptr1;
 
51
  IntrusivePtr<A> ptr2(new A);
 
52
 
 
53
  TestBox tb(t, pstatus);
 
54
 
 
55
  tb = REGRESSION_TEST_PASSED;
 
56
 
 
57
  tb.check(!ptr1, "Default construct pointer is not empty.");
 
58
  tb.check(ptr2, "Construction from pointer was empty.");
 
59
 
 
60
  AList alist1;
 
61
 
 
62
  tb.check(ptr2->useCount() == 1, "Bad use count: expected 1 got %d", ptr2->useCount());
 
63
  alist1.append(ptr2);
 
64
  tb.check(ptr2->useCount() == 2, "Bad use count: expected 2 got %d", ptr2->useCount());
 
65
  alist1.remove(ptr2);
 
66
  tb.check(ptr2->useCount() == 1, "Bad use count: expected 1 got %d", ptr2->useCount());
 
67
  alist1.prepend(ptr2);
 
68
  tb.check(ptr2->useCount() == 2, "Bad use count: expected 2 got %d", ptr2->useCount());
 
69
  for ( AList::iterator spot = alist1.begin(), limit = alist1.end()
 
70
          ; spot != limit
 
71
          ; ++spot
 
72
  ) {
 
73
    if (spot->_data) break;
 
74
  }
 
75
}