From: <svn...@op...> - 2009-09-25 14:16:47
|
Author: bellmich Date: Fri Sep 25 16:16:36 2009 New Revision: 1287 URL: http://libsyncml.opensync.org/changeset/1287 Log: fixed binary content type test (base64 conversion is tested now) Modified: trunk/tests/check_data_sync_api.c Modified: trunk/tests/check_data_sync_api.c ============================================================================== --- trunk/tests/check_data_sync_api.c Fri Sep 25 16:13:12 2009 (r1286) +++ trunk/tests/check_data_sync_api.c Fri Sep 25 16:16:36 2009 (r1287) @@ -36,6 +36,7 @@ GList *items; SmlDataSync *client; SmlDataSyncDataStore *data_store; + gboolean is_binary; } SmlDataSyncTestClient; SmlDataSync *server; @@ -117,7 +118,11 @@ SmlDataSyncChangeItem *item = sml_data_sync_change_item_new(); sml_data_sync_change_item_set_action(item, SML_CHANGE_ADD); - sml_fail_unless(sml_data_sync_change_item_set_data(item, list->data, 0, error), "%s", GET_ERROR_MESSAGE((*error))); + if (client->is_binary) { + sml_fail_unless(sml_data_sync_change_item_set_binary_data(item, list->data, strlen(list->data), error), "%s", GET_ERROR_MESSAGE((*error))); + } else { + sml_fail_unless(sml_data_sync_change_item_set_data(item, list->data, 0, error), "%s", GET_ERROR_MESSAGE((*error))); + } sml_fail_unless(sml_data_sync_change_item_set_location(item, loc, error), "%s", GET_ERROR_MESSAGE((*error))); g_object_unref(loc); loc = NULL; @@ -233,9 +238,7 @@ count++; /* test the uid */ - smlTrace(TRACE_INTERNAL, "%s - case 1 %p %p", __func__, item, sml_data_sync_change_item_get_location(item)); const gchar *uid = sml_location_get_full_uri(sml_data_sync_change_item_get_location(item)); - smlTrace(TRACE_INTERNAL, "%s - case 1", __func__); char *name = g_strdup_printf("%d", count); if (strcmp(name, uid)) { smlSafeCFree(&name); @@ -245,8 +248,22 @@ /* item with correct uid */ const gchar *data = sml_data_sync_change_item_get_data(item); - if (strcmp(list->data, data)) { - sml_fail_unless(FALSE, "The data of the item %s was wrong(%s != %s).", uid, data, list->data); + if (client->is_binary) { + /* this is a base64 encoded item */ + if (!strcmp(list->data, data)) { + sml_fail_unless(FALSE, "The binary item was not base64 encoded.", uid, data, list->data); + } + gchar *binary = NULL; + gsize size = 0; + sml_fail_unless(sml_data_sync_change_item_get_binary_data(item, &binary, &size, error), "%s", GET_ERROR_MESSAGE((*error))); + sml_fail_unless(strlen(list->data) == size, "The length of the decoded item is wrong."); + sml_fail_unless(strcmp(list->data, binary) == 0, "The data of the decoded item is wrong."); + smlSafeCFree(&binary); + } else { + /* this is a plain text item */ + if (strcmp(list->data, data)) { + sml_fail_unless(FALSE, "The data of the item %s was wrong(%s != %s).", uid, data, list->data); + } } } @@ -691,6 +708,7 @@ client->data_store = sml_data_sync_data_store_new(); sml_data_sync_data_store_set_content_type (client->data_store, "image/jpeg"); sml_data_sync_data_store_set_local_uri (client->data_store, "dcim"); + client->is_binary = TRUE; sml_data_sync_data_store_register_change_callback(client->data_store, clientRecvChangeCallback, NULL); if (!sml_data_sync_add_data_store(client->client, client->data_store, &error)) goto error; |