summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2014-10-05 18:38:24 +0200
committerCarlos Garnacho <carlosg@gnome.org>2014-12-23 11:11:32 +0100
commit8400bc61775511ed7b4fbdeb4922f13824b2b65a (patch)
tree12ad34c09155c1c655ae876645e63f434bd38733
parent021370e3bf24ffdbf22e7d168a7487d51c519d93 (diff)
downloadlibgdata-8400bc61775511ed7b4fbdeb4922f13824b2b65a.tar.gz
tests: Add tests for Freebase search API
https://bugzilla.gnome.org/show_bug.cgi?id=737541
-rw-r--r--gdata/tests/freebase.c139
-rw-r--r--gdata/tests/traces/freebase/search28
-rw-r--r--gdata/tests/traces/freebase/search-complex28
3 files changed, 195 insertions, 0 deletions
diff --git a/gdata/tests/freebase.c b/gdata/tests/freebase.c
index fd99bdba..86f9b2a5 100644
--- a/gdata/tests/freebase.c
+++ b/gdata/tests/freebase.c
@@ -61,6 +61,135 @@ async_ready_callback (GObject *object,
g_main_loop_quit (closure->main_loop);
}
+/* Search */
+static GDataFreebaseSearchResult *
+freebase_search (GDataFreebaseSearchQuery *query, const gchar *trace)
+{
+ GDataFreebaseSearchResult *result;
+ GError *error = NULL;
+
+ gdata_test_mock_server_start_trace (mock_server, trace);
+ result = gdata_freebase_service_search (GDATA_FREEBASE_SERVICE (service), query, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (result != NULL);
+ uhm_server_end_trace (mock_server);
+
+ return result;
+}
+
+static GDataFreebaseSearchResult *
+freebase_search_async (GDataFreebaseSearchQuery *query, const gchar *trace)
+{
+ AsyncClosure closure = { 0 };
+
+ gdata_test_mock_server_start_trace (mock_server, trace);
+ closure.main_loop = g_main_loop_new (NULL, TRUE);
+
+ gdata_freebase_service_search_async (GDATA_FREEBASE_SERVICE (service), query, NULL,
+ async_ready_callback, &closure);
+
+ g_main_loop_run (closure.main_loop);
+ g_assert_no_error (closure.error);
+ g_assert (closure.data != NULL);
+ g_assert (GDATA_IS_FREEBASE_SEARCH_RESULT (closure.data));
+
+ g_main_loop_unref (closure.main_loop);
+ uhm_server_end_trace (mock_server);
+
+ return closure.data;
+}
+
+static void
+test_freebase_search_query_sync (void)
+{
+ GDataFreebaseSearchQuery *query; /* owned */
+ GDataFreebaseSearchResult *result; /* owned */
+
+ query = gdata_freebase_search_query_new ("prado museum");
+ gdata_freebase_search_query_set_language (query, "en");
+
+ result = freebase_search (query, "search");
+ g_object_unref (query);
+
+ g_assert_cmpint (gdata_freebase_search_result_get_num_items (result), ==, 20);
+ g_assert_cmpint (gdata_freebase_search_result_get_total_hits (result), ==, 235);
+
+ g_object_unref (result);
+}
+
+static void
+test_freebase_search_query_async (void)
+{
+ GDataFreebaseSearchQuery *query; /* owned */
+ GDataFreebaseSearchResult *result; /* owned */
+
+ query = gdata_freebase_search_query_new ("prado museum");
+ gdata_freebase_search_query_set_language (query, "en");
+
+ result = freebase_search_async (query, "search");
+ g_object_unref (query);
+
+ g_assert_cmpint (gdata_freebase_search_result_get_num_items (result), ==, 20);
+ g_assert_cmpint (gdata_freebase_search_result_get_total_hits (result), ==, 235);
+
+ g_object_unref (result);
+}
+
+static void
+test_freebase_search_query_complex (void)
+{
+ GDataFreebaseSearchQuery *query; /* owned */
+ GDataFreebaseSearchResult *result; /* owned */
+
+ query = gdata_freebase_search_query_new ("prado");
+ gdata_freebase_search_query_set_language (query, "en");
+ gdata_query_set_max_results (GDATA_QUERY (query), 1);
+
+ gdata_freebase_search_query_open_filter (query, GDATA_FREEBASE_SEARCH_FILTER_ALL);
+ gdata_freebase_search_query_add_location (query, 10000, 40.413889, -3.6925);
+
+ gdata_freebase_search_query_open_filter (query, GDATA_FREEBASE_SEARCH_FILTER_ANY);
+ gdata_freebase_search_query_add_filter (query, "type", "/travel/tourist_attraction");
+ gdata_freebase_search_query_add_filter (query, "type", "/architecture/museum");
+
+ gdata_freebase_search_query_open_filter (query, GDATA_FREEBASE_SEARCH_FILTER_NOT);
+ gdata_freebase_search_query_add_filter (query, "type", "/protected_sites/protected_site");
+
+ gdata_freebase_search_query_close_filter (query);
+ gdata_freebase_search_query_close_filter (query);
+ gdata_freebase_search_query_close_filter (query);
+
+ result = freebase_search (query, "search-complex");
+ g_object_unref (query);
+
+ g_assert_cmpint (gdata_freebase_search_result_get_num_items (result), ==, 1);
+ g_assert_cmpint (gdata_freebase_search_result_get_total_hits (result), ==, 27);
+
+ g_object_unref (result);
+}
+
+static void
+test_freebase_search_reply_items (void)
+{
+ GDataFreebaseSearchQuery *query; /* owned */
+ GDataFreebaseSearchResult *result; /* owned */
+ const GDataFreebaseSearchResultItem *item;
+
+ query = gdata_freebase_search_query_new ("prado museum");
+ gdata_freebase_search_query_set_language (query, "en");
+
+ result = freebase_search (query, "search");
+ g_object_unref (query);
+
+ item = gdata_freebase_search_result_get_item (result, 19);
+ g_assert_cmpstr (gdata_freebase_search_result_item_get_mid (item), ==, "/m/05h1sls");
+ g_assert_cmpstr (gdata_freebase_search_result_item_get_name (item), ==, "Visitation");
+ g_assert_cmpstr (gdata_freebase_search_result_item_get_notable_name (item), ==, "History Painting");
+ g_assert_cmpfloat (gdata_freebase_search_result_item_get_score (item), ==, 19.286610);
+
+ g_object_unref (result);
+}
+
/* Topic */
static GDataFreebaseTopicResult *
freebase_topic (GDataFreebaseTopicQuery *query, const gchar *trace)
@@ -279,6 +408,16 @@ main (int argc, char *argv[])
service = GDATA_SERVICE (gdata_freebase_service_new (NULL, NULL));
+ /* Search */
+ g_test_add_func ("/freebase/search/query/sync",
+ test_freebase_search_query_sync);
+ g_test_add_func ("/freebase/search/query/async",
+ test_freebase_search_query_async);
+ g_test_add_func ("/freebase/search/query/complex",
+ test_freebase_search_query_complex);
+ g_test_add_func ("/freebase/search/reply/items",
+ test_freebase_search_reply_items);
+
/* Topic */
g_test_add_func ("/freebase/topic/query/sync",
test_freebase_topic_query_sync);
diff --git a/gdata/tests/traces/freebase/search b/gdata/tests/traces/freebase/search
new file mode 100644
index 00000000..2979be69
--- /dev/null
+++ b/gdata/tests/traces/freebase/search
@@ -0,0 +1,28 @@
+> GET /freebase/v1/search?query=prado%20museum&lang=en HTTP/1.1
+> Soup-Debug-Timestamp: 1412519720
+> Soup-Debug: SoupSession 1 (0x21c0110), SoupMessage 1 (0x25d00c0), SoupSocket 1 (0x23cd910)
+> Host: www.googleapis.com
+> GData-Version: 2
+> Accept-Encoding: gzip, deflate
+> User-Agent: libgdata/0.17.0 - gzip
+> Connection: Keep-Alive
+
+< HTTP/1.1 200 OK
+< Soup-Debug-Timestamp: 1412519720
+< Soup-Debug: SoupMessage 1 (0x25d00c0)
+< Expires: Sun, 05 Oct 2014 14:35:20 GMT
+< Date: Sun, 05 Oct 2014 14:35:20 GMT
+< Cache-Control: private, max-age=0, must-revalidate, no-transform
+< Content-Disposition: attachment
+< ETag: "VaUFyVE5DtoMHwqA6ftX69x4w8Y/tuBTotVarxUvPdnjjBoc370krE0"
+< Content-Type: application/json; charset=UTF-8
+< Content-Encoding: gzip
+< X-Content-Type-Options: nosniff
+< X-Frame-Options: SAMEORIGIN
+< X-XSS-Protection: 1; mode=block
+< Server: GSE
+< Alternate-Protocol: 443:quic,p=0.01
+< Transfer-Encoding: chunked
+<
+< {"status":"200 OK","result":[{"mid":"/m/01hlq3","id":"/en/prado_museum","name":"Museo Nacional Del Prado","notable":{"name":"Art Gallery","id":"/m/0hhbr"},"lang":"en","score":603.212463},{"mid":"/m/0jzpgw_","name":"Prado Museum Guard","notable":{"name":"Film character","id":"/film/film_character"},"lang":"en","score":75.608864},{"mid":"/m/04pz69t","name":"Prado Museum, Velazquez entrance.","lang":"en","score":65.479202},{"mid":"/m/0jzpgj1","name":"Antonio, Prado Museum Guard","notable":{"name":"Film character","id":"/film/film_character"},"lang":"en","score":65.479202},{"mid":"/m/0d9p6vc","id":"/authority/stanford/control/48509","name":"Velazquez in the Prado museum","notable":{"name":"Book Edition","id":"/book/book_edition"},"lang":"en","score":58.566372},{"mid":"/m/0br6qr2","id":"/en/a_guide_book_to_the_prado_museum","name":"A guide-book to the Prado Museum","notable":{"name":"Book","id":"/book/book"},"lang":"en","score":55.680264},{"mid":"/m/0cryg0p","id":"/authority/netflix/tiny/BVPnR","name":"The Glory of Spain: Music & Masterpieces from Madrid's El Prado Museum","notable":{"name":"Music Film","id":"/m/04rlf"},"lang":"en","score":50.219574},{"mid":"/m/03tmb3c","name":"Madonna and Child, by Luis de Morales. Prado Museum.","lang":"en","score":44.560253},{"mid":"/m/0c70lx2","id":"/authority/stanford/control/2262848","name":"A guide-book of the Prado Museum; a critical and historical study","notable":{"name":"Book Edition","id":"/book/book_edition"},"lang":"en","score":43.854767},{"mid":"/m/0brtkm1","id":"/authority/stanford/control/194915","name":"A guide-book to the Prado Museum : including a commentary and general historical information","notable":{"name":"Book Edition","id":"/book/book_edition"},"lang":"en","score":41.805313},{"mid":"/m/03rsy9z","name":"Paul de Vos, Dear Hunt, mid-17th century, 212 \u00d7 347 cm, Oil on canvas, Prado Museum, Madrid","lang":"en","score":31.762075},{"mid":"/m/02z5_vj","id":"/en/prado_montevideo","name":"Prado, Montevideo","notable":{"name":"Location","id":"/location/location"},"lang":"en","score":25.294312},{"mid":"/m/0c0tclx","name":"Those paintings, which have survived a number of fires over the centuries, form the core of the collection of the Prado Museum in Madrid.","lang":"en","score":24.764435},{"mid":"/m/03frxr","id":"/en/luis_de_morales","name":"Luis de Morales","notable":{"name":"Painting Artist","id":"/m/05qdh"},"lang":"en","score":22.030073},{"mid":"/m/0kjg2","id":"/en/thalia","name":"Thalia","notable":{"name":"Fictional Character","id":"/fictional_universe/fictional_character"},"lang":"en","score":21.522394},{"mid":"/m/0fcj0d","id":"/en/la_maja_vestida","name":"La maja vestida","notable":{"name":"Painting Artwork","id":"/m/05qdh"},"lang":"en","score":21.183151},{"mid":"/m/04rq60","id":"/en/rafael_moneo","name":"Rafael Moneo","notable":{"name":"Architect","id":"/architecture/architect"},"lang":"en","score":20.858194},{"mid":"/m/05f56h3","id":"/en/the_jester_calabacillas","name":"The Jester Calabacillas","notable":{"name":"Artwork","id":"/visual_art/artwork"},"lang":"en","score":20.233606},{"mid":"/m/0fr_0v","id":"/en/meadows_museum","name":"Meadows Museum","notable":{"name":"Art Museum","id":"/m/0hhbr"},"lang":"en","score":20.220625},{"mid":"/m/05h1sls","name":"Visitation","notable":{"name":"History Painting","id":"/m/03n77"},"lang":"en","score":19.286610}],"cursor":20,"cost":7,"hits":235}
+
diff --git a/gdata/tests/traces/freebase/search-complex b/gdata/tests/traces/freebase/search-complex
new file mode 100644
index 00000000..a1cc74ce
--- /dev/null
+++ b/gdata/tests/traces/freebase/search-complex
@@ -0,0 +1,28 @@
+> GET /freebase/v1/search?query=prado&filter=(all(within%20radius:10000m%20lon:-3.6925%20lat:40.4139)(any%20type:"/travel/tourist_attraction"%20type:"/architecture/museum"(not%20type:"/protected_sites/protected_site")))&lang=en&limit=1 HTTP/1.1
+> Soup-Debug-Timestamp: 1412526407
+> Soup-Debug: SoupSession 1 (0x1d71110), SoupMessage 1 (0x1ece0c0), SoupSocket 1 (0x20a0110)
+> Host: www.googleapis.com
+> GData-Version: 2
+> Accept-Encoding: gzip, deflate
+> User-Agent: libgdata/0.17.0 - gzip
+> Connection: Keep-Alive
+
+< HTTP/1.1 200 OK
+< Soup-Debug-Timestamp: 1412526407
+< Soup-Debug: SoupMessage 1 (0x1ece0c0)
+< Expires: Sun, 05 Oct 2014 16:26:47 GMT
+< Date: Sun, 05 Oct 2014 16:26:47 GMT
+< Cache-Control: private, max-age=0, must-revalidate, no-transform
+< Content-Disposition: attachment
+< ETag: "VaUFyVE5DtoMHwqA6ftX69x4w8Y/rT7viZeDX9VUq0YVZUaAOg0U9xc"
+< Content-Type: application/json; charset=UTF-8
+< Content-Encoding: gzip
+< X-Content-Type-Options: nosniff
+< X-Frame-Options: SAMEORIGIN
+< X-XSS-Protection: 1; mode=block
+< Server: GSE
+< Alternate-Protocol: 443:quic,p=0.01
+< Transfer-Encoding: chunked
+<
+< {"status":"200 OK","result":[{"mid":"/m/01hlq3","id":"/en/prado_museum","name":"Museo Nacional Del Prado","notable":{"name":"Art Gallery","id":"/m/0hhbr"},"lang":"en","score":70.377022}],"cursor":1,"cost":6,"hits":27}
+