diff options
author | Seonah Moon <seonah1.moon@samsung.com> | 2019-12-09 14:52:00 +0900 |
---|---|---|
committer | Seonah Moon <seonah1.moon@samsung.com> | 2019-12-09 14:52:24 +0900 |
commit | 58894334cd3f0b89c865304e8e9d6eea3cd20a55 (patch) | |
tree | 6fdb22df40c774e8db791bc7cd27b39680a12fb0 /tests/xmlrpc-test.c | |
parent | 9f52ffa8b526e717e324fe0835ab794478650f11 (diff) | |
download | libsoup-58894334cd3f0b89c865304e8e9d6eea3cd20a55.tar.gz libsoup-58894334cd3f0b89c865304e8e9d6eea3cd20a55.tar.bz2 libsoup-58894334cd3f0b89c865304e8e9d6eea3cd20a55.zip |
Imported Upstream version 2.62.2upstream/2.62.2
Change-Id: Id151dafaa6ac9f569d76f08282b5c9e4c3b19621
Diffstat (limited to 'tests/xmlrpc-test.c')
-rw-r--r-- | tests/xmlrpc-test.c | 583 |
1 files changed, 397 insertions, 186 deletions
diff --git a/tests/xmlrpc-test.c b/tests/xmlrpc-test.c index f6b20b8f..58d96abc 100644 --- a/tests/xmlrpc-test.c +++ b/tests/xmlrpc-test.c @@ -1,14 +1,11 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2001-2003, Ximian, Inc. + * Copyright 2001-2003, Ximian, Inc. + * Copyright 2015, Collabora ltd. */ #include "test-utils.h" -#ifdef G_GNUC_BEGIN_IGNORE_DEPRECATIONS -G_GNUC_BEGIN_IGNORE_DEPRECATIONS -#endif - static SoupSession *session; static const char *default_uri = "http://127.0.0.1:47524/xmlrpc-server.php"; static const char *uri = NULL; @@ -26,20 +23,8 @@ static gboolean server_test = FALSE; } G_STMT_END #endif -static const char *const value_type[] = { - "BAD", - "int", - "boolean", - "string", - "double", - "datetime", - "base64", - "struct", - "array" -}; - static gboolean -send_xmlrpc (const char *body, GValue *retval) +send_xmlrpc (const char *body, const char *signature, GVariant **retval) { SoupMessage *msg; GError *err = NULL; @@ -51,115 +36,94 @@ send_xmlrpc (const char *body, GValue *retval) soup_test_assert_message_status (msg, SOUP_STATUS_OK); - if (!soup_xmlrpc_parse_method_response (msg->response_body->data, - msg->response_body->length, - retval, &err)) { - if (err) { + *retval = soup_xmlrpc_parse_response (msg->response_body->data, + msg->response_body->length, + signature, &err); + if (!*retval) { + if (err->domain == SOUP_XMLRPC_FAULT) soup_test_assert (FALSE, "FAULT: %d %s\n", err->code, err->message); - g_error_free (err); - } else - soup_test_assert (FALSE, "ERROR: could not parse response\n"); + else + soup_test_assert (FALSE, "ERROR: %s\n", err->message); + g_error_free (err); g_object_unref (msg); return FALSE; } - g_object_unref (msg); return TRUE; } static gboolean -do_xmlrpc (const char *method, GValue *retval, ...) +do_xmlrpc (const char *method, GVariant *args, const char *signature, GVariant **retval) { - va_list args; - GValueArray *params; - char *body; gboolean ret; + char *body; + GError *error = NULL; - va_start (args, retval); - params = soup_value_array_from_args (args); - va_end (args); - - body = soup_xmlrpc_build_method_call (method, params->values, - params->n_values); - g_value_array_free (params); + body = soup_xmlrpc_build_request (method, args, &error); + g_assert_no_error (error); if (!body) return FALSE; - ret = send_xmlrpc (body, retval); + ret = send_xmlrpc (body, signature, retval); g_free (body); return ret; } -static gboolean -check_xmlrpc (GValue *value, GType type, ...) -{ - va_list args; - - if (!G_VALUE_HOLDS (value, type)) { - g_assert_true (G_VALUE_HOLDS (value, type)); - return FALSE; - } - - va_start (args, type); - SOUP_VALUE_GETV (value, type, args); - va_end (args); - return TRUE; -} - static void test_sum (void) { - GValueArray *ints; - int i, val, sum, result; - GValue retval; + GVariantBuilder builder; + int i; + double val, sum, result; + GVariant *retval; gboolean ok; SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER; - debug_printf (2, "sum (array of int -> int): "); + debug_printf (2, "sum (array of double -> double): "); - ints = g_value_array_new (10); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("ad")); for (i = sum = 0; i < 10; i++) { - val = g_random_int_range (0, 100); - debug_printf (2, "%s%d", i == 0 ? "[" : ", ", val); - soup_value_array_append (ints, G_TYPE_INT, val); + val = g_random_int_range (0, 400) / 4.0; + debug_printf (2, "%s%.2f", i == 0 ? "[" : ", ", val); + g_variant_builder_add (&builder, "d", val); sum += val; } debug_printf (2, "] -> "); - ok = (do_xmlrpc ("sum", &retval, - G_TYPE_VALUE_ARRAY, ints, - G_TYPE_INVALID) && - check_xmlrpc (&retval, G_TYPE_INT, &result)); - g_value_array_free (ints); + ok = do_xmlrpc ("sum", + g_variant_new ("(@ad)", g_variant_builder_end (&builder)), + "d", &retval); if (!ok) return; - debug_printf (2, "%d\n", result); - g_assert_cmpint (result, ==, sum); + result = g_variant_get_double (retval); + debug_printf (2, "%.2f\n", result); + g_assert_cmpfloat (result, ==, sum); + + g_variant_unref (retval); } static void test_countBools (void) { - GValueArray *bools; + GVariantBuilder builder; int i, trues, falses; - GValue retval; + GVariant *retval; int ret_trues, ret_falses; gboolean val, ok; - GHashTable *result; SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER; debug_printf (2, "countBools (array of boolean -> struct of ints): "); - bools = g_value_array_new (10); + g_variant_builder_init (&builder, G_VARIANT_TYPE ("ab")); for (i = trues = falses = 0; i < 10; i++) { val = g_random_boolean (); debug_printf (2, "%s%c", i == 0 ? "[" : ", ", val ? 'T' : 'F'); - soup_value_array_append (bools, G_TYPE_BOOLEAN, val); + g_variant_builder_add (&builder, "b", val); if (val) trues++; else @@ -167,18 +131,16 @@ test_countBools (void) } debug_printf (2, "] -> "); - ok = (do_xmlrpc ("countBools", &retval, - G_TYPE_VALUE_ARRAY, bools, - G_TYPE_INVALID) && - check_xmlrpc (&retval, G_TYPE_HASH_TABLE, &result)); - g_value_array_free (bools); + ok = do_xmlrpc ("countBools", + g_variant_new ("(@ab)", g_variant_builder_end (&builder)), + "a{si}", &retval); if (!ok) return; - g_assert_true (soup_value_hash_lookup (result, "true", G_TYPE_INT, &ret_trues)); - g_assert_true (soup_value_hash_lookup (result, "false", G_TYPE_INT, &ret_falses)); - - g_hash_table_destroy (result); + g_assert_true (g_variant_lookup (retval, "true", "i", &ret_trues)); + g_assert_true (g_variant_lookup (retval, "false", "i", &ret_falses)); + g_assert_cmpint (g_variant_n_children (retval), ==, 2); + g_variant_unref (retval); debug_printf (2, "{ true: %d, false: %d }\n", ret_trues, ret_falses); g_assert_cmpint (trues, ==, ret_trues); @@ -188,12 +150,12 @@ test_countBools (void) static void test_md5sum (void) { - GByteArray *data, *result; + GByteArray *data; int i; GChecksum *checksum; guchar digest[16]; gsize digest_len = sizeof (digest); - GValue retval; + GVariant *retval; gboolean ok; SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER; @@ -210,27 +172,30 @@ test_md5sum (void) g_checksum_get_digest (checksum, digest, &digest_len); g_checksum_free (checksum); - ok = (do_xmlrpc ("md5sum", &retval, - SOUP_TYPE_BYTE_ARRAY, data, - G_TYPE_INVALID) && - check_xmlrpc (&retval, SOUP_TYPE_BYTE_ARRAY, &result)); + ok = do_xmlrpc ("md5sum", + g_variant_new ("(@ay)", + g_variant_new_from_data (G_VARIANT_TYPE_BYTESTRING, + data->data, data->len, + TRUE, NULL, NULL)), + "ay", &retval); g_byte_array_free (data, TRUE); if (!ok) return; - soup_assert_cmpmem (result->data, result->len, + soup_assert_cmpmem (g_variant_get_data (retval), g_variant_get_size (retval), digest, digest_len); - g_byte_array_free (result, TRUE); + g_variant_unref (retval); } static void test_dateChange (void) { - GHashTable *structval; + GVariantDict structval; SoupDate *date, *result; char *timestamp; - GValue retval; + GVariant *retval; gboolean ok; + GError *error = NULL; SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER; @@ -243,65 +208,69 @@ test_dateChange (void) g_random_int_range (0, 60), g_random_int_range (0, 60)); if (debug_level >= 2) { - timestamp = soup_date_to_string (date, SOUP_DATE_ISO8601_XMLRPC); - debug_printf (2, "date: %s, {", timestamp); - g_free (timestamp); + char *tmp; + + tmp = soup_date_to_string (date, SOUP_DATE_ISO8601_XMLRPC); + debug_printf (2, "date: %s, {", tmp); + g_free (tmp); } - structval = soup_value_hash_new (); + g_variant_dict_init (&structval, NULL); #define MAYBE (g_random_int_range (0, 3) != 0) if (MAYBE) { date->year = 1970 + (g_random_int_range (0, 50)); debug_printf (2, "tm_year: %d, ", date->year - 1900); - soup_value_hash_insert (structval, "tm_year", - G_TYPE_INT, date->year - 1900); + g_variant_dict_insert (&structval, "tm_year", + "i", date->year - 1900); } if (MAYBE) { date->month = 1 + g_random_int_range (0, 12); debug_printf (2, "tm_mon: %d, ", date->month - 1); - soup_value_hash_insert (structval, "tm_mon", - G_TYPE_INT, date->month - 1); + g_variant_dict_insert (&structval, "tm_mon", + "i", date->month - 1); } if (MAYBE) { date->day = 1 + g_random_int_range (0, 28); debug_printf (2, "tm_mday: %d, ", date->day); - soup_value_hash_insert (structval, "tm_mday", - G_TYPE_INT, date->day); + g_variant_dict_insert (&structval, "tm_mday", + "i", date->day); } if (MAYBE) { date->hour = g_random_int_range (0, 24); debug_printf (2, "tm_hour: %d, ", date->hour); - soup_value_hash_insert (structval, "tm_hour", - G_TYPE_INT, date->hour); + g_variant_dict_insert (&structval, "tm_hour", + "i", date->hour); } if (MAYBE) { date->minute = g_random_int_range (0, 60); debug_printf (2, "tm_min: %d, ", date->minute); - soup_value_hash_insert (structval, "tm_min", - G_TYPE_INT, date->minute); + g_variant_dict_insert (&structval, "tm_min", + "i", date->minute); } if (MAYBE) { date->second = g_random_int_range (0, 60); debug_printf (2, "tm_sec: %d, ", date->second); - soup_value_hash_insert (structval, "tm_sec", - G_TYPE_INT, date->second); + g_variant_dict_insert (&structval, "tm_sec", + "i", date->second); } debug_printf (2, "} -> "); - ok = (do_xmlrpc ("dateChange", &retval, - SOUP_TYPE_DATE, date, - G_TYPE_HASH_TABLE, structval, - G_TYPE_INVALID) && - check_xmlrpc (&retval, SOUP_TYPE_DATE, &result)); - g_hash_table_destroy (structval); + ok = do_xmlrpc ("dateChange", + g_variant_new ("(vv)", + soup_xmlrpc_variant_new_datetime (date), + g_variant_dict_end (&structval)), + NULL, &retval); if (!ok) { soup_date_free (date); return; } + result = soup_xmlrpc_variant_get_datetime (retval, &error); + g_assert_no_error (error); + if (debug_level >= 2) { timestamp = soup_date_to_string (result, SOUP_DATE_ISO8601_XMLRPC); debug_printf (2, "%s\n", timestamp); @@ -317,81 +286,58 @@ test_dateChange (void) soup_date_free (date); soup_date_free (result); + g_variant_unref (retval); } static const char *const echo_strings[] = { "This is a test", "& so is this", "and so is <this>", - "& so is <this>" -}; -#define N_ECHO_STRINGS G_N_ELEMENTS (echo_strings) - -static const char *const echo_strings_broken[] = { - "This is a test", - " so is this", - "and so is this", - "amp; so is lt;thisgt;" + "& so is <this>", + NULL }; static void test_echo (void) { - GValueArray *originals, *echoes; - GValue retval; - int i; + GVariant *originals; + GVariant *retval; + char *str; SOUP_TEST_SKIP_IF_NO_XMLRPC_SERVER; debug_printf (2, "echo (array of string -> array of string):\n"); - originals = g_value_array_new (N_ECHO_STRINGS); - for (i = 0; i < N_ECHO_STRINGS; i++) { - soup_value_array_append (originals, G_TYPE_STRING, echo_strings[i]); - debug_printf (2, "%s\"%s\"", i == 0 ? "[" : ", ", echo_strings[i]); - } - debug_printf (2, "] -> "); + originals = g_variant_new ("^as", echo_strings); + g_variant_ref_sink (originals); + str = g_variant_print (originals, TRUE); + debug_printf (2, "%s -> ", str); + g_free (str); - if (!(do_xmlrpc ("echo", &retval, - G_TYPE_VALUE_ARRAY, originals, - G_TYPE_INVALID) && - check_xmlrpc (&retval, G_TYPE_VALUE_ARRAY, &echoes))) { - g_value_array_free (originals); + if (!do_xmlrpc ("echo", + g_variant_new ("(@as)", originals), + "as", &retval)) { + g_variant_unref (originals); return; } - g_value_array_free (originals); - if (debug_level >= 2) { - for (i = 0; i < echoes->n_values; i++) { - debug_printf (2, "%s\"%s\"", i == 0 ? "[" : ", ", - g_value_get_string (&echoes->values[i])); - } - debug_printf (2, "]\n"); - } + str = g_variant_print (retval, TRUE); + debug_printf (2, "%s\n", str); + g_free (str); - g_assert_cmpint (echoes->n_values, ==, N_ECHO_STRINGS); + g_assert_true (g_variant_equal (originals, retval)); - for (i = 0; i < echoes->n_values; i++) { - if (!server_test && strcmp (echo_strings_broken[i], g_value_get_string (&echoes->values[i])) == 0) { - g_test_skip ("PHP bug"); - g_value_array_free (echoes); - return; - } - - g_assert_cmpstr (echo_strings[i], ==, g_value_get_string (&echoes->values[i])); - } - - g_value_array_free (echoes); + g_variant_unref (originals); + g_variant_unref (retval); } static void test_ping (gconstpointer include_params) { - GValueArray *params; - GValue retval; + GVariant *retval; char *request; - char *out; gboolean ret; + GError *error = NULL; g_test_bug ("671661"); @@ -400,10 +346,8 @@ test_ping (gconstpointer include_params) debug_printf (2, "ping (void (%s) -> string)\n", include_params ? "empty <params>" : "no <params>"); - params = soup_value_array_new (); - request = soup_xmlrpc_build_method_call ("ping", params->values, - params->n_values); - g_value_array_free (params); + request = soup_xmlrpc_build_request ("ping", g_variant_new ("()"), &error); + g_assert_no_error (error); if (!request) return; @@ -419,15 +363,14 @@ test_ping (gconstpointer include_params) memmove (params, end, strlen (end) + 1); } - ret = send_xmlrpc (request, &retval); + ret = send_xmlrpc (request, "s", &retval); g_free (request); - if (!ret || !check_xmlrpc (&retval, G_TYPE_STRING, &out)) + if (!ret) return; - g_assert_cmpstr (out, ==, "pong"); - - g_free (out); + g_assert_cmpstr (g_variant_get_string (retval, NULL), ==, "pong"); + g_variant_unref (retval); } static void @@ -435,7 +378,6 @@ do_bad_xmlrpc (const char *body) { SoupMessage *msg; GError *err = NULL; - GValue retval; msg = soup_message_new ("POST", uri); soup_message_set_request (msg, "text/xml", SOUP_MEMORY_COPY, @@ -444,17 +386,17 @@ do_bad_xmlrpc (const char *body) soup_test_assert_message_status (msg, SOUP_STATUS_OK); - if (!soup_xmlrpc_parse_method_response (msg->response_body->data, - msg->response_body->length, - &retval, &err)) { - if (err) { + if (!soup_xmlrpc_parse_response (msg->response_body->data, + msg->response_body->length, + "()", &err)) { + if (err->domain == SOUP_XMLRPC_FAULT) { debug_printf (1, "FAULT: %d %s (OK!)\n", err->code, err->message); g_error_free (err); g_object_unref (msg); return; } else - soup_test_assert (FALSE, "ERROR: could not parse response\n"); + soup_test_assert (FALSE, "ERROR: could not parse response: %s\n", err->message); } else soup_test_assert (FALSE, "Unexpectedly got successful response!\n"); @@ -485,6 +427,272 @@ test_fault_args (void) do_bad_xmlrpc ("<methodCall><methodName>sum</methodName><params><param><value><int>1</int></value></param></params></methodCall>"); } +#define BODY_PREFIX \ + "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" \ + "<methodCall><methodName>MyMethod</methodName>" +#define BODY_SUFFIX \ + "</methodCall>\n" + +static void +verify_serialization (GVariant *value, + const char *expected_params) +{ + char *debug; + char *body; + char *params; + GError *error = NULL; + + debug = g_variant_print (value, TRUE); + + body = soup_xmlrpc_build_request ("MyMethod", value, &error); + g_assert_no_error (error); + g_assert (g_str_has_prefix (body, BODY_PREFIX)); + g_assert (g_str_has_suffix (body, BODY_SUFFIX)); + + params = g_strndup (body + strlen (BODY_PREFIX), + strlen (body) - strlen (BODY_PREFIX) + - strlen (BODY_SUFFIX)); + + if (!g_str_equal (params, expected_params)) + g_error ("Failed to serialize '%s':\n" + " expected: %s\n" + " got: %s\n", + debug, expected_params, params); + + g_free (params); + g_free (body); + g_free (debug); +} + +static void +verify_serialization_fail (GVariant *value) +{ + char *body; + GError *error = NULL; + + body = soup_xmlrpc_build_request ("MyMethod", value, &error); + g_assert (body == NULL); + g_assert (error != NULL); +} + +static void +test_serializer (void) +{ + SoupDate *date; + + verify_serialization (g_variant_new_parsed ("()"), + "<params/>"); + verify_serialization (g_variant_new_parsed ("(1, 2)"), + "<params>" + "<param><value><int>1</int></value></param>" + "<param><value><int>2</int></value></param>" + "</params>"); + verify_serialization (g_variant_new_parsed ("((1, 2),)"), + "<params><param><value><array><data>" + "<value><int>1</int></value>" + "<value><int>2</int></value>" + "</data></array></value></param></params>"); + verify_serialization (g_variant_new_parsed ("({'one', 1},)"), + "<params><param><value><struct>" + "<member><name>one</name><value><int>1</int></value></member>" + "</struct></value></param></params>"); + verify_serialization (g_variant_new_parsed ("([{'one', 1},{'two', 2}],)"), + "<params><param><value><struct>" + "<member><name>one</name><value><int>1</int></value></member>" + "<member><name>two</name><value><int>2</int></value></member>" + "</struct></value></param></params>"); + verify_serialization (g_variant_new ("(^ay)", "bytestring"), + "<params><param>" + "<value><base64>Ynl0ZXN0cmluZwA=</base64></value>" + "</param></params>"); + verify_serialization (g_variant_new ("(y)", 42), + "<params>" + "<param><value><int>42</int></value></param>" + "</params>"); + date = soup_date_new_from_time_t (1434161309); + verify_serialization (g_variant_new ("(v)", soup_xmlrpc_variant_new_datetime (date)), + "<params>" + "<param><value><dateTime.iso8601>20150613T02:08:29</dateTime.iso8601></value></param>" + "</params>"); + soup_date_free (date); + verify_serialization (g_variant_new ("(s)", "<>&"), + "<params>" + "<param><value><string><>&</string></value></param>" + "</params>"); + verify_serialization (g_variant_new ("(u)", 0), + "<params>" + "<param><value><i8>0</i8></value></param>" + "</params>"); + + verify_serialization_fail (g_variant_new_parsed ("({1, 2},)")); + verify_serialization_fail (g_variant_new ("(mi)", NULL)); + verify_serialization_fail (g_variant_new ("(t)", 0)); +} + +static void +verify_deserialization (GVariant *expected_variant, + const char *signature, + const char *params) +{ + char *body; + char *method_name; + SoupXMLRPCParams *out_params = NULL; + GVariant *variant; + GError *error = NULL; + + body = g_strconcat (BODY_PREFIX, params, BODY_SUFFIX, NULL); + method_name = soup_xmlrpc_parse_request (body, strlen (body), + &out_params, + &error); + g_assert_no_error (error); + g_assert_cmpstr (method_name, ==, "MyMethod"); + + variant = soup_xmlrpc_params_parse (out_params, signature, &error); + g_assert_no_error (error); + + if (!g_variant_equal (variant, expected_variant)) { + char *str1, *str2; + + str1 = g_variant_print (expected_variant, TRUE); + str2 = g_variant_print (variant, TRUE); + g_error ("Failed to deserialize '%s':\n" + " expected: %s\n" + " got: %s\n", + params, str1, str2); + g_free (str1); + g_free (str2); + } + + soup_xmlrpc_params_free (out_params); + g_variant_unref (variant); + g_free (method_name); + g_free (body); +} + +static void +verify_deserialization_fail (const char *signature, + const char *params) +{ + char *body; + char *method_name; + SoupXMLRPCParams *out_params = NULL; + GVariant *variant; + GError *error = NULL; + + body = g_strconcat (BODY_PREFIX, params, BODY_SUFFIX, NULL); + method_name = soup_xmlrpc_parse_request (body, strlen (body), + &out_params, + &error); + g_assert_no_error (error); + g_assert_cmpstr (method_name, ==, "MyMethod"); + + variant = soup_xmlrpc_params_parse (out_params, signature, &error); + g_assert_error (error, SOUP_XMLRPC_ERROR, SOUP_XMLRPC_ERROR_ARGUMENTS); + g_assert (variant == NULL); + + g_free (body); + soup_xmlrpc_params_free (out_params); +} + +static void +test_deserializer (void) +{ + char *tmp; + SoupDate *date; + + verify_deserialization (g_variant_new_parsed ("@av []"), + NULL, + "<params/>"); + verify_deserialization (g_variant_new_parsed ("()"), + "()", + "<params/>"); + verify_deserialization (g_variant_new_parsed ("(@y 1,@n 2)"), + "(yn)", + "<params>" + "<param><value><int>1</int></value></param>" + "<param><value><int>2</int></value></param>" + "</params>"); + verify_deserialization (g_variant_new_parsed ("[<[{'one', <1>},{'two', <2>}]>]"), + NULL, + "<params><param><value><struct>" + "<member><name>one</name><value><int>1</int></value></member>" + "<member><name>two</name><value><int>2</int></value></member>" + "</struct></value></param></params>"); + verify_deserialization (g_variant_new_parsed ("([{'one', 1},{'two', 2}],)"), + "(a{si})", + "<params><param><value><struct>" + "<member><name>one</name><value><int>1</int></value></member>" + "<member><name>two</name><value><int>2</int></value></member>" + "</struct></value></param></params>"); + date = soup_date_new_from_time_t (1434146909); + verify_deserialization (g_variant_new_parsed ("[%v]", soup_xmlrpc_variant_new_datetime (date)), + NULL, + "<params>" + "<param><value><dateTime.iso8601>20150612T22:08:29</dateTime.iso8601></value></param>" + "</params>"); + soup_date_free (date); + verify_deserialization (g_variant_new_parsed ("[<b'bytestring'>]"), + NULL, + "<params>" + "<param><value><base64>Ynl0ZXN0cmluZwA=</base64></value></param>" + "</params>"); + verify_deserialization (g_variant_new_parsed ("[<1>]"), + "av", + "<params><param><value><int>1</int></value></param></params>"); + verify_deserialization (g_variant_new_parsed ("[<%s>]", "<>&"), + NULL, + "<params>" + "<param><value><string><>&</string></value></param>" + "</params>"); + verify_deserialization (g_variant_new_parsed ("(@y 255,)"), + "(y)", + "<params>" + "<param><value><int>255</int></value></param>" + "</params>"); + + tmp = g_strdup_printf ("<params>" + "<param><value><int>%"G_GUINT64_FORMAT"</int></value></param>" + "</params>", G_MAXUINT64); + verify_deserialization (g_variant_new ("(t)", G_MAXUINT64), + "(t)", tmp); + g_free (tmp); + + verify_deserialization_fail (NULL, + "<params>" + "<param><value><boolean>2</boolean></value></param>" + "</params>"); + verify_deserialization_fail ("(y)", + "<params>" + "<param><value><int>256</int></value></param>" + "</params>"); + verify_deserialization_fail ("(ii)", + "<params>" + "<param><value><int>1</int></value></param>" + "</params>"); + verify_deserialization_fail ("(i)", + "<params>" + "<param><value><int>1</int></value></param>" + "<param><value><int>2</int></value></param>" + "</params>"); +} + +static void +test_fault (void) +{ + char *body; + GVariant *reply; + GError *error = NULL; + + body = soup_xmlrpc_build_fault (1, "error: %s", "failed"); + reply = soup_xmlrpc_parse_response (body, strlen (body), NULL, &error); + g_assert_error (error, SOUP_XMLRPC_FAULT, 1); + g_assert_cmpstr (error->message, ==, "error: failed"); + g_assert (reply == NULL); + + g_free (body); + g_clear_error (&error); +} + static GOptionEntry xmlrpc_entries[] = { { "uri", 'U', 0, G_OPTION_ARG_STRING, &uri, "Alternate URI for server", NULL }, @@ -507,16 +715,19 @@ main (int argc, char **argv) session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL); - g_test_add_func ("/xmlrpc/sum", test_sum); - g_test_add_func ("/xmlrpc/countBools", test_countBools); - g_test_add_func ("/xmlrpc/md5sum", test_md5sum); - g_test_add_func ("/xmlrpc/dateChange", test_dateChange); - g_test_add_func ("/xmlrpc/echo", test_echo); - g_test_add_data_func ("/xmlrpc/ping/empty-params", GINT_TO_POINTER (TRUE), test_ping); - g_test_add_data_func ("/xmlrpc/ping/no-params", GINT_TO_POINTER (FALSE), test_ping); - g_test_add_func ("/xmlrpc/fault/malformed", test_fault_malformed); - g_test_add_func ("/xmlrpc/fault/method", test_fault_method); - g_test_add_func ("/xmlrpc/fault/args", test_fault_args); + g_test_add_func ("/xmlrpc/variant/serializer", test_serializer); + g_test_add_func ("/xmlrpc/variant/deserializer", test_deserializer); + g_test_add_func ("/xmlrpc/variant/fault", test_fault); + g_test_add_func ("/xmlrpc/variant/sum", test_sum); + g_test_add_func ("/xmlrpc/variant/countBools", test_countBools); + g_test_add_func ("/xmlrpc/variant/md5sum", test_md5sum); + g_test_add_func ("/xmlrpc/variant/dateChange", test_dateChange); + g_test_add_func ("/xmlrpc/variant/echo", test_echo); + g_test_add_data_func ("/xmlrpc/variant/ping/empty-params", GINT_TO_POINTER (TRUE), test_ping); + g_test_add_data_func ("/xmlrpc/variant/ping/no-params", GINT_TO_POINTER (FALSE), test_ping); + g_test_add_func ("/xmlrpc/variant/fault/malformed", test_fault_malformed); + g_test_add_func ("/xmlrpc/variant/fault/method", test_fault_method); + g_test_add_func ("/xmlrpc/variant/fault/args", test_fault_args); ret = g_test_run (); |