[geocode-glib/gnome-maps: 3/9] Add testcase for our & freegeoip JSON formats
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geocode-glib/gnome-maps: 3/9] Add testcase for our & freegeoip JSON formats
- Date: Sun, 31 Mar 2013 01:50:37 +0000 (UTC)
commit 8235df2d082ee400645328f4768b917c942d352b
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Wed Mar 27 03:23:10 2013 +0200
Add testcase for our & freegeoip JSON formats
https://bugzilla.gnome.org/show_bug.cgi?id=696525
geocode-glib/geocode-ip-server/Makefile.am | 3 +-
geocode-glib/geocode-ip-server/test-geoipformat.c | 91 +++++++++++++++++++++
2 files changed, 93 insertions(+), 1 deletions(-)
---
diff --git a/geocode-glib/geocode-ip-server/Makefile.am b/geocode-glib/geocode-ip-server/Makefile.am
index 7c7d9e0..313608d 100644
--- a/geocode-glib/geocode-ip-server/Makefile.am
+++ b/geocode-glib/geocode-ip-server/Makefile.am
@@ -6,11 +6,12 @@ AM_CFLAGS = -I$(top_srcdir) $(GEOCODE_SERVER_CFLAGS) $(COMMON_CFLAGS) $(WARN_CFL
bin_PROGRAMS = geoip-update
-TEST_PROGS += geoip-lookup
+TEST_PROGS += geoip-lookup test-geoipformat
noinst_PROGRAMS = $(TEST_PROGS)
geoip_lookup_LDADD = $(GEOCODE_SERVER_LIBS)
geoip_update_LDADD = $(GEOCODE_DBUPDATE_LIBS)
+test_geoipformat_LDADD = $(GEOCODE_LIBS)
MAINTAINERCLEANFILES = Makefile.in
diff --git a/geocode-glib/geocode-ip-server/test-geoipformat.c
b/geocode-glib/geocode-ip-server/test-geoipformat.c
new file mode 100644
index 0000000..35393ce
--- /dev/null
+++ b/geocode-glib/geocode-ip-server/test-geoipformat.c
@@ -0,0 +1,91 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
+
+#include <glib.h>
+#include <string.h>
+#include <json-glib/json-glib.h>
+
+#define ATTRIBUTION "This product includes GeoLite data created by MaxMind, " \
+ "available from http://www.maxmind.com\n"
+#define OUR_SERVER_RESPONSE "{\"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\":\"" ATTRIBUTION "\"}"
+#define FREEGEOIP_RESPONSE "{\"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\":\"\"}"
+
+static void
+test_response_data (gconstpointer data)
+{
+ const char *json = (const char *) data;
+ JsonParser *parser;
+ JsonNode *node;
+ JsonObject *object;
+ double latitude, longitude;
+
+ parser = json_parser_new ();
+
+ g_assert (json_parser_load_from_data (parser, json, -1, NULL));
+
+ node = json_parser_get_root (parser);
+ g_assert (JSON_NODE_HOLDS_OBJECT (node));
+ object = json_node_get_object (node);
+ g_assert (object != NULL);
+
+ g_assert (json_object_has_member (object, "ip"));
+ g_assert (strcmp (json_object_get_string_member (object, "ip"), "213.243.180.91") == 0);
+
+ g_assert (json_object_has_member (object, "latitude"));
+ latitude = json_object_get_double_member (object, "latitude");
+ g_assert (latitude > 60.1755 && latitude <= 60.1756);
+ g_assert (json_object_has_member (object, "longitude"));
+ longitude = json_object_get_double_member (object, "longitude");
+ g_assert (longitude >= 24.9342 && longitude < 24.9343);
+
+ g_assert (json_object_has_member (object, "city"));
+ g_assert (strcmp (json_object_get_string_member (object, "city"), "Helsinki") == 0);
+ g_assert (json_object_has_member (object, "region_name"));
+ g_assert (strcmp (json_object_get_string_member (object, "region_name"), "Southern Finland") == 0);
+ g_assert (json_object_has_member (object, "country_name"));
+ g_assert (strcmp (json_object_get_string_member (object, "country_name"), "Finland") == 0);
+
+ if (json_object_has_member (object, "accuracy"))
+ g_assert (strcmp (json_object_get_string_member (object, "accuracy"), "city") == 0);
+ if (json_object_has_member (object, "timezone"))
+ g_assert (strcmp (json_object_get_string_member (object, "timezone"), "Europe/Helsinki") == 0);
+ if (json_object_has_member (object, "attribution"))
+ g_assert (strcmp (json_object_get_string_member (object, "attribution"), ATTRIBUTION) == 0);
+
+ g_object_unref (parser);
+}
+
+int
+main (int argc, char **argv)
+{
+ 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/geocode-glib-server-format",
+ OUR_SERVER_RESPONSE,
+ test_response_data);
+ g_test_add_data_func ("/geoip/geocode-freegeoip-format",
+ FREEGEOIP_RESPONSE,
+ test_response_data);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]