1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ 2 3 #ifdef HAVE_CONFIG_H 4 #include "config.h" 5 #endif 6 7 #include <string.h> 8 #include <stdlib.h> 9 10 #define LIBSOUP_USE_UNSTABLE_REQUEST_API 11 12 #include "libsoup/soup.h" 13 #include "libsoup/soup-requester.h" 14 15 void test_init (int argc, char **argv, GOptionEntry *entries); 16 void test_cleanup (void); 17 18 extern int debug_level; 19 extern gboolean tls_available; 20 extern gboolean apache_available; 21 void debug_printf (int level, const char *format, ...) G_GNUC_PRINTF (2, 3); 22 23 #define SOUP_TEST_SKIP_IF_NO_TLS \ 24 G_STMT_START { \ 25 if (!tls_available) { \ 26 g_test_skip ("TLS is not available"); \ 27 return; \ 28 } \ 29 } G_STMT_END 30 31 #ifdef HAVE_APACHE 32 void apache_init (void); 33 void apache_cleanup (void); 34 #define SOUP_TEST_SKIP_IF_NO_APACHE 35 #else 36 #define apache_init() 37 #define apache_cleanup() 38 #define SOUP_TEST_SKIP_IF_NO_APACHE \ 39 G_STMT_START { \ 40 g_test_skip ("apache is not available"); \ 41 return; \ 42 } G_STMT_END 43 #endif 44 45 gboolean have_curl (void); 46 47 typedef enum { 48 SOUP_TEST_REQUEST_NONE = 0, 49 SOUP_TEST_REQUEST_CANCEL_MESSAGE = (1 << 0), 50 SOUP_TEST_REQUEST_CANCEL_CANCELLABLE = (1 << 1), 51 SOUP_TEST_REQUEST_CANCEL_SOON = (1 << 2), 52 SOUP_TEST_REQUEST_CANCEL_IMMEDIATE = (1 << 3), 53 SOUP_TEST_REQUEST_CANCEL_PREEMPTIVE = (1 << 4), 54 SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH = (1 << 5), 55 } SoupTestRequestFlags; 56 57 #undef SOUP_TYPE_SESSION_ASYNC 58 #define SOUP_TYPE_SESSION_ASYNC (_soup_session_async_get_type_undeprecated ()) 59 #undef SOUP_TYPE_SESSION_SYNC 60 #define SOUP_TYPE_SESSION_SYNC (_soup_session_sync_get_type_undeprecated ()) 61 62 SoupSession *soup_test_session_new (GType type, ...); 63 void soup_test_session_abort_unref (SoupSession *session); 64 65 typedef enum { 66 SOUP_TEST_SERVER_DEFAULT = 0, 67 SOUP_TEST_SERVER_IN_THREAD = (1 << 0), 68 SOUP_TEST_SERVER_NO_DEFAULT_LISTENER = (1 << 1) 69 } SoupTestServerOptions; 70 71 SoupServer *soup_test_server_new (SoupTestServerOptions options); 72 SoupURI *soup_test_server_get_uri (SoupServer *server, 73 const char *scheme, 74 const char *host); 75 void soup_test_server_quit_unref (SoupServer *server); 76 77 GInputStream *soup_test_request_send (SoupRequest *req, 78 GCancellable *cancellable, 79 guint flags, 80 GError **error); 81 gboolean soup_test_request_read_all (SoupRequest *req, 82 GInputStream *stream, 83 GCancellable *cancellable, 84 GError **error); 85 gboolean soup_test_request_close_stream (SoupRequest *req, 86 GInputStream *stream, 87 GCancellable *cancellable, 88 GError **error); 89 90 void soup_test_register_resources (void); 91 SoupBuffer *soup_test_load_resource (const char *name, 92 GError **error); 93 94 SoupBuffer *soup_test_get_index (void); 95 96 #ifdef G_HAVE_ISO_VARARGS 97 #define soup_test_assert(expr, ...) \ 98 G_STMT_START { \ 99 char *_message; \ 100 if (G_UNLIKELY (!(expr))) { \ 101 _message = g_strdup_printf (__VA_ARGS__); \ 102 g_assertion_message (G_LOG_DOMAIN, \ 103 __FILE__, __LINE__, G_STRFUNC, \ 104 _message); \ 105 g_free (_message); \ 106 } \ 107 } G_STMT_END 108 #else 109 void soup_test_assert (gboolean expr, const char *fmt, ...); 110 #endif 111 112 #define soup_test_assert_message_status(msg, status) \ 113 G_STMT_START { \ 114 SoupMessage *_msg = (msg); \ 115 guint _status = (status); \ 116 char *_message; \ 117 \ 118 if (G_UNLIKELY (_msg->status_code != _status)) { \ 119 _message = g_strdup_printf ("Unexpected status %d %s (expected %d %s)", \ 120 _msg->status_code, _msg->reason_phrase, \ 121 _status, soup_status_get_phrase (_status)); \ 122 g_assertion_message (G_LOG_DOMAIN, \ 123 __FILE__, __LINE__, G_STRFUNC, \ 124 _message); \ 125 g_free (_message); \ 126 } \ 127 } G_STMT_END 128 129 #define soup_assert_cmpmem(s1, l1, s2, l2) \ 130 G_STMT_START { \ 131 int __l1 = l1, __l2 = l2; \ 132 gconstpointer __s1 = s1, __s2 = s2; \ 133 if (G_UNLIKELY ((__l1) != (__l2))) { \ 134 g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 135 "len(" #s1 ") == len(" #s2 ")", __l1, "==", __l2, \ 136 'i'); \ 137 } else if (G_UNLIKELY (memcmp (__s1, __s2, __l1) != 0)) { \ 138 g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \ 139 "assertion failed (" #s1 " == " #s2 ")"); \ 140 } \ 141 } G_STMT_END 142