[geocode-glib/gnome-maps: 1/6] Add testcases for _geocode_ip_json_to_location()



commit eb38f38d3af6ef2846c719e1a8435417854ddac2
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                       |   13 ++++--
 geocode-glib/data/freegeoip-results.json       |    1 +
 geocode-glib/data/gglib-ip-server-results.json |    1 +
 geocode-glib/test-geoip-parse.c                |   53 ++++++++++++++++++++++++
 4 files changed, 63 insertions(+), 5 deletions(-)
---
diff --git a/geocode-glib/Makefile.am b/geocode-glib/Makefile.am
index 5ad7fac..b3e39f0 100644
--- a/geocode-glib/Makefile.am
+++ b/geocode-glib/Makefile.am
@@ -94,16 +94,19 @@ CLEANFILES += $(gir_DATA) $(typelib_DATA)
 
 endif # HAVE_INTROSPECTION
 
-TEST_PROGS += test-gcglib test-geoip
+TEST_PROGS += test-gcglib test-geoip test-geoip-parse
 noinst_PROGRAMS = $(TEST_PROGS)
 
 test_gcglib_LDADD = libgeocode-glib.la $(GEOCODE_LIBS)
 test_geoip_LDADD = libgeocode-glib.la $(GEOCODE_LIBS)
+test_geoip_parse_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-parse.c b/geocode-glib/test-geoip-parse.c
new file mode 100644
index 0000000..e4eb81f
--- /dev/null
+++ b/geocode-glib/test-geoip-parse.c
@@ -0,0 +1,53 @@
+#include "config.h"
+#include <locale.h>
+#include <glib.h>
+#include <stdlib.h>
+#include <string.h>
+#include <gio/gio.h>
+#include "geocode-glib-private.h"
+
+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);
+}
+
+int main (int argc, char **argv)
+{
+        setlocale (LC_ALL, "");
+        g_type_init ();
+        g_test_init (&argc, &argv, NULL);
+        g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=";);
+
+        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]