1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/) *
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. *
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. *
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 ******************************************************************************/
20 #include "icinga/notification.hpp"
21 #include <BoostTestTargetConfig.h>
24 using namespace icinga;
26 BOOST_AUTO_TEST_SUITE(icinga_notification)
28 BOOST_AUTO_TEST_CASE(state_filter)
32 Array::Ptr states = new Array();
34 states->Add("Warning");
36 Notification::Ptr notification = new Notification();
38 notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
39 notification->Activate();
40 notification->SetAuthority(true);
42 /* Test passing notification state */
43 fstate = StateFilterWarning;
44 std::cout << "#1 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass. " << std::endl;
45 BOOST_CHECK(notification->GetStateFilter() & fstate);
47 /* Test filtered notification state */
48 fstate = StateFilterUnknown;
49 std::cout << "#2 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
50 BOOST_CHECK(!(notification->GetStateFilter() & fstate));
52 /* Test unset states filter configuration */
53 notification->SetStateFilter(FilterArrayToInt(Array::Ptr(), notification->GetStateFilterMap(), ~0));
55 fstate = StateFilterOK;
56 std::cout << "#3 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass." << std::endl;
57 BOOST_CHECK(notification->GetStateFilter() & fstate);
59 /* Test empty states filter configuration */
61 notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
63 fstate = StateFilterCritical;
64 std::cout << "#4 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
65 BOOST_CHECK(!(notification->GetStateFilter() & fstate));
67 BOOST_AUTO_TEST_CASE(type_filter)
71 Array::Ptr types = new Array();
72 types->Add("Problem");
73 types->Add("DowntimeStart");
74 types->Add("DowntimeEnd");
76 Notification::Ptr notification = new Notification();
78 notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
79 notification->Activate();
80 notification->SetAuthority(true);
82 /* Test passing notification type */
83 ftype = NotificationProblem;
84 std::cout << "#1 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
85 BOOST_CHECK(notification->GetTypeFilter() & ftype);
87 /* Test filtered notification type */
88 ftype = NotificationCustom;
89 std::cout << "#2 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
90 BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
92 /* Test unset types filter configuration */
93 notification->SetTypeFilter(FilterArrayToInt(Array::Ptr(), notification->GetTypeFilterMap(), ~0));
95 ftype = NotificationRecovery;
96 std::cout << "#3 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
97 BOOST_CHECK(notification->GetTypeFilter() & ftype);
99 /* Test empty types filter configuration */
101 notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
103 ftype = NotificationProblem;
104 std::cout << "#4 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
105 BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
107 BOOST_AUTO_TEST_SUITE_END()