[tracker/libtracker-bus: 27/51] tests/functional-tests: Refactored the update tests



commit a7741596c1f9f678eb1eaf982381a67783729c89
Author: Philip Van Hoof <philip codeminded be>
Date:   Thu Jul 22 11:23:49 2010 +0200

    tests/functional-tests: Refactored the update tests

 tests/functional-tests/.gitignore              |    1 +
 tests/functional-tests/Makefile.am             |   10 +-
 tests/functional-tests/bus-update-test.vala    |   42 +----------
 tests/functional-tests/direct-update-test.vala |   41 ----------
 tests/functional-tests/shared-update-test.vala |   96 ++++++++++++++++++++++++
 5 files changed, 105 insertions(+), 85 deletions(-)
---
diff --git a/tests/functional-tests/.gitignore b/tests/functional-tests/.gitignore
index 2d405c8..7ee8336 100644
--- a/tests/functional-tests/.gitignore
+++ b/tests/functional-tests/.gitignore
@@ -1,3 +1,4 @@
+shared-update-test.c
 bus-query-test
 bus-query-test.c
 bus-update-test
diff --git a/tests/functional-tests/Makefile.am b/tests/functional-tests/Makefile.am
index 2982a7a..9df606c 100644
--- a/tests/functional-tests/Makefile.am
+++ b/tests/functional-tests/Makefile.am
@@ -73,11 +73,11 @@ MAINTAINERCLEANFILES =					\
 	$(BUILT_SOURCES)				\
 	$(busy_handling_test_VALASOURCES:.vala=.c)
 
-direct_update_test_VALASOURCES = direct-update-test.vala
+default_update_test_VALASOURCES = shared-update-test.vala default-update-test.vala
 
-direct_update_test_SOURCES = \
-	direct_update_test.vala.stamp \
-	$(direct_update_test_VALASOURCES:.vala=.c)
+default_update_test_SOURCES = \
+	default_update_test.vala.stamp \
+	$(default_update_test_VALASOURCES:.vala=.c)
 
 bus_query_test_VALASOURCES = bus-query-test.vala
 
@@ -85,7 +85,7 @@ bus_query_test_SOURCES = \
 	bus_query_test.vala.stamp \
 	$(bus_query_test_VALASOURCES:.vala=.c)
 
-bus_update_test_VALASOURCES = bus-update-test.vala
+bus_update_test_VALASOURCES = shared-update-test.vala bus-update-test.vala
 
 bus_update_test_SOURCES = \
 	bus_update_test.vala.stamp \
diff --git a/tests/functional-tests/bus-update-test.vala b/tests/functional-tests/bus-update-test.vala
index 6514fdb..e48b5d4 100644
--- a/tests/functional-tests/bus-update-test.vala
+++ b/tests/functional-tests/bus-update-test.vala
@@ -1,48 +1,12 @@
 using Tracker;
 using Tracker.Sparql;
 
-private int iter_cursor (Cursor cursor)
-{
-	try {
-		while (cursor.next()) {
-			int i;
-
-			for (i = 0; i < cursor.n_columns; i++) {
-				print ("%s%s", i != 0 ? ",":"", cursor.get_string (i));
-			}
-
-			print ("\n");
-		}
-	} catch (GLib.Error e) {
-		warning ("Couldn't iterate query results: %s", e.message);
-		return -1;
-	}
-
-	return (0);
-}
-
 int
 main( string[] args )
 {
-	Sparql.Connection con = new Tracker.Bus.Connection ();
-	Cursor cursor;
-	int a;
-
-	try {
-		con.update ("INSERT { <test01> a nie:InformationElement ; nie:title 'test01' }");
-	} catch (GLib.Error e) {
-		warning ("Couldn't perform query: %s", e.message);
-		return -1;
-	}
-
-	try {
-		cursor = con.query ("SELECT ?title WHERE { <test01> nie:title ?title }");
-	} catch (GLib.Error e) {
-		warning ("Couldn't perform query: %s", e.message);
-		return -1;
-	}
+	TestApp app = new TestApp (new  Tracker.Bus.Connection ());
 
-	a = iter_cursor (cursor);
+	app.run ();
 
-	return a;
+	return 0;
 }
diff --git a/tests/functional-tests/shared-update-test.vala b/tests/functional-tests/shared-update-test.vala
new file mode 100644
index 0000000..22c966c
--- /dev/null
+++ b/tests/functional-tests/shared-update-test.vala
@@ -0,0 +1,96 @@
+using Tracker;
+using Tracker.Sparql;
+
+
+public class TestApp : GLib.Object {
+	MainLoop loop;
+	Sparql.Connection con;
+
+	public TestApp (Sparql.Connection connection) {
+		con = connection;
+	}
+
+	int iter_cursor (Cursor cursor) {
+		try {
+			while (cursor.next()) {
+				int i;
+
+				for (i = 0; i < cursor.n_columns; i++) {
+					print ("%s%s", i != 0 ? ",":"", cursor.get_string (i));
+				}
+
+				print ("\n");
+			}
+		} catch (GLib.Error e) {
+			warning ("Couldn't iterate query results: %s", e.message);
+			return -1;
+		}
+
+		return (0);
+	}
+
+	void update_query () {
+		Cursor cursor;
+		int a;
+
+		try {
+			con.update ("INSERT { <test01> a nie:InformationElement ; nie:title 'test01' }");
+		} catch (Tracker.Sparql.Error ea) {
+			warning ("Couldn't update: %s", ea.message);
+		}
+
+		try {
+			cursor = con.query ("SELECT ?title WHERE { <test01> nie:title ?title }");
+			a = iter_cursor (cursor);
+		} catch (Tracker.Sparql.Error eb) {
+			warning ("Couldn't query: %s", eb.message);
+		}
+
+	}
+
+	async void update_query_async () {
+		Cursor cursor;
+		int a;
+
+		try {
+			yield con.update_async ("INSERT { <test01> a nie:InformationElement ; nie:title 'test01' }");
+		} catch (Tracker.Sparql.Error ea) {
+			warning ("Couldn't update: %s", ea.message);
+		}
+
+		try {
+			cursor = con.query ("SELECT ?title WHERE { <test01> nie:title ?title }");
+			a = iter_cursor (cursor);
+		} catch (Tracker.Sparql.Error eb) {
+			warning ("Couldn't query: %s", eb.message);
+		}
+
+	}
+
+	void do_sync_tests () {
+		update_query ();
+	}
+
+	async void do_async_tests () {
+		yield update_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 void run () {
+		loop = new MainLoop (null, false);
+
+		Idle.add (in_mainloop);
+
+		loop.run ();
+	}
+}



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