[couchdb-glib] Added more API tests
- From: Rodrigo Moya <rodrigo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [couchdb-glib] Added more API tests
- Date: Thu, 3 Jun 2010 14:39:22 +0000 (UTC)
commit 07cce1be54aa8febafb2563971ab8c689cf6a831
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Thu Jun 3 16:17:06 2010 +0200
Added more API tests
tests/test-couchdb-glib.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 75 insertions(+), 0 deletions(-)
---
diff --git a/tests/test-couchdb-glib.c b/tests/test-couchdb-glib.c
index 4f9425f..6f347fa 100644
--- a/tests/test-couchdb-glib.c
+++ b/tests/test-couchdb-glib.c
@@ -24,6 +24,79 @@
static CouchdbSession *couchdb;
+static CouchdbArrayField *
+create_fake_array (void)
+{
+ CouchdbArrayField *array;
+ gint i;
+
+ array = couchdb_array_field_new ();
+ for (i = 0; i < 10; i++)
+ couchdb_array_field_add_int_element (array, i);
+
+ return array;
+}
+
+static void
+test_array_field (void)
+{
+ CouchdbArrayField *array, *tmp_array;
+
+ array = couchdb_array_field_new ();
+ g_assert (COUCHDB_IS_ARRAY_FIELD (array));
+
+ tmp_array = create_fake_array ();
+ couchdb_array_field_add_array_element (array, tmp_array);
+ g_assert (couchdb_array_field_get_length (couchdb_array_field_get_array_element (array, couchdb_array_field_get_length (array) - 1))
+ == couchdb_array_field_get_length (tmp_array));
+ g_object_unref (G_OBJECT (tmp_array));
+
+ couchdb_array_field_add_boolean_element (array, TRUE);
+ g_assert (couchdb_array_field_get_boolean_element (array, couchdb_array_field_get_length (array) - 1) == TRUE);
+
+ couchdb_array_field_add_double_element (array, 1.0);
+ g_assert (couchdb_array_field_get_double_element (array, couchdb_array_field_get_length (array) - 1) == 1.0);
+
+ couchdb_array_field_add_int_element (array, 1);
+ g_assert (couchdb_array_field_get_int_element (array, couchdb_array_field_get_length (array) - 1) == 1);
+
+ couchdb_array_field_add_string_element (array, "hola");
+ g_assert (g_strcmp0 (couchdb_array_field_get_string_element (array, couchdb_array_field_get_length (array) - 1),
+ "hola") == 0);
+
+ do {
+ gint length = couchdb_array_field_get_length (array);
+
+ couchdb_array_field_remove_element (array, 0);
+ g_assert (couchdb_array_field_get_length (array) == length - 1);
+ } while (couchdb_array_field_get_length (array) > 0);
+
+ g_object_unref (G_OBJECT (array));
+}
+
+static void
+test_struct_field (void)
+{
+ CouchdbStructField *sf;
+
+ sf = couchdb_struct_field_new ();
+ g_assert (COUCHDB_IS_STRUCT_FIELD (sf));
+
+ couchdb_struct_field_set_boolean_field (sf, "boolean", TRUE);
+ g_assert (couchdb_struct_field_get_boolean_field (sf, "boolean") == TRUE);
+
+ couchdb_struct_field_set_double_field (sf, "double", 1.0);
+ g_assert (couchdb_struct_field_get_double_field (sf, "double") == 1.0);
+
+ couchdb_struct_field_set_int_field (sf, "int", 1);
+ g_assert (couchdb_struct_field_get_int_field (sf, "int") == 1);
+
+ couchdb_struct_field_set_string_field (sf, "string", "hola");
+ g_assert (g_strcmp0 (couchdb_struct_field_get_string_field (sf, "string"), "hola") == 0);
+
+ g_object_unref (G_OBJECT (sf));
+}
+
static void
test_list_databases (void)
{
@@ -230,6 +303,8 @@ main (int argc, char *argv[])
g_signal_connect (G_OBJECT (couchdb), "database_deleted", G_CALLBACK (db_deleted_cb), NULL);
/* Setup test functions */
+ g_test_add_func ("/testcouchdbglib/TestArrayField", test_array_field);
+ g_test_add_func ("/testcouchdbglib/TestStructField", test_struct_field);
g_test_add_func ("/testcouchdbglib/ListDatabases", test_list_databases);
g_test_add_func ("/testcouchdbglib/ListDocuments", test_list_documents);
g_test_add_func ("/testcouchdbglib/ChangeDatabases", test_change_databases);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]