tracker r1670 - in branches/xesam-support: . tests/trackerd tests/trackerd/xesam



Author: pvanhoof
Date: Fri Jun 13 09:14:16 2008
New Revision: 1670
URL: http://svn.gnome.org/viewvc/tracker?rev=1670&view=rev

Log:
2008-06-13  Philip Van Hoof  <pvanhoof gnome org>

	* tests/trackerd/tracker-xesam-test.c
	* tests/trackerd/tracker-xesam-hit-test.c
	* tests/trackerd/Makefile.am
	* tests/trackerd/tracker-xesam-hits-test.c
	* tests/trackerd/tracker-xesam-hit-test.h
	* tests/trackerd/xesam/xesam-g-globals-private.h
	* tests/trackerd/xesam/Makefile.am
	* tests/trackerd/tracker-xesam-hits-test.h

	Ported two more tests from xesam-glib's tests repository over. These
	tests are not fully functional at the moment of writing (we need to
	make them succeed in order to support Xesam, the tests themselves are
	or should be ~ correct).



Added:
   branches/xesam-support/tests/trackerd/tracker-xesam-hit-test.c
   branches/xesam-support/tests/trackerd/tracker-xesam-hit-test.h
   branches/xesam-support/tests/trackerd/tracker-xesam-hits-test.c
   branches/xesam-support/tests/trackerd/tracker-xesam-hits-test.h
   branches/xesam-support/tests/trackerd/xesam/xesam-g-globals-private.h
Modified:
   branches/xesam-support/ChangeLog
   branches/xesam-support/tests/trackerd/Makefile.am
   branches/xesam-support/tests/trackerd/tracker-xesam-test.c
   branches/xesam-support/tests/trackerd/xesam/Makefile.am

Modified: branches/xesam-support/tests/trackerd/Makefile.am
==============================================================================
--- branches/xesam-support/tests/trackerd/Makefile.am	(original)
+++ branches/xesam-support/tests/trackerd/Makefile.am	Fri Jun 13 09:14:16 2008
@@ -22,7 +22,11 @@
 tracker_xesam_SOURCES = \
 	tracker-xesam-test.c \
 	tracker-xesam-session-test.c \
-	tracker-xesam-session-test.h
+	tracker-xesam-session-test.h \
+	tracker-xesam-hit-test.c \
+	tracker-xesam-hit-test.h \
+	tracker-xesam-hits-test.c \
+	tracker-xesam-hits-test.h
 
 tracker_xesam_LDADD = \
 	$(top_builddir)/tests/trackerd/xesam/libxesamhelper.la \

