1 /*****************************************************************************
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *****************************************************************************/
21 #include "utils_base.h"
26 main (int argc
, char **argv
)
30 thresholds
*thresholds
= NULL
;
35 range
= parse_range_string("6");
36 ok( range
!= NULL
, "'6' is valid range");
37 ok( range
->start
== 0, "Start correct");
38 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
39 ok( range
->end
== 6, "End correct");
40 ok( range
->end_infinity
== FALSE
, "Not using infinity");
43 range
= parse_range_string("1:12%%");
44 ok( range
!= NULL
, "'1:12%%' is valid - percentages are ignored");
45 ok( range
->start
== 1, "Start correct");
46 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
47 ok( range
->end
== 12, "End correct");
48 ok( range
->end_infinity
== FALSE
, "Not using infinity");
51 range
= parse_range_string("-7:23");
52 ok( range
!= NULL
, "'-7:23' is valid range");
53 ok( range
->start
== -7, "Start correct");
54 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
55 ok( range
->end
== 23, "End correct");
56 ok( range
->end_infinity
== FALSE
, "Not using infinity");
59 range
= parse_range_string(":5.75");
60 ok( range
!= NULL
, "':5.75' is valid range");
61 ok( range
->start
== 0, "Start correct");
62 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
63 ok( range
->end
== 5.75, "End correct");
64 ok( range
->end_infinity
== FALSE
, "Not using infinity");
67 range
= parse_range_string("~:-95.99");
68 ok( range
!= NULL
, "~:-95.99' is valid range");
69 ok( range
->start_infinity
== TRUE
, "Using negative infinity");
70 ok( range
->end
== -95.99, "End correct (with rounding errors)");
71 ok( range
->end_infinity
== FALSE
, "Not using infinity");
74 range
= parse_range_string("12345678901234567890:");
75 temp
= atof("12345678901234567890"); /* Can't just use this because number too large */
76 ok( range
!= NULL
, "'12345678901234567890:' is valid range");
77 ok( range
->start
== temp
, "Start correct");
78 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
79 ok( range
->end_infinity
== TRUE
, "Using infinity");
80 /* Cannot do a "-1" on temp, as it appears to be same value */
81 ok( check_range(temp
/1.1, range
) == TRUE
, "12345678901234567890/1.1 - alert");
82 ok( check_range(temp
, range
) == FALSE
, "12345678901234567890 - no alert");
83 ok( check_range(temp
*2, range
) == FALSE
, "12345678901234567890*2 - no alert");
86 range
= parse_range_string("~:0");
87 ok( range
!= NULL
, "'~:0' is valid range");
88 ok( range
->start_infinity
== TRUE
, "Using negative infinity");
89 ok( range
->end
== 0, "End correct");
90 ok( range
->end_infinity
== FALSE
, "Not using infinity");
91 ok( range
->alert_on
== OUTSIDE
, "Will alert on outside of this range");
92 ok( check_range(0.5, range
) == TRUE
, "0.5 - alert");
93 ok( check_range(-10, range
) == FALSE
, "-10 - no alert");
94 ok( check_range(0, range
) == FALSE
, "0 - no alert");
97 range
= parse_range_string("@0:657.8210567");
98 ok( range
!= 0, "@0:657.8210567' is a valid range");
99 ok( range
->start
== 0, "Start correct");
100 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
101 ok( range
->end
== 657.8210567, "End correct");
102 ok( range
->end_infinity
== FALSE
, "Not using infinity");
103 ok( range
->alert_on
== INSIDE
, "Will alert on inside of this range" );
104 ok( check_range(32.88, range
) == TRUE
, "32.88 - alert");
105 ok( check_range(-2, range
) == FALSE
, "-2 - no alert");
106 ok( check_range(657.8210567, range
) == TRUE
, "657.8210567 - alert");
107 ok( check_range(0, range
) == TRUE
, "0 - alert");
110 range
= parse_range_string("1:1");
111 ok( range
!= NULL
, "'1:1' is a valid range");
112 ok( range
->start
== 1, "Start correct");
113 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
114 ok( range
->end
== 1, "End correct");
115 ok( range
->end_infinity
== FALSE
, "Not using infinity");
116 ok( check_range(0.5, range
) == TRUE
, "0.5 - alert");
117 ok( check_range(1, range
) == FALSE
, "1 - no alert");
118 ok( check_range(5.2, range
) == TRUE
, "5.2 - alert");
121 range
= parse_range_string("2:1");
122 ok( range
== NULL
, "'2:1' rejected");
124 rc
= _set_thresholds(&thresholds
, NULL
, NULL
);
125 ok( rc
== 0, "Thresholds (NULL, NULL) set");
126 ok( thresholds
->warning
== NULL
, "Warning not set");
127 ok( thresholds
->critical
== NULL
, "Critical not set");
129 rc
= _set_thresholds(&thresholds
, NULL
, "80");
130 ok( rc
== 0, "Thresholds (NULL, '80') set");
131 ok( thresholds
->warning
== NULL
, "Warning not set");
132 ok( thresholds
->critical
->end
== 80, "Critical set correctly");
134 rc
= _set_thresholds(&thresholds
, "5:33", NULL
);
135 ok( rc
== 0, "Thresholds ('5:33', NULL) set");
136 ok( thresholds
->warning
->start
== 5, "Warning start set");
137 ok( thresholds
->warning
->end
== 33, "Warning end set");
138 ok( thresholds
->critical
== NULL
, "Critical not set");
140 rc
= _set_thresholds(&thresholds
, "30", "60");
141 ok( rc
== 0, "Thresholds ('30', '60') set");
142 ok( thresholds
->warning
->end
== 30, "Warning set correctly");
143 ok( thresholds
->critical
->end
== 60, "Critical set correctly");
144 ok( get_status(15.3, thresholds
) == STATE_OK
, "15.3 - ok");
145 ok( get_status(30.0001, thresholds
) == STATE_WARNING
, "30.0001 - warning");
146 ok( get_status(69, thresholds
) == STATE_CRITICAL
, "69 - critical");
149 test
= np_escaped_string("bob\\n");
150 ok( strcmp(test
, "bob\n") == 0, "bob\\n ok");
153 test
= np_escaped_string("rhuba\\rb");
154 ok( strcmp(test
, "rhuba\rb") == 0, "rhuba\\rb okay");
157 test
= np_escaped_string("ba\\nge\\r");
158 ok( strcmp(test
, "ba\nge\r") == 0, "ba\\nge\\r okay");
161 test
= np_escaped_string("\\rabbi\\t");
162 ok( strcmp(test
, "\rabbi\t") == 0, "\\rabbi\\t okay");
165 test
= np_escaped_string("and\\\\or");
166 ok( strcmp(test
, "and\\or") == 0, "and\\\\or okay");
169 test
= np_escaped_string("bo\\gus");
170 ok( strcmp(test
, "bogus") == 0, "bo\\gus okay");
173 test
= np_escaped_string("everything");
174 ok( strcmp(test
, "everything") == 0, "everything okay");
177 test
= basename("/here/is/a/path");
178 ok( strcmp(test
, "path") == 0, "basename okay");
180 return exit_status();