[nagiosplug] Add skeleton tests
Ton Voon
tonvoon at users.sourceforge.net
Mon Jun 21 14:07:59 CEST 2010
Module: nagiosplug
Branch: ton/state
Commit: 301599a4eca67e214ef79bd609843a9e1e710b3a
Author: Ton Voon <ton.voon at opsera.com>
Date: Thu Jun 17 10:57:59 2010 +0100
URL: http://nagiosplug.git.sf.net/git/gitweb.cgi?p=nagiosplug/nagiosplug;a=commit;h=301599a
Add skeleton tests
---
lib/tests/test_utils.c | 28 ++++++++++++++++++++++++++++
lib/utils_base.c | 11 +++++++++--
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 3a45944..057c484 100644
--- a/lib/tests/test_utils.c
+++ b/lib/tests/test_utils.c
@@ -28,6 +28,10 @@ main (int argc, char **argv)
double temp;
thresholds *thresholds = NULL;
int rc;
+ char *temp_string;
+ state_key *temp_state_key = NULL;
+ state_data *temp_state_data;
+ time_t current_time;
plan_tests(81+23);
@@ -251,5 +255,29 @@ main (int argc, char **argv)
test=np_extract_ntpvar("", "foo");
ok(!test, "Empty string return NULL");
+
+ temp_string = np_state_generate_key(argv);
+ ok(!strcmp(temp_string, "Ahash"), "Got hash" );
+
+ ok(temp_state_key==NULL, "temp_state_key initially empty");
+ temp_state_key = np_state_init("check_test", temp_string, 54);
+ ok( !strcmp(temp_state_key->plugin_name, "check_test"), "Got plugin name" );
+ ok( !strcmp(temp_state_key->name, temp_string), "Got key name" );
+ ok( !strcmp(temp_state_key->_filename, "Tobedone"), "Got internal filename" );
+ ok( temp_state_key->data_version==54, "Version set" );
+
+ temp_state_data = np_state_read(temp_state_key);
+ ok( temp_state_data==NULL, "Got state data" );
+
+ time(¤t_time);
+ np_state_write_string(temp_state_key, NULL, "New data");
+
+ temp_state_data = np_state_read(temp_state_key);
+ /* Check time is set to current_time */
+
+
+ np_state_cleanup(temp_state_key);
+ ok(temp_state_key==NULL, "temp_state_key cleared");
+
return exit_status();
}
diff --git a/lib/utils_base.c b/lib/utils_base.c
index c9f0912..fb44240 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -28,6 +28,8 @@
#include <stdarg.h>
#include "utils_base.h"
+#define np_free(ptr) { if(ptr) { free(ptr); ptr = NULL; } }
+
void
die (int result, const char *fmt, ...)
{
@@ -315,7 +317,7 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
* hopefully a unique key per service/plugin invocation. Use the extra-opts
* parse of argv, so that uniqueness in parameters are reflected there.
*/
-char *np_state_generate_key(const char **argv) {
+char *np_state_generate_key(char **argv) {
return "Ahash";
}
@@ -352,6 +354,9 @@ state_key *np_state_init(char *plugin_name, char *keyname, int expected_data_ver
state_data *np_state_read(state_key *my_state_key) {
state_data *this_state_data=NULL;
my_state_key->state_data = this_state_data;
+
+ /* Open file */
+
return this_state_data;
}
@@ -362,12 +367,14 @@ state_data *np_state_read(state_key *my_state_key) {
* two things writing to same key at same time.
* Will die with UNKNOWN if errors
*/
-void np_state_write_string(state_key *my_state_key, time_t data_time, char *data_string) {
+void np_state_write_string(state_key *my_state_key, time_t *data_time, char *data_string) {
}
/*
* Cleanup
*/
void np_state_cleanup(state_key *my_state_key) {
+ free(my_state_key);
+ my_state_key=NULL;
}
diff --git a/lib/utils_base.h b/lib/utils_base.h
index 6e1af94..bec6c66 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -85,10 +85,10 @@ char *np_extract_value(const char*, const char*, char);
#define np_extract_ntpvar(l, n) np_extract_value(l, n, ',')
-char *np_state_generate_key(const char **);
+char *np_state_generate_key(char **);
state_key *np_state_init(char *, char *, int);
state_data *np_state_read(state_key *);
-void np_state_write_string(state_key *, time_t, char *);
+void np_state_write_string(state_key *, time_t *, char *);
void np_state_cleanup(state_key *);
#endif /* _UTILS_BASE_ */
More information about the Commits
mailing list