Blame tests/xmlrpc-old-test.c

rpm-build 4f3c61
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
rpm-build 4f3c61
/*
rpm-build 4f3c61
 * Copyright (C) 2001-2003, Ximian, Inc.
rpm-build 4f3c61
 */
rpm-build 4f3c61
rpm-build 4f3c61
#include "test-utils.h"
rpm-build 4f3c61
rpm-build 4f3c61
#ifdef G_GNUC_BEGIN_IGNORE_DEPRECATIONS
rpm-build 4f3c61
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
rpm-build 4f3c61
#endif
rpm-build 4f3c61
rpm-build 4f3c61
static SoupSession *session;
rpm-build 4f3c61
static const char *default_uri = "http://127.0.0.1:47524/xmlrpc-server.php";
rpm-build 4f3c61
static const char *uri = NULL;
rpm-build 4f3c61
static gboolean server_test = FALSE;
rpm-build 4f3c61
rpm-build 4f3c61
#ifdef HAVE_PHP_XMLRPC
rpm-build 4f3c61
#define SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER
rpm-build 4f3c61
#else
rpm-build 4f3c61
#define SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER				\
rpm-build 4f3c61
	G_STMT_START {							\
rpm-build 4f3c61
		if (!server_test) {					\
rpm-build 4f3c61
			g_test_skip ("php-xmlrpc is not available");	\
rpm-build 4f3c61
			return;						\
rpm-build 4f3c61
		}							\
rpm-build 4f3c61
	} G_STMT_END
rpm-build 4f3c61
#endif
rpm-build 4f3c61
rpm-build 4f3c61
static gboolean
rpm-build 4f3c61
send_xmlrpc (const char *body, GValue *retval)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupMessage *msg;
rpm-build 4f3c61
	GError *err = NULL;
rpm-build 4f3c61
rpm-build 4f3c61
	msg = soup_message_new ("POST", uri);
rpm-build 4f3c61
	soup_message_set_request (msg, "text/xml", SOUP_MEMORY_COPY,
rpm-build 4f3c61
				  body, strlen (body));
rpm-build 4f3c61
	soup_session_send_message (session, msg);
rpm-build 4f3c61
rpm-build 4f3c61
	soup_test_assert_message_status (msg, SOUP_STATUS_OK);
rpm-build 4f3c61
rpm-build 4f3c61
	if (!soup_xmlrpc_parse_method_response (msg->response_body->data,
rpm-build 4f3c61
						msg->response_body->length,
rpm-build 4f3c61
						retval, &err)) {
rpm-build 4f3c61
		if (err) {
rpm-build 4f3c61
			soup_test_assert (FALSE, "FAULT: %d %s\n", err->code, err->message);
rpm-build 4f3c61
			g_error_free (err);
rpm-build 4f3c61
		} else
rpm-build 4f3c61
			soup_test_assert (FALSE, "ERROR: could not parse response\n");
rpm-build 4f3c61
		g_object_unref (msg);
rpm-build 4f3c61
		return FALSE;
rpm-build 4f3c61
	}
rpm-build 4f3c61
	g_object_unref (msg);
rpm-build 4f3c61
rpm-build 4f3c61
	return TRUE;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static gboolean
