]> granicus.if.org Git - icinga2/blob - test/base-object.cpp
Merge branch 'feature/freebsd-tests-4990' into next
[icinga2] / test / base-object.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/)   *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #include "base/object.h"
21 #include "base/value.h"
22 #include <boost/test/unit_test.hpp>
23 #include <boost/smart_ptr/make_shared.hpp>
24
25 using namespace icinga;
26
27 class TestObject : public Object
28 {
29 public:
30         typedef boost::shared_ptr<TestObject> Ptr;
31         typedef boost::weak_ptr<TestObject> WeakPtr;
32
33         TestObject::Ptr GetTestRef(void)
34         {
35                 return GetSelf();
36         }
37 };
38
39 BOOST_AUTO_TEST_SUITE(base_object)
40
41 BOOST_AUTO_TEST_CASE(construct)
42 {
43         Object::Ptr tobject = boost::make_shared<TestObject>();
44         BOOST_CHECK(tobject);
45 }
46
47 BOOST_AUTO_TEST_CASE(getself)
48 {
49         TestObject::Ptr tobject = boost::make_shared<TestObject>();
50         TestObject::Ptr tobject_self = tobject->GetTestRef();
51         BOOST_CHECK(tobject == tobject_self);
52
53         Value vobject = tobject;
54         BOOST_CHECK(!vobject.IsEmpty());
55         BOOST_CHECK(vobject.IsObjectType<TestObject>());
56 }
57
58 BOOST_AUTO_TEST_CASE(weak)
59 {
60         TestObject::Ptr tobject = boost::make_shared<TestObject>();
61         TestObject::WeakPtr wtobject = tobject;
62         tobject.reset();
63         BOOST_CHECK(!tobject);
64         BOOST_CHECK(!wtobject.lock());
65 }
66
67 BOOST_AUTO_TEST_SUITE_END()