source: icXML/icXML-devel/tests/src/UtilTests/CoreTests_CountedPointer.cpp @ 2726

Last change on this file since 2726 was 2726, checked in by cameron, 7 years ago

Add original Xerces tests and samples directories

File size: 2.6 KB
Line 
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id: CoreTests_CountedPointer.cpp 470088 2006-11-01 20:35:12Z amassari $
20 */
21
22
23// ---------------------------------------------------------------------------
24//  XML4C2 Includes
25// ---------------------------------------------------------------------------
26#include "CoreTests.hpp"
27#include <xercesc/util/CountedPointer.hpp>
28
29
30// ---------------------------------------------------------------------------
31//  A local class used for testing
32// ---------------------------------------------------------------------------
33class TestClass
34{
35public :
36    static unsigned int gCounter;
37
38    TestClass()
39    {
40        gCounter++;
41    }
42
43    ~TestClass()
44    {
45        gCounter--;
46    }
47
48    void addRef()
49    {
50        refCount++;
51    }
52
53    void removeRef()
54    {
55        refCount--;
56        if (refCount == 0)
57            delete this;
58    }
59
60private :
61    unsigned int refCount;
62};
63
64unsigned int TestClass::gCounter = 0;
65
66
67// ---------------------------------------------------------------------------
68//  Force a full instantiation to test syntax
69// ---------------------------------------------------------------------------
70template class CountedPointerTo<TestClass>;
71
72
73// ---------------------------------------------------------------------------
74//  Test entry point
75// ---------------------------------------------------------------------------
76bool testCountedPointer()
77{
78    XERCES_STD_QUALIFIER wcout  << L"----------------------------------\n"
79                << L"Testing CountedPointerTo class\n"
80                << L"----------------------------------" << XERCES_STD_QUALIFIER endl;
81
82    bool retVal = true;
83
84    try
85    {
86    }
87
88    catch(const XMLException& toCatch)
89    {
90        XERCES_STD_QUALIFIER wcout << L"  ERROR: Unexpected exception!\n   Msg: "
91                   << toCatch.getMessage() << XERCES_STD_QUALIFIER endl;
92        return false;
93    }
94    return retVal;
95}
Note: See TracBrowser for help on using the repository browser.