Blame tests/test-utils.h

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