Adapt libecal to the new ESource API.
[platform/upstream/evolution-data-server.git] / tests / libecal / test-ecal-stress-factory--open-async.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 #include <stdlib.h>
4 #include <libecal/e-cal.h>
5
6 #include "ecal-test-utils.h"
7
8 #define OPEN_ASYNC_TIMEOUT 200
9 #define NUM_CALS 200
10
11 static void open_timeout_cb (gpointer user_data) __attribute__ ((noreturn));
12
13 static guint open_timeout_id = 0;
14 static ECal *cals[NUM_CALS];
15 static gint cals_processed = 0;
16
17 static void
18 open_complete_cb (ECalTestClosure *closure)
19 {
20         g_source_remove (open_timeout_id);
21
22         cals_processed++;
23
24         if (cals_processed == NUM_CALS) {
25                 test_print ("asynchronously opened all calendars successfully\n");
26                 g_main_loop_quit ((GMainLoop *) closure->user_data);
27         }
28 }
29
30 static void
31 open_timeout_cb (gpointer user_data)
32 {
33         g_error ("failed to get a response for the async 'open' within a "
34                         "reasonable time frame");
35 }
36
37 gint
38 main (gint argc,
39       gchar **argv)
40 {
41         gchar *uri = NULL;
42         GMainLoop *loop;
43         gint i;
44
45         g_type_init ();
46
47         open_timeout_id = g_timeout_add_seconds (OPEN_ASYNC_TIMEOUT,
48                         (GSourceFunc) open_timeout_cb, NULL);
49
50         loop = g_main_loop_new (NULL, TRUE);
51
52         /* open and close many calendars in parallel */
53         for (i = 0; i < NUM_CALS; i++) {
54                 cals[i] = ecal_test_utils_cal_new_temp (&uri,
55                                 E_CAL_SOURCE_TYPE_EVENT);
56                 ecal_test_utils_cal_async_open (cals[i], FALSE,
57                                 (GSourceFunc) open_complete_cb, loop);
58
59                 g_free (uri);
60         }
61
62         g_main_loop_run (loop);
63
64         return 0;
65 }