static gboolean test_countBools (void) { GValueArray *bools; int i, trues, falses; GValue retval; int ret_trues, ret_falses; gboolean val, ok; GHashTable *result; debug_printf (1, "countBools (array of boolean -> struct of ints): "); bools = g_value_array_new (10); for (i = trues = falses = 0; i < 10; i++) { val = rand () > (RAND_MAX / 2); debug_printf (2, "%s%c", i == 0 ? "[" : ", ", val ? 'T' : 'F'); soup_value_array_append (bools, G_TYPE_BOOLEAN, val); if (val) trues++; else falses++; } 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); if (!ok) return FALSE; if (!soup_value_hash_lookup (result, "true", G_TYPE_INT, &ret_trues)) { debug_printf (1, "NO 'true' value in response\n"); return FALSE; } if (!soup_value_hash_lookup (result, "false", G_TYPE_INT, &ret_falses)) { debug_printf (1, "NO 'false' value in response\n"); return FALSE; } g_hash_table_destroy (result); debug_printf (2, "{ true: %d, false: %d } ", ret_trues, ret_falses); ok = (trues == ret_trues) && (falses == ret_falses); debug_printf (1, "%s\n", ok ? "OK!" : "WRONG!"); return ok; }
static void do_dateChange (SoupMessage *msg, GValueArray *params) { GHashTable *arg; SoupDate *date; int val; if (params->n_values != 2) { args_error (msg, params, 2); return; } if (!soup_value_array_get_nth (params, 0, SOUP_TYPE_DATE, &date)) { type_error (msg, SOUP_TYPE_DATE, params, 0); return; } if (!soup_value_array_get_nth (params, 1, G_TYPE_HASH_TABLE, &arg)) { type_error (msg, G_TYPE_HASH_TABLE, params, 1); return; } if (soup_value_hash_lookup (arg, "tm_year", G_TYPE_INT, &val)) date->year = val + 1900; if (soup_value_hash_lookup (arg, "tm_mon", G_TYPE_INT, &val)) date->month = val + 1; if (soup_value_hash_lookup (arg, "tm_mday", G_TYPE_INT, &val)) date->day = val; if (soup_value_hash_lookup (arg, "tm_hour", G_TYPE_INT, &val)) date->hour = val; if (soup_value_hash_lookup (arg, "tm_min", G_TYPE_INT, &val)) date->minute = val; if (soup_value_hash_lookup (arg, "tm_sec", G_TYPE_INT, &val)) date->second = val; soup_xmlrpc_set_response (msg, SOUP_TYPE_DATE, date); }