[libgweather] tests: Add tests for timezone validity
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgweather] tests: Add tests for timezone validity
- Date: Thu, 7 Dec 2017 00:29:18 +0000 (UTC)
commit 2dab8a8183aaac959ad89c2db4f4acb307ecb407
Author: Bastien Nocera <hadess hadess net>
Date: Wed Dec 6 14:46:00 2017 +0100
tests: Add tests for timezone validity
For every location at the country level, or smaller, check whether we
have at least one timezone defined. If only one timezone is defined for
the location, verify its validity.
This generated 3 errors:
(MSG: Location 'Anywhere on Earth (AoE)' has invalid timezone 'Etc/UTC-12')
(MSG: Location 'Wake Island, Wake Island Army Airfield Airport' does not have an associated timezone)
(MSG: Location 'Wake Island, Wake Island Army Airfield Airport' does not have an associated timezone)
https://bugzilla.gnome.org/show_bug.cgi?id=791307
libgweather/test_libgweather.c | 61 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 61 insertions(+), 0 deletions(-)
---
diff --git a/libgweather/test_libgweather.c b/libgweather/test_libgweather.c
index d51de20..1e47298 100644
--- a/libgweather/test_libgweather.c
+++ b/libgweather/test_libgweather.c
@@ -51,6 +51,66 @@ test_named_timezones (void)
}
static void
+test_timezone (GWeatherLocation *location)
+{
+ GWeatherTimezone *gtz;
+ const char *tz;
+
+ tz = gweather_location_get_timezone_str (location);
+ if (!tz) {
+ GWeatherTimezone **tzs;
+
+ tzs = gweather_location_get_timezones (location);
+ g_assert (tzs);
+
+ /* Only countries should have multiple timezones associated */
+ if (tzs[0] == NULL ||
+ gweather_location_get_level (location) > GWEATHER_LOCATION_COUNTRY) {
+ g_test_message ("Location '%s' does not have an associated timezone",
+ gweather_location_get_name (location));
+ g_test_fail ();
+ }
+ gweather_location_free_timezones (location, tzs);
+ return;
+ }
+
+ gtz = gweather_timezone_get_by_tzid (tz);
+ if (!gtz) {
+ g_test_message ("Location '%s' has invalid timezone '%s'",
+ gweather_location_get_name (location),
+ tz);
+ g_test_fail ();
+ }
+}
+
+static void
+test_timezones_children (GWeatherLocation *location)
+{
+ GWeatherLocation **children;
+ guint i;
+
+ children = gweather_location_get_children (location);
+ for (i = 0; children[i] != NULL; i++) {
+ if (gweather_location_get_level (children[i]) >= GWEATHER_LOCATION_COUNTRY)
+ test_timezone (children[i]);
+
+ test_timezones_children (children[i]);
+ }
+}
+
+static void
+test_timezones (void)
+{
+ GWeatherLocation *world;
+
+ world = gweather_location_new_world_for_path (TEST_SRCDIR "../data/Locations.xml");
+ g_assert (world);
+
+ test_timezones_children (world);
+ gweather_location_unref (world);
+}
+
+static void
log_handler (const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer user_data)
{
g_test_message ("%s", message);
@@ -68,6 +128,7 @@ main (int argc, char *argv[])
g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, log_handler,
NULL);
g_test_add_func ("/weather/named-timezones", test_named_timezones);
+ g_test_add_func ("/weather/timezones", test_timezones);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]