tracker r1822 - in branches/indexer-split: . tests tests/tracker-indexer
- From: ifrade svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r1822 - in branches/indexer-split: . tests tests/tracker-indexer
- Date: Wed, 2 Jul 2008 11:55:35 +0000 (UTC)
Author: ifrade
Date: Wed Jul 2 11:55:35 2008
New Revision: 1822
URL: http://svn.gnome.org/viewvc/tracker?rev=1822&view=rev
Log:
Added tests to tracker-index
Added:
branches/indexer-split/tests/tracker-indexer/
branches/indexer-split/tests/tracker-indexer/Makefile.am
branches/indexer-split/tests/tracker-indexer/tracker-index-test.c
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/tests/Makefile.am
Modified: branches/indexer-split/tests/Makefile.am
==============================================================================
--- branches/indexer-split/tests/Makefile.am (original)
+++ branches/indexer-split/tests/Makefile.am Wed Jul 2 11:55:35 2008
@@ -1,4 +1,9 @@
include $(top_srcdir)/Makefile.decl
-SUBDIRS = common libtracker-common trackerd scripts libtracker-db
+SUBDIRS = common \
+ libtracker-common \
+ trackerd \
+ scripts \
+ libtracker-db \
+ tracker-indexer
Added: branches/indexer-split/tests/tracker-indexer/Makefile.am
==============================================================================
--- (empty file)
+++ branches/indexer-split/tests/tracker-indexer/Makefile.am Wed Jul 2 11:55:35 2008
@@ -0,0 +1,30 @@
+include $(top_srcdir)/Makefile.decl
+
+noinst_PROGRAMS = $(TEST_PROGS)
+
+TEST_PROGS += tracker-index
+
+INCLUDES = \
+ -g \
+ -DG_LOG_DOMAIN=\"Tracker\" \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/tests/common \
+ $(QDBM_CFLAGS) \
+ $(GMODULE_CFLAGS) \
+ $(GTHREAD_CFLAGS) \
+ $(GLIB2_CFLAGS)
+
+
+
+tracker_index_SOURCES = \
+ tracker-index-test.c \
+ $(top_srcdir)/src/tracker-indexer/tracker-index.c
+
+tracker_index_LDADD = \
+ $(top_builddir)/src/libtracker-common/libtracker-common.la \
+ $(top_builddir)/tests/common/libtracker-testcommon.la \
+ $(QDBM_LIBS) \
+ $(GMODULE_LIBS) \
+ $(GTHREAD_LIBS) \
+ $(GLIB2_LIBS)
+
Added: branches/indexer-split/tests/tracker-indexer/tracker-index-test.c
==============================================================================
--- (empty file)
+++ branches/indexer-split/tests/tracker-indexer/tracker-index-test.c Wed Jul 2 11:55:35 2008
@@ -0,0 +1,174 @@
+#include <glib.h>
+#include <glib/gtestutils.h>
+#include <glib/gstdio.h>
+
+#include <tracker-indexer/tracker-index.h>
+
+#include <qdbm/depot.h>
+
+
+// Private struct. Used here to test results
+typedef struct {
+ guint32 id;
+ guint32 amalgamated;
+} TrackerIndexElement;
+
+#define BUCKET_COUNT 100
+
+
+/* Helper functions to read the index */
+gint
+get_number_words_in_index (const gchar *index_file)
+{
+ DEPOT *index;
+ gint words;
+
+ index = dpopen (index_file, DP_OREADER, BUCKET_COUNT);
+
+ words = dprnum (index);
+
+ dpclose (index);
+
+ return words;
+}
+
+gint
+get_results_for_word (const gchar *index_file, const gchar *word)
+{
+ DEPOT *index;
+ gint result;
+
+ index = dpopen (index_file, DP_OREADER, BUCKET_COUNT);
+
+ result = dpvsiz (index, word, -1);
+
+ dpclose (index);
+
+ return result / sizeof (TrackerIndexElement);
+}
+
+void
+debug_print_index (const gchar *index_file) {
+
+ DEPOT *index;
+ gint rsiz, elements, i;
+ gchar *iter;
+ TrackerIndexElement *results;
+
+ g_print ("Contents of %s\n", index_file);
+
+ index = dpopen (index_file, DP_OREADER, BUCKET_COUNT);
+
+ dpiterinit (index);
+
+ while ((iter = dpiternext (index, NULL)) != NULL) {
+ g_print ("word: %s doc_ids:", iter);
+ results = (TrackerIndexElement *)dpget (index, iter, -1, 0, -1, &rsiz);
+
+ if (!results) {
+ g_print ("[No results]\n");
+ continue;
+ } else {
+ elements = rsiz / sizeof (TrackerIndexElement);
+ for (i = 0; i < elements; i++) {
+ g_print ("%d ", results[i].id);
+ }
+ g_print ("\n");
+ }
+ }
+}
+
+/* Actual tests */
+
+static void
+test_add_one_word ()
+{
+ TrackerIndex *index;
+ const gchar *indexname = "test-add-one-word.index";
+
+ g_remove (indexname);
+ index = tracker_index_new (indexname, BUCKET_COUNT);
+
+ tracker_index_add_word (index, "word1", 1, 1, 1);
+ tracker_index_flush (index);
+ tracker_index_free (index);
+
+ g_assert_cmpint (get_number_words_in_index (indexname), ==, 1);
+ g_assert_cmpint (get_results_for_word (indexname, "word1"), ==, 1);
+
+ g_remove (indexname);
+}
+
+
+static void
+test_add_n_words ()
+{
+ TrackerIndex *index;
+ const gchar *indexname = "test-add-n-words.index";
+ gint i;
+ gchar *word;
+
+ g_remove (indexname);
+
+ g_remove (indexname);
+ index = tracker_index_new (indexname, BUCKET_COUNT);
+
+ for ( i = 0; i < 20; i++) {
+ word = g_strdup_printf ("word%d", i);
+ tracker_index_add_word (index, word, 1, 1, 1);
+ g_free (word);
+ }
+
+ tracker_index_flush (index);
+ tracker_index_free (index);
+
+ g_assert_cmpint (get_number_words_in_index (indexname), ==, 20);
+ g_assert_cmpint (get_results_for_word (indexname, "word5"), ==, 1);
+ g_remove (indexname);
+}
+
+static void
+test_add_word_n_times ()
+{
+ TrackerIndex *index;
+ gint i;
+ const gchar *indexname = "test-add-word-n-times.index";
+
+ g_remove (indexname);
+ index = tracker_index_new (indexname, BUCKET_COUNT);
+
+ for ( i = 0; i < 20; i++) {
+ tracker_index_add_word (index, "word", i, 1, 1);
+ }
+
+ tracker_index_flush (index);
+ tracker_index_free (index);
+
+ g_assert_cmpint (get_number_words_in_index (indexname), ==, 1);
+ g_assert_cmpint (get_results_for_word (indexname, "word"), ==, 20);
+
+ g_remove (indexname);
+}
+
+
+int
+main (int argc, char **argv) {
+
+ int result;
+
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/tracker/tracker-indexer/tracker-index/add_word",
+ test_add_one_word);
+
+ g_test_add_func ("/tracker/tracker-indexer/tracker-index/add_n_words",
+ test_add_n_words);
+
+ g_test_add_func ("/tracker/tracker-indexer/tracker-index/add_word_n_times",
+ test_add_word_n_times);
+
+ result = g_test_run ();
+
+ return result;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]