e-test-server-utils: Add support for testing Direct Read Access books.
[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_DIRECT_ADDRESS_BOOK: An #EBookCLient in direct read access mode will be created and opened for the test
64  * @E_TEST_SERVER_CALENDAR: An #ECalClient will be created and opened for the test
65  * @E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK: An #EBook will be created and opened for the test
66  *
67  * The type of service to test
68  */
69 typedef enum {
70         E_TEST_SERVER_NONE = 0,
71         E_TEST_SERVER_ADDRESS_BOOK,
72         E_TEST_SERVER_DIRECT_ADDRESS_BOOK,
73         E_TEST_SERVER_CALENDAR,
74         E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK,
75         E_TEST_SERVER_DEPRECATED_CALENDAR
76 } ETestServiceType;
77
78 /**
79  * ETestServerClosure:
80  * @flags:                The #ETestServiceFlags to use for this test
81  * @customize:            An #ETestSourceCustomizeFunc to use to parameterize the scratch #ESource, or %NULL
82  * @calendar_source_type: An #ECalClientSourceType or #ECalSourceType; for %E_TEST_SERVER_CALENDAR
83  *                        and %E_TEST_SERVER_DEPRECATED_CALENDAR tests
84  *
85  * This structure provides the parameters for the #ETestServerFixture tests,
86  * it can be included as the first member of a derived structure
87  * for any tests deriving from the #ETestServerFixture test type
88  */
89 struct _ETestServerClosure {
90         ETestServiceType         type;
91         ETestSourceCustomizeFunc customize;
92         gint                     calendar_source_type;
93         gboolean                 keep_work_directory;
94         GDestroyNotify           destroy_closure_func;
95 };
96
97 /**
98  * ETestService:
99  * @book_client: An #EBookClient, created for %E_TEST_SERVER_ADDRESS_BOOK tests
100  * @calendar_client: An #ECalClient, created for %E_TEST_SERVER_CALENDAR tests
101  * @book: An #EBook, created for %E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK tests
102  * @calendar: An #ECal, created for %E_TEST_SERVER_DEPRECATED_CALENDAR tests
103  *
104  * A union of service types, holds the object to test in a #ETestServerFixture.
105  *
106  */
107 typedef union {
108         gpointer     generic;
109         EBookClient *book_client;
110         ECalClient  *calendar_client;
111         EBook       *book;
112         ECal        *calendar;
113 } ETestService;
114
115 /**
116  * ETestServerFixture:
117  * @loop: A Main loop to run traffic in
118  * @dbus: The D-Bus test scaffold
119  * @registry: An #ESourceRegistry
120  * @service: The #ETestService
121  * @timeout_source_id: A private detail, tracks the idle source which times out if the registry cannot create an ESource.
122  *
123  * A fixture for running tests on the Evolution Data Server
124  * components in an encapsulated D-Bus environment.
125  */
126 struct _ETestServerFixture {
127         GMainLoop       *loop;
128         GTestDBus       *dbus;
129         ESourceRegistry *registry;
130         ETestService     service;
131         guint            timeout_source_id;
132 };
133
134 void e_test_server_utils_setup    (ETestServerFixture *fixture,
135                                    gconstpointer       user_data);
136
137 void e_test_server_utils_teardown (ETestServerFixture *fixture,
138                                    gconstpointer       user_data);
139
140 gint e_test_server_utils_run      (void);
141
142 #endif /* E_TEST_UTILS_H */