summaryrefslogtreecommitdiffstats
path: root/plugins/tests/test_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/tests/test_utils.c')
-rw-r--r--plugins/tests/test_utils.c176
1 files changed, 0 insertions, 176 deletions
diff --git a/plugins/tests/test_utils.c b/plugins/tests/test_utils.c
deleted file mode 100644
index 67c304a..0000000
--- a/plugins/tests/test_utils.c
+++ /dev/null
@@ -1,176 +0,0 @@
1/******************************************************************************
2
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 2 of the License, or
6 (at your option) any later version.
7
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.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
17 $Id$
18
19******************************************************************************/
20
21const char *progname = "utils";
22
23#include "common.h"
24#include "utils.h"
25#include "popen.h"
26
27#include "tap.h"
28
29int
30main (int argc, char **argv)
31{
32 range *range;
33 double temp;
34 thresholds *thresholds = NULL;
35 int rc;
36
37 plan_tests(74);
38
39 range = parse_range_string("6");
40 ok( range != NULL, "'6' is valid range");
41 ok( range->start == 0, "Start correct");
42 ok( range->start_infinity == FALSE, "Not using negative infinity");
43 ok( range->end == 6, "End correct");
44 ok( range->end_infinity == FALSE, "Not using infinity");
45 free(range);
46
47 range = parse_range_string("-7:23");
48 ok( range != NULL, "'-7:23' is valid range");
49 ok( range->start == -7, "Start correct");
50 ok( range->start_infinity == FALSE, "Not using negative infinity");
51 ok( range->end == 23, "End correct");
52 ok( range->end_infinity == FALSE, "Not using infinity");
53 free(range);
54
55 range = parse_range_string(":5.75");
56 ok( range != NULL, "':5.75' is valid range");
57 ok( range->start == 0, "Start correct");
58 ok( range->start_infinity == FALSE, "Not using negative infinity");
59 ok( range->end == 5.75, "End correct");
60 ok( range->end_infinity == FALSE, "Not using infinity");
61 free(range);
62
63 range = parse_range_string("~:-95.99");
64 ok( range != NULL, "~:-95.99' is valid range");
65 ok( range->start_infinity == TRUE, "Using negative infinity");
66 ok( range->end == -95.99, "End correct (with rounding errors)");
67 ok( range->end_infinity == FALSE, "Not using infinity");
68 free(range);
69
70 range = parse_range_string("12345678901234567890:");
71 temp = atof("12345678901234567890"); /* Can't just use this because number too large */
72 ok( range != NULL, "'12345678901234567890:' is valid range");
73 ok( range->start == temp, "Start correct");
74 ok( range->start_infinity == FALSE, "Not using negative infinity");
75 ok( range->end_infinity == TRUE, "Using infinity");
76 /* Cannot do a "-1" on temp, as it appears to be same value */
77 ok( check_range(temp/1.1, range) == TRUE, "12345678901234567890/1.1 - alert");
78 ok( check_range(temp, range) == FALSE, "12345678901234567890 - no alert");
79 ok( check_range(temp*2, range) == FALSE, "12345678901234567890*2 - no alert");
80 free(range);
81
82 range = parse_range_string("~:0");
83 ok( range != NULL, "'~:0' is valid range");
84 ok( range->start_infinity == TRUE, "Using negative infinity");
85 ok( range->end == 0, "End correct");
86 ok( range->end_infinity == FALSE, "Not using infinity");
87 ok( range->alert_on == OUTSIDE, "Will alert on outside of this range");
88 ok( check_range(0.5, range) == TRUE, "0.5 - alert");
89 ok( check_range(-10, range) == FALSE, "-10 - no alert");
90 ok( check_range(0, range) == FALSE, "0 - no alert");
91 free(range);
92
93 range = parse_range_string("@0:657.8210567");
94 ok( range != 0, "@0:657.8210567' is a valid range");
95 ok( range->start == 0, "Start correct");
96 ok( range->start_infinity == FALSE, "Not using negative infinity");
97 ok( range->end == 657.8210567, "End correct");
98 ok( range->end_infinity == FALSE, "Not using infinity");
99 ok( range->alert_on == INSIDE, "Will alert on inside of this range" );
100 ok( check_range(32.88, range) == TRUE, "32.88 - alert");
101 ok( check_range(-2, range) == FALSE, "-2 - no alert");
102 ok( check_range(657.8210567, range) == TRUE, "657.8210567 - alert");
103 ok( check_range(0, range) == TRUE, "0 - alert");
104 free(range);
105
106 range = parse_range_string("1:1");
107 ok( range != NULL, "'1:1' is a valid range");
108 ok( range->start == 1, "Start correct");
109 ok( range->start_infinity == FALSE, "Not using negative infinity");
110 ok( range->end == 1, "End correct");
111 ok( range->end_infinity == FALSE, "Not using infinity");
112 ok( check_range(0.5, range) == TRUE, "0.5 - alert");
113 ok( check_range(1, range) == FALSE, "1 - no alert");
114 ok( check_range(5.2, range) == TRUE, "5.2 - alert");
115 free(range);
116
117 range = parse_range_string("2:1");
118 ok( range == NULL, "'2:1' rejected");
119
120 rc = _set_thresholds(&thresholds, NULL, "80");
121 ok( rc == 0, "Thresholds (NULL, '80') set");
122 ok( thresholds->warning == NULL, "Warning not set");
123 ok( thresholds->critical->end == 80, "Critical set correctly");
124
125 rc = _set_thresholds(&thresholds, "5:33", NULL);
126 ok( rc == 0, "Thresholds ('5:33', NULL) set");
127 ok( thresholds->warning->start == 5, "Warning start set");
128 ok( thresholds->warning->end == 33, "Warning end set");
129 ok( thresholds->critical == NULL, "Critical not set");
130
131 rc = _set_thresholds(&thresholds, "30", "60");
132 ok( rc == 0, "Thresholds ('30', '60') set");
133 ok( thresholds->warning->end == 30, "Warning set correctly");
134 ok( thresholds->critical->end == 60, "Critical set correctly");
135 ok( get_status(15.3, thresholds) == STATE_OK, "15.3 - ok");
136 ok( get_status(30.0001, thresholds) == STATE_WARNING, "30.0001 - warning");
137 ok( get_status(69, thresholds) == STATE_CRITICAL, "69 - critical");
138
139 char *test;
140 test = np_escaped_string("bob\\n");
141 ok( strcmp(test, "bob\n") == 0, "bob\\n ok");
142 free(test);
143
144 test = np_escaped_string("rhuba\\rb");
145 ok( strcmp(test, "rhuba\rb") == 0, "rhuba\\rb okay");
146 free(test);
147
148 test = np_escaped_string("ba\\nge\\r");
149 ok( strcmp(test, "ba\nge\r") == 0, "ba\\nge\\r okay");
150 free(test);
151
152 test = np_escaped_string("\\rabbi\\t");
153 ok( strcmp(test, "\rabbi\t") == 0, "\\rabbi\\t okay");
154 free(test);
155
156 test = np_escaped_string("and\\\\or");
157 ok( strcmp(test, "and\\or") == 0, "and\\\\or okay");
158 free(test);
159
160 test = np_escaped_string("bo\\gus");
161 ok( strcmp(test, "bogus") == 0, "bo\\gus okay");
162 free(test);
163
164 test = np_escaped_string("everything");
165 ok( strcmp(test, "everything") == 0, "everything okay");
166 free(test);
167
168 test = basename("/here/is/a/path");
169 ok( strcmp(test, "path") == 0, "basename okay");
170
171 return exit_status();
172}
173
174void print_usage() {
175 printf("Dummy");
176}