static gboolean test_sum (void) { GValueArray *ints; int i, val, sum, result; GValue retval; gboolean ok; debug_printf (1, "sum (array of int -> int): "); ints = g_value_array_new (10); for (i = sum = 0; i < 10; i++) { val = rand () % 100; debug_printf (2, "%s%d", i == 0 ? "[" : ", ", val); soup_value_array_append (ints, G_TYPE_INT, 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); if (!ok) return FALSE; debug_printf (2, "%d: ", result); debug_printf (1, "%s\n", result == sum ? "OK!" : "WRONG!"); return result == sum; }
static gboolean test_echo (void) { GValueArray *originals, *echoes; GValue retval; int i; gboolean php_bug = FALSE; debug_printf (1, "echo (array of string -> array of string): "); 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, "] -> "); 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); return FALSE; } 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, "] -> "); } if (echoes->n_values != N_ECHO_STRINGS) { debug_printf (1, " WRONG! Wrong number of return strings"); g_value_array_free (echoes); return FALSE; } for (i = 0; i < echoes->n_values; i++) { if (strcmp (echo_strings[i], g_value_get_string (&echoes->values[i])) != 0) { if (!server_test && strcmp (echo_strings_broken[i], g_value_get_string (&echoes->values[i])) == 0) php_bug = TRUE; else { debug_printf (1, " WRONG! Mismatch at %d\n", i + 1); g_value_array_free (echoes); return FALSE; } } } if (php_bug) debug_printf (1, "WRONG, but it's php's fault\n"); else debug_printf (1, "OK!\n"); g_value_array_free (echoes); return TRUE; }
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 gboolean test_md5sum (void) { GByteArray *data, *result; int i; GChecksum *checksum; guchar digest[16]; gsize digest_len = sizeof (digest); GValue retval; gboolean ok; debug_printf (1, "md5sum (base64 -> base64): "); data = g_byte_array_new (); g_byte_array_set_size (data, 256); for (i = 0; i < data->len; i++) data->data[i] = (char)(rand ()); checksum = g_checksum_new (G_CHECKSUM_MD5); g_checksum_update (checksum, data->data, data->len); 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)); g_byte_array_free (data, TRUE); if (!ok) return FALSE; if (result->len != digest_len) { debug_printf (1, "result has WRONG length (%d)\n", result->len); g_byte_array_free (result, TRUE); return FALSE; } ok = (memcmp (digest, result->data, digest_len) == 0); debug_printf (1, "%s\n", ok ? "OK!" : "WRONG!"); g_byte_array_free (result, TRUE); return ok; }
GList* roadmap_engine_get_tickets (RoadmapEngine *self, gchar *username) { GValue retval; GValueArray *tickets; int i, j; gboolean ok; GList *r_tickets; RoadmapEnginePrivate *priv; priv = ROADMAP_ENGINE_GET_PRIVATE(self); r_tickets = NULL; ok = (do_xmlrpc (priv->session, "ticket.query", &retval, G_TYPE_STRING, g_strdup_printf ("owner=%s", username), G_TYPE_INVALID) && check_xmlrpc (&retval, G_TYPE_VALUE_ARRAY, &tickets)); if (!ok) { g_print ("No se han podido obtener los tickets"); return NULL; } for (i = 0; i < tickets->n_values; i++) { GValueArray *ticket_info; gint t_id; GHashTable *attributes; GList *keys; RoadmapTicket *rd_ticket; gchar *test; t_id = g_value_get_int (g_value_array_get_nth (tickets, i)); ok = (do_xmlrpc (priv->session, "ticket.get", &retval, G_TYPE_STRING, g_strdup_printf ("%d", t_id), G_TYPE_INVALID) && check_xmlrpc (&retval, G_TYPE_VALUE_ARRAY, &ticket_info)); if (!ok) { g_print ("No se ha encontrado información del ticket: %d", t_id); return NULL; } // String?, SoupDate*, SoupDate*, GHashTable* // g_print ("ID: %d (%d)\n", t_id, ticket_info->n_values); // The 3 element it's the hash table with the ticket description attributes = (GHashTable *) g_value_get_boxed (g_value_array_get_nth (ticket_info, 3)); /* keys = g_hash_table_get_keys (attributes); while (keys) { g_print (" Attr: %s\n", ((gchar*) keys->data)); keys = g_list_next (keys); } g_list_free (keys); */ /* for (j = 0; j < ticket_info->n_values; j++) { GValue *ti; ti = g_value_array_get_nth (ticket_info, j); g_print ("%s\n", g_strdup_value_contents (ti)); } */ rd_ticket = g_object_new (ROADMAP_TYPE_TICKET, "id", t_id, "attributes", attributes, NULL); r_tickets = g_list_append (r_tickets, rd_ticket); } return r_tickets; }
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; }