[libgweather] GWeatherLocation: Remove _get_world_for_path() API



commit d8e61523dac2b9c960aba6846cac0b4c1a1895a0
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Dec 6 20:03:55 2017 +0100

    GWeatherLocation: Remove _get_world_for_path() API
    
    And the changes it required from commit ad604b79. There are a number
    of internal uses of gweather_location_get_world(), including in the
    GWeatherTimezone code, and adding new API for the sake of our tests
    feels wrong, and would complicate the public API for no reason.
    
    Instead, allow using the LIBGWEATHER_LOCATIONS_PATH envvar to override
    the location of the Locations.xml file. This makes it easy to use the
    same API in our tests and installed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=791317

 libgweather/gweather-location.c |   41 ++++++++++++++------------------------
 libgweather/gweather-location.h |    3 --
 libgweather/test_libgweather.c  |   11 +++++----
 3 files changed, 21 insertions(+), 34 deletions(-)
---
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index 0543729..82d0295 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -340,7 +340,19 @@ gweather_location_get_world (void)
     GWeatherParser *parser;
 
     if (!global_world) {
-       parser = _gweather_parser_new ();
+        const char *locations_path;
+
+        locations_path = g_getenv ("LIBGWEATHER_LOCATIONS_PATH");
+        if (locations_path) {
+            parser = _gweather_parser_new_for_path (locations_path);
+            if (!parser) {
+                g_warning ("Failed to open '%s' as LIBGWEATHER_LOCATIONS_PATH",
+                           locations_path);
+                parser = _gweather_parser_new ();
+            }
+        } else {
+            parser = _gweather_parser_new ();
+        }
        if (!parser)
            return NULL;
 
@@ -352,31 +364,6 @@ gweather_location_get_world (void)
 }
 
 /**
- * gweather_location_new_world_for_path:
- *
- * The same as gweather_location_get_world() but for a specific Locations.xml
- * file. This is usually only needed for debugging and testing purposes.
- *
- * Return value: (allow-none) (transfer full): a %GWEATHER_LOCATION_WORLD
- * location, or %NULL if Locations.xml could not be found or could not be parsed.
- **/
-GWeatherLocation *
-gweather_location_new_world_for_path (const char *path)
-{
-    GWeatherParser *parser;
-    GWeatherLocation *world;
-
-    parser = _gweather_parser_new_for_path (path);
-    if (!parser)
-        return NULL;
-
-    world = location_new_from_xml (parser, GWEATHER_LOCATION_WORLD, NULL);
-    _gweather_parser_free (parser);
-
-    return world;
-}
-
-/**
  * gweather_location_ref:
  * @loc: a #GWeatherLocation
  *
@@ -410,6 +397,8 @@ gweather_location_unref (GWeatherLocation *loc)
     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);
diff --git a/libgweather/gweather-location.h b/libgweather/gweather-location.h
index 84a3dae..a7edfb0 100644
--- a/libgweather/gweather-location.h
+++ b/libgweather/gweather-location.h
@@ -56,9 +56,6 @@ GWEATHER_EXTERN
 GWeatherLocation      *gweather_location_get_world      (void);
 
 GWEATHER_EXTERN
-GWeatherLocation      *gweather_location_new_world_for_path (const char *path);
-
-GWEATHER_EXTERN
 GWeatherLocation      *gweather_location_ref            (GWeatherLocation  *loc);
 GWEATHER_EXTERN
 void                   gweather_location_unref          (GWeatherLocation  *loc);
diff --git a/libgweather/test_libgweather.c b/libgweather/test_libgweather.c
index 1e47298..e2b5093 100644
--- a/libgweather/test_libgweather.c
+++ b/libgweather/test_libgweather.c
@@ -29,7 +29,7 @@ test_named_timezones (void)
     GWeatherLocation *world, **children;
     guint i;
 
-    world = gweather_location_new_world_for_path (TEST_SRCDIR "../data/Locations.xml");
+    world = gweather_location_get_world ();
     g_assert (world);
 
     children = gweather_location_get_children (world);
@@ -46,8 +46,6 @@ test_named_timezones (void)
         g_assert_nonnull (code);
         g_assert_true (code[0] == '@');
     }
-
-    gweather_location_unref (world);
 }
 
 static void
@@ -103,11 +101,10 @@ test_timezones (void)
 {
     GWeatherLocation *world;
 
-    world = gweather_location_new_world_for_path (TEST_SRCDIR "../data/Locations.xml");
+    world = gweather_location_get_world ();
     g_assert (world);
 
     test_timezones_children (world);
-    gweather_location_unref (world);
 }
 
 static void
@@ -127,6 +124,10 @@ main (int argc, char *argv[])
        /* We need to handle log messages produced by g_message so they're interpreted correctly by the 
GTester framework */
        g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, log_handler, 
NULL);
 
+       g_setenv ("LIBGWEATHER_LOCATIONS_PATH",
+                 TEST_SRCDIR "../data/Locations.xml",
+                 FALSE);
+
        g_test_add_func ("/weather/named-timezones", test_named_timezones);
        g_test_add_func ("/weather/timezones", test_timezones);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]