alpar@1977
|
1 |
/* -*- C++ -*-
|
alpar@1977
|
2 |
*
|
alpar@1977
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@1977
|
4 |
*
|
alpar@2553
|
5 |
* Copyright (C) 2003-2008
|
alpar@1977
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@1977
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@1977
|
8 |
*
|
alpar@1977
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@1977
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@1977
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@1977
|
12 |
*
|
alpar@1977
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@1977
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@1977
|
15 |
* purpose.
|
alpar@1977
|
16 |
*
|
alpar@1977
|
17 |
*/
|
alpar@1977
|
18 |
|
alpar@1977
|
19 |
#include<lemon/refptr.h>
|
alpar@1977
|
20 |
#include "test_tools.h"
|
alpar@1977
|
21 |
#include <iostream>
|
alpar@1977
|
22 |
|
alpar@1977
|
23 |
class Test
|
alpar@1977
|
24 |
{
|
alpar@1977
|
25 |
int &_counter;
|
alpar@1977
|
26 |
public:
|
alpar@1977
|
27 |
Test(int &co) : _counter(co)
|
alpar@1977
|
28 |
{
|
alpar@1977
|
29 |
std::cerr << "Init\n";
|
alpar@1977
|
30 |
_counter++;
|
alpar@1977
|
31 |
}
|
alpar@1977
|
32 |
~Test()
|
alpar@1977
|
33 |
{
|
alpar@1977
|
34 |
std::cerr << "Destroy\n";
|
alpar@1977
|
35 |
_counter--;
|
alpar@1977
|
36 |
}
|
alpar@1977
|
37 |
int &counter() { return _counter; }
|
alpar@1977
|
38 |
|
alpar@1977
|
39 |
};
|
alpar@1977
|
40 |
|
alpar@1977
|
41 |
int main()
|
alpar@1977
|
42 |
{
|
alpar@1977
|
43 |
int c=0;
|
alpar@1977
|
44 |
|
alpar@1977
|
45 |
{
|
alpar@1977
|
46 |
RefPtr<Test> a = new Test(c);
|
alpar@1977
|
47 |
check(a->counter() == 1, "Wrong number of initialization");
|
alpar@1977
|
48 |
{
|
alpar@1977
|
49 |
RefPtr<Test> b = a;
|
alpar@1977
|
50 |
check((*b).counter() == 1, "Wrong number of initialization");
|
alpar@1977
|
51 |
b=a;
|
alpar@1977
|
52 |
a=b;
|
alpar@1977
|
53 |
check((*a).counter() == 1, "Wrong number of initialization");
|
alpar@1977
|
54 |
}
|
alpar@1977
|
55 |
check(a->counter() == 1, "Wrong number of initialization");
|
alpar@1977
|
56 |
}
|
alpar@1977
|
57 |
check(c == 0, "Wrong number of initialization");
|
alpar@1977
|
58 |
|
alpar@1977
|
59 |
return 0;
|
alpar@1977
|
60 |
}
|
alpar@1977
|
61 |
|