[geocode-glib] Add testcases for _geocode_ip_json_to_location()



commit 67aa20324a1b0b2f35ded742cb81b6e01a71522a
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        |    3 +-
 geocode-glib/test-geoip-parse.c |   53 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletions(-)
---
diff --git a/geocode-glib/Makefile.am b/geocode-glib/Makefile.am
index af9108a..b3e39f0 100644
--- a/geocode-glib/Makefile.am
+++ b/geocode-glib/Makefile.am
@@ -94,11 +94,12 @@ 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
 
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]