[libgweather/Community/Purism/libgweather-location-get-english-name: 3/3] GWeatherLocation: Add gweather_location_get_english_name()



commit 9155bc6e1e50cadb86c9966010ed009002b6139c
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Mon Jun 10 14:13:21 2019 +0200

    GWeatherLocation: Add gweather_location_get_english_name()
    
    This is needed to replicate the behavior of GWeatherLocationEntry out of
    libgweather.
    
    This also adds a test for location name getters.

 doc/libgweather-sections.txt    |  1 +
 libgweather/gweather-location.c | 16 ++++++++++++++++
 libgweather/gweather-location.h |  2 ++
 libgweather/test_libgweather.c  | 31 +++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+)
---
diff --git a/doc/libgweather-sections.txt b/doc/libgweather-sections.txt
index 4a58ba9..ad7d04c 100644
--- a/doc/libgweather-sections.txt
+++ b/doc/libgweather-sections.txt
@@ -70,6 +70,7 @@ gweather_location_get_children
 <SUBSECTION>
 gweather_location_get_name
 gweather_location_get_sort_name
+gweather_location_get_english_name
 gweather_location_has_coords
 gweather_location_get_coords
 gweather_location_get_distance
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index ce56617..3967956 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -599,6 +599,22 @@ gweather_location_get_sort_name (GWeatherLocation *loc)
     return loc->local_sort_name;
 }
 
+/**
+ * gweather_location_get_english_name:
+ * @loc: a #GWeatherLocation
+ *
+ * Gets @loc's English name.
+ *
+ * Return value: @loc's English name
+ **/
+const char *
+gweather_location_get_english_name (GWeatherLocation *loc)
+{
+    g_return_val_if_fail (loc != NULL, NULL);
+
+    return loc->english_name;
+}
+
 /**
  * gweather_location_get_level:
  * @loc: a #GWeatherLocation
diff --git a/libgweather/gweather-location.h b/libgweather/gweather-location.h
index eeea3dd..ef2eb8e 100644
--- a/libgweather/gweather-location.h
+++ b/libgweather/gweather-location.h
@@ -63,6 +63,8 @@ const char            *gweather_location_get_name       (GWeatherLocation  *loc)
 GWEATHER_EXTERN
 const char            *gweather_location_get_sort_name  (GWeatherLocation  *loc);
 GWEATHER_EXTERN
+const char            *gweather_location_get_english_name (GWeatherLocation  *loc);
+GWEATHER_EXTERN
 GWeatherLocationLevel  gweather_location_get_level      (GWeatherLocation  *loc);
 GWEATHER_EXTERN
 GWeatherLocation      *gweather_location_get_parent     (GWeatherLocation  *loc);
diff --git a/libgweather/test_libgweather.c b/libgweather/test_libgweather.c
index 7115f28..06f51ee 100644
--- a/libgweather/test_libgweather.c
+++ b/libgweather/test_libgweather.c
@@ -638,6 +638,36 @@ test_duplicate_weather_stations (void)
     _gweather_location_reset_world ();
 }
 
+static void
+test_location_names (void)
+{
+    GWeatherLocation *world, *brussels;
+
+    world = gweather_location_get_world ();
+    g_assert (world);
+
+    brussels = gweather_location_find_nearest_city (world, 50.833333, 4.333333);
+    g_assert (brussels);
+    g_assert_cmpstr (gweather_location_get_name (brussels), ==, "Brussels");
+    g_assert_cmpstr (gweather_location_get_sort_name (brussels), ==, "brussels");
+    g_assert_cmpstr (gweather_location_get_english_name (brussels), ==, "Brussels");
+
+    setlocale (LC_ALL, "fr_FR.UTF-8");
+    _gweather_location_reset_world ();
+
+    world = gweather_location_get_world ();
+    g_assert (world);
+
+    brussels = gweather_location_find_nearest_city (world, 50.833333, 4.333333);
+    g_assert (brussels);
+    g_assert_cmpstr (gweather_location_get_name (brussels), ==, "Bruxelles");
+    g_assert_cmpstr (gweather_location_get_sort_name (brussels), ==, "bruxelles");
+    g_assert_cmpstr (gweather_location_get_english_name (brussels), ==, "Brussels");
+
+    setlocale (LC_ALL, "");
+    _gweather_location_reset_world ();
+}
+
 static void
 log_handler (const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer user_data)
 {
@@ -670,6 +700,7 @@ main (int argc, char *argv[])
        /* Modifies environment, so needs to run last */
        g_test_add_func ("/weather/bad_duplicate_weather_stations", test_bad_duplicate_weather_stations);
        g_test_add_func ("/weather/duplicate_weather_stations", test_duplicate_weather_stations);
+       g_test_add_func ("/weather/location-names", test_location_names);
 
        return g_test_run ();
 }


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