blob: 4a7352d43ebe7b59ce07ef8d0e8990b3448aa3d3 (
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
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include "SharedHandle.h"
#include "common.h"
#include <string>
#include <cppunit/extensions/HelperMacros.h>
using namespace std;
class SharedHandleTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(SharedHandleTest);
CPPUNIT_TEST(testSharedHandle);
CPPUNIT_TEST_SUITE_END();
static SharedHandle<int> staticHandle;
public:
void setUp() {
}
static SharedHandle<int> getInstance() {
if(staticHandle.isNull()) {
staticHandle = new int(1);
}
return staticHandle;
}
void testSharedHandle();
};
SharedHandle<int> SharedHandleTest::staticHandle = 0;
CPPUNIT_TEST_SUITE_REGISTRATION( SharedHandleTest );
void SharedHandleTest::testSharedHandle() {
cerr << "xh:" << endl;
SharedHandle<int> xh = new int(1);
CPPUNIT_ASSERT_EQUAL((int32_t)1, xh.getRefCount()->totalRefCount);
CPPUNIT_ASSERT_EQUAL((int32_t)1, xh.getRefCount()->strongRefCount);
cerr << "nullHandle:" << endl;
SharedHandle<int> nullHandle = 0;
CPPUNIT_ASSERT_EQUAL((int32_t)1, nullHandle.getRefCount()->totalRefCount);
CPPUNIT_ASSERT_EQUAL((int32_t)1, nullHandle.getRefCount()->strongRefCount);
cerr << "staticHandle:" << endl;
CPPUNIT_ASSERT_EQUAL((int32_t)1, staticHandle.getRefCount()->totalRefCount);
CPPUNIT_ASSERT_EQUAL((int32_t)1, staticHandle.getRefCount()->strongRefCount);
SharedHandle<int> localStaticHandle = getInstance();
CPPUNIT_ASSERT_EQUAL((int32_t)2, localStaticHandle.getRefCount()->totalRefCount);
CPPUNIT_ASSERT_EQUAL((int32_t)2, localStaticHandle.getRefCount()->strongRefCount);
}
|