diff options
Diffstat (limited to 'lib/tests')
-rw-r--r-- | lib/tests/test_utils.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c index aae358f3..d7cdc336 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c | |||
@@ -34,6 +34,7 @@ main (int argc, char **argv) | |||
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 | nagios_plugin *temp_nagios_plugin; |
37 | FILE *temp_fp; | ||
37 | 38 | ||
38 | plan_tests(81+23); | 39 | plan_tests(81+23); |
39 | 40 | ||
@@ -288,14 +289,14 @@ main (int argc, char **argv) | |||
288 | 289 | ||
289 | ok(temp_state_key==NULL, "temp_state_key initially empty"); | 290 | ok(temp_state_key==NULL, "temp_state_key initially empty"); |
290 | 291 | ||
291 | np_state_init(NULL, 51); | 292 | np_enable_state(NULL, 51); |
292 | temp_state_key = temp_nagios_plugin->state; | 293 | temp_state_key = temp_nagios_plugin->state; |
293 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | 294 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); |
294 | ok( !strcmp(temp_state_key->name, "Ahash"), "Got key name" ); | 295 | ok( !strcmp(temp_state_key->name, "Ahash"), "Got key name" ); |
295 | 296 | ||
296 | 297 | ||
297 | printf("Filename=%s\n", temp_state_key->_filename); | 298 | printf("Filename=%s\n", temp_state_key->_filename); |
298 | np_state_init("funnykeyname", 54); | 299 | np_enable_state("funnykeyname", 54); |
299 | temp_state_key = temp_nagios_plugin->state; | 300 | 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->plugin_name, "check_test"), "Got plugin name" ); |
301 | ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); | 302 | ok( !strcmp(temp_state_key->name, "funnykeyname"), "Got key name" ); |
@@ -309,11 +310,29 @@ main (int argc, char **argv) | |||
309 | temp_state_data = np_state_read(temp_state_key); | 310 | temp_state_data = np_state_read(temp_state_key); |
310 | ok( temp_state_data==NULL, "Got no state data as file does not exist" ); | 311 | ok( temp_state_data==NULL, "Got no state data as file does not exist" ); |
311 | 312 | ||
313 | |||
314 | /* | ||
315 | temp_fp = fopen("var/statefile", "r"); | ||
316 | if (temp_fp==NULL) | ||
317 | printf("Error opening. errno=%d\n", errno); | ||
318 | printf("temp_fp=%s\n", temp_fp); | ||
319 | ok( _np_state_read_file(temp_fp) == TRUE, "Can read state file" ); | ||
320 | fclose(temp_fp); | ||
321 | */ | ||
322 | |||
312 | temp_state_key->_filename="var/statefile"; | 323 | temp_state_key->_filename="var/statefile"; |
313 | temp_state_data = np_state_read(temp_state_key); | 324 | temp_state_data = np_state_read(temp_state_key); |
314 | ok( temp_state_data!=NULL, "Got state data now" ); | 325 | ok( temp_nagios_plugin->state->state_data!=NULL, "Got state data now" ); |
326 | ok( temp_nagios_plugin->state->state_data->time==1234567890, "Got time" ); | ||
327 | ok( !strcmp((char *)temp_nagios_plugin->state->state_data->data, "String to read"), "Data as expected" ); | ||
328 | printf("state_data=%s|\n", temp_nagios_plugin->state->state_data->data); | ||
315 | 329 | ||
316 | 330 | ||
331 | temp_state_key->_filename="var/nonexistant"; | ||
332 | temp_state_data = np_state_read(temp_state_key); | ||
333 | ok( temp_state_data==NULL, "Missing file gives NULL" ); | ||
334 | ok( temp_nagios_plugin->state->state_data==NULL, "No state information" ); | ||
335 | |||
317 | time(¤t_time); | 336 | time(¤t_time); |
318 | np_state_write_string(NULL, "New data"); | 337 | np_state_write_string(NULL, "New data"); |
319 | 338 | ||