[couchdb-glib] Fixed test program



commit eee0aecfab695f275f8048a162410a69c2a4e2b3
Author: Rodrigo Moya <rodrigo gnome-db org>
Date:   Thu Jun 3 09:45:32 2010 +0200

    Fixed test program

 tests/test-couchdb-glib.c |   47 +++++++++++++++++++++++----------------------
 1 files changed, 24 insertions(+), 23 deletions(-)
---
diff --git a/tests/test-couchdb-glib.c b/tests/test-couchdb-glib.c
index 6c9f702..4f9425f 100644
--- a/tests/test-couchdb-glib.c
+++ b/tests/test-couchdb-glib.c
@@ -120,6 +120,26 @@ test_list_documents (void)
 }
 
 static void
+doc_changed_cb (CouchdbDatabase *database, CouchdbDocument *document, gpointer user_data)
+{
+	char *doc_str;
+
+	doc_str = couchdb_document_to_string (document);
+	g_print ("Document %s has been %s: %s\n",
+		 couchdb_document_get_id (document),
+		 (const gchar *) user_data,
+		 doc_str);
+
+	g_free (doc_str);
+}
+
+static void
+doc_deleted_cb (CouchdbDatabase *database, const char *docid, gpointer user_data)
+{
+	g_print ("Document %s in database %s has been deleted\n", docid, couchdb_database_get_name (database));
+}
+
+static void
 test_change_databases (void)
 {
 	char *dbname;
@@ -142,6 +162,10 @@ test_change_databases (void)
 	}
 
 	database = couchdb_session_get_database (couchdb, dbname, &error);
+	g_signal_connect (G_OBJECT (database), "document_created", G_CALLBACK (doc_changed_cb), "created");
+	g_signal_connect (G_OBJECT (database), "document_updated", G_CALLBACK (doc_changed_cb), "updated");
+	g_signal_connect (G_OBJECT (database), "document_deleted", G_CALLBACK (doc_deleted_cb), NULL);
+
 	couchdb_database_listen_for_changes (database);
 
 	/* Create some documents */
@@ -186,26 +210,6 @@ db_deleted_cb (CouchdbSession *couchdb, const char *dbname, gpointer user_data)
 	g_print ("Database %s has been deleted\n", dbname);
 }
 
-static void
-doc_changed_cb (CouchdbSession *couchdb, const char *dbname, CouchdbDocument *document, gpointer user_data)
-{
-	char *doc_str;
-
-	doc_str = couchdb_document_to_string (document);
-	g_print ("Document %s has been %s: %s\n",
-		 couchdb_document_get_id (document),
-		 (const gchar *) user_data,
-		 doc_str);
-
-	g_free (doc_str);
-}
-
-static void
-doc_deleted_cb (CouchdbSession *couchdb, const char *dbname, const char *docid, gpointer user_data)
-{
-	g_print ("Document %s in database %s has been deleted\n", docid, dbname);
-}
-
 int
 main (int argc, char *argv[])
 {
@@ -224,9 +228,6 @@ main (int argc, char *argv[])
 
 	g_signal_connect (G_OBJECT (couchdb), "database_created", G_CALLBACK (db_created_cb), NULL);
 	g_signal_connect (G_OBJECT (couchdb), "database_deleted", G_CALLBACK (db_deleted_cb), NULL);
-	g_signal_connect (G_OBJECT (couchdb), "document_created", G_CALLBACK (doc_changed_cb), "created");
-	g_signal_connect (G_OBJECT (couchdb), "document_updated", G_CALLBACK (doc_changed_cb), "updated");
-	g_signal_connect (G_OBJECT (couchdb), "document_deleted", G_CALLBACK (doc_deleted_cb), NULL);
 
 	/* Setup test functions */
 	g_test_add_func ("/testcouchdbglib/ListDatabases", test_list_databases);



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