[geocode-glib] Add testcases for _geocode_ip_json_to_location()



commit 4f1f6aa2340d7b201ec0279614bb6a9e5dde3e23
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Apr 3 01:04:24 2013 +0300

    Add testcases for _geocode_ip_json_to_location()
    
    Test this function against responses from both our server and freegeoip.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=696526

 geocode-glib/Makefile.am                       |   10 ++++--
 geocode-glib/data/freegeoip-results.json       |    1 +
 geocode-glib/data/gglib-ip-server-results.json |    1 +
 geocode-glib/test-geoip.c                      |   38 ++++++++++++++++++++++++
 4 files changed, 46 insertions(+), 4 deletions(-)
---
diff --git a/geocode-glib/Makefile.am b/geocode-glib/Makefile.am
index 5ad7fac..af9108a 100644
--- a/geocode-glib/Makefile.am
+++ b/geocode-glib/Makefile.am
@@ -102,8 +102,10 @@ test_geoip_LDADD = libgeocode-glib.la $(GEOCODE_LIBS)
 
 MAINTAINERCLEANFILES = Makefile.in
 
-EXTRA_DIST +=                                  \
-       data/geoplanet-rio.json                 \
-       data/placefinder-area.json              \
-       data/placefinder-got-error.json         \
+EXTRA_DIST +=                                   \
+       data/freegeoip-results.json              \
+       data/geoplanet-rio.json                  \
+       data/gglib-ip-server-results.json        \
+       data/placefinder-area.json               \
+       data/placefinder-got-error.json          \
        data/placefinder-no-results.json
diff --git a/geocode-glib/data/freegeoip-results.json b/geocode-glib/data/freegeoip-results.json
new file mode 100644
index 0000000..ca4a53b
--- /dev/null
+++ b/geocode-glib/data/freegeoip-results.json
@@ -0,0 +1 @@
+{"ip":"213.243.180.91","country_code":"FI","country_name":"Finland","region_code":"13","region_name":"Southern
 Finland","city":"Helsinki","zipcode":"","latitude":60.1756,"longitude":24.9342,"metro_code":"","areacode":""}
diff --git a/geocode-glib/data/gglib-ip-server-results.json b/geocode-glib/data/gglib-ip-server-results.json
new file mode 100644
index 0000000..e4f1368
--- /dev/null
+++ b/geocode-glib/data/gglib-ip-server-results.json
@@ -0,0 +1 @@
+{"ip":"213.243.180.91","latitude":60.17559814453125,"longitude":24.934200286865234,"country_name":"Finland","country_code":"FI","region_name":"Southern
 Finland","city":"Helsinki","accuracy":"city","timezone":"Europe/Helsinki","attribution":"This product 
includes GeoLite data created by MaxMind, available from http://www.maxmind.com\n"}
\ No newline at end of file
diff --git a/geocode-glib/test-geoip.c b/geocode-glib/test-geoip.c
index 895e643..193b8e3 100644
--- a/geocode-glib/test-geoip.c
+++ b/geocode-glib/test-geoip.c
@@ -6,6 +6,7 @@
 #include <string.h>
 #include <gio/gio.h>
 #include <geocode-ipclient.h>
+#include "geocode-glib-private.h"
 
 static GMainLoop *loop = NULL;
 
@@ -18,6 +19,35 @@ typedef struct {
 } TestData;
 
 static void
+test_parse_json (gconstpointer data)
+{
+        GeocodeLocation *location;
+        GFile *file;
+        char *contents;
+        char *path;
+        GError *error = NULL;
+
+        path = g_build_filename (TEST_SRCDIR, (const char *) data, NULL);
+        g_assert (path != NULL);
+        file = g_file_new_for_path (path);
+        if (!g_file_load_contents (file, NULL, &contents, NULL, NULL, &error)) {
+                g_warning ("Failed to load file '%s': %s", path, error->message);
+                g_error_free (error);
+                g_assert_not_reached ();
+        }
+
+        location = _geocode_ip_json_to_location (contents, &error);
+        if (!location) {
+                g_warning ("Failed to parse '%s': %s", path, error->message);
+                g_error_free (error);
+        }
+        g_free (contents);
+        g_free (path);
+        geocode_location_free (location);
+}
+
+
+static void
 test_search (gconstpointer data)
 {
         GeocodeIpclient *ipclient;
@@ -102,6 +132,14 @@ int main (int argc, char **argv)
 
                 data.ip = "24.24.24.24";
                 g_test_add_data_func ("/geoip/search_with_ip", &data, test_search);
+
+                g_test_add_data_func ("/geoip/parse-freegeoip-response",
+                                      "freegeoip-results.json",
+                                      test_parse_json);
+
+                g_test_add_data_func ("/geoip/parse-geocode-glib-response",
+                                      "gglib-ip-server-results.json",
+                                      test_parse_json);
                 return g_test_run ();
         }
 


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