File: e-test-server-utils.h

package info (click to toggle)
evolution-data-server 3.56.2-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 46,656 kB
  • sloc: ansic: 365,352; xml: 578; cpp: 482; perl: 297; sh: 62; makefile: 60; python: 35; javascript: 29
file content (166 lines) | stat: -rw-r--r-- 6,015 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* e-test-server-utils.h - Test scaffolding to run tests with in-tree data server.
 *
 * Copyright (C) 2012 Intel Corporation
 *
 * This library is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library. If not, see <http://www.gnu.org/licenses/>.
 *
 * Authors: Tristan Van Berkom <tristanvb@openismus.com>
 */

#ifndef E_TEST_UTILS_H
#define E_TEST_UTILS_H

#include <libedataserver/libedataserver.h>
#include <libebook/libebook.h>
#include <libecal/libecal.h>

typedef struct _ETestServerFixture ETestServerFixture;
typedef struct _ETestServerClosure ETestServerClosure;

/**
 * E_TEST_SERVER_UTILS_SERVICE:
 * @fixture: An #ETestServerFixture
 * @service_type: The type to cast for the service in use
 *
 * A convenience macro to fetch the service for a given test case:
 *
 * |[
 *    EBookClient *book = E_TEST_SERVER_UTILS_SERVICE (fixture, EBookClient);
 * ]|
 *
 */
#define E_TEST_SERVER_UTILS_SERVICE(fixture, service_type) \
	((service_type *)((ETestServerFixture *) fixture)->service.generic)

/**
 * ETestSourceCustomizeFunc:
 * @scratch: The scratch #ESource template being used to create an addressbook or calendar
 * @closure: The #ETestServerClosure for this test case
 *
 * This can be used to parameterize the addressbook or calendar @scratch #ESource
 * before creating/committing it.
 */
typedef void (* ETestSourceCustomizeFunc) (ESource            *scratch,
					   ETestServerClosure *closure);

/**
 * ETestServiceType:
 * @E_TEST_SERVER_NONE: Only the #ESourceRegistry will be created
 * @E_TEST_SERVER_ADDRESS_BOOK: An #EBookClient will be created and opened for the test
 * @E_TEST_SERVER_DIRECT_ADDRESS_BOOK: An #EBookClient in direct read access mode will be created and opened for the test
 * @E_TEST_SERVER_CALENDAR: An #ECalClient will be created and opened for the test
 * @E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK: An #EBook will be created and opened for the test
 *
 * The type of service to test
 */
typedef enum {
	E_TEST_SERVER_NONE = 0,
	E_TEST_SERVER_ADDRESS_BOOK,
	E_TEST_SERVER_DIRECT_ADDRESS_BOOK,
	E_TEST_SERVER_CALENDAR,
	E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK
} ETestServiceType;

/**
 * ETestServerClosure:
 * @type:                 An #ETestServiceType, type of the service
 * @customize:            An #ETestSourceCustomizeFunc to use to parameterize the scratch #ESource, or %NULL
 * @calendar_source_type: An #ECalClientSourceType for %E_TEST_SERVER_CALENDAR tests
 * @keep_work_directory:  If specified, the work directory will not be deleted between tests
 * @destroy_closure_func: A function to destroy an allocated #ETestServerClosure, this it
 *                        typically used by sub-fixtures which embed this structure in their closures.
 * @use_async_connect:    Specifies whether a synchronous or asyncrhonous API should be used to
 *                        create the #EClient you plan to test.
 *
 * This structure provides the parameters for the #ETestServerFixture tests,
 * it can be included as the first member of a derived structure
 * for any tests deriving from the #ETestServerFixture test type
 */
struct _ETestServerClosure {
	ETestServiceType         type;
	ETestSourceCustomizeFunc customize;
	ECalClientSourceType     calendar_source_type;
	gboolean                 keep_work_directory;
	GDestroyNotify           destroy_closure_func;
	gboolean                 use_async_connect;
};

/**
 * ETestService:
 * @generic: A generic pointer for the test service.
 * @book_client: An #EBookClient, created for %E_TEST_SERVER_ADDRESS_BOOK tests
 * @calendar_client: An #ECalClient, created for %E_TEST_SERVER_CALENDAR tests
 * @book: An #EBook, created for %E_TEST_SERVER_DEPRECATED_ADDRESS_BOOK tests
 *
 * A union of service types, holds the object to test in an #ETestServerFixture.
 *
 */
typedef union {
	gpointer     generic;
	EBookClient *book_client;
	ECalClient  *calendar_client;
	EBook       *book;
} ETestService;

/**
 * ETestServerFixture:
 * @loop: A Main loop to run traffic in
 * @dbus: The D-Bus test scaffold
 * @registry: An #ESourceRegistry
 * @service: The #ETestService
 * @source_name: This can be given an allocated string before calling e_test_server_utils_setup() and will be the #ESource UID
 * for the test addressbook or calendar, leaving this %NULL will result in a suitable unique id being generated for the test. 
 *
 * A fixture for running tests on the Evolution Data Server
 * components in an encapsulated D-Bus environment.
 */
struct _ETestServerFixture {
	GMainLoop       *loop;
	GTestDBus       *dbus;
	ESourceRegistry *registry;
	ETestService     service;
	gchar           *source_name;

	/*< private >*/
	guint            timeout_source_id;
	GWeakRef         registry_ref;
	GWeakRef         client_ref;
};

/**
 * ETestServiceFlags:
 * @E_TEST_SERVER_KEEP_WORK_DIRECTORY: Don't delete working directory upon startup.
 *
 * Instructions upon e_test_server_utils_run_full() operation.
 */
typedef enum {
	E_TEST_SERVER_KEEP_WORK_DIRECTORY = (1 << 0)
} ETestServerFlags;

void e_test_server_utils_setup    (ETestServerFixture *fixture,
				   gconstpointer       user_data);

void e_test_server_utils_teardown (ETestServerFixture *fixture,
				   gconstpointer       user_data);

gint e_test_server_utils_run      (gint argc,
				   gchar *argv[]);
gint e_test_server_utils_run_full (gint argc,
				   gchar *argv[],
				   ETestServerFlags flags);
void e_test_server_utils_prepare_run (gint argc,
				      gchar *argv[],
				      ETestServerFlags flags);
void e_test_server_utils_finish_run (void);

#endif /* E_TEST_UTILS_H */