summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTravis Reitter <treitter@gmail.com>2009-12-29 15:30:01 -0800
committerTravis Reitter <treitter@gmail.com>2009-12-29 15:30:01 -0800
commit25135cc7e4002f27ab9a544829477ffd3bfe548d (patch)
tree2875154bf70d9e958fec5bcc2f27486ddf0ea4fd
parentad854acba0a8091375e7c2231e30462df0701e32 (diff)
downloadevolution-data-server-treitter-test-suites.tar.gz
Add tests to stress-test the addressbook factory.treitter-test-suites
-rw-r--r--addressbook/tests/ebook/Makefile.am9
-rw-r--r--addressbook/tests/ebook/ebook-test-utils.c25
-rw-r--r--addressbook/tests/ebook/ebook-test-utils.h3
-rw-r--r--addressbook/tests/ebook/test-ebook-stress-factory--fifo.c33
-rw-r--r--addressbook/tests/ebook/test-ebook-stress-factory--serial.c29
-rw-r--r--addressbook/tests/ebook/test-ebook-stress-factory--single-book.c35
6 files changed, 126 insertions, 8 deletions
diff --git a/addressbook/tests/ebook/Makefile.am b/addressbook/tests/ebook/Makefile.am
index 5a476dedf..cf04e2d75 100644
--- a/addressbook/tests/ebook/Makefile.am
+++ b/addressbook/tests/ebook/Makefile.am
@@ -35,6 +35,9 @@ TESTS = \
test-ebook-remove-contact \
test-ebook-remove-contact-by-id \
test-ebook-remove-contacts \
+ test-ebook-stress-factory--serial \
+ test-ebook-stress-factory--fifo \
+ test-ebook-stress-factory--single-book \
$(NULL)
noinst_PROGRAMS = \
@@ -91,6 +94,12 @@ test_ebook_remove_contact_by_id_LDADD=$(TEST_LIBS)
test_ebook_remove_contact_by_id_CPPFLAGS=$(TEST_CPPFLAGS)
test_ebook_remove_contacts_LDADD=$(TEST_LIBS)
test_ebook_remove_contacts_CPPFLAGS=$(TEST_CPPFLAGS)
+test_ebook_stress_factory__fifo_LDADD=$(TEST_LIBS)
+test_ebook_stress_factory__fifo_CPPFLAGS=$(TEST_CPPFLAGS)
+test_ebook_stress_factory__serial_LDADD=$(TEST_LIBS)
+test_ebook_stress_factory__serial_CPPFLAGS=$(TEST_CPPFLAGS)
+test_ebook_stress_factory__single_book_LDADD=$(TEST_LIBS)
+test_ebook_stress_factory__single_book_CPPFLAGS=$(TEST_CPPFLAGS)
test_changes_LDADD=$(TEST_LIBS)
test_changes_CPPFLAGS=$(TEST_CPPFLAGS)
test_categories_LDADD=$(TEST_LIBS)
diff --git a/addressbook/tests/ebook/ebook-test-utils.c b/addressbook/tests/ebook/ebook-test-utils.c
index 66c73cc62..46e03c2e3 100644
--- a/addressbook/tests/ebook/ebook-test-utils.c
+++ b/addressbook/tests/ebook/ebook-test-utils.c
@@ -624,6 +624,22 @@ ebook_test_utils_book_async_remove_contacts (EBook *book,
}
EBook*
+ebook_test_utils_book_new_from_uri (const char *uri)
+{
+ EBook *book;
+ GError *error = NULL;
+
+ test_print ("loading addressbook\n");
+ book = e_book_new_from_uri (uri, &error);
+ if (!book) {
+ g_error ("failed to create addressbook: `%s': %s", uri,
+ error->message);
+ }
+
+ return book;
+}
+
+EBook*
ebook_test_utils_book_new_temp (char **uri)
{
EBook *book;
@@ -643,14 +659,7 @@ ebook_test_utils_book_new_temp (char **uri)
}
g_free (file_template);
- /* create a temp addressbook in /tmp */
- test_print ("loading addressbook\n");
- book = e_book_new_from_uri (uri_result, &error);
- if (!book) {
- g_warning ("failed to create addressbook: `%s': %s", *uri,
- error->message);
- exit(1);
- }
+ book = ebook_test_utils_book_new_from_uri (uri_result);
if (uri)
*uri = g_strdup (uri_result);
diff --git a/addressbook/tests/ebook/ebook-test-utils.h b/addressbook/tests/ebook/ebook-test-utils.h
index 5cb36b7dc..47f33eb63 100644
--- a/addressbook/tests/ebook/ebook-test-utils.h
+++ b/addressbook/tests/ebook/ebook-test-utils.h
@@ -55,6 +55,9 @@ ebook_test_utils_contacts_are_equal_shallow (EContact *a,
EContact *b);
EBook*
+ebook_test_utils_book_new_from_uri (const char *uri);
+
+EBook*
ebook_test_utils_book_new_temp (char **uri);
const char*
diff --git a/addressbook/tests/ebook/test-ebook-stress-factory--fifo.c b/addressbook/tests/ebook/test-ebook-stress-factory--fifo.c
new file mode 100644
index 000000000..cf8e03e47
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-stress-factory--fifo.c
@@ -0,0 +1,33 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libebook/e-book.h>
+
+#include "ebook-test-utils.h"
+
+#define NUM_BOOKS 200
+
+gint
+main (gint argc, gchar **argv)
+{
+ char *uri = NULL;
+ EBook *books[NUM_BOOKS];
+ gint i;
+
+ g_type_init ();
+
+ /* Create and open many books; then remove each of them */
+
+ for (i = 0; i < NUM_BOOKS; i++) {
+ books[i] = ebook_test_utils_book_new_temp (&uri);
+ ebook_test_utils_book_open (books[i], FALSE);
+
+ g_free (uri);
+ }
+
+ for (i = 0; i < NUM_BOOKS; i++) {
+ ebook_test_utils_book_remove (books[i]);
+ }
+
+ return 0;
+}
diff --git a/addressbook/tests/ebook/test-ebook-stress-factory--serial.c b/addressbook/tests/ebook/test-ebook-stress-factory--serial.c
new file mode 100644
index 000000000..64bfc345d
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-stress-factory--serial.c
@@ -0,0 +1,29 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <libebook/e-book.h>
+
+#include "ebook-test-utils.h"
+
+#define NUM_BOOKS 200
+
+gint
+main (gint argc, gchar **argv)
+{
+ char *uri = NULL;
+ gint i;
+
+ g_type_init ();
+
+ /* Serially create, open, (close), and remove many books */
+ for (i = 0; i < NUM_BOOKS; i++) {
+ EBook *book;
+
+ book = ebook_test_utils_book_new_temp (&uri);
+ ebook_test_utils_book_open (book, FALSE);
+ ebook_test_utils_book_remove (book);
+
+ g_free (uri);
+ }
+
+ return 0;
+}
diff --git a/addressbook/tests/ebook/test-ebook-stress-factory--single-book.c b/addressbook/tests/ebook/test-ebook-stress-factory--single-book.c
new file mode 100644
index 000000000..9e3e9be30
--- /dev/null
+++ b/addressbook/tests/ebook/test-ebook-stress-factory--single-book.c
@@ -0,0 +1,35 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+#include <stdlib.h>
+#include <libebook/e-book.h>
+
+#include "ebook-test-utils.h"
+
+#define NUM_OPENS 200
+
+gint
+main (gint argc, gchar **argv)
+{
+ char *uri = NULL;
+ EBook *book;
+ gint i;
+
+ g_type_init ();
+
+ book = ebook_test_utils_book_new_temp (&uri);
+ g_object_unref (book);
+
+ /* open and close the same book repeatedly */
+ for (i = 0; i < NUM_OPENS-1; i++) {
+ book = ebook_test_utils_book_new_from_uri (uri);
+ ebook_test_utils_book_open (book, FALSE);
+ g_object_unref (book);
+ }
+
+ book = ebook_test_utils_book_new_from_uri (uri);
+ ebook_test_utils_book_remove (book);
+
+ g_free (uri);
+
+ return 0;
+}