1 | // $Id: smart_ptr_test.cc 1045 2008-02-06 22:34:45Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2008 Peter Johansson |
---|
5 | |
---|
6 | This file is part of the yat library, http://trac.thep.lu.se/yat |
---|
7 | |
---|
8 | The yat library is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License as |
---|
10 | published by the Free Software Foundation; either version 2 of the |
---|
11 | License, or (at your option) any later version. |
---|
12 | |
---|
13 | The yat library is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
21 | 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "yat/utility/SmartPtr.h" |
---|
25 | #include "yat/utility/matrix.h" |
---|
26 | |
---|
27 | #include <fstream> |
---|
28 | #include <iostream> |
---|
29 | |
---|
30 | int main(const int argc,const char* argv[]) |
---|
31 | |
---|
32 | { |
---|
33 | using namespace theplu::yat; |
---|
34 | |
---|
35 | std::ostream* error; |
---|
36 | if (argc>1 && argv[1]==std::string("-v")) |
---|
37 | error = &std::cerr; |
---|
38 | else { |
---|
39 | error = new std::ofstream("/dev/null"); |
---|
40 | if (argc>1) |
---|
41 | std::cout << "smart_ptr_test -v : for printing extra information\n"; |
---|
42 | } |
---|
43 | *error << "testing smart_ptr" << std::endl; |
---|
44 | |
---|
45 | bool ok = true; |
---|
46 | |
---|
47 | utility::SmartPtr<utility::matrix> m(new utility::matrix(10,10)); |
---|
48 | if (m->columns()==10){ |
---|
49 | utility::SmartPtr<utility::matrix> m2(m); |
---|
50 | m2 = m; |
---|
51 | } |
---|
52 | else |
---|
53 | ok = false; |
---|
54 | |
---|
55 | m = m; |
---|
56 | utility::matrix m2 = *m; |
---|
57 | |
---|
58 | if (m->columns()!=10) |
---|
59 | ok = false; |
---|
60 | |
---|
61 | if(ok) |
---|
62 | *error << "OK" << std::endl; |
---|
63 | else |
---|
64 | *error << "Failed" << std::endl; |
---|
65 | if (error!=&std::cerr) |
---|
66 | delete error; |
---|
67 | |
---|
68 | |
---|
69 | if (ok) |
---|
70 | return 0; |
---|
71 | return -1; |
---|
72 | |
---|
73 | } |
---|