summaryrefslogtreecommitdiffstats
path: root/lib/tests/test_utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tests/test_utils.c')
-rw-r--r--lib/tests/test_utils.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index ccc4a52..ce79fc6 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -24,6 +24,8 @@
24#include <sys/types.h> 24#include <sys/types.h>
25#include <sys/stat.h> 25#include <sys/stat.h>
26 26
27#include "utils_base.c"
28
27int 29int
28main (int argc, char **argv) 30main (int argc, char **argv)
29{ 31{
@@ -36,19 +38,16 @@ main (int argc, char **argv)
36 state_data *temp_state_data; 38 state_data *temp_state_data;
37 time_t current_time; 39 time_t current_time;
38 char *temp_filename; 40 char *temp_filename;
39 nagios_plugin *temp_nagios_plugin;
40 FILE *temp_fp; 41 FILE *temp_fp;
41 42
42 plan_tests(138); 43 plan_tests(137);
43 44
44 _get_nagios_plugin( &temp_nagios_plugin ); 45 ok( this_nagios_plugin==NULL, "nagios_plugin not initialised");
45 ok( temp_nagios_plugin==NULL, "nagios_plugin not initialised");
46 46
47 np_init( "check_test", argc, argv ); 47 np_init( "check_test", argc, argv );
48 48
49 _get_nagios_plugin( &temp_nagios_plugin ); 49 ok( this_nagios_plugin!=NULL, "nagios_plugin now initialised");
50 ok( temp_nagios_plugin!=NULL, "nagios_plugin now initialised"); 50 ok( !strcmp(this_nagios_plugin->plugin_name, "check_test"), "plugin name initialised" );
51 ok( !strcmp(temp_nagios_plugin->plugin_name, "check_test"), "plugin name initialised" );
52 51
53 52
54 range = parse_range_string("6"); 53 range = parse_range_string("6");
@@ -277,21 +276,21 @@ main (int argc, char **argv)
277 ok(!strcmp(temp_string, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got hash with exe and no parameters" ); 276 ok(!strcmp(temp_string, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got hash with exe and no parameters" );
278 277
279 278
280 temp_nagios_plugin->argc=4; 279 this_nagios_plugin->argc=4;
281 temp_nagios_plugin->argv[0] = "./test_utils"; 280 this_nagios_plugin->argv[0] = "./test_utils";
282 temp_nagios_plugin->argv[1] = "here"; 281 this_nagios_plugin->argv[1] = "here";
283 temp_nagios_plugin->argv[2] = "--and"; 282 this_nagios_plugin->argv[2] = "--and";
284 temp_nagios_plugin->argv[3] = "now"; 283 this_nagios_plugin->argv[3] = "now";
285 temp_string = (char *) _np_state_generate_key(); 284 temp_string = (char *) _np_state_generate_key();
286 ok(!strcmp(temp_string, "94b5e17bf5abf51cb15aff5f69b96f2f8dac5ecd"), "Got based on expected argv" ); 285 ok(!strcmp(temp_string, "94b5e17bf5abf51cb15aff5f69b96f2f8dac5ecd"), "Got based on expected argv" );
287 286
288 unsetenv("NAGIOS_PLUGIN_STATE_DIRECTORY"); 287 unsetenv("NAGIOS_PLUGIN_STATE_DIRECTORY");
289 temp_string = (char *) _np_state_calculate_location_prefix(); 288 temp_string = (char *) _np_state_calculate_location_prefix();
290 ok(!strcmp(temp_string, NP_SHAREDSTATE_DIR), "Got default directory" ); 289 ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory" );
291 290
292 setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "", 1); 291 setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "", 1);
293 temp_string = (char *) _np_state_calculate_location_prefix(); 292 temp_string = (char *) _np_state_calculate_location_prefix();
294 ok(!strcmp(temp_string, NP_SHAREDSTATE_DIR), "Got default directory even with empty string" ); 293 ok(!strcmp(temp_string, NP_STATE_DIR_PREFIX), "Got default directory even with empty string" );
295 294
296 setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "/usr/local/nagios/var", 1); 295 setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "/usr/local/nagios/var", 1);
297 temp_string = (char *) _np_state_calculate_location_prefix(); 296 temp_string = (char *) _np_state_calculate_location_prefix();
@@ -301,22 +300,22 @@ main (int argc, char **argv)
301 300
302 ok(temp_state_key==NULL, "temp_state_key initially empty"); 301 ok(temp_state_key==NULL, "temp_state_key initially empty");
303 302
304 temp_nagios_plugin->argc=1; 303 this_nagios_plugin->argc=1;
305 temp_nagios_plugin->argv[0] = "./test_utils"; 304 this_nagios_plugin->argv[0] = "./test_utils";
306 np_enable_state(NULL, 51); 305 np_enable_state(NULL, 51);
307 temp_state_key = temp_nagios_plugin->state; 306 temp_state_key = this_nagios_plugin->state;
308 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); 307 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
309 ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" ); 308 ok( !strcmp(temp_state_key->name, "83d877b6cdfefb5d6f06101fd6fe76762f21792c"), "Got generated filename" );
310 309
311 310
312 np_enable_state("bad^chars$in@here", 77); 311 np_enable_state("bad^chars$in@here", 77);
313 temp_state_key = temp_nagios_plugin->state; 312 temp_state_key = this_nagios_plugin->state;
314 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); 313 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
315 ok( !strcmp(temp_state_key->name, "bad_chars_in_here"), "Got key name with bad chars replaced" ); 314 ok( !strcmp(temp_state_key->name, "bad_chars_in_here"), "Got key name with bad chars replaced" );
316 ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/bad_chars_in_here"), "Got internal filename" ); 315 ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/bad_chars_in_here"), "Got internal filename" );
317 316
318 np_enable_state("funnykeyname", 54); 317 np_enable_state("funnykeyname", 54);
319 temp_state_key = temp_nagios_plugin->state; 318 temp_state_key = this_nagios_plugin->state;
320 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); 319 ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
321 ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); 320 ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" );
322 321
@@ -340,9 +339,9 @@ main (int argc, char **argv)
340 339
341 temp_state_key->_filename="var/statefile"; 340 temp_state_key->_filename="var/statefile";
342 temp_state_data = np_state_read(temp_state_key); 341 temp_state_data = np_state_read(temp_state_key);
343 ok( temp_nagios_plugin->state->state_data!=NULL, "Got state data now" ); 342 ok( this_nagios_plugin->state->state_data!=NULL, "Got state data now" );
344 ok( temp_nagios_plugin->state->state_data->time==1234567890, "Got time" ); 343 ok( this_nagios_plugin->state->state_data->time==1234567890, "Got time" );
345 ok( !strcmp((char *)temp_nagios_plugin->state->state_data->data, "String to read"), "Data as expected" ); 344 ok( !strcmp((char *)this_nagios_plugin->state->state_data->data, "String to read"), "Data as expected" );
346 345
347 temp_state_key->data_version=53; 346 temp_state_key->data_version=53;
348 temp_state_data = np_state_read(temp_state_key); 347 temp_state_data = np_state_read(temp_state_key);
@@ -352,7 +351,7 @@ main (int argc, char **argv)
352 temp_state_key->_filename="var/nonexistant"; 351 temp_state_key->_filename="var/nonexistant";
353 temp_state_data = np_state_read(temp_state_key); 352 temp_state_data = np_state_read(temp_state_key);
354 ok( temp_state_data==NULL, "Missing file gives NULL" ); 353 ok( temp_state_data==NULL, "Missing file gives NULL" );
355 ok( temp_nagios_plugin->state->state_data==NULL, "No state information" ); 354 ok( this_nagios_plugin->state->state_data==NULL, "No state information" );
356 355
357 temp_state_key->_filename="var/oldformat"; 356 temp_state_key->_filename="var/oldformat";
358 temp_state_data = np_state_read(temp_state_key); 357 temp_state_data = np_state_read(temp_state_key);
@@ -399,7 +398,7 @@ main (int argc, char **argv)
399 temp_state_data = np_state_read(temp_state_key); 398 temp_state_data = np_state_read(temp_state_key);
400 /* Check time is set to current_time */ 399 /* Check time is set to current_time */
401 ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time"); 400 ok(system("cmp var/generated var/statefile > /dev/null")!=0, "Generated file should be different this time");
402 ok(temp_nagios_plugin->state->state_data->time-current_time<=1, "Has time generated from current time"); 401 ok(this_nagios_plugin->state->state_data->time-current_time<=1, "Has time generated from current time");
403 402
404 403
405 /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */ 404 /* Don't know how to automatically test this. Need to be able to redefine die and catch the error */
@@ -410,8 +409,9 @@ main (int argc, char **argv)
410 409
411 410
412 np_cleanup(); 411 np_cleanup();
413 ok(temp_state_key==NULL, "temp_state_key cleared"); 412
414 ok( temp_nagios_plugin==NULL, "Reset" ); 413 ok( this_nagios_plugin==NULL, "Free'd this_nagios_plugin" );
415 414
416 return exit_status(); 415 return exit_status();
417} 416}
417