[systemd-devel] [PATCH 7/8] tests: add tests for time-util.c
Ronny Chevalier
chevalier.ronny at gmail.com
Sat Aug 16 05:19:11 PDT 2014
add tests for:
- timezone_is_valid
- get_timezones
---
src/test/test-time.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/src/test/test-time.c b/src/test/test-time.c
index 7c29f96..87e7ae7 100644
--- a/src/test/test-time.c
+++ b/src/test/test-time.c
@@ -20,6 +20,7 @@
***/
#include "time-util.h"
+#include "strv.h"
static void test_parse_sec(void) {
usec_t u;
@@ -126,11 +127,33 @@ static void test_format_timespan(usec_t accuracy) {
test_format_timespan_one(9*USEC_PER_YEAR/5 - 23, accuracy);
}
+static void test_timezone_is_valid(void) {
+ assert_se(timezone_is_valid("Europe/Berlin"));
+ assert_se(timezone_is_valid("Australia/Sydney"));
+ assert_se(!timezone_is_valid("Europe/Do not exist"));
+}
+
+static void test_get_timezones(void) {
+ _cleanup_strv_free_ char **zones = NULL;
+ int r;
+ char **zone;
+
+ r = get_timezones(&zones);
+ assert_se(r == 0);
+
+ STRV_FOREACH(zone, zones) {
+ assert_se(timezone_is_valid(*zone));
+ }
+}
+
int main(int argc, char *argv[]) {
test_parse_sec();
test_parse_nsec();
test_format_timespan(1);
test_format_timespan(USEC_PER_MSEC);
test_format_timespan(USEC_PER_SEC);
+ test_timezone_is_valid();
+ test_get_timezones();
+
return 0;
}
--
2.0.4
More information about the systemd-devel
mailing list