]> granicus.if.org Git - icinga2/blob - test/icinga-notification.cpp
Merge pull request #6999 from Icinga/bugfix/compiler-warnings
[icinga2] / test / icinga-notification.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "icinga/notification.hpp"
4 #include <BoostTestTargetConfig.h>
5 #include <iostream>
6
7 using namespace icinga;
8
9 BOOST_AUTO_TEST_SUITE(icinga_notification)
10
11 BOOST_AUTO_TEST_CASE(state_filter)
12 {
13         unsigned long fstate;
14
15         Array::Ptr states = new Array();
16         states->Add("OK");
17         states->Add("Warning");
18
19         Notification::Ptr notification = new Notification();
20
21         notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
22         notification->Activate();
23         notification->SetAuthority(true);
24
25         /* Test passing notification state */
26         fstate = StateFilterWarning;
27         std::cout << "#1 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass. " << std::endl;
28         BOOST_CHECK(notification->GetStateFilter() & fstate);
29
30         /* Test filtered notification state */
31         fstate = StateFilterUnknown;
32         std::cout << "#2 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
33         BOOST_CHECK(!(notification->GetStateFilter() & fstate));
34
35         /* Test unset states filter configuration */
36         notification->SetStateFilter(FilterArrayToInt(Array::Ptr(), notification->GetStateFilterMap(), ~0));
37
38         fstate = StateFilterOK;
39         std::cout << "#3 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must pass." << std::endl;
40         BOOST_CHECK(notification->GetStateFilter() & fstate);
41
42         /* Test empty states filter configuration */
43         states->Clear();
44         notification->SetStateFilter(FilterArrayToInt(states, notification->GetStateFilterMap(), ~0));
45
46         fstate = StateFilterCritical;
47         std::cout << "#4 Notification state: " << fstate << " against " << notification->GetStateFilter() << " must fail." << std::endl;
48         BOOST_CHECK(!(notification->GetStateFilter() & fstate));
49 }
50 BOOST_AUTO_TEST_CASE(type_filter)
51 {
52         unsigned long ftype;
53
54         Array::Ptr types = new Array();
55         types->Add("Problem");
56         types->Add("DowntimeStart");
57         types->Add("DowntimeEnd");
58
59         Notification::Ptr notification = new Notification();
60
61         notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
62         notification->Activate();
63         notification->SetAuthority(true);
64
65         /* Test passing notification type */
66         ftype = NotificationProblem;
67         std::cout << "#1 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
68         BOOST_CHECK(notification->GetTypeFilter() & ftype);
69
70         /* Test filtered notification type */
71         ftype = NotificationCustom;
72         std::cout << "#2 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
73         BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
74
75         /* Test unset types filter configuration */
76         notification->SetTypeFilter(FilterArrayToInt(Array::Ptr(), notification->GetTypeFilterMap(), ~0));
77
78         ftype = NotificationRecovery;
79         std::cout << "#3 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must pass." << std::endl;
80         BOOST_CHECK(notification->GetTypeFilter() & ftype);
81
82         /* Test empty types filter configuration */
83         types->Clear();
84         notification->SetTypeFilter(FilterArrayToInt(types, notification->GetTypeFilterMap(), ~0));
85
86         ftype = NotificationProblem;
87         std::cout << "#4 Notification type: " << ftype << " against " << notification->GetTypeFilter() << " must fail." << std::endl;
88         BOOST_CHECK(!(notification->GetTypeFilter() & ftype));
89 }
90 BOOST_AUTO_TEST_SUITE_END()