[tracker/direct-access: 115/158] tests/functional-tests: Refactoring the query test



commit 642a1262f558245903799d85b0458291f99aab2a
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Jul 22 12:56:01 2010 +0200

    tests/functional-tests: Refactoring the query test

 tests/functional-tests/direct-query-test.vala |   11 +++-
 tests/functional-tests/shared-query-test.vala |   68 ++++++++++++++++++++++---
 2 files changed, 69 insertions(+), 10 deletions(-)
---
diff --git a/tests/functional-tests/direct-query-test.vala b/tests/functional-tests/direct-query-test.vala
index 231d047..27ea709 100644
--- a/tests/functional-tests/direct-query-test.vala
+++ b/tests/functional-tests/direct-query-test.vala
@@ -4,7 +4,14 @@ using Tracker.Sparql;
 int
 main( string[] args )
 {
-	TestApp app = new TestApp (new  Tracker.Direct.Connection ());
+	int res = -1;
 
-	return app.run ();
+	try {
+		TestApp app = new TestApp (new Tracker.Direct.Connection ());
+		res = app.run ();
+	} catch (Sparql.Error e) {
+		warning ("Couldn't perform test: %s", e.message);
+	}
+
+	return res;
 }
diff --git a/tests/functional-tests/shared-query-test.vala b/tests/functional-tests/shared-query-test.vala
index b11cdce..2f0eba9 100644
--- a/tests/functional-tests/shared-query-test.vala
+++ b/tests/functional-tests/shared-query-test.vala
@@ -2,7 +2,9 @@ using Tracker;
 using Tracker.Sparql;
 
 public class TestApp : GLib.Object {
+	MainLoop loop;
 	Sparql.Connection con;
+	int res = 0;
 
 	public TestApp (Sparql.Connection connection) {
 		con = connection;
@@ -27,28 +29,78 @@ public class TestApp : GLib.Object {
 		return (0);
 	}
 
-	public int run () {
+	private void test_query () {
 		Cursor cursor;
-		int a;
 
 		try {
 			cursor = con.query ("SELECT ?u WHERE { ?u a rdfs:Class }");
 		} catch (GLib.Error e) {
 			warning ("Couldn't perform query: %s", e.message);
-			return -1;
+			res = -1;
+			return;
 		}
 
-		a = iter_cursor (cursor);
+		res = iter_cursor (cursor);
 
-		if (a == -1)
-			return a;
+		if (res == -1)
+			return;
 
 		print ("\nRewinding\n");
 		cursor.rewind ();
 
 		print ("\nSecond run\n");
-		a = iter_cursor (cursor);
+		res = iter_cursor (cursor);
+	}
+
+	private async void test_query_async () {
+		Cursor cursor;
+
+		try {
+			cursor = yield con.query_async ("SELECT ?u WHERE { ?u a rdfs:Class }");
+		} catch (GLib.Error e) {
+			warning ("Couldn't perform query: %s", e.message);
+			res = -1;
+			return;
+		}
+
+		res = iter_cursor (cursor);
+
+		if (res == -1)
+			return;
+
+		print ("\nRewinding\n");
+		cursor.rewind ();
+
+		print ("\nSecond run\n");
+		res = iter_cursor (cursor);
+	}
+
+	void do_sync_tests () {
+		test_query ();
+	}
+
+	async void do_async_tests () {
+		yield test_query_async ();
+
+		print ("Async tests done, now I can quit the mainloop\n");
+		loop.quit ();
+	}
+
+	bool in_mainloop () {
+
+		do_sync_tests ();
+		do_async_tests ();
+
+		return false;
+	}
+
+	public int run () {
+		loop = new MainLoop (null, false);
+
+		Idle.add (in_mainloop);
+
+		loop.run ();
 
-		return a;
+		return res;
 	}
 }



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