diff options
Diffstat (limited to 'lib/tests')
| -rw-r--r-- | lib/tests/test_utils.c | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c index 763392a8..aae358f3 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c | |||
| @@ -33,9 +33,19 @@ main (int argc, char **argv) | |||
| 33 | state_data *temp_state_data; | 33 | state_data *temp_state_data; |
| 34 | time_t current_time; | 34 | time_t current_time; |
| 35 | char *temp_filename; | 35 | char *temp_filename; |
| 36 | nagios_plugin *temp_nagios_plugin; | ||
| 36 | 37 | ||
| 37 | plan_tests(81+23); | 38 | plan_tests(81+23); |
| 38 | 39 | ||
| 40 | _get_nagios_plugin( &temp_nagios_plugin ); | ||
| 41 | ok( temp_nagios_plugin==NULL, "nagios_plugin not initialised"); | ||
| 42 | |||
| 43 | np_init( "check_test" ); | ||
| 44 | _get_nagios_plugin( &temp_nagios_plugin ); | ||
| 45 | ok( temp_nagios_plugin!=NULL, "nagios_plugin now initialised"); | ||
| 46 | ok( !strcmp(temp_nagios_plugin->plugin_name, "check_test"), "plugin name initialised" ); | ||
| 47 | |||
| 48 | |||
| 39 | range = parse_range_string("6"); | 49 | range = parse_range_string("6"); |
| 40 | ok( range != NULL, "'6' is valid range"); | 50 | ok( range != NULL, "'6' is valid range"); |
| 41 | ok( range->start == 0, "Start correct"); | 51 | ok( range->start == 0, "Start correct"); |
| @@ -257,33 +267,63 @@ main (int argc, char **argv) | |||
| 257 | ok(!test, "Empty string return NULL"); | 267 | ok(!test, "Empty string return NULL"); |
| 258 | 268 | ||
| 259 | 269 | ||
| 260 | temp_string = np_state_generate_key(argv); | 270 | temp_string = (char *) _np_state_generate_key(); |
| 261 | ok(!strcmp(temp_string, "Ahash"), "Got hash" ); | 271 | ok(!strcmp(temp_string, "Ahash"), "Got hash" ); |
| 262 | 272 | ||
| 263 | temp_string = _np_state_calculate_location_prefix(); | 273 | |
| 274 | |||
| 275 | unsetenv("NAGIOS_PLUGIN_STATE_DIRECTORY"); | ||
| 276 | temp_string = (char *) _np_state_calculate_location_prefix(); | ||
| 264 | ok(!strcmp(temp_string, NP_SHAREDSTATE_DIR), "Got default directory" ); | 277 | ok(!strcmp(temp_string, NP_SHAREDSTATE_DIR), "Got default directory" ); |
| 265 | 278 | ||
| 279 | setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "", 1); | ||
| 280 | temp_string = (char *) _np_state_calculate_location_prefix(); | ||
| 281 | ok(!strcmp(temp_string, NP_SHAREDSTATE_DIR), "Got default directory even with empty string" ); | ||
| 282 | |||
| 283 | setenv("NAGIOS_PLUGIN_STATE_DIRECTORY", "/usr/local/nagios/var", 1); | ||
| 284 | temp_string = (char *) _np_state_calculate_location_prefix(); | ||
| 285 | ok(!strcmp(temp_string, "/usr/local/nagios/var"), "Got default directory" ); | ||
| 286 | |||
| 287 | |||
| 288 | |||
| 266 | ok(temp_state_key==NULL, "temp_state_key initially empty"); | 289 | ok(temp_state_key==NULL, "temp_state_key initially empty"); |
| 267 | temp_state_key = np_state_init("check_test", temp_string, 54); | 290 | |
| 291 | np_state_init(NULL, 51); | ||
| 292 | temp_state_key = temp_nagios_plugin->state; | ||
| 268 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 293 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); |
| 269 | ok( !strcmp(temp_state_key->name, temp_string), "Got key name" ); | 294 | ok( !strcmp(temp_state_key->name, "Ahash"), "Got key name" ); |
| 295 | |||
| 296 | |||
| 297 | printf("Filename=%s\n", temp_state_key->_filename); | ||
| 298 | np_state_init("funnykeyname", 54); | ||
| 299 | temp_state_key = temp_nagios_plugin->state; | ||
| 300 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | ||
| 301 | ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); | ||
| 302 | |||
| 270 | printf("Filename=%s\n", temp_state_key->_filename); | 303 | printf("Filename=%s\n", temp_state_key->_filename); |
| 271 | 304 | ||
| 272 | ok( !strcmp(temp_state_key->_filename, "Tobedone"), "Got internal filename" ); | 305 | |
| 306 | ok( !strcmp(temp_state_key->_filename, "/usr/local/nagios/var/check_test/funnykeyname"), "Got internal filename" ); | ||
| 273 | ok( temp_state_key->data_version==54, "Version set" ); | 307 | ok( temp_state_key->data_version==54, "Version set" ); |
| 274 | 308 | ||
| 275 | temp_state_data = np_state_read(temp_state_key); | 309 | temp_state_data = np_state_read(temp_state_key); |
| 276 | ok( temp_state_data==NULL, "Got state data" ); | 310 | ok( temp_state_data==NULL, "Got no state data as file does not exist" ); |
| 311 | |||
| 312 | temp_state_key->_filename="var/statefile"; | ||
| 313 | temp_state_data = np_state_read(temp_state_key); | ||
| 314 | ok( temp_state_data!=NULL, "Got state data now" ); | ||
| 315 | |||
| 277 | 316 | ||
| 278 | time(¤t_time); | 317 | time(¤t_time); |
| 279 | np_state_write_string(temp_state_key, NULL, "New data"); | 318 | np_state_write_string(NULL, "New data"); |
| 280 | 319 | ||
| 281 | temp_state_data = np_state_read(temp_state_key); | 320 | temp_state_data = np_state_read(temp_state_key); |
| 282 | /* Check time is set to current_time */ | 321 | /* Check time is set to current_time */ |
| 283 | 322 | ||
| 284 | 323 | ||
| 285 | np_state_cleanup(temp_state_key); | 324 | np_cleanup(); |
| 286 | ok(temp_state_key==NULL, "temp_state_key cleared"); | 325 | ok(temp_state_key==NULL, "temp_state_key cleared"); |
| 326 | ok( temp_nagios_plugin==NULL, "Reset" ); | ||
| 287 | 327 | ||
| 288 | return exit_status(); | 328 | return exit_status(); |
| 289 | } | 329 | } |
