]> granicus.if.org Git - icinga2/blob - test/base-value.cpp
Update copyright headers for 2016
[icinga2] / test / base-value.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2016 Icinga Development Team (https://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/value.hpp"
21 #include <boost/test/unit_test.hpp>
22
23 using namespace icinga;
24
25 BOOST_AUTO_TEST_SUITE(base_value)
26
27 BOOST_AUTO_TEST_CASE(scalar)
28 {
29         Value v;
30
31         v = 3;
32         BOOST_CHECK(v.IsScalar());
33
34         v = "hello";
35         BOOST_CHECK(v.IsScalar());
36
37         v = Empty;
38         BOOST_CHECK(!v.IsScalar());
39 }
40
41 BOOST_AUTO_TEST_CASE(convert)
42 {
43         Value v;
44         BOOST_CHECK(v.IsEmpty());
45         BOOST_CHECK(v == "");
46         BOOST_CHECK(static_cast<double>(v) == 0);
47         BOOST_CHECK(!v.IsScalar());
48         BOOST_CHECK(!v.IsObjectType<Object>());
49
50         BOOST_CHECK(v + "hello" == "hello");
51         BOOST_CHECK("hello" + v == "hello");
52 }
53
54 BOOST_AUTO_TEST_CASE(format)
55 {
56         Value v = 3;
57
58         std::ostringstream obuf;
59         obuf << v;
60
61         BOOST_CHECK(obuf.str() == "3");
62
63         std::istringstream ibuf("3");
64         ibuf >> v;
65
66         BOOST_CHECK(v != 3);
67 }
68
69 BOOST_AUTO_TEST_SUITE_END()