summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2014-01-29 22:03:04 -0500
committerThomas Guyot-Sionnest <dermoth@aei.ca>2014-01-29 22:03:04 -0500
commit7310030ae7a30f61990641c5c1674531823f457f (patch)
tree7f4670acda3f33abcdcf9ab7fb338586322694e5
parent2dc150da81169ec6d81858478b6203eb3aa164a9 (diff)
downloadmonitoring-plugins-7310030.tar.gz
Add tests for mp_translate_state()
-rw-r--r--lib/tests/test_utils.c55
1 files changed, 50 insertions, 5 deletions
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c
index 0571340b..08eed240 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -32,13 +32,13 @@ main (int argc, char **argv)
32 range *range; 32 range *range;
33 double temp; 33 double temp;
34 thresholds *thresholds = NULL; 34 thresholds *thresholds = NULL;
35 int rc; 35 int i, rc;
36 char *temp_string; 36 char *temp_string;
37 state_key *temp_state_key = NULL; 37 state_key *temp_state_key = NULL;
38 state_data *temp_state_data; 38 state_data *temp_state_data;
39 time_t current_time; 39 time_t current_time;
40 40
41 plan_tests(151); 41 plan_tests(172);
42 42
43 ok( this_monitoring_plugin==NULL, "monitoring_plugin not initialised"); 43 ok( this_monitoring_plugin==NULL, "monitoring_plugin not initialised");
44 44
@@ -438,9 +438,54 @@ main (int argc, char **argv)
438 438
439 np_cleanup(); 439 np_cleanup();
440 440
441 ok( this_monitoring_plugin==NULL, "Free'd this_monitoring_plugin" ); 441 ok(this_monitoring_plugin==NULL, "Free'd this_monitoring_plugin");
442 442
443 ok( mp_suid() == FALSE, "test aren't suid" ); 443 ok(mp_suid() == FALSE, "test aren't suid");
444
445 /* base states with random case */
446 char *states[] = {
447 "Ok",
448 "wArnINg",
449 "cRiTIcaL",
450 "UnKNoWN",
451 NULL
452 };
453
454 for (i=0; states[i]!=NULL; i++) {
455 /* out of the random case states, create the lower and upper versions + numeric string one */
456 char *statelower = strdup(states[i]);
457 char *stateupper = strdup(states[i]);
458 char statenum[2];
459 char *temp_ptr;
460 for (temp_ptr = statelower; *temp_ptr; temp_ptr++) {
461 *temp_ptr = tolower(*temp_ptr);
462 }
463 for (temp_ptr = stateupper; *temp_ptr; temp_ptr++) {
464 *temp_ptr = toupper(*temp_ptr);
465 }
466 snprintf(statenum, 2, "%i", i);
467
468 /* Base test names, we'll append the state string */
469 char testname[64] = "Translate state string: ";
470 int tlen = strlen(testname);
471
472 strcpy(testname+tlen, states[i]);
473 ok(i==mp_translate_state(states[i]), testname);
474
475 strcpy(testname+tlen, statelower);
476 ok(i==mp_translate_state(statelower), testname);
477
478 strcpy(testname+tlen, stateupper);
479 ok(i==mp_translate_state(stateupper), testname);
480
481 strcpy(testname+tlen, statenum);
482 ok(i==mp_translate_state(statenum), testname);
483 }
484 ok(ERROR==mp_translate_state("warningfewgw"), "Translate state string with garbage");
485 ok(ERROR==mp_translate_state("00"), "Translate state string: bad numeric string 1");
486 ok(ERROR==mp_translate_state("01"), "Translate state string: bad numeric string 2");
487 ok(ERROR==mp_translate_state("10"), "Translate state string: bad numeric string 3");
488 ok(ERROR==mp_translate_state(""), "Translate state string: empty string");
444 489
445 return exit_status(); 490 return exit_status();
446} 491}