Added: branches/xesam-support/tests/trackerd/tracker-xesam-hit-test.c
==============================================================================
--- (empty file)
+++ branches/xesam-support/tests/trackerd/tracker-xesam-hit-test.c	Fri Jun 13 09:14:16 2008
@@ -0,0 +1,247 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with main.c; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
+ */
+ 
+#include <glib.h>
+#include <glib/gtestutils.h>
+#include <glib-object.h>
+
+#include <xesam-glib/xesam-glib.h>
+#include "xesam/xesam-g-utils.h"
+#include <xesam-glib/xesam-g-searcher.h>
+#include <xesam-glib/xesam-g-dbussearcher.h>
+#include <xesam-glib/xesam-g-session.h>
+#include <xesam-glib/xesam-g-search.h>
+#include "xesam/xesam-g-globals-private.h"
+#include "xesam/xesam-g-debug-private.h"
+#include "xesam/xesam-g-testsearcher.h"
+#include "xesam/gtestextensions.h"
+
+/* Shortcut to defining a test */
+#define TEST(func) g_test_add ("/tracker/xesam/hit/"#func, Fixture, NULL, (void (*) (Fixture*, gconstpointer))setup, test_##func, teardown);
+
+#define TIMEOUT 500
+#define TEST_XML "<request><query><contains><field name=\"xesam:album\" /><string>ne</string></contains></query></request>"
+#define NUM_FIELDS _get_num_fields()
+
+/* Fields set in the session's hit-fields property */
+const gchar *TEST_FIELDS[2] = 
+{
+//	"xesam:url",
+//	"xesam:title",
+//	"xesam:subject",
+	"xesam:album",
+	NULL
+};
+
+/* Test fixture passed to all tests */
+typedef struct {
+	GMainLoop		*mainloop;
+	GError			*error;
+	XesamGSearcher		*searcher;
+	XesamGSession		*session;
+	XesamGSearch		*search;
+	XesamGHits		*hits;
+} Fixture;
+
+/* HELPER METHODS BEGIN */
+
+static guint
+_get_num_fields (void)
+{
+	int	i;
+	static	guint num_fields = 0;
+	
+	if (num_fields != 0)
+		return num_fields;
+	
+	for (i = 0; ; i++) {
+		if (TEST_FIELDS[i] == NULL) {
+			num_fields = i;
+			return i;
+		}
+	}
+}
+
+/* HELPER METHODS END */
+
+static void
+setup (Fixture		 *fix,
+	   GType *searcher_type)
+{
+	fix->mainloop = g_main_loop_new (NULL, FALSE);
+	fix->searcher = XESAM_G_SEARCHER(xesam_g_dbus_searcher_new_default ());
+	fix->session = xesam_g_session_new (fix->searcher);
+	
+	g_object_set (fix->session, "hit-fields", TEST_FIELDS, NULL);
+	
+	fix->search = xesam_g_session_new_search (fix->session, xesam_g_query_new_from_xml(TEST_XML));
+	
+	g_assert (XESAM_IS_G_SEARCHER (fix->searcher));
+	g_assert (XESAM_IS_G_SESSION (fix->session));
+	g_assert (XESAM_IS_G_SEARCH (fix->search));
+	
+	xesam_g_search_start (fix->search);
+	if (gtx_wait_for_signal(G_OBJECT(fix->search), TIMEOUT, "hits-added",
+				&fix->hits))
+		g_critical ("Test search '%s' did not spawn any hits",
+			    TEST_XML);
+	
+	g_assert (XESAM_IS_G_HITS (fix->hits));
+	g_assert_cmpint (xesam_g_hits_get_count (fix->hits), >, 0);
+}
+
+static void
+teardown (Fixture		*fix,
+		  gconstpointer test_data)
+{
+	/* Make sure we did not screw up the searcher and session in the test */
+	g_assert (XESAM_IS_G_SEARCHER(fix->searcher));
+	g_assert (XESAM_IS_G_SESSION(fix->session));
+	g_assert (XESAM_IS_G_SEARCH(fix->search));
+	g_assert (XESAM_IS_G_HITS(fix->hits));
+	
+	/* Allow to process any dangling async calls. This is needed
+	 * to make the leak detecction below work. */
+	gtx_yield_main_loop (TIMEOUT);
+	
+	g_main_loop_unref (fix->mainloop);
+	gtx_assert_last_unref (fix->hits);
+	gtx_assert_last_unref (fix->search);
+	gtx_assert_last_unref (fix->session);
+	
+	/* Allow to process any dangling async calls. This is needed
+	 * to make the leak detecction below work. Yes, we need it two times */
+	gtx_yield_main_loop (TIMEOUT);
+	
+	gtx_assert_last_unref (fix->searcher);
+	
+	if (fix->error)
+		g_error_free (fix->error);
+	
+}
+
+static void
+test_field_data (Fixture	*fix,
+	  gconstpointer	data)
+{
+	guint		hit_count, i, j;
+	XesamGHit	*hit;
+	const GPtrArray	*raw;
+	
+	hit_count = xesam_g_hits_get_count (fix->hits);
+	g_assert_cmpint (hit_count, >, 0);
+	
+	for (i = 0; i < hit_count; i++) {
+		hit = xesam_g_hits_get (fix->hits, i);
+		g_assert (XESAM_IS_G_HIT (hit));
+		
+		raw = xesam_g_hit_get_data (hit);
+		g_assert (raw != NULL);
+		g_assert_cmpint (raw->len, ==, NUM_FIELDS);
+		
+		/* Assert that all field data members are valid GValues */
+		for (j = 0; j < raw->len; j++) {
+			g_assert (G_IS_VALUE(g_ptr_array_index(raw, j)));
+		}
+	}
+}
+
+static void
+test_get_field (Fixture		*fix,
+		gconstpointer	data)
+{
+	XesamGHit	*hit;
+	const GValue	*field_value;
+	guint		i;
+	
+	/* We just check the first Hit in the Hits object */
+	hit = xesam_g_hits_get (fix->hits, 0);
+	
+	for (i = 0; i < NUM_FIELDS; i++) {
+		field_value = xesam_g_hit_get_field (hit, TEST_FIELDS[i]);
+		g_assert (G_IS_VALUE (field_value));
+	}
+}
+
+static void
+test_get_field_by_id (Fixture		*fix,
+		      gconstpointer	data)
+{
+	XesamGHit	*hit;
+	const GValue	*field_value_by_key, *field_value_by_id;
+	guint		i;
+	
+	/* We just check the first Hit in the Hits object */
+	hit = xesam_g_hits_get (fix->hits, 0);
+	
+	for (i = 0; i < NUM_FIELDS; i++) {
+		field_value_by_key = xesam_g_hit_get_field (hit, TEST_FIELDS[i]);
+		field_value_by_id = xesam_g_hit_get_field_by_id (hit, i);
+		
+		g_assert (field_value_by_key == field_value_by_id);
+		g_assert (G_IS_VALUE (field_value_by_key));
+		g_assert (G_IS_VALUE (field_value_by_id));
+	}
+}
+
+static void
+test_get_id (Fixture		*fix,
+	     gconstpointer	data)
+{
+	XesamGHit	*hit;
+	guint		i;
+	
+	for (i = 0; i < xesam_g_hits_get_count (fix->hits); i++) {
+		hit = xesam_g_hits_get (fix->hits, i);
+		
+		/* This assumes that hit is the first XesamGHit to be delievered */
+		g_assert_cmpint (i, ==, xesam_g_hit_get_id (hit));
+		g_print ("id: %d\n", xesam_g_hit_get_id(hit));
+	}
+}
+
+static void
+test_get_field_names (Fixture		*fix,
+		      gconstpointer	data)
+{
+	XesamGHit	*hit;
+	GStrv		field_names;
+	guint		i;
+	
+	hit = xesam_g_hits_get (fix->hits, 0);
+	field_names = xesam_g_hit_get_field_names (hit);
+	
+	/* This also tests that both arrays ends with NULL */
+	for (i = 0; i <= NUM_FIELDS; i++) {
+		g_assert_cmpstr (TEST_FIELDS[i], ==, field_names[i]);
+	}
+	
+	g_strfreev (field_names);
+}
+
+
+void 
+g_test_add_hit_tests (void)
+{
+
+	TEST (field_data);
+	TEST (get_field);
+	TEST (get_field_by_id);
+	TEST (get_id);
+	TEST (get_field_names);
+	
+	return;
+}

