1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/test/refptr_test.cc Tue Feb 21 12:37:00 2006 +0000
1.3 @@ -0,0 +1,61 @@
1.4 +/* -*- C++ -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library
1.7 + *
1.8 + * Copyright (C) 2003-2006
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +#include<lemon/refptr.h>
1.23 +#include "test_tools.h"
1.24 +#include <iostream>
1.25 +
1.26 +class Test
1.27 +{
1.28 + int &_counter;
1.29 +public:
1.30 + Test(int &co) : _counter(co)
1.31 + {
1.32 + std::cerr << "Init\n";
1.33 + _counter++;
1.34 + }
1.35 + ~Test()
1.36 + {
1.37 + std::cerr << "Destroy\n";
1.38 + _counter--;
1.39 + }
1.40 + int &counter() { return _counter; }
1.41 +
1.42 +};
1.43 +
1.44 +int main()
1.45 +{
1.46 + int c=0;
1.47 +
1.48 + {
1.49 + RefPtr<Test> a = new Test(c);
1.50 + check(a->counter() == 1, "Wrong number of initialization");
1.51 + {
1.52 + RefPtr<Test> b = a;
1.53 + check((*b).counter() == 1, "Wrong number of initialization");
1.54 + b=a;
1.55 + a=b;
1.56 + check((*a).counter() == 1, "Wrong number of initialization");
1.57 + }
1.58 + check(a->counter() == 1, "Wrong number of initialization");
1.59 + }
1.60 + check(c == 0, "Wrong number of initialization");
1.61 +
1.62 + return 0;
1.63 +}
1.64 +