[tracker] Added initial libtracker-miner unit tests.



commit 4d17f2ecf31c9494503d5795e84c74f611c357a7
Author: Carlos Garnacho <carlos lanedo com>
Date:   Fri Mar 5 12:14:42 2010 +0100

    Added initial libtracker-miner unit tests.
    
    At the moment, there are only tests for TrackerCrawler.

 configure.ac                                      |    1 +
 tests/Makefile.am                                 |    1 +
 tests/libtracker-miner/Makefile.am                |   39 +++
 tests/libtracker-miner/tracker-crawler-test.c     |  346 +++++++++++++++++++++
 4 files changed, 387 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 5af81b1..e797e47 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1681,6 +1681,7 @@ AC_CONFIG_FILES([
 	tests/libtracker-data/subqueries/Makefile
 	tests/libtracker-data/error/Makefile
 	tests/libtracker-data/turtle/Makefile
+	tests/libtracker-miner/Makefile
 	tests/libtracker-db/Makefile
 	tests/libtracker-fts/Makefile
 	tests/libtracker-fts/limits/Makefile
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d51f877..cc536ca 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,6 +4,7 @@ SUBDIRS = 			\
 	common 			\
 	libtracker-common	\
 	libtracker-extract	\
+	libtracker-miner	\
 	libtracker-data		\
 	libtracker-db 		\
 	libtracker-fts 		\
diff --git a/tests/libtracker-miner/Makefile.am b/tests/libtracker-miner/Makefile.am
new file mode 100644
index 0000000..d33c678
--- /dev/null
+++ b/tests/libtracker-miner/Makefile.am
@@ -0,0 +1,39 @@
+include $(top_srcdir)/Makefile.decl
+
+noinst_PROGRAMS = $(TEST_PROGS)
+
+TEST_PROGS += tracker-crawler
+
+INCLUDES = 									\
+	-DTEST									\
+	-DG_LOG_DOMAIN=\"Tracker\"						\
+	-DPKGLIBDIR=\""$(libdir)/tracker-$(TRACKER_API_VERSION)"\"		\
+	-DLIBEXEC_PATH=\""$(libexecdir)"\"					\
+	-DTRACKER_COMPILATION							\
+	-DTEST_DATA_DIR=\""$(abs_top_builddir)/tests/libtracker-miner/data"\"	\
+	-I$(top_srcdir)/src							\
+	-I$(top_srcdir)/tests/common						\
+	-I$(top_builddir)/src/tracker-store					\
+	$(WARN_CFLAGS)								\
+	$(GLIB2_CFLAGS)								\
+	$(GCOV_CFLAGS)								\
+	$(GMODULE_CFLAGS)							\
+	$(GTHREAD_CFLAGS)							\
+	$(PANGO_CFLAGS)								\
+	$(DBUS_CFLAGS)
+
+tracker_crawler_SOURCES = 							\
+	$(top_srcdir)/src/libtracker-miner/tracker-marshal.c			\
+	$(top_srcdir)/src/libtracker-miner/tracker-marshal.h			\
+	$(top_srcdir)/src/libtracker-miner/tracker-utils.c			\
+	$(top_srcdir)/src/libtracker-miner/tracker-utils.h			\
+	$(top_srcdir)/src/libtracker-miner/tracker-crawler.c			\
+	tracker-crawler-test.c
+
+tracker_crawler_LDADD = 								\
+	$(top_builddir)/src/libtracker-common/libtracker-common.la 		\
+	$(DBUS_LIBS)								\
+	$(GCOV_LIBS)								\
+	$(GMODULE_LIBS)								\
+	$(GTHREAD_LIBS)								\
+	$(GLIB2_LIBS)
diff --git a/tests/libtracker-miner/data/dir/empty-dir/.hidden b/tests/libtracker-miner/data/dir/empty-dir/.hidden
new file mode 100644
index 0000000..e69de29
diff --git a/tests/libtracker-miner/data/dir/file1 b/tests/libtracker-miner/data/dir/file1
new file mode 100644
index 0000000..e69de29
diff --git a/tests/libtracker-miner/data/dir/file2 b/tests/libtracker-miner/data/dir/file2
new file mode 100644
index 0000000..e69de29
diff --git a/tests/libtracker-miner/data/empty-dir/.hidden b/tests/libtracker-miner/data/empty-dir/.hidden
new file mode 100644
index 0000000..e69de29
diff --git a/tests/libtracker-miner/data/file1 b/tests/libtracker-miner/data/file1
new file mode 100644
index 0000000..e69de29
diff --git a/tests/libtracker-miner/tracker-crawler-test.c b/tests/libtracker-miner/tracker-crawler-test.c
new file mode 100644
index 0000000..56afde1
--- /dev/null
+++ b/tests/libtracker-miner/tracker-crawler-test.c
@@ -0,0 +1,346 @@
+/*
+ * Copyright (C) 2010, Nokia (urho konttori nokia com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include <libtracker-miner/tracker-crawler.h>
+
+typedef struct CrawlerTest CrawlerTest;
+
+struct CrawlerTest {
+	GMainLoop *main_loop;
+	guint directories_found;
+	guint directories_ignored;
+	guint files_found;
+	guint files_ignored;
+	gboolean interrupted;
+
+	/* signals statistics */
+	guint n_check_directory;
+	guint n_check_directory_contents;
+	guint n_check_file;
+};
+
+static void
+crawler_finished_cb (TrackerCrawler *crawler,
+                     gboolean        interrupted,
+                     gpointer        user_data)
+{
+	CrawlerTest *test = user_data;
+
+	test->interrupted = interrupted;
+
+	if (test->main_loop) {
+		g_main_loop_quit (test->main_loop);
+	}
+}
+
+static void
+crawler_directory_crawled_cb (TrackerCrawler *crawler,
+                              GFile          *directory,
+                              GNode          *tree,
+                              guint           directories_found,
+                              guint           directories_ignored,
+                              guint           files_found,
+                              guint           files_ignored,
+                              gpointer        user_data)
+{
+	CrawlerTest *test = user_data;
+
+	test->directories_found = directories_found;
+	test->directories_ignored = directories_ignored;
+	test->files_found = files_found;
+	test->files_ignored = files_ignored;
+
+	g_assert_cmpint (g_node_n_nodes (tree, G_TRAVERSE_ALL), ==, directories_found + files_found);
+}
+
+static gboolean
+crawler_check_directory_cb (TrackerCrawler *crawler,
+			    GFile          *file,
+			    gpointer        user_data)
+{
+	CrawlerTest *test = user_data;
+
+	test->n_check_directory++;
+
+	return TRUE;
+}
+
+static gboolean
+crawler_check_file_cb (TrackerCrawler *crawler,
+		       GFile          *file,
+		       gpointer        user_data)
+{
+	CrawlerTest *test = user_data;
+
+	test->n_check_file++;
+
+	return TRUE;
+}
+
+static gboolean
+crawler_check_directory_contents_cb (TrackerCrawler *crawler,
+				     GFile          *file,
+				     GList          *contents,
+				     gpointer        user_data)
+{
+	CrawlerTest *test = user_data;
+
+	test->n_check_directory_contents++;
+
+	return TRUE;
+}
+
+static void
+test_crawler_crawl (void)
+{
+	TrackerCrawler *crawler;
+	CrawlerTest test = { 0 };
+	gboolean started;
+	GFile *file;
+
+	test.main_loop = g_main_loop_new (NULL, FALSE);
+
+	crawler = tracker_crawler_new ();
+	g_signal_connect (crawler, "finished",
+			  G_CALLBACK (crawler_finished_cb), &test);
+
+	file = g_file_new_for_path (TEST_DATA_DIR);
+
+	started = tracker_crawler_start (crawler, file, TRUE);
+
+	g_assert_cmpint (started, ==, 1);
+
+	g_main_loop_run (test.main_loop);
+
+	g_assert_cmpint (test.interrupted, ==, 0);
+
+	g_main_loop_unref (test.main_loop);
+	g_object_unref (crawler);
+	g_object_unref (file);
+}
+
+static void
+test_crawler_crawl_interrupted (void)
+{
+	TrackerCrawler *crawler;
+	CrawlerTest test = { 0 };
+	gboolean started;
+	GFile *file;
+
+	crawler = tracker_crawler_new ();
+	g_signal_connect (crawler, "finished",
+			  G_CALLBACK (crawler_finished_cb), &test);
+
+	file = g_file_new_for_path (TEST_DATA_DIR);
+
+	started = tracker_crawler_start (crawler, file, TRUE);
+
+	g_assert_cmpint (started, ==, 1);
+
+	tracker_crawler_stop (crawler);
+
+	g_assert_cmpint (test.interrupted, ==, 1);
+
+	g_object_unref (crawler);
+	g_object_unref (file);
+}
+
+static void
+test_crawler_crawl_nonexisting (void)
+{
+	TrackerCrawler *crawler;
+	GFile *file;
+	gboolean started;
+
+	crawler = tracker_crawler_new ();
+	file = g_file_new_for_path (TEST_DATA_DIR "-idontexist");
+
+	started = tracker_crawler_start (crawler, file, TRUE);
+
+	g_assert_cmpint (started, ==, 0);
+
+	g_object_unref (crawler);
+	g_object_unref (file);
+}
+
+static void
+test_crawler_crawl_recursive (void)
+{
+	TrackerCrawler *crawler;
+	CrawlerTest test = { 0 };
+	GFile *file;
+
+	test.main_loop = g_main_loop_new (NULL, FALSE);
+
+	crawler = tracker_crawler_new ();
+	g_signal_connect (crawler, "finished",
+			  G_CALLBACK (crawler_finished_cb), &test);
+	g_signal_connect (crawler, "directory-crawled",
+			  G_CALLBACK (crawler_directory_crawled_cb), &test);
+
+	file = g_file_new_for_path (TEST_DATA_DIR);
+
+	tracker_crawler_start (crawler, file, TRUE);
+
+	g_main_loop_run (test.main_loop);
+
+	/* There are 4 directories and 5 (2 hidden) files */
+	g_assert_cmpint (test.directories_found, ==, 4);
+	g_assert_cmpint (test.directories_ignored, ==, 0);
+	g_assert_cmpint (test.files_found, ==, 5);
+	g_assert_cmpint (test.files_ignored, ==, 0);
+
+	g_main_loop_unref (test.main_loop);
+	g_object_unref (crawler);
+	g_object_unref (file);
+}
+
+static void
+test_crawler_crawl_non_recursive (void)
+{
+	TrackerCrawler *crawler;
+	CrawlerTest test = { 0 };
+	GFile *file;
+
+	test.main_loop = g_main_loop_new (NULL, FALSE);
+
+	crawler = tracker_crawler_new ();
+	g_signal_connect (crawler, "finished",
+			  G_CALLBACK (crawler_finished_cb), &test);
+	g_signal_connect (crawler, "directory-crawled",
+			  G_CALLBACK (crawler_directory_crawled_cb), &test);
+
+	file = g_file_new_for_path (TEST_DATA_DIR);
+
+	tracker_crawler_start (crawler, file, FALSE);
+
+	g_main_loop_run (test.main_loop);
+
+	/* There are 3 directories (including parent) and 1 file in toplevel dir */
+	g_assert_cmpint (test.directories_found, ==, 3);
+	g_assert_cmpint (test.directories_ignored, ==, 0);
+	g_assert_cmpint (test.files_found, ==, 1);
+	g_assert_cmpint (test.files_ignored, ==, 0);
+
+	g_main_loop_unref (test.main_loop);
+	g_object_unref (crawler);
+	g_object_unref (file);
+}
+
+static void
+test_crawler_crawl_n_signals (void)
+{
+	TrackerCrawler *crawler;
+	CrawlerTest test = { 0 };
+	GFile *file;
+
+	test.main_loop = g_main_loop_new (NULL, FALSE);
+
+	crawler = tracker_crawler_new ();
+	g_signal_connect (crawler, "finished",
+			  G_CALLBACK (crawler_finished_cb), &test);
+	g_signal_connect (crawler, "directory-crawled",
+			  G_CALLBACK (crawler_directory_crawled_cb), &test);
+	g_signal_connect (crawler, "check-directory",
+			  G_CALLBACK (crawler_check_directory_cb), &test);
+	g_signal_connect (crawler, "check-directory-contents",
+			  G_CALLBACK (crawler_check_directory_contents_cb), &test);
+	g_signal_connect (crawler, "check-file",
+			  G_CALLBACK (crawler_check_file_cb), &test);
+
+	file = g_file_new_for_path (TEST_DATA_DIR);
+
+	tracker_crawler_start (crawler, file, TRUE);
+
+	g_main_loop_run (test.main_loop);
+
+	g_assert_cmpint (test.directories_found, ==, test.n_check_directory);
+	g_assert_cmpint (test.directories_found, ==, test.n_check_directory_contents);
+	g_assert_cmpint (test.files_found, ==, test.n_check_file);
+
+	g_main_loop_unref (test.main_loop);
+	g_object_unref (crawler);
+	g_object_unref (file);
+}
+
+static void
+test_crawler_crawl_n_signals_non_recursive (void)
+{
+	TrackerCrawler *crawler;
+	CrawlerTest test = { 0 };
+	GFile *file;
+
+	test.main_loop = g_main_loop_new (NULL, FALSE);
+
+	crawler = tracker_crawler_new ();
+	g_signal_connect (crawler, "finished",
+			  G_CALLBACK (crawler_finished_cb), &test);
+	g_signal_connect (crawler, "directory-crawled",
+			  G_CALLBACK (crawler_directory_crawled_cb), &test);
+	g_signal_connect (crawler, "check-directory",
+			  G_CALLBACK (crawler_check_directory_cb), &test);
+	g_signal_connect (crawler, "check-directory-contents",
+			  G_CALLBACK (crawler_check_directory_contents_cb), &test);
+	g_signal_connect (crawler, "check-file",
+			  G_CALLBACK (crawler_check_file_cb), &test);
+
+	file = g_file_new_for_path (TEST_DATA_DIR);
+
+	tracker_crawler_start (crawler, file, FALSE);
+
+	g_main_loop_run (test.main_loop);
+
+	g_assert_cmpint (test.directories_found, ==, test.n_check_directory);
+	g_assert_cmpint (1, ==, test.n_check_directory_contents);
+	g_assert_cmpint (test.files_found, ==, test.n_check_file);
+
+	g_main_loop_unref (test.main_loop);
+	g_object_unref (crawler);
+	g_object_unref (file);
+}
+
+int
+main (int    argc,
+      char **argv)
+{
+	g_type_init ();
+	g_thread_init (NULL);
+	g_test_init (&argc, &argv, NULL);
+
+	g_test_message ("Testing filesystem crawler");
+
+	g_test_add_func ("/libtracker-miner/tracker-crawler/crawl",
+	                 test_crawler_crawl);
+	g_test_add_func ("/libtracker-miner/tracker-crawler/crawl-interrupted",
+	                 test_crawler_crawl_interrupted);
+	g_test_add_func ("/libtracker-miner/tracker-crawler/crawl-nonexisting",
+	                 test_crawler_crawl_nonexisting);
+
+	g_test_add_func ("/libtracker-miner/tracker-crawler/crawl-recursive",
+	                 test_crawler_crawl_recursive);
+	g_test_add_func ("/libtracker-miner/tracker-crawler/crawl-non-recursive",
+	                 test_crawler_crawl_non_recursive);
+
+	g_test_add_func ("/libtracker-miner/tracker-crawler/crawl-n-signals",
+	                 test_crawler_crawl_n_signals);
+	g_test_add_func ("/libtracker-miner/tracker-crawler/crawl-n-signals-non-recursive",
+	                 test_crawler_crawl_n_signals_non_recursive);
+
+	return g_test_run ();
+}



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