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
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <stdlib.h>
#define LIBSOUP_USE_UNSTABLE_REQUEST_API
#include "libsoup/soup.h"
#include "libsoup/soup-requester.h"
void test_init (int argc, char **argv, GOptionEntry *entries);
void test_cleanup (void);
extern int debug_level;
extern gboolean tls_available;
extern gboolean apache_available;
void debug_printf (int level, const char *format, ...) G_GNUC_PRINTF (2, 3);
#define SOUP_TEST_SKIP_IF_NO_TLS \
G_STMT_START { \
if (!tls_available) { \
g_test_skip ("TLS is not available"); \
return; \
} \
} G_STMT_END
#ifdef HAVE_APACHE
void apache_init (void);
void apache_cleanup (void);
#define SOUP_TEST_SKIP_IF_NO_APACHE
#else
#define apache_init()
#define apache_cleanup()
#define SOUP_TEST_SKIP_IF_NO_APACHE \
G_STMT_START { \
g_test_skip ("apache is not available"); \
return; \
} G_STMT_END
#endif
gboolean have_curl (void);
typedef enum {
SOUP_TEST_REQUEST_NONE = 0,
SOUP_TEST_REQUEST_CANCEL_MESSAGE = (1 << 0),
SOUP_TEST_REQUEST_CANCEL_CANCELLABLE = (1 << 1),
SOUP_TEST_REQUEST_CANCEL_SOON = (1 << 2),
SOUP_TEST_REQUEST_CANCEL_IMMEDIATE = (1 << 3),
SOUP_TEST_REQUEST_CANCEL_PREEMPTIVE = (1 << 4),
SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH = (1 << 5),
} SoupTestRequestFlags;
#undef SOUP_TYPE_SESSION_ASYNC
#define SOUP_TYPE_SESSION_ASYNC (_soup_session_async_get_type_undeprecated ())
#undef SOUP_TYPE_SESSION_SYNC
#define SOUP_TYPE_SESSION_SYNC (_soup_session_sync_get_type_undeprecated ())
SoupSession *soup_test_session_new (GType type, ...);
void soup_test_session_abort_unref (SoupSession *session);
typedef enum {
SOUP_TEST_SERVER_DEFAULT = 0,
SOUP_TEST_SERVER_IN_THREAD = (1 << 0),
SOUP_TEST_SERVER_NO_DEFAULT_LISTENER = (1 << 1)
} SoupTestServerOptions;
SoupServer *soup_test_server_new (SoupTestServerOptions options);
SoupURI *soup_test_server_get_uri (SoupServer *server,
const char *scheme,
const char *host);
void soup_test_server_quit_unref (SoupServer *server);
GInputStream *soup_test_request_send (SoupRequest *req,
GCancellable *cancellable,
guint flags,
GError **error);
gboolean soup_test_request_read_all (SoupRequest *req,
GInputStream *stream,
GCancellable *cancellable,
GError **error);
gboolean soup_test_request_close_stream (SoupRequest *req,
GInputStream *stream,
GCancellable *cancellable,
GError **error);
void soup_test_register_resources (void);
SoupBuffer *soup_test_load_resource (const char *name,
GError **error);
SoupBuffer *soup_test_get_index (void);
#ifdef G_HAVE_ISO_VARARGS
#define soup_test_assert(expr, ...) \
G_STMT_START { \
char *_message; \
if (G_UNLIKELY (!(expr))) { \
_message = g_strdup_printf (__VA_ARGS__); \
g_assertion_message (G_LOG_DOMAIN, \
__FILE__, __LINE__, G_STRFUNC, \
_message); \
g_free (_message); \
} \
} G_STMT_END
#else
void soup_test_assert (gboolean expr, const char *fmt, ...);
#endif
#define soup_test_assert_message_status(msg, status) \
G_STMT_START { \
SoupMessage *_msg = (msg); \
guint _status = (status); \
char *_message; \
\
if (G_UNLIKELY (_msg->status_code != _status)) { \
_message = g_strdup_printf ("Unexpected status %d %s (expected %d %s)", \
_msg->status_code, _msg->reason_phrase, \
_status, soup_status_get_phrase (_status)); \
g_assertion_message (G_LOG_DOMAIN, \
__FILE__, __LINE__, G_STRFUNC, \
_message); \
g_free (_message); \
} \
} G_STMT_END
#define soup_assert_cmpmem(s1, l1, s2, l2) \
G_STMT_START { \
int __l1 = l1, __l2 = l2; \
gconstpointer __s1 = s1, __s2 = s2; \
if (G_UNLIKELY ((__l1) != (__l2))) { \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"len(" #s1 ") == len(" #s2 ")", __l1, "==", __l2, \
'i'); \
} else if (G_UNLIKELY (memcmp (__s1, __s2, __l1) != 0)) { \
g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
"assertion failed (" #s1 " == " #s2 ")"); \
} \
} G_STMT_END
|