[tracker/direct-access: 90/122] tests/functional-tests: Refactored the tests a bit more
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/direct-access: 90/122] tests/functional-tests: Refactored the tests a bit more
- Date: Fri, 6 Aug 2010 10:21:40 +0000 (UTC)
commit 40d9123a66650dd913b5aea2993ccd7160f741f0
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Jul 22 12:42:11 2010 +0200
tests/functional-tests: Refactored the tests a bit more
tests/functional-tests/.gitignore | 1 +
tests/functional-tests/Makefile.am | 4 +-
tests/functional-tests/bus-query-test.vala | 45 +------------------
tests/functional-tests/bus-update-test.vala | 4 +-
tests/functional-tests/default-update-test.vala | 4 +-
tests/functional-tests/direct-query-test.vala | 46 +------------------
tests/functional-tests/shared-query-test.vala | 54 +++++++++++++++++++++++
tests/functional-tests/shared-update-test.vala | 9 +++-
8 files changed, 71 insertions(+), 96 deletions(-)
---
diff --git a/tests/functional-tests/.gitignore b/tests/functional-tests/.gitignore
index 2af8552..ea6303e 100644
--- a/tests/functional-tests/.gitignore
+++ b/tests/functional-tests/.gitignore
@@ -1,3 +1,4 @@
+shared-query-test.c
shared-update-test.c
bus-query-test
bus-query-test.c
diff --git a/tests/functional-tests/Makefile.am b/tests/functional-tests/Makefile.am
index 8c3ba59..52b4509 100644
--- a/tests/functional-tests/Makefile.am
+++ b/tests/functional-tests/Makefile.am
@@ -67,7 +67,7 @@ busy_handling_test_LDADD = \
$(GLIB2_LIBS) \
$(DBUS_LIBS)
-direct_query_test_VALASOURCES = direct-query-test.vala
+direct_query_test_VALASOURCES = shared-query-test.vala direct-query-test.vala
direct_query_test_SOURCES = \
direct_query_test.vala.stamp \
@@ -79,7 +79,7 @@ default_update_test_SOURCES = \
default_update_test.vala.stamp \
$(default_update_test_VALASOURCES:.vala=.c)
-bus_query_test_VALASOURCES = bus-query-test.vala
+bus_query_test_VALASOURCES = shared-query-test.vala bus-query-test.vala
bus_query_test_SOURCES = \
bus_query_test.vala.stamp \
diff --git a/tests/functional-tests/bus-query-test.vala b/tests/functional-tests/bus-query-test.vala
index df88a0d..1867fed 100644
--- a/tests/functional-tests/bus-query-test.vala
+++ b/tests/functional-tests/bus-query-test.vala
@@ -1,51 +1,10 @@
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 {
- cursor = con.query ("SELECT ?u WHERE { ?u a rdfs:Class }");
- } catch (GLib.Error e) {
- warning ("Couldn't perform query: %s", e.message);
- return -1;
- }
-
- a = iter_cursor (cursor);
-
- if (a == -1)
- return a;
-
- print ("\nRewinding\n");
- cursor.rewind ();
-
- print ("\nSecond run\n");
- a = iter_cursor (cursor);
-
+ TestApp app = new TestApp (new Tracker.Bus.Connection ());
- return a;
+ return app.run ();
}
diff --git a/tests/functional-tests/bus-update-test.vala b/tests/functional-tests/bus-update-test.vala
index e48b5d4..1867fed 100644
--- a/tests/functional-tests/bus-update-test.vala
+++ b/tests/functional-tests/bus-update-test.vala
@@ -6,7 +6,5 @@ main( string[] args )
{
TestApp app = new TestApp (new Tracker.Bus.Connection ());
- app.run ();
-
- return 0;
+ return app.run ();
}
diff --git a/tests/functional-tests/default-update-test.vala b/tests/functional-tests/default-update-test.vala
index 4dacd6e..54914f1 100644
--- a/tests/functional-tests/default-update-test.vala
+++ b/tests/functional-tests/default-update-test.vala
@@ -3,7 +3,5 @@ main( string[] args )
{
TestApp app = new TestApp (Tracker.Sparql.Connection.get());
- app.run ();
-
- return 0;
+ return app.run ();
}
diff --git a/tests/functional-tests/direct-query-test.vala b/tests/functional-tests/direct-query-test.vala
index f1ec29e..231d047 100644
--- a/tests/functional-tests/direct-query-test.vala
+++ b/tests/functional-tests/direct-query-test.vala
@@ -1,52 +1,10 @@
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.Direct.Connection ();
- 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;
- }
+ TestApp app = new TestApp (new Tracker.Direct.Connection ());
- a = iter_cursor (cursor);
-
- if (a == -1)
- return a;
-
- print ("\nRewinding\n");
- cursor.rewind ();
-
- print ("\nSecond run\n");
- a = iter_cursor (cursor);
-
-
- return a;
+ return app.run ();
}
-
diff --git a/tests/functional-tests/shared-query-test.vala b/tests/functional-tests/shared-query-test.vala
new file mode 100644
index 0000000..b11cdce
--- /dev/null
+++ b/tests/functional-tests/shared-query-test.vala
@@ -0,0 +1,54 @@
+using Tracker;
+using Tracker.Sparql;
+
+public class TestApp : GLib.Object {
+ 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);
+ }
+
+ public int run () {
+ 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;
+ }
+
+ a = iter_cursor (cursor);
+
+ if (a == -1)
+ return a;
+
+ print ("\nRewinding\n");
+ cursor.rewind ();
+
+ print ("\nSecond run\n");
+ a = iter_cursor (cursor);
+
+ return a;
+ }
+}
diff --git a/tests/functional-tests/shared-update-test.vala b/tests/functional-tests/shared-update-test.vala
index 22c966c..3d6c57f 100644
--- a/tests/functional-tests/shared-update-test.vala
+++ b/tests/functional-tests/shared-update-test.vala
@@ -5,6 +5,7 @@ using Tracker.Sparql;
public class TestApp : GLib.Object {
MainLoop loop;
Sparql.Connection con;
+ private int res = 0;
public TestApp (Sparql.Connection connection) {
con = connection;
@@ -37,6 +38,7 @@ public class TestApp : GLib.Object {
con.update ("INSERT { <test01> a nie:InformationElement ; nie:title 'test01' }");
} catch (Tracker.Sparql.Error ea) {
warning ("Couldn't update: %s", ea.message);
+ res = -1;
}
try {
@@ -44,6 +46,7 @@ public class TestApp : GLib.Object {
a = iter_cursor (cursor);
} catch (Tracker.Sparql.Error eb) {
warning ("Couldn't query: %s", eb.message);
+ res = -1;
}
}
@@ -56,6 +59,7 @@ public class TestApp : GLib.Object {
yield con.update_async ("INSERT { <test01> a nie:InformationElement ; nie:title 'test01' }");
} catch (Tracker.Sparql.Error ea) {
warning ("Couldn't update: %s", ea.message);
+ res = -1;
}
try {
@@ -63,6 +67,7 @@ public class TestApp : GLib.Object {
a = iter_cursor (cursor);
} catch (Tracker.Sparql.Error eb) {
warning ("Couldn't query: %s", eb.message);
+ res = -1;
}
}
@@ -86,11 +91,13 @@ public class TestApp : GLib.Object {
return false;
}
- public void run () {
+ public int run () {
loop = new MainLoop (null, false);
Idle.add (in_mainloop);
loop.run ();
+
+ return res;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]