]> granicus.if.org Git - icinga2/blob - test/base-convert.cpp
Merge branch 'feature/debian-packaging-4988' into next
[icinga2] / test / base-convert.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/convert.h"
21 #include "base/object.h"
22 #include <boost/test/unit_test.hpp>
23 #include <iostream>
24
25 using namespace icinga;
26
27 BOOST_AUTO_TEST_SUITE(base_convert)
28
29 BOOST_AUTO_TEST_CASE(tolong)
30 {
31         BOOST_CHECK_THROW(Convert::ToLong(" 7"), boost::exception);
32         BOOST_CHECK(Convert::ToLong("-7") == -7);
33         BOOST_CHECK_THROW(Convert::ToLong("7a"), boost::exception);
34 }
35
36 BOOST_AUTO_TEST_CASE(todouble)
37 {
38         BOOST_CHECK_THROW(Convert::ToDouble(" 7.3"), boost::exception);
39         BOOST_CHECK(Convert::ToDouble("-7.3") == -7.3);
40         BOOST_CHECK_THROW(Convert::ToDouble("7.3a"), boost::exception);
41 }
42
43 BOOST_AUTO_TEST_CASE(tostring)
44 {
45         BOOST_CHECK(Convert::ToString(7) == "7");
46         BOOST_CHECK(Convert::ToString(7.3) == "7.3");
47         BOOST_CHECK(Convert::ToString("hello") == "hello");
48
49         Object::Ptr object = make_shared<Object>();
50         BOOST_CHECK(Convert::ToString(object) == "Object of type 'icinga::Object'");
51 }
52
53 BOOST_AUTO_TEST_CASE(tobool)
54 {
55         BOOST_CHECK_THROW(Convert::ToBool("a"), boost::exception);
56         BOOST_CHECK(Convert::ToBool("0") == false);
57         BOOST_CHECK(Convert::ToBool("1") == true);
58         BOOST_CHECK(Convert::ToBool("2") == true);
59 }
60
61 BOOST_AUTO_TEST_SUITE_END()