static void do_countBools (SoupMessage *msg, GValueArray *params) { int i, trues = 0, falses = 0; GValueArray *bools; GHashTable *ret = soup_value_hash_new (); gboolean val; if (params->n_values != 1) { args_error (msg, params, 1); return; } if (!soup_value_array_get_nth (params, 0, G_TYPE_VALUE_ARRAY, &bools)) { type_error (msg, G_TYPE_VALUE_ARRAY, params, 0); return; } for (i = 0; i < bools->n_values; i++) { if (!soup_value_array_get_nth (bools, i, G_TYPE_BOOLEAN, &val)) { type_error (msg, G_TYPE_BOOLEAN, params, i); return; } if (val) trues++; else falses++; } soup_value_hash_insert (ret, "true", G_TYPE_INT, trues); soup_value_hash_insert (ret, "false", G_TYPE_INT, falses); soup_xmlrpc_set_response (msg, G_TYPE_HASH_TABLE, ret); g_hash_table_destroy (ret); }
static gboolean test_dateChange (void) { GHashTable *structval; SoupDate *date, *result; char *timestamp; GValue retval; gboolean ok; debug_printf (1, "dateChange (date, struct of ints -> time): "); date = soup_date_new (1970 + (rand () % 50), 1 + rand () % 12, 1 + rand () % 28, rand () % 24, rand () % 60, rand () % 60); if (debug_level >= 2) { timestamp = soup_date_to_string (date, SOUP_DATE_ISO8601_XMLRPC); debug_printf (2, "date: %s, {", timestamp); g_free (timestamp); } structval = soup_value_hash_new (); if (rand () % 3) { date->year = 1970 + (rand () % 50); debug_printf (2, "tm_year: %d, ", date->year - 1900); soup_value_hash_insert (structval, "tm_year", G_TYPE_INT, date->year - 1900); } if (rand () % 3) { date->month = 1 + rand () % 12; debug_printf (2, "tm_mon: %d, ", date->month - 1); soup_value_hash_insert (structval, "tm_mon", G_TYPE_INT, date->month - 1); } if (rand () % 3) { date->day = 1 + rand () % 28; debug_printf (2, "tm_mday: %d, ", date->day); soup_value_hash_insert (structval, "tm_mday", G_TYPE_INT, date->day); } if (rand () % 3) { date->hour = rand () % 24; debug_printf (2, "tm_hour: %d, ", date->hour); soup_value_hash_insert (structval, "tm_hour", G_TYPE_INT, date->hour); } if (rand () % 3) { date->minute = rand () % 60; debug_printf (2, "tm_min: %d, ", date->minute); soup_value_hash_insert (structval, "tm_min", G_TYPE_INT, date->minute); } if (rand () % 3) { date->second = rand () % 60; debug_printf (2, "tm_sec: %d, ", date->second); soup_value_hash_insert (structval, "tm_sec", G_TYPE_INT, 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); if (!ok) { soup_date_free (date); return FALSE; } if (debug_level >= 2) { timestamp = soup_date_to_string (result, SOUP_DATE_ISO8601_XMLRPC); debug_printf (2, "%s: ", timestamp); g_free (timestamp); } ok = ((date->year == result->year) && (date->month == result->month) && (date->day == result->day) && (date->hour == result->hour) && (date->minute == result->minute) && (date->second == result->second)); soup_date_free (date); soup_date_free (result); debug_printf (1, "%s\n", ok ? "OK!" : "WRONG!"); return ok; }