diff -r a71f388045f9 -r 8ef02f0c4245 test/refptr_test.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/refptr_test.cc Tue Feb 21 12:37:00 2006 +0000 @@ -0,0 +1,61 @@ +/* -*- C++ -*- + * + * This file is a part of LEMON, a generic C++ optimization library + * + * Copyright (C) 2003-2006 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport + * (Egervary Research Group on Combinatorial Optimization, EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#include +#include "test_tools.h" +#include + +class Test +{ + int &_counter; +public: + Test(int &co) : _counter(co) + { + std::cerr << "Init\n"; + _counter++; + } + ~Test() + { + std::cerr << "Destroy\n"; + _counter--; + } + int &counter() { return _counter; } + +}; + +int main() +{ + int c=0; + + { + RefPtr a = new Test(c); + check(a->counter() == 1, "Wrong number of initialization"); + { + RefPtr b = a; + check((*b).counter() == 1, "Wrong number of initialization"); + b=a; + a=b; + check((*a).counter() == 1, "Wrong number of initialization"); + } + check(a->counter() == 1, "Wrong number of initialization"); + } + check(c == 0, "Wrong number of initialization"); + + return 0; +} +