2 #include "nagios/objects.h"
3 #include "nagios/nagios.h"
4 #include "logutils.h" /* for colors */
5 #include "test_utils.h"
8 * These only exist so dt_depth_*() functions
9 * in utils.c can fail gracefully
11 host
*find_host(char *h
)
16 service
*find_service(char *h
, char *s
)
21 host
*host_list
= NULL
, *host_list_tail
= NULL
;
22 service
*service_list
= NULL
, *service_list_tail
= NULL
;
23 sched_info scheduling_info
= { 0 };
26 /* test helper functions */
27 const char *cyan
= "", *red
= "", *green
= "", *yellow
= "", *reset
= "";
28 uint passed
, failed
, t_verbose
= 0;
30 static const char *indent_str
= " ";
32 void t_set_colors(int force
)
34 if (force
== 1 || isatty(fileno(stdout
))) {
43 static void t_indent(int depth
)
46 for (i
= 0; i
< depth
; i
++) {
47 printf("%s", indent_str
);
51 void t_start(const char *fmt
, ...)
59 vfprintf(stdout
, fmt
, ap
);
68 if (!t_depth
|| failed
) {
70 printf("Test results: %s%u passed%s, %s%u failed%s\n",
71 green
, passed
, reset
, failed
? red
: "", failed
, failed
? reset
: "");
73 return failed
? EXIT_FAILURE
: EXIT_SUCCESS
;
76 void t_pass(const char *fmt
, ...)
84 printf("%sPASS%s ", green
, reset
);
86 vfprintf(stdout
, fmt
, ap
);
91 void t_fail(const char *fmt
, ...)
97 printf("%sFAIL%s ", red
, reset
);
99 vfprintf(stdout
, fmt
, ap
);
104 void t_diag(const char *fmt
, ...)
108 t_indent(t_depth
+ 1);
110 vfprintf(stdout
, fmt
, ap
);
116 int ok_int(int a
, int b
, const char *name
)
124 t_diag("%d != %d", a
, b
);
128 int ok_uint(uint a
, uint b
, const char *name
)
136 t_diag("%u != %d", a
, b
);
140 int ok_str(const char *a
, const char *b
, const char *name
)
142 if ((!a
&& !b
) || (a
&& b
&& !strcmp(a
, b
))) {
148 t_diag("'%s' != '%s'", a
, b
);