[tracker/busy-handling: 2/2] tests/functional-tests: Added test that illustrates how to use busy-handling



commit 88adb878c872a06f35be85ed5ee31bec3a54afdb
Author: Philip Van Hoof <philip codeminded be>
Date:   Tue Jul 27 12:59:07 2010 +0200

    tests/functional-tests: Added test that illustrates how to use busy-handling

 tests/functional-tests/.gitignore              |    2 +
 tests/functional-tests/Makefile.am             |   36 +++++++-
 tests/functional-tests/busy-handling-test.vala |  115 ++++++++++++++++++++++++
 3 files changed, 152 insertions(+), 1 deletions(-)
---
diff --git a/tests/functional-tests/.gitignore b/tests/functional-tests/.gitignore
index 9206124..d3c085d 100644
--- a/tests/functional-tests/.gitignore
+++ b/tests/functional-tests/.gitignore
@@ -2,3 +2,5 @@ ttl
 force-sqlite-misused-batch.sh
 force-sqlite-misused.sh
 helper-test-data.sh
+busy-handling-test
+busy-handling-test.c
diff --git a/tests/functional-tests/Makefile.am b/tests/functional-tests/Makefile.am
index c46f740..743673c 100644
--- a/tests/functional-tests/Makefile.am
+++ b/tests/functional-tests/Makefile.am
@@ -2,6 +2,13 @@ include $(top_srcdir)/Makefile.decl
 
 SUBDIRS = data
 
+INCLUDES =					\
+	$(WARN_CFLAGS)				\
+	$(DBUS_CFLAGS)				\
+	$(GLIB2_CFLAGS)				\
+	$(GIO_CFLAGS)				\
+	$(GTHREAD_CFLAGS)
+
 configdir = $(datadir)/tracker-tests
 
 config_SCRIPTS =			\
@@ -39,9 +46,36 @@ bashscripts_SCRIPTS = 				\
 	@sed -e "s|@topsrcdir[ ]|${top_srcdir}|" \
 	     -e "s|@libexecdir[ ]|${libexecdir}|" $< > $@
 
+noinst_PROGRAMS = busy-handling-test
+
+busy_handling_test_VALASOURCES = busy-handling-test.vala
+
+busy_handling_test_SOURCES = \
+	busy-handling-test.vala.stamp \
+	$(busy_handling_test_VALASOURCES:.vala=.c)
+
+busy-handling-test.vala.stamp: $(busy_handling_test_VALASOURCES)
+	$(AM_V_GEN)$(VALAC) $(GCOV_VALAFLAGS) -C $(VALAFLAGS) --pkg gio-2.0 --pkg dbus-glib-1 $^
+	$(AM_V_GEN)touch $@
+
+busy_handling_test_LDADD = \
+	$(GIO_LIBS) \
+	$(GLIB2_LIBS) \
+	$(DBUS_LIBS)
+
+BUILT_SOURCES = 				\
+	busy-handling-test.vala.stamp
+
+MAINTAINERCLEANFILES =					\
+	$(BUILT_SOURCES)				\
+	$(busy_handling_test_VALASOURCES:.vala=.c)
+
 EXTRA_DIST = 					\
 	$(config_SCRIPTS) 			\
 	$(bashscripts_SCRIPTS)			\
-	$(bashscripts_in_files)
+	$(bashscripts_in_files)			\
+	$(BUILT_SOURCES)			\
+	$(busy_handling_test_VALASOURCES)
 
 CLEANFILES = $(bashscripts_SCRIPTS)
+
diff --git a/tests/functional-tests/busy-handling-test.vala b/tests/functional-tests/busy-handling-test.vala
new file mode 100644
index 0000000..095ff42
--- /dev/null
+++ b/tests/functional-tests/busy-handling-test.vala
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2008, Nokia <ivan frade nokia com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library 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 Library 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.
+ */
+
+// To run this test:
+// -===-------------
+//
+// tracker-control -k
+// rm ~/.cache/tracker/meta.db
+// export TRACKER_DEBUG_MAKE_JOURNAL_READER_GO_VERY_SLOW=yes
+// tracker-store
+// ./busy-handling-test
+
+[DBus (name = "org.freedesktop.Tracker1.Resources")]
+private interface Resources : GLib.Object {
+	[DBus (name = "SparqlQuery", timeout = 99999999999)]
+	public abstract async string[,] sparql_query_async (string query) throws DBus.Error;
+}
+
+[DBus (name = "org.freedesktop.Tracker1.Status")]
+private interface Status: GLib.Object {
+	public signal void progress (string status, double progress);
+}
+
+public class TestApp {
+	static DBus.Connection connection;
+	static Resources resources_object;
+	static Status status_object;
+	int res = -1;
+	MainLoop loop;
+	bool initialized = false;
+
+	public TestApp ()
+	requires (!initialized) {
+		try {
+			connection = DBus.Bus.get (DBus.BusType.SESSION);
+			resources_object = (Resources) connection.get_object ("org.freedesktop.Tracker1",
+			                                                      "/org/freedesktop/Tracker1/Resources",
+			                                                      "org.freedesktop.Tracker1.Resources");
+			status_object = (Status) connection.get_object ("org.freedesktop.Tracker1",
+			                                                "/org/freedesktop/Tracker1/Status",
+			                                                "org.freedesktop.Tracker1.Status");
+
+			status_object.progress.connect (on_status_cb);
+
+		} catch (DBus.Error e) {
+			warning ("Could not connect to D-Bus service: %s", e.message);
+			initialized = false;
+			res = -1;
+			return;
+		}
+		initialized = true;
+	}
+
+
+	void on_status_cb (string status, double progress) {
+		print ("%s: %f\n", status, progress);
+	}
+
+	async void do_query_tests_async () {
+		try {
+			string[,] results = yield resources_object.sparql_query_async ("SELECT ?u { ?u a rdfs:Resource }");
+			foreach (string res in results) {
+				print ("%s\n", res);
+			}
+		} catch (GLib.Error e) {
+			print ("Fail: %s\n", e.message);
+			res = -1;
+		}
+	}
+
+	async void do_async_query_tests () {
+		yield do_query_tests_async ();
+
+		print ("Async tests done, now I can quit the mainloop\n");
+		loop.quit ();
+	}
+
+	bool in_mainloop () {
+		do_async_query_tests ();
+
+		return false;
+	}
+
+	public int run () {
+		loop = new MainLoop (null, false);
+
+		Idle.add (in_mainloop);
+
+		loop.run ();
+
+		return res;
+	}
+}
+
+int main (string[] args) {
+	TestApp app = new TestApp ();
+
+	return app.run ();
+}



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