Adapt libecal to the new ESource API.
[platform/upstream/evolution-data-server.git] / tests / libecal / test-ecal-set-mode.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 SET_MODE_TIMEOUT 30
9 #define MODE_FINAL CAL_MODE_LOCAL
10
11 static void cal_set_mode_timeout_cb (gpointer user_data) __attribute__ ((noreturn));
12
13 static guint cal_set_mode_timeout_id = 0;
14
15 static void
16 cal_set_mode_cb (ECalTestClosure *closure)
17 {
18         g_source_remove (cal_set_mode_timeout_id);
19
20         if (closure->mode != MODE_FINAL) {
21                 g_warning ("set mode to %d, but we expected %d", closure->mode,
22                                 MODE_FINAL);
23         }
24
25         g_main_loop_quit ((GMainLoop *) closure->user_data);
26 }
27
28 static void
29 cal_set_mode_timeout_cb (gpointer user_data)
30 {
31         g_warning ("failed to get a confirmation for the new calendar mode we "
32                         "set (within a reasonable time frame)");
33         exit (1);
34 }
35
36 gint
37 main (gint argc,
38       gchar **argv)
39 {
40         ECal *cal;
41         gchar *uri = NULL;
42         GMainLoop *loop;
43
44         g_type_init ();
45
46         cal = ecal_test_utils_cal_new_temp (&uri, E_CAL_SOURCE_TYPE_EVENT);
47         ecal_test_utils_cal_open (cal, FALSE);
48
49         cal_set_mode_timeout_id = g_timeout_add_seconds (SET_MODE_TIMEOUT,
50                         (GSourceFunc) cal_set_mode_timeout_cb, cal);
51
52         loop = g_main_loop_new (NULL, TRUE);
53         ecal_test_utils_cal_set_mode (cal, MODE_FINAL,
54                         (GSourceFunc) cal_set_mode_cb, loop);
55
56         g_main_loop_run (loop);
57
58         return 0;
59 }