forked from urbanserj/entente
-
Notifications
You must be signed in to change notification settings - Fork 1
/
log_test.c
59 lines (55 loc) · 1.7 KB
/
log_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Force DEBUG on so that tests can use assert(). */
#undef NDEBUG
#include <assert.h>
#include <stdio.h>
#include "log.h"
/* openlog() stub function for testing. */
void openlog(const char *ident, int option, int facility)
{
printf("log_test: openlog(\"%s\", %#x, %d)\n", ident, option, facility);
}
/* syslog() stub function for testing. */
void syslog(int priority, const char *format, ...)
{
printf("log_test: syslog(%d, \"%s\", ...)\n", priority, format);
}
/* setlogmask() stub function for testing. */
int setlogmask(int mask)
{
printf("log_test: setlogmask(%#x)\n", mask);
return LOG_UPTO(LOG_DEBUG);
}
int main(void)
{
/* Test default behaviour */
assert(log_level == LOG_DEBUG);
assert(log_func == errlog);
assert(log_prefix == log_prefix_color);
ldebug("something interesting");
linfo("something boring");
lnote("something important");
lwarn("something concerning");
lwarnx("something concerning");
/* Test syslog behavior */
log_init("test", 1, LOG_WARNING);
assert(log_level == LOG_WARNING);
assert(log_func == syslog);
assert(log_prefix == log_prefix_plain);
ldebug("something interesting");
linfo("something boring");
lnote("something important");
lwarn("something concerning");
lwarnx("something concerning");
/* Test errlog behaviour */
log_init("test", 0, LOG_ERR);
assert(log_level == LOG_ERR);
assert(log_func == errlog);
assert(log_prefix == log_prefix_color);
ldebug("something interesting");
linfo("something boring");
lnote("something important");
lwarn("something concerning");
lwarnx("something concerning");
lerr(0, "something scary");
lerrx(1, "lerr() failed to exit");
}