3 no warnings qw(redefine once);
5 use subs qw(exit print);
8 use Test::More tests => 33;
14 require './l7directord';
17 our $ld_log_called = 0;
20 open *STDOUT, '>', '/dev/null';
22 open *STDERR, '>', '/dev/null';
24 #...............................................
28 local *ld_log = \&__ld_log;
29 my $got = ld_openlog();
30 is $got, 1, 'ld_openlog - log_config is undef';
33 local *ld_log = \&__ld_log;
34 local $main::DEBUG_LEVEL = 1;
35 my $got = ld_openlog('logfile');
36 is $got, 0, 'ld_openlog - debug mode';
39 local *ld_log = \&__ld_log;
40 local $main::CONFIG{supervised} = 1;
41 my $got = ld_openlog('logfile');
42 is $got, 0, 'ld_openlog - supervised mode';
45 local *ld_log = \&__ld_log;
46 my $log_config = '/tmp/' . time;
47 my $got = ld_openlog($log_config);
48 is $got, 0, 'ld_openlog - open normal logfile';
52 local *ld_log = \&__ld_log;
53 my $log_config = '/tmp';
54 my $got = ld_openlog($log_config);
55 is $got, 1, 'ld_openlog - cannot open normal logfile';
58 local *ld_log = \&__ld_log;
59 my $log_config = 'local0';
60 my $got = ld_openlog($log_config);
61 is $got, 0, 'ld_openlog - open syslog';
65 skip 'aboid logging', 1;
67 is $got, 1, 'ld_log - message is undef';
70 local $main::PROC_STAT{pid} = 12345;
71 local $main::CONFIG{logfile} = '/tmp/' . time;
72 my $got = ld_log('test');
73 is $got, 0, 'ld_log - write message to logfile';
74 unlink $main::CONFIG{logfile};
77 local $main::PROC_STAT{pid} = 12345;
78 local $main::CONFIG{logfile} = '/tmp';
79 my $got = ld_log('test');
80 is $got, 1, 'ld_log - cannot write message to logfile';
83 local $main::PROC_STAT{pid} = 12345;
84 local $main::CONFIG{logfile} = 'local0';
85 my $got = ld_log('test');
86 is $got, 0, 'ld_log - write message to syslog';
89 local $main::CONFIG{supervised} = 1;
90 local $main::PROC_STAT{pid} = 12345;
91 local $main::CONFIG{logfile} = 'local0';
92 my $got = ld_log('test');
93 is $got, 0, 'ld_log - write message to stderr(supervised mode)';
97 local *ld_log = \&__ld_log;
99 pass 'ld_debug - args is undef';
102 local *ld_log = \&__ld_log;
103 ld_debug(undef, 'test');
104 pass 'ld_debug - priority is undef';
107 local *ld_log = \&__ld_log;
108 ld_debug('fatal', 'test');
109 pass 'ld_debug - priority is string';
112 local *ld_log = \&__ld_log;
114 pass 'ld_debug - message is undef';
117 local *ld_log = \&__ld_log;
118 local $main::DEBUG_LEVEL = 10;
119 ld_debug(3, 'debug');
120 pass 'ld_debug - priority and message is ok';
124 local *ld_log = \&__ld_log;
125 local $main::DEBUG_LEVEL = 0;
126 local $ld_log_called = 0;
128 is $ld_log_called, 0, 'ld_exit - args is undef';
131 local *ld_log = \&__ld_log;
132 local $main::DEBUG_LEVEL = 0;
133 local $ld_log_called = 0;
134 ld_exit(undef, 'exit');
135 is $ld_log_called, 0, 'ld_exit - status is undef';
138 local *ld_log = \&__ld_log;
139 local $main::DEBUG_LEVEL = 0;
140 local $ld_log_called = 0;
142 is $ld_log_called, 0, 'ld_exit - message is undef';
145 local *ld_log = \&__ld_log;
146 local $main::DEBUG_LEVEL = 0;
147 local $ld_log_called = 0;
149 is $ld_log_called, 1, 'ld_exit - status is 0 (normal exit)';
152 local *ld_log = \&__ld_log;
153 local $main::DEBUG_LEVEL = 3;
154 local $ld_log_called = 0;
156 is $ld_log_called, 1, 'ld_exit - debug enable';
159 local *ld_log = \&__ld_log;
160 local $main::DEBUG_LEVEL = 0;
161 local $ld_log_called = 0;
163 is $ld_log_called, 1, 'ld_exit - status is 1 (some error)';
167 local *ld_log = \&__ld_log;
168 local *ld_exit = \&__ld_exit;
169 local $main::DEBUG_LEVEL = 0;
170 local $ld_log_called = 0;
172 is $ld_log_called, 0, 'init_error - message is undef';
175 local *ld_log = \&__ld_log;
176 local *ld_exit = \&__ld_exit;
177 local $main::DEBUG_LEVEL = 0;
178 local $ld_log_called = 0;
179 init_error('init error');
180 is $ld_log_called, 1, 'init_error - no debug';
183 local *ld_log = \&__ld_log;
184 local *ld_exit = \&__ld_exit;
185 local $main::DEBUG_LEVEL = 1;
186 local $ld_log_called = 0;
187 init_error('init error');
188 is $ld_log_called, 1, 'init_error - debug mode';
192 local *ld_log = \&__ld_log;
193 local *ld_exit = \&__ld_exit;
194 local $main::CONFIG_FILE{path} = 'filepath';
195 local $main::PROC_STAT{initialized} = 1;
196 local $main::DEBUG_LEVEL = 1;
197 local $ld_log_called = 0;
198 eval { config_error(1, 'WRN0004'); };
199 is $ld_log_called, 0, 'config_error - debug mode';
200 ok $@, 'config_error - initialized and died';
203 local *ld_log = \&__ld_log;
204 local *ld_exit = \&__ld_exit;
205 local $main::CONFIG_FILE{path} = 'filepath';
206 local $main::PROC_STAT{initialized} = 0;
207 local $main::DEBUG_LEVEL = 1;
208 local $ld_log_called = 0;
209 eval { config_error(1, 'WRN0004'); };
210 is $ld_log_called, 0, 'config_error - debug mode';
211 is $@, '', 'config_error - not initialized exit';
214 local *ld_log = \&__ld_log;
215 local *ld_exit = \&__ld_exit;
216 local $main::CONFIG_FILE{path} = 'filepath';
217 local $main::PROC_STAT{initialized} = 1;
218 local $main::DEBUG_LEVEL = 0;
219 local $ld_log_called = 0;
220 eval { config_error(0, 'WRN0004'); };
221 is $ld_log_called, 1, 'config_error - no debug mode and line is 0';
222 ok $@, 'config_error - initialized and died';
225 local *ld_log = \&__ld_log;
226 local *ld_exit = \&__ld_exit;
227 local $main::CONFIG_FILE{path} = 'filepath';
228 local $main::PROC_STAT{initialized} = 1;
229 local $main::DEBUG_LEVEL = 0;
230 local $ld_log_called = 0;
231 eval { config_error(1, 'WRN0004'); };
232 is $ld_log_called, 2, 'config_error - no debug mode and line is 1';
233 ok $@, 'config_error - initialized and died';
236 #...............................................