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/>.
17 *****************************************************************************/
20 #include "utils_base.h"
25 main (int argc
, char **argv
)
29 thresholds
*thresholds
= NULL
;
34 range
= parse_range_string("6");
35 ok( range
!= NULL
, "'6' is valid range");
36 ok( range
->start
== 0, "Start correct");
37 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
38 ok( range
->end
== 6, "End correct");
39 ok( range
->end_infinity
== FALSE
, "Not using infinity");
42 range
= parse_range_string("1:12%%");
43 ok( range
!= NULL
, "'1:12%%' is valid - percentages are ignored");
44 ok( range
->start
== 1, "Start correct");
45 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
46 ok( range
->end
== 12, "End correct");
47 ok( range
->end_infinity
== FALSE
, "Not using infinity");
50 range
= parse_range_string("-7:23");
51 ok( range
!= NULL
, "'-7:23' is valid range");
52 ok( range
->start
== -7, "Start correct");
53 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
54 ok( range
->end
== 23, "End correct");
55 ok( range
->end_infinity
== FALSE
, "Not using infinity");
58 range
= parse_range_string(":5.75");
59 ok( range
!= NULL
, "':5.75' is valid range");
60 ok( range
->start
== 0, "Start correct");
61 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
62 ok( range
->end
== 5.75, "End correct");
63 ok( range
->end_infinity
== FALSE
, "Not using infinity");
66 range
= parse_range_string("~:-95.99");
67 ok( range
!= NULL
, "~:-95.99' is valid range");
68 ok( range
->start_infinity
== TRUE
, "Using negative infinity");
69 ok( range
->end
== -95.99, "End correct (with rounding errors)");
70 ok( range
->end_infinity
== FALSE
, "Not using infinity");
73 range
= parse_range_string("12345678901234567890:");
74 temp
= atof("12345678901234567890"); /* Can't just use this because number too large */
75 ok( range
!= NULL
, "'12345678901234567890:' is valid range");
76 ok( range
->start
== temp
, "Start correct");
77 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
78 ok( range
->end_infinity
== TRUE
, "Using infinity");
79 /* Cannot do a "-1" on temp, as it appears to be same value */
80 ok( check_range(temp
/1.1, range
) == TRUE
, "12345678901234567890/1.1 - alert");
81 ok( check_range(temp
, range
) == FALSE
, "12345678901234567890 - no alert");
82 ok( check_range(temp
*2, range
) == FALSE
, "12345678901234567890*2 - no alert");
85 range
= parse_range_string("~:0");
86 ok( range
!= NULL
, "'~:0' is valid range");
87 ok( range
->start_infinity
== TRUE
, "Using negative infinity");
88 ok( range
->end
== 0, "End correct");
89 ok( range
->end_infinity
== FALSE
, "Not using infinity");
90 ok( range
->alert_on
== OUTSIDE
, "Will alert on outside of this range");
91 ok( check_range(0.5, range
) == TRUE
, "0.5 - alert");
92 ok( check_range(-10, range
) == FALSE
, "-10 - no alert");
93 ok( check_range(0, range
) == FALSE
, "0 - no alert");
96 range
= parse_range_string("@0:657.8210567");
97 ok( range
!= 0, "@0:657.8210567' is a valid range");
98 ok( range
->start
== 0, "Start correct");
99 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
100 ok( range
->end
== 657.8210567, "End correct");
101 ok( range
->end_infinity
== FALSE
, "Not using infinity");
102 ok( range
->alert_on
== INSIDE
, "Will alert on inside of this range" );
103 ok( check_range(32.88, range
) == TRUE
, "32.88 - alert");
104 ok( check_range(-2, range
) == FALSE
, "-2 - no alert");
105 ok( check_range(657.8210567, range
) == TRUE
, "657.8210567 - alert");
106 ok( check_range(0, range
) == TRUE
, "0 - alert");
109 range
= parse_range_string("1:1");
110 ok( range
!= NULL
, "'1:1' is a valid range");
111 ok( range
->start
== 1, "Start correct");
112 ok( range
->start_infinity
== FALSE
, "Not using negative infinity");
113 ok( range
->end
== 1, "End correct");
114 ok( range
->end_infinity
== FALSE
, "Not using infinity");
115 ok( check_range(0.5, range
) == TRUE
, "0.5 - alert");
116 ok( check_range(1, range
) == FALSE
, "1 - no alert");
117 ok( check_range(5.2, range
) == TRUE
, "5.2 - alert");
120 range
= parse_range_string("2:1");
121 ok( range
== NULL
, "'2:1' rejected");
123 rc
= _set_thresholds(&thresholds
, NULL
, NULL
);
124 ok( rc
== 0, "Thresholds (NULL, NULL) set");
125 ok( thresholds
->warning
== NULL
, "Warning not set");
126 ok( thresholds
->critical
== NULL
, "Critical not set");
128 rc
= _set_thresholds(&thresholds
, NULL
, "80");
129 ok( rc
== 0, "Thresholds (NULL, '80') set");
130 ok( thresholds
->warning
== NULL
, "Warning not set");
131 ok( thresholds
->critical
->end
== 80, "Critical set correctly");
133 rc
= _set_thresholds(&thresholds
, "5:33", NULL
);
134 ok( rc
== 0, "Thresholds ('5:33', NULL) set");
135 ok( thresholds
->warning
->start
== 5, "Warning start set");
136 ok( thresholds
->warning
->end
== 33, "Warning end set");
137 ok( thresholds
->critical
== NULL
, "Critical not set");
139 rc
= _set_thresholds(&thresholds
, "30", "60");
140 ok( rc
== 0, "Thresholds ('30', '60') set");
141 ok( thresholds
->warning
->end
== 30, "Warning set correctly");
142 ok( thresholds
->critical
->end
== 60, "Critical set correctly");
143 ok( get_status(15.3, thresholds
) == STATE_OK
, "15.3 - ok");
144 ok( get_status(30.0001, thresholds
) == STATE_WARNING
, "30.0001 - warning");
145 ok( get_status(69, thresholds
) == STATE_CRITICAL
, "69 - critical");
148 test
= np_escaped_string("bob\\n");
149 ok( strcmp(test
, "bob\n") == 0, "bob\\n ok");
152 test
= np_escaped_string("rhuba\\rb");
153 ok( strcmp(test
, "rhuba\rb") == 0, "rhuba\\rb okay");
156 test
= np_escaped_string("ba\\nge\\r");
157 ok( strcmp(test
, "ba\nge\r") == 0, "ba\\nge\\r okay");
160 test
= np_escaped_string("\\rabbi\\t");
161 ok( strcmp(test
, "\rabbi\t") == 0, "\\rabbi\\t okay");
164 test
= np_escaped_string("and\\\\or");
165 ok( strcmp(test
, "and\\or") == 0, "and\\\\or okay");
168 test
= np_escaped_string("bo\\gus");
169 ok( strcmp(test
, "bogus") == 0, "bo\\gus okay");
172 test
= np_escaped_string("everything");
173 ok( strcmp(test
, "everything") == 0, "everything okay");
176 test
= (char *)basename("/here/is/a/path");
177 ok( strcmp(test
, "path") == 0, "basename okay");
179 return exit_status();