[geocode-glib] tests: Add GeoPlanet parsing test case



commit 67d2a4884526b7adfbfdafdf0bfaee4eae9b8c14
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Nov 26 10:29:12 2012 +0100

    tests: Add GeoPlanet parsing test case

 TODO                                 |    1 -
 geocode-glib/data/geoplanet-rio.json |    1 +
 geocode-glib/test-gcglib.c           |   20 +++++++++++++++++++-
 3 files changed, 20 insertions(+), 2 deletions(-)
---
diff --git a/TODO b/TODO
index 17ce18c..a219413 100644
--- a/TODO
+++ b/TODO
@@ -2,5 +2,4 @@
 - Write examples
 
 - Create better descriptions from the search results, and fix Paris test case for it
-- Add test case for search json parsing
 - Make answer count a property and immutable if XEP params are passed
diff --git a/geocode-glib/data/geoplanet-rio.json b/geocode-glib/data/geoplanet-rio.json
new file mode 100644
index 0000000..2a22731
--- /dev/null
+++ b/geocode-glib/data/geoplanet-rio.json
@@ -0,0 +1 @@
+{"places":{"place":[{"woeid":455825,"placeTypeName":"Town","placeTypeName attrs":{"code":7},"name":"Rio de Janeiro","country":"Brazil","country attrs":{"type":"Country","code":"BR","woeid":23424768},"admin1":"Rio de Janeiro","admin1 attrs":{"type":"State","code":"BR-RJ","woeid":2344862},"admin2":"Rio de Janeiro","admin2 attrs":{"type":"Municipality","code":"","woeid":12581062},"admin3":"","locality1":"Rio de Janeiro","locality1 attrs":{"type":"Town","woeid":455825},"locality2":"","postal":"","centroid":{"latitude":-22.97673,"longitude":-43.19508},"boundingBox":{"southWest":{"latitude":-23.078119,"longitude":-43.795799},"northEast":{"latitude":-22.74906,"longitude":-43.101261}},"areaRank":7,"popRank":13,"uri":"http:\/\/where.yahooapis.com\/v1\/place\/455825","lang":"en-GB"},{"woeid":29382249,"placeTypeName":"Town","placeTypeName attrs":{"code":7},"name":"Rio","country":"Portugal","country attrs":{"type":"Country","code":"PT","woeid":23424925},"admin1":"Porto","admin1 attrs":{
 "type":"District","code":"PT-13","woeid":2346575},"admin2":"Maia","admin2 attrs":{"type":"Municipality","code":"","woeid":12596546},"admin3":"","locality1":"Rio","locality1 attrs":{"type":"Town","woeid":29382249},"locality2":"","postal":"4475","postal attrs":{"type":"Postal Code","woeid":23707080},"centroid":{"latitude":41.23,"longitude":-8.5883},"boundingBox":{"southWest":{"latitude":41.220901,"longitude":-8.60034},"northEast":{"latitude":41.239079,"longitude":-8.57616}},"areaRank":2,"popRank":1,"uri":"http:\/\/where.yahooapis.com\/v1\/place\/29382249","lang":"en-GB"},{"woeid":721688,"placeTypeName":"Town","placeTypeName attrs":{"code":7},"name":"Rio","country":"Italy","country attrs":{"type":"Country","code":"IT","woeid":23424853},"admin1":"Liguria","admin1 attrs":{"type":"Region","code":"","woeid":7153337},"admin2":"La Spezia","admin2 attrs":{"type":"Province","code":"IT-SP","woeid":12591883},"admin3":"Sesta Godano","admin3 attrs":{"type":"Commune","code":"","woeid":12678
 637},"locality1":"Rio","locality1 attrs":{"type":"Town","woeid":721688},"locality2":"","postal":"19020","postal attrs":{"type":"Postal Code","woeid":12844564},"centroid":{"latitude":44.306831,"longitude":9.67509},"boundingBox":{"southWest":{"latitude":44.297729,"longitude":9.6624},"northEast":{"latitude":44.31591,"longitude":9.6878}},"areaRank":2,"popRank":1,"uri":"http:\/\/where.yahooapis.com\/v1\/place\/721688","lang":"en-GB"},{"woeid":2481582,"placeTypeName":"Town","placeTypeName attrs":{"code":7},"name":"Rio","country":"United States","country attrs":{"type":"Country","code":"US","woeid":23424977},"admin1":"Wisconsin","admin1 attrs":{"type":"State","code":"US-WI","woeid":2347608},"admin2":"Columbia","admin2 attrs":{"type":"County","code":"","woeid":12590544},"admin3":"","locality1":"Rio","locality1 attrs":{"type":"Town","woeid":2481582},"locality2":"","postal":"53960","postal attrs":{"type":"Zip Code","woeid":12781146},"centroid":{"latitude":43.44939,"longitude":-89.2433
 17},"boundingBox":{"southWest":{"latitude":43.44199,"longitude":-89.256638},"northEast":{"latitude":43.459129,"longitude":-89.2258}},"areaRank":1,"popRank":1,"uri":"http:\/\/where.yahooapis.com\/v1\/place\/2481582","lang":"en-GB"},{"woeid":2481576,"placeTypeName":"Town","placeTypeName attrs":{"code":7},"name":"Rio","country":"United States","country attrs":{"type":"Country","code":"US","woeid":23424977},"admin1":"Illinois","admin1 attrs":{"type":"State","code":"US-IL","woeid":2347572},"admin2":"Knox","admin2 attrs":{"type":"County","code":"","woeid":12588125},"admin3":"","locality1":"Rio","locality1 attrs":{"type":"Town","woeid":2481576},"locality2":"","postal":"61472","postal attrs":{"type":"Zip Code","woeid":12784655},"centroid":{"latitude":41.107922,"longitude":-90.398987},"boundingBox":{"southWest":{"latitude":41.105171,"longitude":-90.404778},"northEast":{"latitude":41.11338,"longitude":-90.390182}},"areaRank":0,"popRank":1,"uri":"http:\/\/where.yahooapis.com\/v1\/place
 \/2481576","lang":"en-GB"},{"woeid":2481581,"placeTypeName":"Town","placeTypeName attrs":{"code":7},"name":"Rio","country":"United States","country attrs":{"type":"Country","code":"US","woeid":23424977},"admin1":"West Virginia","admin1 attrs":{"type":"State","code":"US-WV","woeid":2347607},"admin2":"Hampshire","admin2 attrs":{"type":"County","code":"","woeid":12590492},"admin3":"","locality1":"Rio","locality1 attrs":{"type":"Town","woeid":2481581},"locality2":"","postal":"26714","postal attrs":{"type":"Zip Code","woeid":12768834},"centroid":{"latitude":39.139339,"longitude":-78.66011},"boundingBox":{"southWest":{"latitude":39.134411,"longitude":-78.668114},"northEast":{"latitude":39.152592,"longitude":-78.644653}},"areaRank":2,"popRank":1,"uri":"http:\/\/where.yahooapis.com\/v1\/place\/2481581","lang":"en-GB"},{"woeid":26806313,"placeTypeName":"District","placeTypeName attrs":{"code":9},"name":"Rio","country":"Puerto Rico","country attrs":{"type":"Territory","code":"PR","woe
 id":23424935},"admin1":"Guaynabo","admin1 attrs":{"type":"Municipality","code":"","woeid":2346814},"admin2":"Rio","admin2 attrs":{"type":"District","code":"","woeid":26806313},"admin3":"","locality1":"","locality2":"","postal":"","centroid":{"latitude":18.32226,"longitude":-66.092987},"boundingBox":{"southWest":{"latitude":18.30509,"longitude":-66.103592},"northEast":{"latitude":18.33943,"longitude":-66.08239}},"areaRank":2,"popRank":0,"uri":"http:\/\/where.yahooapis.com\/v1\/place\/26806313","lang":"en-GB"},{"woeid":771894,"placeTypeName":"Town","placeTypeName attrs":{"code":7},"name":"Rio","country":"Spain","country attrs":{"type":"Country","code":"ES","woeid":23424950},"admin1":"Cantabria","admin1 attrs":{"type":"Autonomous Community","code":"ES-S","woeid":12578028},"admin2":"Cantabria","admin2 attrs":{"type":"Province","code":"","woeid":23388418},"admin3":"Lamason","admin3 attrs":{"type":"Municipality","code":"","woeid":12688555},"locality1":"Rio","locality1 attrs":{"typ
 e":"Town","woeid":771894},"locality2":"","postal":"","centroid":{"latitude":43.244469,"longitude":-4.48858},"boundingBox":{"southWest":{"latitude":43.188591,"longitude":-4.49444},"northEast":{"latitude":43.252899,"longitude":-4.46857}},"areaRank":3,"popRank":1,"uri":"http:\/\/where.yahooapis.com\/v1\/place\/771894","lang":"en-GB"},{"woeid":771891,"placeTypeName":"Town","placeTypeName attrs":{"code":7},"name":"S Juan","country":"Spain","country attrs":{"type":"Country","code":"ES","woeid":23424950},"admin1":"Galicia","admin1 attrs":{"type":"Autonomous Community","code":"ES-GA","woeid":12578036},"admin2":"Orense","admin2 attrs":{"type":"Province","code":"","woeid":12602132},"admin3":"San Xoan De Rio","admin3 attrs":{"type":"Municipality","code":"","woeid":12694935},"locality1":"S Juan","locality1 attrs":{"type":"Town","woeid":771891},"locality2":"","postal":"","centroid":{"latitude":42.37109,"longitude":-7.29549},"boundingBox":{"southWest":{"latitude":42.335091,"longitude":-7.
 37279},"northEast":{"latitude":42.4296,"longitude":-7.25455}},"areaRank":2,"popRank":8,"uri":"http:\/\/where.yahooapis.com\/v1\/place\/771891","lang":"en-GB"},{"woeid":146507,"placeTypeName":"Town","placeTypeName attrs":{"code":7},"name":"Santa Maria Del Rio","country":"Mexico","country attrs":{"type":"Country","code":"MX","woeid":23424900},"admin1":"San Luis Potosi","admin1 attrs":{"type":"State","code":"MX-SLP","woeid":2346287},"admin2":"Santa Maria del Rio","admin2 attrs":{"type":"Municipality","code":"","woeid":12601503},"admin3":"","locality1":"Santa Maria Del Rio","locality1 attrs":{"type":"Town","woeid":146507},"locality2":"","postal":"795","postal attrs":{"type":"Postal Code","woeid":24552903},"centroid":{"latitude":21.800699,"longitude":-100.735626},"boundingBox":{"southWest":{"latitude":21.789471,"longitude":-100.756554},"northEast":{"latitude":21.81658,"longitude":-100.710861}},"areaRank":2,"popRank":8,"uri":"http:\/\/where.yahooapis.com\/v1\/place\/146507","lang"
 :"en-GB"}],"start":0,"count":10,"total":39}}
\ No newline at end of file
diff --git a/geocode-glib/test-gcglib.c b/geocode-glib/test-gcglib.c
index 752d6dc..74af332 100644
--- a/geocode-glib/test-gcglib.c
+++ b/geocode-glib/test-gcglib.c
@@ -380,7 +380,25 @@ test_resolve_json (void)
 static void
 test_search_json (void)
 {
-	/* FIXME: Implement */
+	GError *error = NULL;
+	GList *list;
+	char *contents;
+	GeocodeLocation *loc;
+
+	if (g_file_get_contents (TEST_SRCDIR "/geoplanet-rio.json",
+				 &contents, NULL, &error) == FALSE) {
+		g_critical ("Couldn't load contents of '%s': %s",
+			    TEST_SRCDIR "/geoplanet-rio.json", error->message);
+	}
+	list = _geocode_parse_search_json (contents, &error);
+
+	g_assert (list != NULL);
+	g_assert_cmpint (g_list_length (list), ==, 10);
+
+	loc = list->data;
+	g_assert_cmpstr (loc->description, ==, "Rio de Janeiro");
+
+	g_list_free_full (list, (GDestroyNotify) geocode_location_free);
 }
 
 static GeocodeLocation *



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