3 no warnings qw(redefine once);
5 use subs qw(exit print);
8 use Test::More tests => 33;
12 require './l7directord';
15 our $ld_log_called = 0;
18 open *STDOUT, '>', '/dev/null';
20 open *STDERR, '>', '/dev/null';
22 #...............................................
26 local *ld_log = \&__ld_log;
27 my $got = ld_openlog();
28 is $got, 1, 'ld_openlog - log_config is undef';
31 local *ld_log = \&__ld_log;
32 local $main::DEBUG_LEVEL = 1;
33 my $got = ld_openlog('logfile');
34 is $got, 0, 'ld_openlog - debug mode';
37 local *ld_log = \&__ld_log;
38 local $main::CONFIG{supervised} = 1;
39 my $got = ld_openlog('logfile');
40 is $got, 0, 'ld_openlog - supervised mode';
43 local *ld_log = \&__ld_log;
44 my $log_config = '/tmp/' . time;
45 my $got = ld_openlog($log_config);
46 is $got, 0, 'ld_openlog - open normal logfile';
50 local *ld_log = \&__ld_log;
51 my $log_config = '/tmp';
52 my $got = ld_openlog($log_config);
53 is $got, 1, 'ld_openlog - cannot open normal logfile';
56 local *ld_log = \&__ld_log;
57 my $log_config = 'local0';
58 my $got = ld_openlog($log_config);
59 is $got, 0, 'ld_openlog - open syslog';
63 skip 'aboid logging', 1;
65 is $got, 1, 'ld_log - message is undef';
68 local $main::PROC_STAT{pid} = 12345;
69 local $main::CONFIG{logfile} = '/tmp/' . time;
70 my $got = ld_log('test');
71 is $got, 0, 'ld_log - write message to logfile';
72 unlink $main::CONFIG{logfile};
75 local $main::PROC_STAT{pid} = 12345;
76 local $main::CONFIG{logfile} = '/tmp';
77 my $got = ld_log('test');
78 is $got, 1, 'ld_log - cannot write message to logfile';
81 local $main::PROC_STAT{pid} = 12345;
82 local $main::CONFIG{logfile} = 'local0';
83 my $got = ld_log('test');
84 is $got, 0, 'ld_log - write message to syslog';
87 local $main::CONFIG{supervised} = 1;
88 local $main::PROC_STAT{pid} = 12345;
89 local $main::CONFIG{logfile} = 'local0';
90 my $got = ld_log('test');
91 is $got, 0, 'ld_log - write message to stderr(supervised mode)';
95 local *ld_log = \&__ld_log;
97 pass 'ld_debug - args is undef';
100 local *ld_log = \&__ld_log;
101 ld_debug(undef, 'test');
102 pass 'ld_debug - priority is undef';
105 local *ld_log = \&__ld_log;
106 ld_debug('fatal', 'test');
107 pass 'ld_debug - priority is string';
110 local *ld_log = \&__ld_log;
112 pass 'ld_debug - message is undef';
115 local *ld_log = \&__ld_log;
116 local $main::DEBUG_LEVEL = 10;
117 ld_debug(3, 'debug');
118 pass 'ld_debug - priority and message is ok';
122 local *ld_log = \&__ld_log;
123 local $main::DEBUG_LEVEL = 0;
124 local $ld_log_called = 0;
126 is $ld_log_called, 0, 'ld_exit - args is undef';
129 local *ld_log = \&__ld_log;
130 local $main::DEBUG_LEVEL = 0;
131 local $ld_log_called = 0;
132 ld_exit(undef, 'exit');
133 is $ld_log_called, 0, 'ld_exit - status is undef';
136 local *ld_log = \&__ld_log;
137 local $main::DEBUG_LEVEL = 0;
138 local $ld_log_called = 0;
140 is $ld_log_called, 0, 'ld_exit - message is undef';
143 local *ld_log = \&__ld_log;
144 local $main::DEBUG_LEVEL = 0;
145 local $ld_log_called = 0;
147 is $ld_log_called, 1, 'ld_exit - status is 0 (normal exit)';
150 local *ld_log = \&__ld_log;
151 local $main::DEBUG_LEVEL = 3;
152 local $ld_log_called = 0;
154 is $ld_log_called, 1, 'ld_exit - debug enable';
157 local *ld_log = \&__ld_log;
158 local $main::DEBUG_LEVEL = 0;
159 local $ld_log_called = 0;
161 is $ld_log_called, 1, 'ld_exit - status is 1 (some error)';
165 local *ld_log = \&__ld_log;
166 local *ld_exit = \&__ld_exit;
167 local $main::DEBUG_LEVEL = 0;
168 local $ld_log_called = 0;
170 is $ld_log_called, 0, 'init_error - message is undef';
173 local *ld_log = \&__ld_log;
174 local *ld_exit = \&__ld_exit;
175 local $main::DEBUG_LEVEL = 0;
176 local $ld_log_called = 0;
177 init_error('init error');
178 is $ld_log_called, 1, 'init_error - no debug';
181 local *ld_log = \&__ld_log;
182 local *ld_exit = \&__ld_exit;
183 local $main::DEBUG_LEVEL = 1;
184 local $ld_log_called = 0;
185 init_error('init error');
186 is $ld_log_called, 1, 'init_error - debug mode';
190 local *ld_log = \&__ld_log;
191 local *ld_exit = \&__ld_exit;
192 local $main::CONFIG_FILE{path} = 'filepath';
193 local $main::PROC_STAT{initialized} = 1;
194 local $main::DEBUG_LEVEL = 1;
195 local $ld_log_called = 0;
196 eval { config_error(1, 'WRN0004'); };
197 is $ld_log_called, 0, 'config_error - debug mode';
198 ok $@, 'config_error - initialized and died';
201 local *ld_log = \&__ld_log;
202 local *ld_exit = \&__ld_exit;
203 local $main::CONFIG_FILE{path} = 'filepath';
204 local $main::PROC_STAT{initialized} = 0;
205 local $main::DEBUG_LEVEL = 1;
206 local $ld_log_called = 0;
207 eval { config_error(1, 'WRN0004'); };
208 is $ld_log_called, 0, 'config_error - debug mode';
209 is $@, '', 'config_error - not initialized exit';
212 local *ld_log = \&__ld_log;
213 local *ld_exit = \&__ld_exit;
214 local $main::CONFIG_FILE{path} = 'filepath';
215 local $main::PROC_STAT{initialized} = 1;
216 local $main::DEBUG_LEVEL = 0;
217 local $ld_log_called = 0;
218 eval { config_error(0, 'WRN0004'); };
219 is $ld_log_called, 1, 'config_error - no debug mode and line is 0';
220 ok $@, 'config_error - initialized and died';
223 local *ld_log = \&__ld_log;
224 local *ld_exit = \&__ld_exit;
225 local $main::CONFIG_FILE{path} = 'filepath';
226 local $main::PROC_STAT{initialized} = 1;
227 local $main::DEBUG_LEVEL = 0;
228 local $ld_log_called = 0;
229 eval { config_error(1, 'WRN0004'); };
230 is $ld_log_called, 2, 'config_error - no debug mode and line is 1';
231 ok $@, 'config_error - initialized and died';
234 #...............................................