1 #include <stdio.h>
2 #include <string.h> /* memset */
3 #include <stdlib.h> /* mktemp */
4
5 #include <fcntl.h> /* O_RDONLY */
6
7 #include <libwzd-core/wzd_structs.h>
8 #include <libwzd-core/wzd_log.h>
9
10 #include <libwzd-core/wzd_debug.h>
11
12 #define C1 0x12345678
13 #define C2 0x9abcdef0
14
main(int argc,char * argv[])15 int main(int argc, char *argv[])
16 {
17 unsigned long c1 = C1;
18 int ret;
19 char template[] = "/tmp/wzd-XXXXXX";
20 int fd;
21 unsigned long c2 = C2;
22
23 wzd_debug_init();
24
25 ret = log_init();
26 if (ret != 0) { fprintf(stderr,"log_init() failed\n"); return 2; }
27
28 log_get(MAX_LOG_CHANNELS+1);
29 log_get(0);
30
31 /* only generate a temporary name, we will create the file */
32 ret = mkstemp(template);
33 if (ret == -1) {
34 fprintf(stderr,"Could not obtain a temp file using mkstemp(), aborting test\n");
35 return -1;
36 }
37 close(ret);
38 unlink(template);
39
40 fd = log_open(template,O_CREAT|O_EXCL|O_RDWR);
41 if (fd < 0) { fprintf(stderr,"log_open(%s) failed\n",template); return 3; }
42
43 if (log_set(RESERVED_LOG_CHANNELS+1,fd)!=0) {
44 fprintf(stderr,"log_set(%d,%d) failed\n",RESERVED_LOG_CHANNELS+1,fd);
45 log_close(fd);
46 unlink(template);
47 return 4;
48 }
49
50 ret = log_get(RESERVED_LOG_CHANNELS+1);
51 if (ret != fd) {
52 fprintf(stderr,"log_get(%d) == %d failed\n",RESERVED_LOG_CHANNELS+1,fd);
53 log_close(fd);
54 unlink(template);
55 return 5;
56 }
57
58 out_log(RESERVED_LOG_CHANNELS+1,"test format %d %s\n",123,"hello");
59
60 log_set(LEVEL_NORMAL,fd);
61 log_message("DEBUG","test 2 format %d %s",123,"hello");
62
63
64
65
66
67 log_close(fd);
68 /*unlink(template);*/
69
70 wzd_debug_fini();
71
72 if (c1 != C1) {
73 fprintf(stderr, "c1 nuked !\n");
74 return -1;
75 }
76 if (c2 != C2) {
77 fprintf(stderr, "c2 nuked !\n");
78 return -1;
79 }
80
81 return 0;
82 }
83