Added: branches/xesam-support/tests/trackerd/tracker-xesam-hit-test.h
==============================================================================
--- (empty file)
+++ branches/xesam-support/tests/trackerd/tracker-xesam-hit-test.h	Fri Jun 13 09:14:16 2008
@@ -0,0 +1,6 @@
+#ifndef _TRACKER_XESAM_HIT_TEST_H_
+#define _TRACKER_XESAM_HIT_TEST_H_
+
+void  g_test_add_hit_tests (void);
+
+#endif

Added: branches/xesam-support/tests/trackerd/tracker-xesam-hits-test.c
==============================================================================
--- (empty file)
+++ branches/xesam-support/tests/trackerd/tracker-xesam-hits-test.c	Fri Jun 13 09:14:16 2008
@@ -0,0 +1,165 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with main.c; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
+ */
+ 
+#include <glib.h>
+#include <glib/gtestutils.h>
+#include <glib-object.h>
+
+#include <xesam-glib/xesam-glib.h>
+#include "xesam/xesam-g-utils.h"
+#include <xesam-glib/xesam-g-searcher.h>
+#include <xesam-glib/xesam-g-dbussearcher.h>
+#include <xesam-glib/xesam-g-session.h>
+#include <xesam-glib/xesam-g-search.h>
+#include "xesam/xesam-g-globals-private.h"
+#include "xesam/xesam-g-debug-private.h"
+#include "xesam/xesam-g-testsearcher.h"
+#include "xesam/gtestextensions.h"
+
+/* Shortcut to defining a test */
+#define TEST(func) g_test_add ("/tracker/xesam/hits/"#func, Fixture, NULL, (void (*) (Fixture*, gconstpointer))setup, test_##func, teardown);
+
+#define TIMEOUT 500
+#define TEST_XML "<request><query><contains><field name=\"xesam:album\" /><string>ne</string></contains></query></request>"
+
+/* Test fixture passed to all tests */
+typedef struct {
+	GMainLoop		*mainloop;
+	GError			*error;
+	XesamGSearcher		*searcher;
+	XesamGSession		*session;
+	XesamGSearch		*search;
+	XesamGHits		*hits;
+	GList			*hit_list;
+} Fixture;
+
+/* HELPER METHODS BEGIN */
+
+
+
+/* HELPER METHODS END */
+
+static void
+setup (Fixture		 *fix,
+	   GType *searcher_type)
+{
+	fix->mainloop = g_main_loop_new (NULL, FALSE);
+	fix->searcher = XESAM_G_SEARCHER(xesam_g_dbus_searcher_new_default ());
+	fix->session = xesam_g_session_new (fix->searcher);
+
+	fix->search = xesam_g_session_new_search (fix->session, xesam_g_query_new_from_xml(TEST_XML));
+	fix->hit_list = NULL;
+	
+	g_assert (XESAM_IS_G_SEARCHER (fix->searcher));
+	g_assert (XESAM_IS_G_SESSION (fix->session));
+	g_assert (XESAM_IS_G_SEARCH (fix->search));
+	
+	xesam_g_search_start (fix->search);
+	if (gtx_wait_for_signal(G_OBJECT(fix->search), TIMEOUT, "hits-added",
+				&fix->hits))
+		g_critical ("Test search '%s' did not spawn any hits",
+			    TEST_XML);
+	
+	g_assert (XESAM_IS_G_HITS (fix->hits));
+}
+
+static void
+teardown (Fixture		*fix,
+		  gconstpointer test_data)
+{
+	/* Make sure we did not screw up the searcher and session in the test */
+	g_assert (XESAM_IS_G_SEARCHER(fix->searcher));
+	g_assert (XESAM_IS_G_SESSION(fix->session));
+	g_assert (XESAM_IS_G_SEARCH(fix->search));
+	g_assert (XESAM_IS_G_HITS(fix->hits));
+	
+	/* Allow to process any dangling async calls. This is needed to make
+	 * the leak detection below work */
+	gtx_yield_main_loop (TIMEOUT);
+	
+	g_main_loop_unref (fix->mainloop);
+	gtx_assert_last_unref (fix->hits);
+	gtx_assert_last_unref (fix->search);
+	gtx_assert_last_unref (fix->session);
+	
+	/* Allow to process any dangling async calls. This is needed to make
+	 * the leak detection below work. Yes we need it again! */
+	gtx_yield_main_loop (TIMEOUT);
+	
+	gtx_assert_last_unref (fix->searcher);
+	
+	if (fix->error)
+		g_error_free (fix->error);
+	
+	
+	/* Assert that all hits in the list are freed */
+	if (fix->hit_list) {
+		GList		*iter;
+		XesamGHit	*hit;
+		
+		xesam_g_debug ("Testing that XesamGHit objects are cleaned up");
+		
+		for (iter = fix->hit_list; iter; iter = iter->next) {
+			hit = XESAM_G_HIT (iter->data);
+			gtx_assert_last_unref (hit);
+		}
+		
+		g_list_free (fix->hit_list);
+	}
+	
+	gtx_yield_main_loop (TIMEOUT);
+}
+
+static void
+test_count (Fixture	    *fix,
+	     gconstpointer  data)
+{
+	guint hit_count;
+	
+	hit_count = xesam_g_hits_get_count (fix->hits);
+	
+	g_assert_cmpint (hit_count, >, 0);
+}
+
+static void
+test_get (Fixture	*fix,
+	  gconstpointer	data)
+{
+	guint		hit_count, i;
+	XesamGHit	*hit;
+	
+	hit_count = xesam_g_hits_get_count (fix->hits);
+	g_assert_cmpint (hit_count, >, 0);
+	
+	for (i = 0; i < hit_count; i++) {
+		//hit = xesam_g_hits_get (fix->hits, i);
+//		g_assert (XESAM_IS_G_HIT (hit));
+		
+		/* Build a list of hit objects with refs. We use this
+		 * to assert that they are properly freed later */
+		fix->hit_list = g_list_prepend (fix->hit_list, hit);
+		g_object_ref (hit);
+	}
+}
+
+void 
+g_test_add_hits_tests (void)
+{
+	TEST (count);
+	TEST (get);
+
+	return;
+}

