Make ETestServerFixture more reliable.
[platform/upstream/evolution-data-server.git] / tests / test-server-utils / test-fixture.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* test-fixture.c - Test to ensure the server test fixture works.
4  *
5  * Copyright (C) 2012 Intel Corporation
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) version 3.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with the program; if not, see <http://www.gnu.org/licenses/>
19  *
20  * Authors: Tristan Van Berkom <tristanvb@openismus.com>
21  */
22
23 #include "e-test-server-utils.h"
24
25 #define N_CYCLES 10
26
27 static ETestServerClosure registry_closure = { E_TEST_SERVER_NONE, NULL, 0 };
28 static ETestServerClosure book_closure     = { E_TEST_SERVER_ADDRESS_BOOK, NULL, 0 };
29 static ETestServerClosure calendar_closure = { E_TEST_SERVER_CALENDAR, NULL, E_CAL_CLIENT_SOURCE_TYPE_EVENTS };
30 static ETestServerClosure deprecated_book_closure     = { E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK, NULL, 0 };
31 static ETestServerClosure deprecated_calendar_closure = { E_TEST_SERVER_DEPRECATED_CALENDAR, NULL, E_CAL_SOURCE_TYPE_EVENT };
32
33 static void
34 empty_test (ETestServerFixture *fixture,
35             gconstpointer user_data)
36 {
37         /* Basic Empty case just to run the fixture */
38 }
39
40 gint
41 main (gint argc,
42       gchar *argv[])
43 {
44         gchar **registry_keys;
45         gchar **book_keys;
46         gchar **calendar_keys;
47         gchar **deprecated_book_keys;
48         gchar **deprecated_calendar_keys;
49         gint i;
50         gint ret;
51
52 #if !GLIB_CHECK_VERSION (2, 35, 1)
53         g_type_init ();
54 #endif
55         g_test_init (&argc, &argv, NULL);
56
57         registry_keys = g_new0 (gchar *, N_CYCLES);
58         book_keys = g_new0 (gchar *, N_CYCLES);
59         calendar_keys = g_new0 (gchar *, N_CYCLES);
60         deprecated_book_keys = g_new0 (gchar *, N_CYCLES);
61         deprecated_calendar_keys = g_new0 (gchar *, N_CYCLES);
62
63         for (i = 0; i < N_CYCLES; i++) {
64                 registry_keys[i] = g_strdup_printf ("/Fixture/Registry%d", i);
65                 g_test_add (registry_keys[i], ETestServerFixture, &registry_closure,
66                             e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
67         }
68
69         for (i = 0; i < N_CYCLES; i++) {
70                 book_keys[i] = g_strdup_printf ("/Fixture/Book%d", i);
71                 g_test_add (book_keys[i], ETestServerFixture, &book_closure,
72                             e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
73         }
74
75         for (i = 0; i < N_CYCLES; i++) {
76                 calendar_keys[i] = g_strdup_printf ("/Fixture/Calendar%d", i);
77                 g_test_add (calendar_keys[i], ETestServerFixture, &calendar_closure,
78                             e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
79         }
80
81         for (i = 0; i < N_CYCLES; i++) {
82                 deprecated_book_keys[i] = g_strdup_printf ("/Fixture/Deprecated/Book%d", i);
83                 g_test_add (deprecated_book_keys[i], ETestServerFixture, &deprecated_book_closure,
84                             e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
85         }
86
87         for (i = 0; i < N_CYCLES; i++) {
88                 deprecated_calendar_keys[i] = g_strdup_printf ("/Fixture/Deprecated/Calendar%d", i);
89                 g_test_add (deprecated_calendar_keys[i], ETestServerFixture, &deprecated_calendar_closure,
90                             e_test_server_utils_setup, empty_test, e_test_server_utils_teardown);
91         }
92
93         ret = e_test_server_utils_run ();
94
95         for (i = 0; i < N_CYCLES; i++) {
96                 g_free (registry_keys[i]);
97                 g_free (book_keys[i]);
98                 g_free (calendar_keys[i]);
99                 g_free (deprecated_book_keys[i]);
100                 g_free (deprecated_calendar_keys[i]);
101         }
102
103         g_free (registry_keys);
104         g_free (book_keys);
105         g_free (calendar_keys);
106         g_free (deprecated_book_keys);
107         g_free (deprecated_calendar_keys);
108
109         return ret;
110 }