[Nagios-devel] [PATCH 5/6] utils: Make internal prototypes easier

Engage with the community of users including those using the open source solutions.
Includes Nagios Core, Plugins, and NCPA

[Nagios-devel] [PATCH 5/6] utils: Make internal prototypes easier

Postby Guest » Mon May 06, 2013 3:21 pm

There was a mention about the old prototype (for an internal method)
making the code easier to test - in fact, it didn't, it just made things
more awkward.

Signed-off-by: Robin Sonefors
---
base/utils.c | 14 +++++++-------
t-tap/test_timeperiods.c | 36 ++++++++++++++++++------------------
2 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/base/utils.c b/base/utils.c
index 739087c..99946fb 100644
--- a/base/utils.c
+++ b/base/utils.c
@@ -970,9 +970,9 @@ int check_time_against_period(time_t test_time, timeperiod *tperiod) {

/*#define TEST_TIMEPERIODS_B 1*/

-void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_time, timeperiod *tperiod);
+void _get_next_valid_time(time_t pref_time, time_t *valid_time, timeperiod *tperiod);

-static void _get_next_invalid_time(time_t pref_time, time_t current_time, time_t *invalid_time, timeperiod *tperiod) {
+static void _get_next_invalid_time(time_t pref_time, time_t *invalid_time, timeperiod *tperiod) {
timeperiodexclusion *temp_timeperiodexclusion = NULL;
int depth = 0;
int max_depth = 300; // commonly roughly equal to "days in the future"
@@ -1029,7 +1029,7 @@ static void _get_next_invalid_time(time_t pref_time, time_t current_time, time_t
}

for(temp_timeperiodexclusion = tperiod->exclusions; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) {
- _get_next_valid_time(last_earliest_time, current_time, &potential_time, temp_timeperiodexclusion->timeperiod_ptr);
+ _get_next_valid_time(last_earliest_time, &potential_time, temp_timeperiodexclusion->timeperiod_ptr);
if (potential_time + 60 < earliest_time)
earliest_time = potential_time + 60;
}
@@ -1044,8 +1044,8 @@ static void _get_next_invalid_time(time_t pref_time, time_t current_time, time_t
*invalid_time = earliest_time;
}

-/* Separate this out from public get_next_valid_time for testing, so we can mock current_time */
-void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_time, timeperiod *tperiod) {
+/* Separate this out from public get_next_valid_time for testing */
+void _get_next_valid_time(time_t pref_time, time_t *valid_time, timeperiod *tperiod) {
timeperiodexclusion *temp_timeperiodexclusion = NULL;
int depth = 0;
int max_depth = 300; // commonly roughly equal to "days in the future"
@@ -1119,7 +1119,7 @@ void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_t
earliest_time = midnight + 86400;
} else {
for(temp_timeperiodexclusion = tperiod->exclusions; temp_timeperiodexclusion != NULL; temp_timeperiodexclusion = temp_timeperiodexclusion->next) {
- _get_next_invalid_time(earliest_time, current_time, &earliest_time, temp_timeperiodexclusion->timeperiod_ptr);
+ _get_next_invalid_time(earliest_time, &earliest_time, temp_timeperiodexclusion->timeperiod_ptr);
#ifdef TEST_TIMEPERIODS_B
printf(" FINAL EARLIEST TIME: %lu = %s", (unsigned long)earliest_time, ctime(&earliest_time));
#endif
@@ -1145,7 +1145,7 @@ void get_next_valid_time(time_t pref_time, time_t *valid_time, timeperiod *tperi

pref_time = (pref_time < current_time) ? current_time : pref_time;

- _get_next_valid_time(pref_time, current_time, valid_time, tperiod);
+ _get_next_valid_time(pref_time, valid_time, tperiod);
}


diff --git a/t-tap/test_timeperiods.c b/t-tap/test_timeperiods.c
index e660855..6aa292f 100644
--- a/t-tap/test_timeperiods.c
+++ b/t-tap/test_timeperiods.c
@@ -147,7 +147,7 @@ int main(int argc, char **argv) {
is_valid_time = check_time_against_period(test_time, temp_timeperiod);
ok(is_valid_time == OK, "Always OK for 24x7 with TZ=UTC, time_t=%lu", test_time);
chosen_valid_time = 0L;
- _get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
+ _get_next_valid_time(test_time, &chosen_valid_time, temp_timeperiod);
ok(test_time == chosen_valid_time, "get_next_valid_time always returns same time");
test_time += 1800;
c++;
@@ -160,7 +160,7 @@ int main(int argc, char **argv) {
while(c < iterations) {
is_valid_time = check_time_against_period(test_time,

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: robin.sonefors@op5.com
Guest
 

Return to Community Support

Who is online

Users browsing this forum: Google [Bot] and 10 guests