]> granicus.if.org Git - icinga2/blob - test/icinga-perfdata.cpp
04812983c46e4d4642864bbe6cffd1ee85b70e4a
[icinga2] / test / icinga-perfdata.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 "icinga/pluginutility.cpp"
21 #include <boost/test/unit_test.hpp>
22
23 using namespace icinga;
24
25 BOOST_AUTO_TEST_SUITE(icinga_perfdata)
26
27 BOOST_AUTO_TEST_CASE(empty)
28 {
29         Dictionary::Ptr pd = PluginUtility::ParsePerfdata("");
30         BOOST_CHECK(pd->GetLength() == 0);
31 }
32
33 BOOST_AUTO_TEST_CASE(simple)
34 {
35         Dictionary::Ptr pd = PluginUtility::ParsePerfdata("test=123456");
36         BOOST_CHECK(pd->Get("test") == 123456);
37
38         String str = PluginUtility::FormatPerfdata(pd);
39         BOOST_CHECK(str == "test=123456");
40 }
41
42 BOOST_AUTO_TEST_CASE(multiple)
43 {
44         Dictionary::Ptr pd = PluginUtility::ParsePerfdata("testA=123456 testB=123456");
45         BOOST_CHECK(pd->Get("testA") == 123456);
46         BOOST_CHECK(pd->Get("testB") == 123456);
47
48         String str = PluginUtility::FormatPerfdata(pd);
49         BOOST_CHECK(str == "testA=123456 testB=123456");
50 }
51
52 BOOST_AUTO_TEST_CASE(uom)
53 {
54         Dictionary::Ptr pd = PluginUtility::ParsePerfdata("test=123456B");
55
56         PerfdataValue::Ptr pv = pd->Get("test");
57         BOOST_CHECK(pv);
58
59         BOOST_CHECK(pv->GetValue() == 123456);
60         BOOST_CHECK(!pv->GetCounter());
61         BOOST_CHECK(pv->GetUnit() == "bytes");
62         BOOST_CHECK(pv->GetCrit() == Empty);
63         BOOST_CHECK(pv->GetWarn() == Empty);
64         BOOST_CHECK(pv->GetMin() == Empty);
65         BOOST_CHECK(pv->GetMax() == Empty);
66
67         String str = PluginUtility::FormatPerfdata(pd);
68         BOOST_CHECK(str == "test=123456B");
69 }
70
71 BOOST_AUTO_TEST_CASE(warncritminmax)
72 {
73         Dictionary::Ptr pd = PluginUtility::ParsePerfdata("test=123456B;1000;2000;3000;4000");
74
75         PerfdataValue::Ptr pv = pd->Get("test");
76         BOOST_CHECK(pv);
77
78         BOOST_CHECK(pv->GetValue() == 123456);
79         BOOST_CHECK(!pv->GetCounter());
80         BOOST_CHECK(pv->GetUnit() == "bytes");
81         BOOST_CHECK(pv->GetWarn() == 1000);
82         BOOST_CHECK(pv->GetCrit() == 2000);
83         BOOST_CHECK(pv->GetMin() == 3000);
84         BOOST_CHECK(pv->GetMax() == 4000);
85
86         String str = PluginUtility::FormatPerfdata(pd);
87         BOOST_CHECK(str == "test=123456B;1000;2000;3000;4000");
88 }
89
90 BOOST_AUTO_TEST_CASE(invalid)
91 {
92         BOOST_CHECK(PluginUtility::ParsePerfdata("test=1,23456") == "test=1,23456");
93         BOOST_CHECK(PluginUtility::ParsePerfdata("test=123456;10%;20%") == "test=123456;10%;20%");
94 }
95
96 BOOST_AUTO_TEST_SUITE_END()