1 /*****************************************************************************
2  *
3  * test_timeperiod.c - Test timeperiod
4  *
5  * Program: Nagios Core Testing
6  * License: GPL
7  * Copyright (c) 2009 Nagios Core Development Team and Community Contributors
8  * Copyright (c) 1999-2009 Ethan Galstad
9  *
10  * First Written:   10-08-2009, based on nagios.c
11  * Last Modified:   10-08-2009
12  *
13  * Description:
14  *
15  * Tests Nagios configuration loading
16  *
17  * License:
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License version 2 as
21  * published by the Free Software Foundation.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31  *
32  *****************************************************************************/
33 
34 #include "../include/config.h"
35 #include "../include/common.h"
36 #include "../include/objects.h"
37 #include "../include/comments.h"
38 #include "../include/downtime.h"
39 #include "../include/statusdata.h"
40 #include "../include/macros.h"
41 #include "../include/nagios.h"
42 #include "../include/sretention.h"
43 #include "../include/perfdata.h"
44 #include "../include/broker.h"
45 #include "../include/nebmods.h"
46 #include "../include/nebmodules.h"
47 #include "tap.h"
48 
49 char		*config_file = NULL;
50 char		*log_file = NULL;
51 char            *command_file = NULL;
52 char            *temp_file = NULL;
53 char            *temp_path = NULL;
54 char            *check_result_path = NULL;
55 char            *lock_file = NULL;
56 char            *log_archive_path = NULL;
57 char            *p1_file = NULL;  /**** EMBEDDED PERL ****/
58 char            *auth_file = NULL; /**** EMBEDDED PERL INTERPRETER AUTH FILE ****/
59 char            *nagios_user = NULL;
60 char            *nagios_group = NULL;
61 
62 extern char     *macro_x[MACRO_X_COUNT];
63 
64 char            *global_host_event_handler = NULL;
65 char            *global_service_event_handler = NULL;
66 command         *global_host_event_handler_ptr = NULL;
67 command         *global_service_event_handler_ptr = NULL;
68 
69 char            *ocsp_command = NULL;
70 char            *ochp_command = NULL;
71 command         *ocsp_command_ptr = NULL;
72 command         *ochp_command_ptr = NULL;
73 
74 char            *illegal_object_chars = NULL;
75 char            *illegal_output_chars = NULL;
76 
77 int             use_regexp_matches = FALSE;
78 int             use_true_regexp_matching = FALSE;
79 
80 int		use_syslog = DEFAULT_USE_SYSLOG;
81 int             log_notifications = DEFAULT_NOTIFICATION_LOGGING;
82 int             log_service_retries = DEFAULT_LOG_SERVICE_RETRIES;
83 int             log_host_retries = DEFAULT_LOG_HOST_RETRIES;
84 int             log_event_handlers = DEFAULT_LOG_EVENT_HANDLERS;
85 int             log_initial_states = DEFAULT_LOG_INITIAL_STATES;
86 int             log_external_commands = DEFAULT_LOG_EXTERNAL_COMMANDS;
87 int             log_passive_checks = DEFAULT_LOG_PASSIVE_CHECKS;
88 
89 unsigned long   logging_options = 0;
90 unsigned long   syslog_options = 0;
91 
92 int             service_check_timeout = DEFAULT_SERVICE_CHECK_TIMEOUT;
93 int             host_check_timeout = DEFAULT_HOST_CHECK_TIMEOUT;
94 int             event_handler_timeout = DEFAULT_EVENT_HANDLER_TIMEOUT;
95 int             notification_timeout = DEFAULT_NOTIFICATION_TIMEOUT;
96 int             ocsp_timeout = DEFAULT_OCSP_TIMEOUT;
97 int             ochp_timeout = DEFAULT_OCHP_TIMEOUT;
98 
99 double          sleep_time = DEFAULT_SLEEP_TIME;
100 int             interval_length = DEFAULT_INTERVAL_LENGTH;
101 int             service_inter_check_delay_method = ICD_SMART;
102 int             host_inter_check_delay_method = ICD_SMART;
103 int             service_interleave_factor_method = ILF_SMART;
104 int             max_host_check_spread = DEFAULT_HOST_CHECK_SPREAD;
105 int             max_service_check_spread = DEFAULT_SERVICE_CHECK_SPREAD;
106 
107 int             command_check_interval = DEFAULT_COMMAND_CHECK_INTERVAL;
108 int             check_reaper_interval = DEFAULT_CHECK_REAPER_INTERVAL;
109 int             max_check_reaper_time = DEFAULT_MAX_REAPER_TIME;
110 int             service_freshness_check_interval = DEFAULT_FRESHNESS_CHECK_INTERVAL;
111 int             host_freshness_check_interval = DEFAULT_FRESHNESS_CHECK_INTERVAL;
112 int             auto_rescheduling_interval = DEFAULT_AUTO_RESCHEDULING_INTERVAL;
113 
114 int             check_external_commands = DEFAULT_CHECK_EXTERNAL_COMMANDS;
115 int             check_orphaned_services = DEFAULT_CHECK_ORPHANED_SERVICES;
116 int             check_orphaned_hosts = DEFAULT_CHECK_ORPHANED_HOSTS;
117 int             check_service_freshness = DEFAULT_CHECK_SERVICE_FRESHNESS;
118 int             check_host_freshness = DEFAULT_CHECK_HOST_FRESHNESS;
119 int             auto_reschedule_checks = DEFAULT_AUTO_RESCHEDULE_CHECKS;
120 int             auto_rescheduling_window = DEFAULT_AUTO_RESCHEDULING_WINDOW;
121 
122 int             additional_freshness_latency = DEFAULT_ADDITIONAL_FRESHNESS_LATENCY;
123 int             allow_empty_hostgroup_assignment = DEFAULT_ALLOW_EMPTY_HOSTGROUP_ASSIGNMENT;
124 
125 int             check_for_updates = DEFAULT_CHECK_FOR_UPDATES;
126 int             bare_update_check = DEFAULT_BARE_UPDATE_CHECK;
127 time_t          last_update_check = 0L;
128 int             update_available = FALSE;
129 char            *last_program_version = NULL;
130 char            *new_program_version = NULL;
131 
132 time_t          last_command_check = 0L;
133 time_t          last_command_status_update = 0L;
134 time_t          last_log_rotation = 0L;
135 
136 int             use_aggressive_host_checking = DEFAULT_AGGRESSIVE_HOST_CHECKING;
137 unsigned long   cached_host_check_horizon = DEFAULT_CACHED_HOST_CHECK_HORIZON;
138 unsigned long   cached_service_check_horizon = DEFAULT_CACHED_SERVICE_CHECK_HORIZON;
139 int             enable_predictive_host_dependency_checks = DEFAULT_ENABLE_PREDICTIVE_HOST_DEPENDENCY_CHECKS;
140 int             enable_predictive_service_dependency_checks = DEFAULT_ENABLE_PREDICTIVE_SERVICE_DEPENDENCY_CHECKS;
141 
142 int             soft_state_dependencies = FALSE;
143 
144 int             retain_state_information = FALSE;
145 int             retention_update_interval = DEFAULT_RETENTION_UPDATE_INTERVAL;
146 int             use_retained_program_state = TRUE;
147 int             use_retained_scheduling_info = FALSE;
148 int             retention_scheduling_horizon = DEFAULT_RETENTION_SCHEDULING_HORIZON;
149 unsigned long   modified_host_process_attributes = MODATTR_NONE;
150 unsigned long   modified_service_process_attributes = MODATTR_NONE;
151 unsigned long   retained_host_attribute_mask = 0L;
152 unsigned long   retained_service_attribute_mask = 0L;
153 unsigned long   retained_contact_host_attribute_mask = 0L;
154 unsigned long   retained_contact_service_attribute_mask = 0L;
155 unsigned long   retained_process_host_attribute_mask = 0L;
156 unsigned long   retained_process_service_attribute_mask = 0L;
157 
158 unsigned long   next_comment_id = 0L;
159 unsigned long   next_downtime_id = 0L;
160 unsigned long   next_event_id = 0L;
161 unsigned long   next_problem_id = 0L;
162 unsigned long   next_notification_id = 0L;
163 
164 int             log_rotation_method = LOG_ROTATION_NONE;
165 
166 int             sigshutdown = FALSE;
167 int             sigrestart = FALSE;
168 char            *sigs[35] = {"EXIT", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "BUS", "FPE", "KILL", "USR1", "SEGV", "USR2", "PIPE", "ALRM", "TERM", "STKFLT", "CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU", "URG", "XCPU", "XFSZ", "VTALRM", "PROF", "WINCH", "IO", "PWR", "UNUSED", "ZERR", "DEBUG", (char *)NULL};
169 int             caught_signal = FALSE;
170 int             sig_id = 0;
171 
172 int             restarting = FALSE;
173 
174 int             verify_config = FALSE;
175 int             verify_object_relationships = TRUE;
176 int             verify_circular_paths = TRUE;
177 int             test_scheduling = FALSE;
178 int             precache_objects = FALSE;
179 int             use_precached_objects = FALSE;
180 
181 int             daemon_mode = FALSE;
182 int             daemon_dumps_core = TRUE;
183 
184 int             max_parallel_service_checks = DEFAULT_MAX_PARALLEL_SERVICE_CHECKS;
185 int             currently_running_service_checks = 0;
186 int             currently_running_host_checks = 0;
187 
188 time_t          program_start = 0L;
189 time_t          event_start = 0L;
190 int             nagios_pid = 0;
191 int             enable_notifications = TRUE;
192 int             execute_service_checks = TRUE;
193 int             accept_passive_service_checks = TRUE;
194 int             execute_host_checks = TRUE;
195 int             accept_passive_host_checks = TRUE;
196 int             enable_event_handlers = TRUE;
197 int             obsess_over_services = FALSE;
198 int             obsess_over_hosts = FALSE;
199 int             enable_failure_prediction = TRUE;
200 
201 int             translate_passive_host_checks = DEFAULT_TRANSLATE_PASSIVE_HOST_CHECKS;
202 int             passive_host_checks_are_soft = DEFAULT_PASSIVE_HOST_CHECKS_SOFT;
203 
204 int             aggregate_status_updates = TRUE;
205 int             status_update_interval = DEFAULT_STATUS_UPDATE_INTERVAL;
206 
207 int             time_change_threshold = DEFAULT_TIME_CHANGE_THRESHOLD;
208 
209 unsigned long   event_broker_options = BROKER_NOTHING;
210 
211 int             process_performance_data = DEFAULT_PROCESS_PERFORMANCE_DATA;
212 
213 int             enable_flap_detection = DEFAULT_ENABLE_FLAP_DETECTION;
214 
215 double          low_service_flap_threshold = DEFAULT_LOW_SERVICE_FLAP_THRESHOLD;
216 double          high_service_flap_threshold = DEFAULT_HIGH_SERVICE_FLAP_THRESHOLD;
217 double          low_host_flap_threshold = DEFAULT_LOW_HOST_FLAP_THRESHOLD;
218 double          high_host_flap_threshold = DEFAULT_HIGH_HOST_FLAP_THRESHOLD;
219 
220 int             use_large_installation_tweaks = DEFAULT_USE_LARGE_INSTALLATION_TWEAKS;
221 int             enable_environment_macros = TRUE;
222 int             free_child_process_memory = -1;
223 int             child_processes_fork_twice = -1;
224 
225 int             enable_embedded_perl = DEFAULT_ENABLE_EMBEDDED_PERL;
226 int             use_embedded_perl_implicitly = DEFAULT_USE_EMBEDDED_PERL_IMPLICITLY;
227 int             embedded_perl_initialized = FALSE;
228 
229 int             date_format = DATE_FORMAT_US;
230 char            *use_timezone = NULL;
231 
232 int             command_file_fd;
233 FILE            *command_file_fp;
234 int             command_file_created = FALSE;
235 unsigned long   update_uid = 0L;
236 
237 
238 extern contact	       *contact_list;
239 extern contactgroup    *contactgroup_list;
240 extern hostgroup       *hostgroup_list;
241 extern command         *command_list;
242 extern timeperiod      *timeperiod_list;
243 extern serviceescalation *serviceescalation_list;
244 extern host 		*host_list;
245 
246 notification    *notification_list;
247 
248 check_result    check_result_info;
249 check_result    *check_result_list = NULL;
250 unsigned long	max_check_result_file_age = DEFAULT_MAX_CHECK_RESULT_AGE;
251 
252 dbuf            check_result_dbuf;
253 
254 circular_buffer external_command_buffer;
255 circular_buffer check_result_buffer;
256 pthread_t       worker_threads[TOTAL_WORKER_THREADS];
257 int             external_command_buffer_slots = DEFAULT_EXTERNAL_COMMAND_BUFFER_SLOTS;
258 
259 check_stats     check_statistics[MAX_CHECK_STATS_TYPES];
260 
261 char            *debug_file;
262 int             debug_level = DEFAULT_DEBUG_LEVEL;
263 int             debug_verbosity = DEFAULT_DEBUG_VERBOSITY;
264 unsigned long   max_debug_file_size = DEFAULT_MAX_DEBUG_FILE_SIZE;
265 
266 
267 /* Dummy variables */
268 sched_info scheduling_info;
269 timed_event event_list_low;
270 timed_event event_list_high;
271 
272 /* Dummy functions */
logit(int data_type,int display,const char * fmt,...)273 void logit(int data_type, int display, const char *fmt, ...) {}
my_sendall(int s,char * buf,int * len,int timeout)274 int my_sendall(int s, char *buf, int *len, int timeout) {}
free_comment_data(void)275 void free_comment_data(void) {}
write_to_log(char * buffer,unsigned long data_type,time_t * timestamp)276 int write_to_log(char *buffer, unsigned long data_type, time_t *timestamp) {}
log_debug_info(int level,int verbosity,const char * fmt,...)277 int log_debug_info(int level, int verbosity, const char *fmt, ...) {}
278 
neb_free_callback_list(void)279 int neb_free_callback_list(void) {}
broker_program_status(int type,int flags,int attr,struct timeval * timestamp)280 void broker_program_status(int type, int flags, int attr, struct timeval *timestamp) {}
neb_deinit_modules(void)281 int neb_deinit_modules(void) {}
broker_program_state(int type,int flags,int attr,struct timeval * timestamp)282 void broker_program_state(int type, int flags, int attr, struct timeval *timestamp) {}
broker_comment_data(int type,int flags,int attr,int comment_type,int entry_type,char * host_name,char * svc_description,time_t entry_time,char * author_name,char * comment_data,int persistent,int source,int expires,time_t expire_time,unsigned long comment_id,struct timeval * timestamp)283 void broker_comment_data(int type, int flags, int attr, int comment_type, int entry_type, char *host_name, char *svc_description, time_t entry_time, char *author_name, char *comment_data, int persistent, int source, int expires, time_t expire_time, unsigned long comment_id, struct timeval *timestamp) {}
neb_unload_all_modules(int flags,int reason)284 int neb_unload_all_modules(int flags, int reason) {}
neb_add_module(char * filename,char * args,int should_be_loaded)285 int neb_add_module(char *filename, char *args, int should_be_loaded) {}
broker_system_command(int type,int flags,int attr,struct timeval start_time,struct timeval end_time,double exectime,int timeout,int early_timeout,int retcode,char * cmd,char * output,struct timeval * timestamp)286 void broker_system_command(int type, int flags, int attr, struct timeval start_time, struct timeval end_time, double exectime, int timeout, int early_timeout, int retcode, char *cmd, char *output, struct timeval *timestamp) {}
287 
schedule_new_event(int event_type,int high_priority,time_t run_time,int recurring,unsigned long event_interval,void * timing_func,int compensate_for_time_change,void * event_data,void * event_args,int event_options)288 int schedule_new_event(int event_type, int high_priority, time_t run_time, int recurring, unsigned long event_interval, void *timing_func, int compensate_for_time_change, void *event_data, void *event_args, int event_options) {}
my_tcp_connect(char * host_name,int port,int * sd,int timeout)289 int my_tcp_connect(char *host_name, int port, int *sd, int timeout) {}
my_recvall(int s,char * buf,int * len,int timeout)290 int my_recvall(int s, char *buf, int *len, int timeout) {}
neb_free_module_list(void)291 int neb_free_module_list(void) {}
292 
main(int argc,char ** argv)293 int main(int argc, char **argv) {
294 	int result;
295 	int error = FALSE;
296 	char *buffer = NULL;
297 	int display_license = FALSE;
298 	int display_help = FALSE;
299 	int c = 0;
300 	struct tm *tm;
301 	time_t current_time;
302 	time_t test_time;
303 	time_t saved_test_time;
304 	time_t next_valid_time = 0L;
305 	time_t chosen_valid_time = 0L;
306 	char datestring[256];
307 	host *temp_host = NULL;
308 	hostgroup *temp_hostgroup = NULL;
309 	hostsmember *temp_member = NULL;
310 	timeperiod *temp_timeperiod = NULL;
311 	int is_valid_time = 0;
312 	int iterations = 1000;
313 
314 	plan_tests(6043);
315 
316 	/* reset program variables */
317 	reset_variables();
318 
319 	printf("Reading configuration data...\n");
320 
321 	config_file = strdup("smallconfig/nagios.cfg");
322 	/* read in the configuration files (main config file, resource and object config files) */
323 	result = read_main_config_file(config_file);
324 	ok(result == OK, "Read main configuration file okay - if fails, use nagios -v to check");
325 
326 	result = read_all_object_data(config_file);
327 	ok(result == OK, "Read all object config files");
328 
329 	result = pre_flight_check();
330 	ok(result == OK, "Preflight check okay");
331 
332 	time(&current_time);
333 	test_time = current_time;
334 	saved_test_time = current_time;
335 
336 	temp_timeperiod = find_timeperiod("none");
337 
338 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
339 	ok(is_valid_time == ERROR, "No valid time because time period is empty");
340 
341 	get_next_valid_time(current_time, &next_valid_time, temp_timeperiod);
342 	ok(current_time == next_valid_time, "There is no valid time due to timeperiod");
343 
344 	temp_timeperiod = find_timeperiod("24x7");
345 
346 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
347 	ok(is_valid_time == OK, "Fine because 24x7");
348 
349 	get_next_valid_time(current_time, &next_valid_time, temp_timeperiod);
350 	ok((next_valid_time - current_time) <= 2, "Next valid time should be the current_time, but with a 2 second tolerance");
351 
352 
353 	/* 2009-10-25 is the day when clocks go back an hour in Europe. Bug happens during 23:00 to 00:00 */
354 	/* This is 23:01:01 */
355 	saved_test_time = 1256511661;
356 	saved_test_time = saved_test_time - (24 * 60 * 60);
357 
358 	putenv("TZ=UTC");
359 	tzset();
360 	test_time = saved_test_time;
361 	c = 0;
362 	while(c < iterations) {
363 		is_valid_time = check_time_against_period(test_time, temp_timeperiod);
364 		ok(is_valid_time == OK, "Always OK for 24x7 with TZ=UTC, time_t=%lu", test_time);
365 		chosen_valid_time = 0L;
366 		_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
367 		ok(test_time == chosen_valid_time, "get_next_valid_time always returns same time");
368 		test_time += 1800;
369 		c++;
370 		}
371 
372 	putenv("TZ=Europe/London");
373 	tzset();
374 	test_time = saved_test_time;
375 	c = 0;
376 	while(c < iterations) {
377 		is_valid_time = check_time_against_period(test_time, temp_timeperiod);
378 		ok(is_valid_time == OK, "Always OK for 24x7 with TZ=Europe/London, time_t=%lu", test_time);
379 		_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
380 		ok(test_time == chosen_valid_time, "get_next_valid_time always returns same time, time_t=%lu", test_time);
381 		test_time += 1800;
382 		c++;
383 		}
384 
385 	/* 2009-11-01 is the day when clocks go back an hour in America. Bug happens during 23:00 to 00:00 */
386 	/* This is 23:01:01 */
387 	saved_test_time = 1256511661;
388 	saved_test_time = saved_test_time - (24 * 60 * 60);
389 
390 	putenv("TZ=America/New_York");
391 	tzset();
392 	test_time = saved_test_time;
393 	c = 0;
394 	while(c < iterations) {
395 		is_valid_time = check_time_against_period(test_time, temp_timeperiod);
396 		ok(is_valid_time == OK, "Always OK for 24x7 with TZ=America/New_York, time_t=%lu", test_time);
397 		_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
398 		ok(test_time == chosen_valid_time, "get_next_valid_time always returns same time, time_t=%lu", test_time);
399 		test_time += 1800;
400 		c++;
401 		}
402 
403 
404 
405 	/* Tests around clock change going back for TZ=Europe/London. 1256511661 = Sun Oct
406 	25 23:01:01 2009 */
407 	/* A little trip to Paris*/
408 	putenv("TZ=Europe/Paris");
409 	tzset();
410 
411 
412 	/* Timeperiod exclude tests, from Jean Gabes */
413 	temp_timeperiod = find_timeperiod("Test_exclude");
414 	ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod");
415 	test_time = 1278939600;
416 	/* printf("Testing at time %s", ctime(&test_time)); */
417 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
418 	ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false");
419 
420 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
421 	/* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */
422 	todo_start("Bug in exclude");
423 	ok(chosen_valid_time == 1288103400, "ME: Next valid time=Tue Oct 26 16:30:00 2010");
424 	todo_end();
425 
426 
427 	temp_timeperiod = find_timeperiod("Test_exclude2");
428 	ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod 2");
429 	test_time = 1278939600;
430 	/* printf("Testing at time %s", ctime(&test_time)); */
431 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
432 	ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false");
433 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
434 	/* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */
435 	todo_start("Bug in exclude 2");
436 	ok(chosen_valid_time == 1279058340, "ME: Next valid time=Tue Jul 13 23:59:00 2010");
437 	todo_end();
438 
439 
440 	temp_timeperiod = find_timeperiod("Test_exclude3");
441 	ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod 3");
442 	test_time = 1278939600;
443 	/* printf("Testing at time %s", ctime(&test_time)); */
444 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
445 	ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false");
446 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
447 	/* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */
448 	todo_start("Bug in exclude 3");
449 	ok(chosen_valid_time == 1284474600, "ME: Next valid time=Tue Sep 14 16:30:00 2010");
450 	todo_end();
451 
452 
453 	temp_timeperiod = find_timeperiod("Test_exclude4");
454 	ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod 4");
455 	test_time = 1278939600;
456 	/* printf("Testing at time %s", ctime(&test_time)); */
457 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
458 	ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false");
459 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
460 	/* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */
461 	todo_start("Bug in exclude 3");
462 	ok(chosen_valid_time == 1283265000, "ME: Next valid time=Tue Aug 31 16:30:00 2010");
463 	todo_end();
464 
465 
466 
467 
468 	/* Back to New york */
469 	putenv("TZ=America/New_York");
470 	tzset();
471 
472 
473 	temp_timeperiod = find_timeperiod("sunday_only");
474 	ok(temp_timeperiod != NULL, "Testing Sunday 00:00-01:15,03:15-22:00");
475 	putenv("TZ=Europe/London");
476 	tzset();
477 
478 
479 	test_time = 1256421000;
480 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
481 	ok(is_valid_time == ERROR, "Sat Oct 24 22:50:00 2009 - false");
482 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
483 	ok(chosen_valid_time == 1256425200, "Next valid time=Sun Oct 25 00:00:00 2009");
484 
485 
486 	test_time = 1256421661;
487 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
488 	ok(is_valid_time == ERROR, "Sat Oct 24 23:01:01 2009 - false");
489 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
490 	ok(chosen_valid_time == 1256425200, "Next valid time=Sun Oct 25 00:00:00 2009");
491 
492 	test_time = 1256425400;
493 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
494 	ok(is_valid_time == OK, "Sun Oct 25 00:03:20 2009 - true");
495 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
496 	ok(chosen_valid_time == test_time, "Next valid time=Sun Oct 25 00:03:20 2009");
497 
498 	test_time = 1256429700;
499 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
500 	ok(is_valid_time == OK, "Sun Oct 25 01:15:00 2009 - true");
501 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
502 	ok(chosen_valid_time == test_time, "Next valid time=Sun Oct 25 01:15:00 2009");
503 
504 	test_time = 1256430400;
505 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
506 	ok(is_valid_time == ERROR, "Sun Oct 25 01:26:40 2009 - false");
507 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
508 	todo_start("Is a bug in get_next_valid_time for a time that falls in the DST change hour period");
509 	ok(chosen_valid_time == 1256440500, "Next valid time=Sun Oct 25 03:15:00 2009") || printf("chosen_valid_time=%lu\n", chosen_valid_time);
510 	todo_end();
511 
512 	test_time = 1256440500;
513 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
514 	ok(is_valid_time == OK, "Sun Oct 25 03:15:00 2009 - true");
515 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
516 	ok(chosen_valid_time == test_time, "Next valid time=Sun Oct 25 03:15:00 2009");
517 
518 	test_time = 1256500000;
519 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
520 	ok(is_valid_time == OK, "Sun Oct 25 19:46:40 2009 - true");
521 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
522 	ok(chosen_valid_time == 1256500000, "Next valid time=Sun Oct 25 19:46:40 2009");
523 
524 	test_time = 1256508000;
525 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
526 	ok(is_valid_time == OK, "Sun Oct 25 22:00:00 2009 - true");
527 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
528 	ok(chosen_valid_time == 1256508000, "Next valid time=Sun Oct 25 22:00:00 2009");
529 
530 	test_time = 1256508001;
531 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
532 	ok(is_valid_time == ERROR, "Sun Oct 25 22:00:01 2009 - false");
533 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
534 	ok(chosen_valid_time == 1257033600, "Next valid time=Sun Nov 1 00:00:00 2009");
535 
536 	test_time = 1256513000;
537 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
538 	ok(is_valid_time == ERROR, "Sun Oct 25 23:23:20 2009 - false");
539 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
540 	ok(chosen_valid_time == 1257033600, "Next valid time=Sun Nov 1 00:00:00 2009");
541 
542 
543 
544 
545 	temp_timeperiod = find_timeperiod("weekly_complex");
546 	ok(temp_timeperiod != NULL, "Testing complex weekly timeperiod definition");
547 	putenv("TZ=America/New_York");
548 	tzset();
549 
550 	test_time = 1268109420;
551 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
552 	ok(is_valid_time == ERROR, "Mon Mar  8 23:37:00 2010 - false");
553 	_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
554 	ok(chosen_valid_time == 1268115300, "Next valid time=Tue Mar  9 01:15:00 2010");
555 
556 
557 
558 
559 
560 	cleanup();
561 
562 	my_free(config_file);
563 
564 	return exit_status();
565 	}
566 
567 
568