[PATCH 5/6] utils: Make internal prototypes easier to use

Robin Sonefors robin.sonefors at op5.com
Mon May 6 18:04:32 CEST 2013


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 <robin.sonefors at op5.com>
---
 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, temp_timeperiod);
 		ok(is_valid_time == OK, "Always OK for 24x7 with TZ=Europe/London, time_t=%lu", test_time);
-		_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, time_t=%lu", test_time);
 		test_time += 1800;
 		c++;
@@ -178,7 +178,7 @@ int main(int argc, char **argv) {
 	while(c < iterations) {
 		is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 		ok(is_valid_time == OK, "Always OK for 24x7 with TZ=America/New_York, time_t=%lu", test_time);
-		_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, time_t=%lu", test_time);
 		test_time += 1800;
 		c++;
@@ -200,7 +200,7 @@ int main(int argc, char **argv) {
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid");
 
-	_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(chosen_valid_time == 1288103400, "Next valid time should be Tue Oct 26 16:30:00 2010, was %s", ctime(&chosen_valid_time));
 
 
@@ -209,7 +209,7 @@ int main(int argc, char **argv) {
 	test_time = 1278939600; //mon jul 12 15:00:00
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid");
-	_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(chosen_valid_time == 1279058340, "Next valid time should be Tue Jul 13 23:59:00 2010, was %s", ctime(&chosen_valid_time));
 
 
@@ -218,7 +218,7 @@ int main(int argc, char **argv) {
 	test_time = 1278939600; //mon jul 12 15:00:00
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid");
-	_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(chosen_valid_time == 1284474600, "Next valid time should be Tue Sep 14 16:30:00 2010, was %s", ctime(&chosen_valid_time));
 
 
@@ -227,7 +227,7 @@ int main(int argc, char **argv) {
 	test_time = 1278939600; //mon jul 12 15:00:00
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == ERROR, "12 Jul 2010 15:00:00 should not be valid");
-	_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(chosen_valid_time == 1283265000, "Next valid time should be Tue Aug 31 16:30:00 2010, was %s", ctime(&chosen_valid_time));
 
 
@@ -247,62 +247,62 @@ int main(int argc, char **argv) {
 	test_time = 1256421000;
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == ERROR, "Sat Oct 24 22:50:00 2009 - false");
-	_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(chosen_valid_time == 1256425200, "Next valid time=Sun Oct 25 00:00:00 2009");
 
 
 	test_time = 1256421661;
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == ERROR, "Sat Oct 24 23:01:01 2009 - false");
-	_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(chosen_valid_time == 1256425200, "Next valid time=Sun Oct 25 00:00:00 2009");
 
 	test_time = 1256425400;
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == OK, "Sun Oct 25 00:03:20 2009 - true");
-	_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(chosen_valid_time == test_time, "Next valid time=Sun Oct 25 00:03:20 2009");
 
 	test_time = 1256429700;
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == OK, "Sun Oct 25 01:15:00 2009 - true");
-	_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(chosen_valid_time == test_time, "Next valid time=Sun Oct 25 01:15:00 2009");
 
 	test_time = 1256430400;
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == ERROR, "Sun Oct 25 01:26:40 2009 - false");
-	_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(chosen_valid_time == 1256440500, "Next valid time should be Sun Oct 25 03:15:00 2009, was %s", ctime(&chosen_valid_time));
 
 	test_time = 1256440500;
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == OK, "Sun Oct 25 03:15:00 2009 - true");
-	_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(chosen_valid_time == test_time, "Next valid time=Sun Oct 25 03:15:00 2009");
 
 	test_time = 1256500000;
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == OK, "Sun Oct 25 19:46:40 2009 - true");
-	_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(chosen_valid_time == 1256500000, "Next valid time=Sun Oct 25 19:46:40 2009");
 
 	test_time = 1256508000;
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == OK, "Sun Oct 25 22:00:00 2009 - true");
-	_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(chosen_valid_time == 1256508000, "Next valid time=Sun Oct 25 22:00:00 2009");
 
 	test_time = 1256508001;
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == ERROR, "Sun Oct 25 22:00:01 2009 - false");
-	_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(chosen_valid_time == 1257033600, "Next valid time=Sun Nov 1 00:00:00 2009");
 
 	test_time = 1256513000;
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == ERROR, "Sun Oct 25 23:23:20 2009 - false");
-	_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(chosen_valid_time == 1257033600, "Next valid time=Sun Nov 1 00:00:00 2009");
 
 
@@ -316,7 +316,7 @@ int main(int argc, char **argv) {
 	test_time = 1268109420;
 	is_valid_time = check_time_against_period(test_time, temp_timeperiod);
 	ok(is_valid_time == ERROR, "Mon Mar  8 23:37:00 2010 - false");
-	_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(chosen_valid_time == 1268115300, "Next valid time=Tue Mar  9 01:15:00 2010");
 
 
-- 
1.7.11.7


------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1




More information about the Developers mailing list