diff options
| author | Ton Voon <ton.voon@opsera.com> | 2010-06-17 10:57:59 +0100 |
|---|---|---|
| committer | Ton Voon <ton.voon@opsera.com> | 2010-06-17 10:57:59 +0100 |
| commit | 301599a4eca67e214ef79bd609843a9e1e710b3a (patch) | |
| tree | e2404d11826e25e632d31dd4c6beea627e4dda9d | |
| parent | 95b190f3dee629b1c1ee2fab5b69c08e511f51b3 (diff) | |
| download | monitoring-plugins-301599a4eca67e214ef79bd609843a9e1e710b3a.tar.gz | |
Add skeleton tests
| -rw-r--r-- | lib/tests/test_utils.c | 28 | ||||
| -rw-r--r-- | lib/utils_base.c | 11 | ||||
| -rw-r--r-- | lib/utils_base.h | 4 |
3 files changed, 39 insertions, 4 deletions
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c index 3a45944a..057c4845 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c | |||
| @@ -28,6 +28,10 @@ main (int argc, char **argv) | |||
| 28 | double temp; | 28 | double temp; |
| 29 | thresholds *thresholds = NULL; | 29 | thresholds *thresholds = NULL; |
| 30 | int rc; | 30 | int rc; |
| 31 | char *temp_string; | ||
| 32 | state_key *temp_state_key = NULL; | ||
| 33 | state_data *temp_state_data; | ||
| 34 | time_t current_time; | ||
| 31 | 35 | ||
| 32 | plan_tests(81+23); | 36 | plan_tests(81+23); |
| 33 | 37 | ||
| @@ -251,5 +255,29 @@ main (int argc, char **argv) | |||
| 251 | test=np_extract_ntpvar("", "foo"); | 255 | test=np_extract_ntpvar("", "foo"); |
| 252 | ok(!test, "Empty string return NULL"); | 256 | ok(!test, "Empty string return NULL"); |
| 253 | 257 | ||
| 258 | |||
| 259 | temp_string = np_state_generate_key(argv); | ||
| 260 | ok(!strcmp(temp_string, "Ahash"), "Got hash" ); | ||
| 261 | |||
| 262 | ok(temp_state_key==NULL, "temp_state_key initially empty"); | ||
| 263 | temp_state_key = np_state_init("check_test", temp_string, 54); | ||
| 264 | ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" ); | ||
| 265 | ok( !strcmp(temp_state_key->name, temp_string), "Got key name" ); | ||
| 266 | ok( !strcmp(temp_state_key->_filename, "Tobedone"), "Got internal filename" ); | ||
| 267 | ok( temp_state_key->data_version==54, "Version set" ); | ||
| 268 | |||
| 269 | temp_state_data = np_state_read(temp_state_key); | ||
| 270 | ok( temp_state_data==NULL, "Got state data" ); | ||
| 271 | |||
| 272 | time(¤t_time); | ||
| 273 | np_state_write_string(temp_state_key, NULL, "New data"); | ||
| 274 | |||
| 275 | temp_state_data = np_state_read(temp_state_key); | ||
| 276 | /* Check time is set to current_time */ | ||
| 277 | |||
| 278 | |||
| 279 | np_state_cleanup(temp_state_key); | ||
| 280 | ok(temp_state_key==NULL, "temp_state_key cleared"); | ||
| 281 | |||
| 254 | return exit_status(); | 282 | return exit_status(); |
| 255 | } | 283 | } |
diff --git a/lib/utils_base.c b/lib/utils_base.c index c9f0912a..fb442400 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
| @@ -28,6 +28,8 @@ | |||
| 28 | #include <stdarg.h> | 28 | #include <stdarg.h> |
| 29 | #include "utils_base.h" | 29 | #include "utils_base.h" |
| 30 | 30 | ||
| 31 | #define np_free(ptr) { if(ptr) { free(ptr); ptr = NULL; } } | ||
| 32 | |||
| 31 | void | 33 | void |
| 32 | die (int result, const char *fmt, ...) | 34 | die (int result, const char *fmt, ...) |
| 33 | { | 35 | { |
| @@ -315,7 +317,7 @@ char *np_extract_value(const char *varlist, const char *name, char sep) { | |||
| 315 | * hopefully a unique key per service/plugin invocation. Use the extra-opts | 317 | * hopefully a unique key per service/plugin invocation. Use the extra-opts |
| 316 | * parse of argv, so that uniqueness in parameters are reflected there. | 318 | * parse of argv, so that uniqueness in parameters are reflected there. |
| 317 | */ | 319 | */ |
| 318 | char *np_state_generate_key(const char **argv) { | 320 | char *np_state_generate_key(char **argv) { |
| 319 | return "Ahash"; | 321 | return "Ahash"; |
| 320 | } | 322 | } |
| 321 | 323 | ||
| @@ -352,6 +354,9 @@ state_key *np_state_init(char *plugin_name, char *keyname, int expected_data_ver | |||
| 352 | state_data *np_state_read(state_key *my_state_key) { | 354 | state_data *np_state_read(state_key *my_state_key) { |
| 353 | state_data *this_state_data=NULL; | 355 | state_data *this_state_data=NULL; |
| 354 | my_state_key->state_data = this_state_data; | 356 | my_state_key->state_data = this_state_data; |
| 357 | |||
| 358 | /* Open file */ | ||
| 359 | |||
| 355 | return this_state_data; | 360 | return this_state_data; |
| 356 | } | 361 | } |
| 357 | 362 | ||
| @@ -362,12 +367,14 @@ state_data *np_state_read(state_key *my_state_key) { | |||
| 362 | * two things writing to same key at same time. | 367 | * two things writing to same key at same time. |
| 363 | * Will die with UNKNOWN if errors | 368 | * Will die with UNKNOWN if errors |
| 364 | */ | 369 | */ |
| 365 | void np_state_write_string(state_key *my_state_key, time_t data_time, char *data_string) { | 370 | void np_state_write_string(state_key *my_state_key, time_t *data_time, char *data_string) { |
| 366 | } | 371 | } |
| 367 | 372 | ||
| 368 | /* | 373 | /* |
| 369 | * Cleanup | 374 | * Cleanup |
| 370 | */ | 375 | */ |
| 371 | void np_state_cleanup(state_key *my_state_key) { | 376 | void np_state_cleanup(state_key *my_state_key) { |
| 377 | free(my_state_key); | ||
| 378 | my_state_key=NULL; | ||
| 372 | } | 379 | } |
| 373 | 380 | ||
diff --git a/lib/utils_base.h b/lib/utils_base.h index 6e1af94a..bec6c66f 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h | |||
| @@ -85,10 +85,10 @@ char *np_extract_value(const char*, const char*, char); | |||
| 85 | #define np_extract_ntpvar(l, n) np_extract_value(l, n, ',') | 85 | #define np_extract_ntpvar(l, n) np_extract_value(l, n, ',') |
| 86 | 86 | ||
| 87 | 87 | ||
| 88 | char *np_state_generate_key(const char **); | 88 | char *np_state_generate_key(char **); |
| 89 | state_key *np_state_init(char *, char *, int); | 89 | state_key *np_state_init(char *, char *, int); |
| 90 | state_data *np_state_read(state_key *); | 90 | state_data *np_state_read(state_key *); |
| 91 | void np_state_write_string(state_key *, time_t, char *); | 91 | void np_state_write_string(state_key *, time_t *, char *); |
| 92 | void np_state_cleanup(state_key *); | 92 | void np_state_cleanup(state_key *); |
| 93 | 93 | ||
| 94 | #endif /* _UTILS_BASE_ */ | 94 | #endif /* _UTILS_BASE_ */ |
