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.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/plugins/tests/test_utils.c b/plugins/tests/test_utils.c
new file mode 100644
index 0000000..1fda367
--- /dev/null
+++ b/plugins/tests/test_utils.c
@@ -0,0 +1,109 @@
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 threshold *range;
33 double temp;
34
35 plan_tests(40);
36
37 range = parse_threshold("6");
38 ok( range != NULL, "'6' is valid threshold");
39 ok( range->start == 0, "Start correct");
40 ok( range->start_infinity == FALSE, "Not using negative infinity");
41 ok( range->end == 6, "End correct");
42 ok( range->end_infinity == FALSE, "Not using infinity");
43 free(range);
44
45 range = parse_threshold("-7:23");
46 ok( range != NULL, "'-7:23' is valid threshold");
47 ok( range->start == -7, "Start correct");
48 ok( range->start_infinity == FALSE, "Not using negative infinity");
49 ok( range->end == 23, "End correct");
50 ok( range->end_infinity == FALSE, "Not using infinity");
51 free(range);
52
53 range = parse_threshold(":5.75");
54 ok( range != NULL, "':5.75' is valid threshold");
55 ok( range->start == 0, "Start correct");
56 ok( range->start_infinity == FALSE, "Not using negative infinity");
57 ok( range->end == 5.75, "End correct");
58 ok( range->end_infinity == FALSE, "Not using infinity");
59 free(range);
60
61 range = parse_threshold("~:-95.99");
62 ok( range != NULL, "~:-95.99' is valid threshold");
63 ok( range->start_infinity == TRUE, "Using negative infinity");
64 ok( range->end == -95.99, "End correct (with rounding errors)");
65 ok( range->end_infinity == FALSE, "Not using infinity");
66 free(range);
67
68 range = parse_threshold("12345678901234567890:");
69 temp = atof("12345678901234567890"); /* Can't just use this because number too large */
70 ok( range != NULL, "'12345678901234567890:' is valid threshold");
71 ok( range->start == temp, "Start correct");
72 ok( range->start_infinity == FALSE, "Not using negative infinity");
73 ok( range->end_infinity == TRUE, "Using infinity");
74 free(range);
75
76 range = parse_threshold("~:0");
77 ok( range != NULL, "'~:0' is valid threshold");
78 ok( range->start_infinity == TRUE, "Using negative infinity");
79 ok( range->end == 0, "End correct");
80 ok( range->end_infinity == FALSE, "Not using infinity");
81 ok( range->alert_on == OUTSIDE, "Will alert on outside of this range");
82 free(range);
83
84 range = parse_threshold("@0:657.8210567");
85 ok( range != 0, "@0:657.8210567' is a valid threshold");
86 ok( range->start == 0, "Start correct");
87 ok( range->start_infinity == FALSE, "Not using negative infinity");
88 ok( range->end == 657.8210567, "End correct");
89 ok( range->end_infinity == FALSE, "Not using infinity");
90 ok( range->alert_on == INSIDE, "Will alert on inside of this range" );
91 free(range);
92
93 range = parse_threshold("1:1");
94 ok( range != NULL, "'1:1' is a valid threshold");
95 ok( range->start == 1, "Start correct");
96 ok( range->start_infinity == FALSE, "Not using negative infinity");
97 ok( range->end == 1, "End correct");
98 ok( range->end_infinity == FALSE, "Not using infinity");
99 free(range);
100
101 range = parse_threshold("2:1");
102 ok( range == NULL, "''2:1' rejected");
103
104 return exit_status();
105}
106
107void print_usage() {
108 printf("Dummy");
109}