[geocode-glib] test: Add search test
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geocode-glib] test: Add search test
- Date: Fri, 19 Oct 2012 17:16:13 +0000 (UTC)
commit 0d732a71d38cb62de4595b8270d505563e534a5c
Author: Bastien Nocera <hadess hadess net>
Date: Fri Oct 19 19:06:21 2012 +0200
test: Add search test
geocode-glib/test-gcglib.c | 55 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/geocode-glib/test-gcglib.c b/geocode-glib/test-gcglib.c
index 57cfe40..46b7d40 100644
--- a/geocode-glib/test-gcglib.c
+++ b/geocode-glib/test-gcglib.c
@@ -146,6 +146,60 @@ test_pub (void)
g_hash_table_destroy (ht);
}
+static gboolean
+key_is_value (GHashTable *ht,
+ const char *key,
+ const char *value)
+{
+ const char *our_val;
+
+ our_val = g_hash_table_lookup (ht, key);
+ if (our_val == NULL)
+ return FALSE;
+ return g_str_equal (value, our_val);
+}
+
+static void
+test_search (void)
+{
+ GeocodeObject *object;
+ GError *error = NULL;
+ GList *results, *l;
+ gboolean got_france, got_texas;
+
+ object = geocode_object_new_for_location ("paris");
+ results = geocode_object_search (object, &error);
+ if (results == NULL) {
+ g_warning ("Failed at geocoding: %s", error->message);
+ g_error_free (error);
+ }
+ g_assert (results != NULL);
+
+ g_object_unref (object);
+
+ /* We need to find Paris in France and in Texas */
+ got_france = FALSE;
+ got_texas = FALSE;
+ for (l = results; l != NULL; l = l->next) {
+ GHashTable *ht = l->data;
+
+ if (key_is_value (ht, "country", "France") &&
+ key_is_value (ht, "name", "Paris"))
+ got_france = TRUE;
+ else if (key_is_value (ht, "admin1", "Texas") &&
+ key_is_value (ht, "name", "Paris"))
+ got_texas = TRUE;
+ g_hash_table_destroy (ht);
+
+ if (got_france && got_texas)
+ break;
+ }
+ g_list_free (results);
+
+ g_assert (got_france);
+ g_assert (got_texas);
+}
+
static void
test_locale (void)
{
@@ -260,6 +314,7 @@ int main (int argc, char **argv)
g_test_add_func ("/geocode/pub", test_pub);
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);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]