rpm-build 4f3c61
do_xmlrpc (const char *method, GValue *retval, ...)
rpm-build 4f3c61
{
rpm-build 4f3c61
	va_list args;
rpm-build 4f3c61
	GValueArray *params;
rpm-build 4f3c61
	char *body;
rpm-build 4f3c61
	gboolean ret;
rpm-build 4f3c61
rpm-build 4f3c61
	va_start (args, retval);
rpm-build 4f3c61
	params = soup_value_array_from_args (args);
rpm-build 4f3c61
	va_end (args);
rpm-build 4f3c61
rpm-build 4f3c61
	body = soup_xmlrpc_build_method_call (method, params->values,
rpm-build 4f3c61
					      params->n_values);
rpm-build 4f3c61
	g_value_array_free (params);
rpm-build 4f3c61
	if (!body)
rpm-build 4f3c61
		return FALSE;
rpm-build 4f3c61
rpm-build 4f3c61
	ret = send_xmlrpc (body, retval);
rpm-build 4f3c61
	g_free (body);
rpm-build 4f3c61
rpm-build 4f3c61
	return ret;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static gboolean
rpm-build 4f3c61
check_xmlrpc (GValue *value, GType type, ...)
rpm-build 4f3c61
{
rpm-build 4f3c61
	va_list args;
rpm-build 4f3c61
rpm-build 4f3c61
	if (!G_VALUE_HOLDS (value, type)) {
rpm-build 4f3c61
		g_assert_true (G_VALUE_HOLDS (value, type));
rpm-build 4f3c61
		return FALSE;
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	va_start (args, type);
rpm-build 4f3c61
	SOUP_VALUE_GETV (value, type, args);
rpm-build 4f3c61
	va_end (args);
rpm-build 4f3c61
	return TRUE;
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
test_sum (void)
rpm-build 4f3c61
{
rpm-build 4f3c61
	GValueArray *dbls;
rpm-build 4f3c61
	int i;
rpm-build 4f3c61
	double val, sum, result;
rpm-build 4f3c61
	GValue retval;
rpm-build 4f3c61
	gboolean ok;
rpm-build 4f3c61
rpm-build 4f3c61
	SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER;
rpm-build 4f3c61
rpm-build 4f3c61
	debug_printf (2, "sum (array of double -> double): ");
rpm-build 4f3c61
rpm-build 4f3c61
	dbls = g_value_array_new (10);
rpm-build 4f3c61
	for (i = sum = 0; i < 10; i++) {
rpm-build 4f3c61
		val = g_random_int_range (0, 400) / 4.0;
rpm-build 4f3c61
		debug_printf (2, "%s%.2f", i == 0 ? "[" : ", ", val);
rpm-build 4f3c61
		soup_value_array_append (dbls, G_TYPE_DOUBLE, val);
rpm-build 4f3c61
		sum += val;
rpm-build 4f3c61
	}
rpm-build 4f3c61
	debug_printf (2, "] -> ");
rpm-build 4f3c61
rpm-build 4f3c61
	ok = (do_xmlrpc ("sum", &retval,
rpm-build 4f3c61
			G_TYPE_VALUE_ARRAY, dbls,
rpm-build 4f3c61
			G_TYPE_INVALID) &&
rpm-build 4f3c61
	      check_xmlrpc (&retval, G_TYPE_DOUBLE, &result));
rpm-build 4f3c61
	g_value_array_free (dbls);
rpm-build 4f3c61
rpm-build 4f3c61
	if (!ok)
rpm-build 4f3c61
		return;
rpm-build 4f3c61
rpm-build 4f3c61
	debug_printf (2, "%.2f\n", result);
rpm-build 4f3c61
	g_assert_cmpfloat (result, ==, sum);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
test_countBools (void)
rpm-build 4f3c61
{
rpm-build 4f3c61
	GValueArray *bools;
rpm-build 4f3c61
	int i, trues, falses;
rpm-build 4f3c61
	GValue retval;
rpm-build 4f3c61
	int ret_trues, ret_falses;
rpm-build 4f3c61
	gboolean val, ok;
rpm-build 4f3c61
	GHashTable *result;
rpm-build 4f3c61
rpm-build 4f3c61
	SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER;
rpm-build 4f3c61
rpm-build 4f3c61
	debug_printf (2, "countBools (array of boolean -> struct of ints): ");
rpm-build 4f3c61
rpm-build 4f3c61
	bools = g_value_array_new (10);
rpm-build 4f3c61
	for (i = trues = falses = 0; i < 10; i++) {
rpm-build 4f3c61
		val = g_random_boolean ();
rpm-build 4f3c61
		debug_printf (2, "%s%c", i == 0 ? "[" : ", ", val ? 'T' : 'F');
rpm-build 4f3c61
		soup_value_array_append (bools, G_TYPE_BOOLEAN, val);
rpm-build 4f3c61
		if (val)
rpm-build 4f3c61
			trues++;
rpm-build 4f3c61
		else
rpm-build 4f3c61
			falses++;
rpm-build 4f3c61
	}
rpm-build 4f3c61
	debug_printf (2, "] -> ");
rpm-build 4f3c61
rpm-build 4f3c61
	ok = (do_xmlrpc ("countBools", &retval,
rpm-build 4f3c61
			 G_TYPE_VALUE_ARRAY, bools,
rpm-build 4f3c61
			 G_TYPE_INVALID) &&
rpm-build 4f3c61
	      check_xmlrpc (&retval, G_TYPE_HASH_TABLE, &result));
rpm-build 4f3c61
	g_value_array_free (bools);
rpm-build 4f3c61
	if (!ok)
rpm-build 4f3c61
		return;
rpm-build 4f3c61
rpm-build 4f3c61
	g_assert_true (soup_value_hash_lookup (result, "true", G_TYPE_INT, &ret_trues));
rpm-build 4f3c61
	g_assert_true (soup_value_hash_lookup (result, "false", G_TYPE_INT, &ret_falses));
rpm-build 4f3c61
rpm-build 4f3c61
	g_hash_table_destroy (result);
rpm-build 4f3c61
rpm-build 4f3c61
	debug_printf (2, "{ true: %d, false: %d }\n", ret_trues, ret_falses);
rpm-build 4f3c61
	g_assert_cmpint (trues, ==, ret_trues);
rpm-build 4f3c61
	g_assert_cmpint (falses, ==, ret_falses);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
test_md5sum (void)
rpm-build 4f3c61
{
rpm-build 4f3c61
	GByteArray *data, *result;
rpm-build 4f3c61
	int i;
rpm-build 4f3c61
	GChecksum *checksum;
rpm-build 4f3c61
	guchar digest[16];
rpm-build 4f3c61
	gsize digest_len = sizeof (digest);
rpm-build 4f3c61
	GValue retval;
rpm-build 4f3c61
	gboolean ok;
rpm-build 4f3c61
rpm-build 4f3c61
	SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER;
rpm-build 4f3c61
rpm-build 4f3c61
	debug_printf (2, "md5sum (base64 -> base64)\n");
rpm-build 4f3c61
rpm-build 4f3c61
	data = g_byte_array_new ();
rpm-build 4f3c61
	g_byte_array_set_size (data, 256);
rpm-build 4f3c61
	for (i = 0; i < data->len; i++)
rpm-build 4f3c61
		data->data[i] = (char)(g_random_int_range (0, 256));
rpm-build 4f3c61
rpm-build 4f3c61
	checksum = g_checksum_new (G_CHECKSUM_MD5);
rpm-build 4f3c61
	g_checksum_update (checksum, data->data, data->len);
rpm-build 4f3c61
	g_checksum_get_digest (checksum, digest, &digest_len);
rpm-build 4f3c61
	g_checksum_free (checksum);
rpm-build 4f3c61
rpm-build 4f3c61
	ok = (do_xmlrpc ("md5sum", &retval,
rpm-build 4f3c61
			 SOUP_TYPE_BYTE_ARRAY, data,
rpm-build 4f3c61
			 G_TYPE_INVALID) &&
rpm-build 4f3c61
	      check_xmlrpc (&retval, SOUP_TYPE_BYTE_ARRAY, &result));
rpm-build 4f3c61
	g_byte_array_free (data, TRUE);
rpm-build 4f3c61
	if (!ok)
rpm-build 4f3c61
		return;
rpm-build 4f3c61
rpm-build 4f3c61
	soup_assert_cmpmem (result->data, result->len,
rpm-build 4f3c61
			    digest, digest_len);
rpm-build 4f3c61
	g_byte_array_free (result, TRUE);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
test_dateChange (void)
rpm-build 4f3c61
{
rpm-build 4f3c61
	GHashTable *structval;
rpm-build 4f3c61
	SoupDate *date, *result;
rpm-build 4f3c61
	char *timestamp;
rpm-build 4f3c61
	GValue retval;
rpm-build 4f3c61
	gboolean ok;
rpm-build 4f3c61
rpm-build 4f3c61
	SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER;
rpm-build 4f3c61
rpm-build 4f3c61
	debug_printf (2, "dateChange (date, struct of ints -> time)\n");
rpm-build 4f3c61
rpm-build 4f3c61
	date = soup_date_new (1970 + (g_random_int_range (0, 50)),
rpm-build 4f3c61
			      1 + g_random_int_range (0, 12),
rpm-build 4f3c61
			      1 + g_random_int_range (0, 28),
rpm-build 4f3c61
			      g_random_int_range (0, 24),
rpm-build 4f3c61
			      g_random_int_range (0, 60),
rpm-build 4f3c61
			      g_random_int_range (0, 60));
rpm-build 4f3c61
	if (debug_level >= 2) {
rpm-build 4f3c61
		timestamp = soup_date_to_string (date, SOUP_DATE_ISO8601_XMLRPC);
rpm-build 4f3c61
		debug_printf (2, "date: %s, {", timestamp);
rpm-build 4f3c61
		g_free (timestamp);
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	structval = soup_value_hash_new ();
rpm-build 4f3c61
rpm-build 4f3c61
#define MAYBE (g_random_int_range (0, 3) != 0)
rpm-build 4f3c61
rpm-build 4f3c61
	if (MAYBE) {
rpm-build 4f3c61
		date->year = 1970 + (g_random_int_range (0, 50));
rpm-build 4f3c61
		debug_printf (2, "tm_year: %d, ", date->year - 1900);
rpm-build 4f3c61
		soup_value_hash_insert (structval, "tm_year",
rpm-build 4f3c61
					G_TYPE_INT, date->year - 1900);
rpm-build 4f3c61
	}
rpm-build 4f3c61
	if (MAYBE) {
rpm-build 4f3c61
		date->month = 1 + g_random_int_range (0, 12);
rpm-build 4f3c61
		debug_printf (2, "tm_mon: %d, ", date->month - 1);
rpm-build 4f3c61
		soup_value_hash_insert (structval, "tm_mon",
rpm-build 4f3c61
					G_TYPE_INT, date->month - 1);
rpm-build 4f3c61
	}
rpm-build 4f3c61
	if (MAYBE) {
rpm-build 4f3c61
		date->day = 1 + g_random_int_range (0, 28);
rpm-build 4f3c61
		debug_printf (2, "tm_mday: %d, ", date->day);
rpm-build 4f3c61
		soup_value_hash_insert (structval, "tm_mday",
rpm-build 4f3c61
					G_TYPE_INT, date->day);
rpm-build 4f3c61
	}
rpm-build 4f3c61
	if (MAYBE) {
rpm-build 4f3c61
		date->hour = g_random_int_range (0, 24);
rpm-build 4f3c61
		debug_printf (2, "tm_hour: %d, ", date->hour);
rpm-build 4f3c61
		soup_value_hash_insert (structval, "tm_hour",
rpm-build 4f3c61
					G_TYPE_INT, date->hour);
rpm-build 4f3c61
	}
rpm-build 4f3c61
	if (MAYBE) {
rpm-build 4f3c61
		date->minute = g_random_int_range (0, 60);
rpm-build 4f3c61
		debug_printf (2, "tm_min: %d, ", date->minute);
rpm-build 4f3c61
		soup_value_hash_insert (structval, "tm_min",
rpm-build 4f3c61
					G_TYPE_INT, date->minute);
rpm-build 4f3c61
	}
rpm-build 4f3c61
	if (MAYBE) {
rpm-build 4f3c61
		date->second = g_random_int_range (0, 60);
rpm-build 4f3c61
		debug_printf (2, "tm_sec: %d, ", date->second);
rpm-build 4f3c61
		soup_value_hash_insert (structval, "tm_sec",
rpm-build 4f3c61
					G_TYPE_INT, date->second);
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	debug_printf (2, "} -> ");
rpm-build 4f3c61
rpm-build 4f3c61
	ok = (do_xmlrpc ("dateChange", &retval,
rpm-build 4f3c61
			 SOUP_TYPE_DATE, date,
rpm-build 4f3c61
			 G_TYPE_HASH_TABLE, structval,
rpm-build 4f3c61
			 G_TYPE_INVALID) &&
rpm-build 4f3c61
	      check_xmlrpc (&retval, SOUP_TYPE_DATE, &result));
rpm-build 4f3c61
	g_hash_table_destroy (structval);
rpm-build 4f3c61
	if (!ok) {
rpm-build 4f3c61
		soup_date_free (date);
rpm-build 4f3c61
		return;
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	if (debug_level >= 2) {
rpm-build 4f3c61
		timestamp = soup_date_to_string (result, SOUP_DATE_ISO8601_XMLRPC);
rpm-build 4f3c61
		debug_printf (2, "%s\n", timestamp);
rpm-build 4f3c61
		g_free (timestamp);
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	g_assert_cmpint (date->year,   ==, result->year);
rpm-build 4f3c61
	g_assert_cmpint (date->month,  ==, result->month);
rpm-build 4f3c61
	g_assert_cmpint (date->day,    ==, result->day);
rpm-build 4f3c61
	g_assert_cmpint (date->hour,   ==, result->hour);
rpm-build 4f3c61
	g_assert_cmpint (date->minute, ==, result->minute);
rpm-build 4f3c61
	g_assert_cmpint (date->second, ==, result->second);
rpm-build 4f3c61
rpm-build 4f3c61
	soup_date_free (date);
rpm-build 4f3c61
	soup_date_free (result);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static const char *const echo_strings[] = {
rpm-build 4f3c61
	"This is a test",
rpm-build 4f3c61
	"& so is this",
rpm-build 4f3c61
	"and so is <this>",
rpm-build 4f3c61
	"& so is <this>"
rpm-build 4f3c61
};
rpm-build 4f3c61
#define N_ECHO_STRINGS G_N_ELEMENTS (echo_strings)
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
test_echo (void)
rpm-build 4f3c61
{
rpm-build 4f3c61
	GValueArray *originals, *echoes;
rpm-build 4f3c61
	GValue retval;
rpm-build 4f3c61
	int i;
rpm-build 4f3c61
rpm-build 4f3c61
	SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER;
rpm-build 4f3c61
rpm-build 4f3c61
	debug_printf (2, "echo (array of string -> array of string):\n");
rpm-build 4f3c61
rpm-build 4f3c61
	originals = g_value_array_new (N_ECHO_STRINGS);
rpm-build 4f3c61
	for (i = 0; i < N_ECHO_STRINGS; i++) {
rpm-build 4f3c61
		soup_value_array_append (originals, G_TYPE_STRING, echo_strings[i]);
rpm-build 4f3c61
		debug_printf (2, "%s\"%s\"", i == 0 ? "[" : ", ", echo_strings[i]);
rpm-build 4f3c61
	}
rpm-build 4f3c61
	debug_printf (2, "] -> ");
rpm-build 4f3c61
rpm-build 4f3c61
	if (!(do_xmlrpc ("echo", &retval,
rpm-build 4f3c61
			 G_TYPE_VALUE_ARRAY, originals,
rpm-build 4f3c61
			 G_TYPE_INVALID) &&
rpm-build 4f3c61
	      check_xmlrpc (&retval, G_TYPE_VALUE_ARRAY, &echoes))) {
rpm-build 4f3c61
		g_value_array_free (originals);
rpm-build 4f3c61
		return;
rpm-build 4f3c61
	}
rpm-build 4f3c61
	g_value_array_free (originals);
rpm-build 4f3c61
rpm-build 4f3c61
	if (debug_level >= 2) {
rpm-build 4f3c61
		for (i = 0; i < echoes->n_values; i++) {
rpm-build 4f3c61
			debug_printf (2, "%s\"%s\"", i == 0 ? "[" : ", ",
rpm-build 4f3c61
				      g_value_get_string (&echoes->values[i]));
rpm-build 4f3c61
		}
rpm-build 4f3c61
		debug_printf (2, "]\n");
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	g_assert_cmpint (echoes->n_values, ==, N_ECHO_STRINGS);
rpm-build 4f3c61
rpm-build 4f3c61
	for (i = 0; i < echoes->n_values; i++)
rpm-build 4f3c61
		g_assert_cmpstr (echo_strings[i], ==, g_value_get_string (&echoes->values[i]));
rpm-build 4f3c61
rpm-build 4f3c61
	g_value_array_free (echoes);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
test_ping (gconstpointer include_params)
rpm-build 4f3c61
{
rpm-build 4f3c61
	GValueArray *params;
rpm-build 4f3c61
	GValue retval;
rpm-build 4f3c61
	char *request;
rpm-build 4f3c61
	char *out;
rpm-build 4f3c61
	gboolean ret;
rpm-build 4f3c61
rpm-build 4f3c61
	g_test_bug ("671661");
rpm-build 4f3c61
rpm-build 4f3c61
	SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER;
rpm-build 4f3c61
rpm-build 4f3c61
	debug_printf (2, "ping (void (%s) -> string)\n",
rpm-build 4f3c61
		      include_params ? "empty <params>" : "no <params>");
rpm-build 4f3c61
rpm-build 4f3c61
	params = soup_value_array_new ();
rpm-build 4f3c61
	request = soup_xmlrpc_build_method_call ("ping", params->values,
rpm-build 4f3c61
						 params->n_values);
rpm-build 4f3c61
	g_value_array_free (params);
rpm-build 4f3c61
	if (!request)
rpm-build 4f3c61
		return;
rpm-build 4f3c61
rpm-build 4f3c61
	if (!include_params) {
rpm-build 4f3c61
		char *params, *end;
rpm-build 4f3c61
rpm-build 4f3c61
		params = strstr (request, "<params/>");
rpm-build 4f3c61
		if (!params) {
rpm-build 4f3c61
			soup_test_assert (FALSE, "ERROR: XML did not contain <params/>!");
rpm-build 4f3c61
			return;
rpm-build 4f3c61
		}
rpm-build 4f3c61
		end = params + strlen ("<params/>");
rpm-build 4f3c61
		memmove (params, end, strlen (end) + 1);
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	ret = send_xmlrpc (request, &retval);
rpm-build 4f3c61
	g_free (request);
rpm-build 4f3c61
rpm-build 4f3c61
	if (!ret || !check_xmlrpc (&retval, G_TYPE_STRING, &out))
rpm-build 4f3c61
		return;
rpm-build 4f3c61
rpm-build 4f3c61
	g_assert_cmpstr (out, ==, "pong");
rpm-build 4f3c61
rpm-build 4f3c61
	g_free (out);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
do_bad_xmlrpc (const char *body)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SoupMessage *msg;
rpm-build 4f3c61
	GError *err = NULL;
rpm-build 4f3c61
	GValue retval;
rpm-build 4f3c61
rpm-build 4f3c61
	msg = soup_message_new ("POST", uri);
rpm-build 4f3c61
	soup_message_set_request (msg, "text/xml", SOUP_MEMORY_COPY,
rpm-build 4f3c61
				  body, strlen (body));
rpm-build 4f3c61
	soup_session_send_message (session, msg);
rpm-build 4f3c61
rpm-build 4f3c61
	soup_test_assert_message_status (msg, SOUP_STATUS_OK);
rpm-build 4f3c61
rpm-build 4f3c61
	if (!soup_xmlrpc_parse_method_response (msg->response_body->data,
rpm-build 4f3c61
						msg->response_body->length,
rpm-build 4f3c61
						&retval, &err)) {
rpm-build 4f3c61
		if (err) {
rpm-build 4f3c61
			debug_printf (1, "FAULT: %d %s (OK!)\n",
rpm-build 4f3c61
				      err->code, err->message);
rpm-build 4f3c61
			g_error_free (err);
rpm-build 4f3c61
			g_object_unref (msg);
rpm-build 4f3c61
			return;
rpm-build 4f3c61
		} else
rpm-build 4f3c61
			soup_test_assert (FALSE, "ERROR: could not parse response\n");
rpm-build 4f3c61
	} else
rpm-build 4f3c61
		soup_test_assert (FALSE, "Unexpectedly got successful response!\n");
rpm-build 4f3c61
rpm-build 4f3c61
	g_object_unref (msg);
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
test_fault_malformed (void)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER;
rpm-build 4f3c61
rpm-build 4f3c61
	do_bad_xmlrpc ("<methodCall/>");
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
test_fault_method (void)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER;
rpm-build 4f3c61
rpm-build 4f3c61
	do_bad_xmlrpc ("<methodCall><methodName>no_such_method</methodName><params><param><value><int>1</int></value></param></params></methodCall>");
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static void
rpm-build 4f3c61
test_fault_args (void)
rpm-build 4f3c61
{
rpm-build 4f3c61
	SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER;
rpm-build 4f3c61
rpm-build 4f3c61
	do_bad_xmlrpc ("<methodCall><methodName>sum</methodName><params><param><value><int>1</int></value></param></params></methodCall>");
rpm-build 4f3c61
}
rpm-build 4f3c61
rpm-build 4f3c61
static GOptionEntry xmlrpc_entries[] = {
rpm-build 4f3c61
        { "uri", 'U', 0, G_OPTION_ARG_STRING, &uri,
rpm-build 4f3c61
          "Alternate URI for server", NULL },
rpm-build 4f3c61
        { "server-test", 'S', 0, G_OPTION_ARG_NONE, &server_test,
rpm-build 4f3c61
          "If this is being run from xmlrpc-old-server-test", NULL },
rpm-build 4f3c61
        { NULL }
rpm-build 4f3c61
};
rpm-build 4f3c61
rpm-build 4f3c61
int
rpm-build 4f3c61
main (int argc, char **argv)
rpm-build 4f3c61
{
rpm-build 4f3c61
	int ret;
rpm-build 4f3c61
rpm-build 4f3c61
	test_init (argc, argv, xmlrpc_entries);
rpm-build 4f3c61
rpm-build 4f3c61
	if (!uri && !server_test) {
rpm-build 4f3c61
		apache_init ();
rpm-build 4f3c61
		uri = default_uri;
rpm-build 4f3c61
	}
rpm-build 4f3c61
rpm-build 4f3c61
	session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
rpm-build 4f3c61
rpm-build 4f3c61
	g_test_add_func ("/xmlrpc-old/sum", test_sum);
rpm-build 4f3c61
	g_test_add_func ("/xmlrpc-old/countBools", test_countBools);
rpm-build 4f3c61
	g_test_add_func ("/xmlrpc-old/md5sum", test_md5sum);
rpm-build 4f3c61
	g_test_add_func ("/xmlrpc-old/dateChange", test_dateChange);
rpm-build 4f3c61
	g_test_add_func ("/xmlrpc-old/echo", test_echo);
rpm-build 4f3c61
	g_test_add_data_func ("/xmlrpc-old/ping/empty-params", GINT_TO_POINTER (TRUE), test_ping);
rpm-build 4f3c61
	g_test_add_data_func ("/xmlrpc-old/ping/no-params", GINT_TO_POINTER (FALSE), test_ping);
rpm-build 4f3c61
	g_test_add_func ("/xmlrpc-old/fault/malformed", test_fault_malformed);
rpm-build 4f3c61
	g_test_add_func ("/xmlrpc-old/fault/method", test_fault_method);
rpm-build 4f3c61
	g_test_add_func ("/xmlrpc-old/fault/args", test_fault_args);
rpm-build 4f3c61
rpm-build 4f3c61
	ret = g_test_run ();
rpm-build 4f3c61
rpm-build 4f3c61
	soup_test_session_abort_unref (session);
rpm-build 4f3c61
rpm-build 4f3c61
	test_cleanup ();
rpm-build 4f3c61
	return ret;
rpm-build 4f3c61
}