[geocode-glib] lib: Fix the coords parsing from searches
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geocode-glib] lib: Fix the coords parsing from searches
- Date: Sun, 25 Nov 2012 02:02:22 +0000 (UTC)
commit 3ea5e3ab27b69ae2b03d98b22437cab2476d8d39
Author: Bastien Nocera <hadess hadess net>
Date: Sun Nov 25 02:56:22 2012 +0100
lib: Fix the coords parsing from searches
The lat/long were swapped. Add a test case for it (-100 is an
invalid latitude).
geocode-glib/geocode-forward.c | 12 ++++++------
geocode-glib/test-gcglib.c | 30 ++++++++++++++++++++++++++++--
2 files changed, 34 insertions(+), 8 deletions(-)
---
diff --git a/geocode-glib/geocode-forward.c b/geocode-glib/geocode-forward.c
index 92d5884..d2276e1 100644
--- a/geocode-glib/geocode-forward.c
+++ b/geocode-glib/geocode-forward.c
@@ -558,8 +558,8 @@ end:
static char *
create_description_from_attrs (GHashTable *ht,
- gdouble *longitude,
- gdouble *latitude)
+ gdouble *latitude,
+ gdouble *longitude)
{
*longitude = g_ascii_strtod (g_hash_table_lookup (ht, "longitude"), NULL);
*latitude = g_ascii_strtod (g_hash_table_lookup (ht, "latitude"), NULL);
@@ -574,10 +574,10 @@ new_location_from_result (GHashTable *ht)
gdouble longitude, latitude;
description = create_description_from_attrs (ht,
- &longitude,
- &latitude);
- loc = geocode_location_new_with_description (longitude,
- latitude,
+ &latitude,
+ &longitude);
+ loc = geocode_location_new_with_description (latitude,
+ longitude,
description);
g_free (description);
diff --git a/geocode-glib/test-gcglib.c b/geocode-glib/test-gcglib.c
index 20acced..808f07f 100644
--- a/geocode-glib/test-gcglib.c
+++ b/geocode-glib/test-gcglib.c
@@ -237,6 +237,30 @@ test_search (void)
}
static void
+test_search_lat_long (void)
+{
+ GeocodeForward *object;
+ GError *error = NULL;
+ GList *res;
+ GeocodeLocation *loc;
+
+ object = geocode_forward_new_for_string ("Santa MarÃa del RÃo");
+ res = geocode_forward_search (object, &error);
+ if (res == NULL) {
+ g_warning ("Failed at geocoding: %s", error->message);
+ g_error_free (error);
+ }
+ g_assert (res != NULL);
+ g_object_unref (object);
+
+ loc = res->data;
+ g_assert_cmpfloat (loc->latitude - 21.800699, <, 0.000001);
+ g_assert_cmpfloat (loc->longitude - -100.735626, <, 0.000001);
+
+ g_list_free_full (res, (GDestroyNotify) geocode_location_free);
+}
+
+static void
test_locale (void)
{
GeocodeForward *object;
@@ -260,8 +284,9 @@ test_locale (void)
loc = res->data;
g_assert_cmpstr (loc->description, ==, "Moskva");
- g_assert_cmpfloat (loc->latitude - 37.614971, <, 0.000001);
- g_assert_cmpfloat (loc->longitude - 55.756950, <, 0.000001);
+ g_assert_cmpfloat (loc->latitude - 55.756950, <, 0.000001);
+ g_assert_cmpfloat (loc->longitude - 37.614971, <, 0.000001);
+ print_loc (loc);
g_list_free_full (res, (GDestroyNotify) geocode_location_free);
@@ -382,6 +407,7 @@ int main (int argc, char **argv)
g_test_add_func ("/geocode/xep-0080", test_xep);
g_test_add_func ("/geocode/locale", test_locale);
g_test_add_func ("/geocode/search", test_search);
+ g_test_add_func ("/geocode/search_lat_long", test_search_lat_long);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]