Added: branches/xesam-support/tests/trackerd/tracker-xesam-hits-test.h
==============================================================================
--- (empty file)
+++ branches/xesam-support/tests/trackerd/tracker-xesam-hits-test.h	Fri Jun 13 09:14:16 2008
@@ -0,0 +1,6 @@
+#ifndef _TRACKER_XESAM_HITS_TEST_H_
+#define _TRACKER_XESAM_HITS_TEST_H_
+
+void  g_test_add_hits_tests (void);
+
+#endif

Modified: branches/xesam-support/tests/trackerd/tracker-xesam-test.c
==============================================================================
--- branches/xesam-support/tests/trackerd/tracker-xesam-test.c	(original)
+++ branches/xesam-support/tests/trackerd/tracker-xesam-test.c	Fri Jun 13 09:14:16 2008
@@ -4,6 +4,8 @@
 #include <dbus/dbus-glib-bindings.h>
 
 #include "tracker-xesam-session-test.h"
+#include "tracker-xesam-hits-test.h"
+#include "tracker-xesam-hit-test.h"
 
 /*
  * This is a hack to initialize the dbus glib specialized types.
@@ -32,6 +34,8 @@
 	g_test_bug_base ("http://bugzilla.gnome.org/";);
 
 	g_test_add_session_tests ();
+	g_test_add_hit_tests ();
+	g_test_add_hits_tests ();
 
 	result = g_test_run ();
 

Modified: branches/xesam-support/tests/trackerd/xesam/Makefile.am
==============================================================================
--- branches/xesam-support/tests/trackerd/xesam/Makefile.am	(original)
+++ branches/xesam-support/tests/trackerd/xesam/Makefile.am	Fri Jun 13 09:14:16 2008
@@ -14,6 +14,7 @@
 libxesamhelper_la_SOURCES = \
 	xesam-g-debug-private.h \
 	xesam-g-utils.h \
+	xesam-g-globals-private.h \
 	gtestextensions.c \
 	gtestextensions.h \
 	xesam-g-test-query-builder.c \

Added: branches/xesam-support/tests/trackerd/xesam/xesam-g-globals-private.h
==============================================================================
--- (empty file)
+++ branches/xesam-support/tests/trackerd/xesam/xesam-g-globals-private.h	Fri Jun 13 09:14:16 2008
@@ -0,0 +1,55 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with main.c; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
+ */
+ 
+/*
+ * This file contains declarations that are considered to be "package private"
+ * in Java terminology. Ie methods and constants for shared use inside 
+ * xesam-glib only.
+ */
+
+#ifndef _XESAM_G_GLOBALS_PRIVATE_H_
+#define _XESAM_G_GLOBALS_PRIVATE_H_
+
+#include <xesam-glib/xesam-g-search.h>
+#include <xesam-glib/xesam-g-hit.h>
+#include <xesam-glib/xesam-g-hits.h>
+
+G_BEGIN_DECLS
+
+XesamGSearch* xesam_g_search_new                    (XesamGSession 	*session, 
+													 XesamGQuery    *query);
+
+XesamGSearch* xesam_g_search_new_from_text          (XesamGSession 	*session, 
+													 gchar 			*search_text);
+
+XesamGHit*    xesam_g_hit_new                       (guint          id,
+                                                     GHashTable     *field_map,
+                                                     GPtrArray      *field_data);
+
+XesamGHits*   xesam_g_hits_new                      (XesamGSearch   *search,
+                                                     guint          batch_offset,                                                     
+                                                     guint          count,
+                                                     GPtrArray      *hits_data);
+
+GHashTable*   xesam_g_session_get_field_map         (XesamGSession  *session);
+
+GHashTable*   xesam_g_search_get_field_map          (XesamGSearch  *search);
+
+
+
+G_END_DECLS
+
+#endif /* _XESAM_G_GLOBALS_PRIVATE_H_ */



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