summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2018-10-09 13:17:15 +0200
committerBastien Nocera <hadess@hadess.net>2018-10-18 12:11:44 +0200
commite64216f67fd52e421b9677edd2a15704a4d3612c (patch)
treeb97ea8c03abc774cdd715a50f75ce868d9fb720f
parent0fcab52c37180ef7e27e7cb312df6df1382347c7 (diff)
downloadlibgweather-e64216f67fd52e421b9677edd2a15704a4d3612c.tar.gz
GWeatherLocation: Add private function to reset the world
So that we can test easily the different envvars.
-rw-r--r--libgweather/gweather-location.c41
-rw-r--r--libgweather/test_libgweather.c2
2 files changed, 29 insertions, 14 deletions
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index fd2439d..1a53d82 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -381,7 +381,15 @@ error_out:
return NULL;
}
-static GWeatherLocation *global_world;
+static GWeatherLocation *global_world = NULL;
+
+static void _gweather_location_unref_no_check (GWeatherLocation *loc);
+
+GWEATHER_EXTERN void
+_gweather_location_reset_world (void)
+{
+ g_clear_pointer (&global_world, _gweather_location_unref_no_check);
+}
/**
* gweather_location_get_world:
@@ -441,25 +449,14 @@ gweather_location_ref (GWeatherLocation *loc)
return loc;
}
-/**
- * gweather_location_unref:
- * @loc: a #GWeatherLocation
- *
- * Subtracts 1 from @loc's reference count, and frees it if the
- * reference count reaches 0.
- **/
-void
-gweather_location_unref (GWeatherLocation *loc)
+static void
+_gweather_location_unref_no_check (GWeatherLocation *loc)
{
int i;
- g_return_if_fail (loc != NULL);
-
if (--loc->ref_count)
return;
- g_return_if_fail (loc->level != GWEATHER_LOCATION_WORLD);
-
g_free (loc->english_name);
g_free (loc->local_name);
g_free (loc->msgctxt);
@@ -495,6 +492,22 @@ gweather_location_unref (GWeatherLocation *loc)
g_slice_free (GWeatherLocation, loc);
}
+/**
+ * gweather_location_unref:
+ * @loc: a #GWeatherLocation
+ *
+ * Subtracts 1 from @loc's reference count, and frees it if the
+ * reference count reaches 0.
+ **/
+void
+gweather_location_unref (GWeatherLocation *loc)
+{
+ g_return_if_fail (loc != NULL);
+ g_return_if_fail (loc->level != GWEATHER_LOCATION_WORLD);
+
+ _gweather_location_unref_no_check (loc);
+}
+
GType
gweather_location_get_type (void)
{
diff --git a/libgweather/test_libgweather.c b/libgweather/test_libgweather.c
index 82a5c9b..d8f6586 100644
--- a/libgweather/test_libgweather.c
+++ b/libgweather/test_libgweather.c
@@ -26,6 +26,8 @@
#include <gweather-version.h>
#include "gweather-location.h"
+extern void _gweather_location_reset_world (void);
+
/* For test_metar_weather_stations */
#define METAR_SOURCES "https://www.aviationweather.gov/docs/metar/stations.txt"