a1a663a5d29e9c34d4b6db05f72a82aee5fd68ae
[platform/upstream/evolution-data-server.git] / tests / test-server-utils / e-test-server-utils.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /* e-test-server-utils.h - Test scaffolding to run tests with in-tree data server.
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 #ifndef E_TEST_UTILS_H
24 #define E_TEST_UTILS_H
25
26 #include <libedataserver/libedataserver.h>
27 #include <libebook/libebook.h>
28 #include <libecal/libecal.h>
29
30 typedef struct _ETestServerFixture ETestServerFixture;
31 typedef struct _ETestServerClosure ETestServerClosure;
32
33 /**
34  * E_TEST_SERVER_UTILS_SERVICE:
35  * @fixture: An #ETestServerFixture
36  * @service_type: The type to cast for the service in use
37  *
38  * A convenience macro to fetch the service for a given test case:
39  *
40  * |[
41  *    EBookClient *book = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
42  * ]|
43  *
44  */
45 #define E_TEST_SERVER_UTILS_SERVICE(fixture, service_type) \
46         ((service_type *)((ETestServerFixture *) fixture)->service.generic)
47
48 /**
49  * ETestSourceCustomizeFunc:
50  * @scratch: The scratch #ESource template being used to create an addressbook or calendar
51  * @closure: The #ETestServerClosure for this test case
52  *
53  * This can be used to parameterize the addressbook or calendar @scratch #ESource
54  * before creating/committing it.
55  */
56 typedef void (* ETestSourceCustomizeFunc) (ESource            *scratch,
57                                            ETestServerClosure *closure);
58
59 /**
60  * ETestServiceType:
61  * @E_TEST_SERVER_NONE: Only the #ESourceRegistry will be created
62  * @E_TEST_SERVER_ADDRESS_BOOK: An #EBookCLient will be created and opened for the test
63  * @E_TEST_SERVER_CALENDAR: An #ECalClient will be created and opened for the test
64  * @E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK: An #EBook will be created and opened for the test
65  *
66  * The type of service to test
67  */
68 typedef enum {
69         E_TEST_SERVER_NONE = 0,
70         E_TEST_SERVER_ADDRESS_BOOK,
71         E_TEST_SERVER_CALENDAR,
72         E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK,
73         E_TEST_SERVER_DEPRECATED_CALENDAR
74 } ETestServiceType;
75
76 /**
77  * ETestServerClosure:
78  * @flags:                The #ETestServiceFlags to use for this test
79  * @customize:            An #ETestSourceCustomizeFunc to use to parameterize the scratch #ESource, or %NULL
80  * @calendar_source_type: An #ECalClientSourceType or #ECalSourceType; for %E_TEST_SERVER_CALENDAR
81  *                        and %E_TEST_SERVER_DEPRECATED_CALENDAR tests
82  *
83  * This structure provides the parameters for the #ETestServerFixture tests,
84  * it can be included as the first member of a derived structure
85  * for any tests deriving from the #ETestServerFixture test type
86  */
87 struct _ETestServerClosure {
88         ETestServiceType         type;
89         ETestSourceCustomizeFunc customize;
90         gint                     calendar_source_type;
91         gboolean                 keep_work_directory;
92         GDestroyNotify           destroy_closure_func;
93 };
94
95 /**
96  * ETestService:
97  * @book_client: An #EBookClient, created for %E_TEST_SERVER_ADDRESS_BOOK tests
98  * @calendar_client: An #ECalClient, created for %E_TEST_SERVER_CALENDAR tests
99  * @book: An #EBook, created for %E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK tests
100  * @calendar: An #ECal, created for %E_TEST_SERVER_DEPRECATED_CALENDAR tests
101  *
102  * A union of service types, holds the object to test in a #ETestServerFixture.
103  *
104  */
105 typedef union {
106         gpointer     generic;
107         EBookClient *book_client;
108         ECalClient  *calendar_client;
109         EBook       *book;
110         ECal        *calendar;
111 } ETestService;
112
113 /**
114  * ETestServerFixture:
115  * @loop: A Main loop to run traffic in
116  * @dbus: The D-Bus test scaffold
117  * @registry: An #ESourceRegistry
118  * @service: The #ETestService
119  *
120  * A fixture for running tests on the Evolution Data Server
121  * components in an encapsulated D-Bus environment.
122  */
123 struct _ETestServerFixture {
124         GMainLoop       *loop;
125         GTestDBus       *dbus;
126         ESourceRegistry *registry;
127         ETestService     service;
128 };
129
130 void e_test_server_utils_setup    (ETestServerFixture *fixture,
131                                    gconstpointer       user_data);
132
133 void e_test_server_utils_teardown (ETestServerFixture *fixture,
134                                    gconstpointer       user_data);
135
136 gint e_test_server_utils_run      (void);
137
138 #endif /* E_TEST_UTILS_H */