[glib] Bug 587434 – regression tests fail
- From: Benjamin Otte <otte src gnome org>
- To: svn-commits-list gnome org
- Subject: [glib] Bug 587434 – regression tests fail
- Date: Tue, 30 Jun 2009 18:45:21 +0000 (UTC)
commit d589da7e86947542790aa0137dc12499a4fe1a3b
Author: Benjamin Otte <otte gnome org>
Date: Tue Jun 30 20:33:19 2009 +0200
Bug 587434 â?? regression tests fail
make this test not only compile, but also run successfully with mad
CFLAGS.
gio/tests/data-output-stream.c | 138 +++++++++++++++++++--------------------
1 files changed, 67 insertions(+), 71 deletions(-)
---
diff --git a/gio/tests/data-output-stream.c b/gio/tests/data-output-stream.c
index 823220a..0172389 100644
--- a/gio/tests/data-output-stream.c
+++ b/gio/tests/data-output-stream.c
@@ -109,33 +109,19 @@ enum TestDataType {
TEST_DATA_UINT64
};
-#define TEST_DATA_RETYPE_BUFF(a, t, v) \
- (a == TEST_DATA_BYTE ? (t) *(guchar*)v : \
- (a == TEST_DATA_INT16 ? (t) *(gint16*)v : \
- (a == TEST_DATA_UINT16 ? (t) *(guint16*)v : \
- (a == TEST_DATA_INT32 ? (t) *(gint32*)v : \
- (a == TEST_DATA_UINT32 ? (t) *(guint32*)v : \
- (a == TEST_DATA_INT64 ? (t) *(gint64*)v : \
- (t) *(guint64*)v ))))))
-
-
-
-
static void
-test_data_array (gpointer buffer, int len,
+test_data_array (guchar *buffer, gsize len,
enum TestDataType data_type, GDataStreamByteOrder byte_order)
{
GOutputStream *stream;
GOutputStream *base_stream;
- gpointer stream_data;
+ guchar *stream_data;
GError *error = NULL;
- int pos;
- int data_size = 1;
+ guint pos;
GDataStreamByteOrder native;
gboolean swap;
gboolean res;
- guint64 data;
/* create objects */
stream_data = g_malloc0 (len);
@@ -143,60 +129,56 @@ test_data_array (gpointer buffer, int len,
stream = G_OUTPUT_STREAM (g_data_output_stream_new (base_stream));
g_data_output_stream_set_byte_order (G_DATA_OUTPUT_STREAM (stream), byte_order);
+ /* Set flag to swap bytes if needed */
+ native = (G_BYTE_ORDER == G_BIG_ENDIAN) ? G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN : G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN;
+ swap = (byte_order != G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN) && (byte_order != native);
- /* Set correct data size */
+ /* set len to length of buffer cast to actual type */
switch (data_type)
{
case TEST_DATA_BYTE:
- data_size = 1;
break;
case TEST_DATA_INT16:
case TEST_DATA_UINT16:
- data_size = 2;
- break;
+ g_assert_cmpint (len % 2, ==, 0);
case TEST_DATA_INT32:
case TEST_DATA_UINT32:
- data_size = 4;
- break;
+ g_assert_cmpint (len % 4, ==, 0);
case TEST_DATA_INT64:
case TEST_DATA_UINT64:
- data_size = 8;
- break;
+ g_assert_cmpint (len % 8, ==, 0);
+ len /= 8;
+ break;
default:
g_assert_not_reached ();
break;
}
-
- /* Set flag to swap bytes if needed */
- native = (G_BYTE_ORDER == G_BIG_ENDIAN) ? G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN : G_DATA_STREAM_BYTE_ORDER_LITTLE_ENDIAN;
- swap = (byte_order != G_DATA_STREAM_BYTE_ORDER_HOST_ENDIAN) && (byte_order != native);
/* Write data to the file */
- pos = 0;
- while (pos < len)
+ for (pos = 0; pos < len; pos++)
{
switch (data_type)
{
case TEST_DATA_BYTE:
- res = g_data_output_stream_put_byte (G_DATA_OUTPUT_STREAM (stream), TEST_DATA_RETYPE_BUFF (data_type, guchar, ((guchar*)buffer + pos)), NULL, &error);
+ res = g_data_output_stream_put_byte (G_DATA_OUTPUT_STREAM (stream), buffer[pos], NULL, &error);
break;
case TEST_DATA_INT16:
- res = g_data_output_stream_put_int16 (G_DATA_OUTPUT_STREAM (stream), TEST_DATA_RETYPE_BUFF (data_type, gint16, ((guchar*)buffer + pos)), NULL, &error);
+ res = g_data_output_stream_put_int16 (G_DATA_OUTPUT_STREAM (stream), ((gint16 *) buffer)[pos], NULL, &error);
break;
case TEST_DATA_UINT16:
- res = g_data_output_stream_put_uint16 (G_DATA_OUTPUT_STREAM (stream), TEST_DATA_RETYPE_BUFF (data_type, guint16, ((guchar*)buffer + pos)), NULL, &error);
+ res = g_data_output_stream_put_uint16 (G_DATA_OUTPUT_STREAM (stream), ((guint16 *) buffer)[pos], NULL, &error);
break;
case TEST_DATA_INT32:
- res = g_data_output_stream_put_int32 (G_DATA_OUTPUT_STREAM (stream), TEST_DATA_RETYPE_BUFF (data_type, gint32, ((guchar*)buffer + pos)), NULL, &error);
+ res = g_data_output_stream_put_int32 (G_DATA_OUTPUT_STREAM (stream), ((gint32 *) buffer)[pos], NULL, &error);
break;
case TEST_DATA_UINT32:
- res = g_data_output_stream_put_uint32 (G_DATA_OUTPUT_STREAM (stream), TEST_DATA_RETYPE_BUFF (data_type, guint32, ((guchar*)buffer + pos)), NULL, &error);
+ res = g_data_output_stream_put_uint32 (G_DATA_OUTPUT_STREAM (stream), ((guint32 *) buffer)[pos], NULL, &error);
break;
case TEST_DATA_INT64:
- res = g_data_output_stream_put_int64 (G_DATA_OUTPUT_STREAM (stream), TEST_DATA_RETYPE_BUFF (data_type, gint64, ((guchar*)buffer + pos)), NULL, &error);
+ res = g_data_output_stream_put_int64 (G_DATA_OUTPUT_STREAM (stream), ((gint64 *) buffer)[pos], NULL, &error);
break;
case TEST_DATA_UINT64:
- res = g_data_output_stream_put_uint64 (G_DATA_OUTPUT_STREAM (stream), TEST_DATA_RETYPE_BUFF (data_type, guint64, ((guchar*)buffer + pos)), NULL, &error);
+ res = g_data_output_stream_put_uint64 (G_DATA_OUTPUT_STREAM (stream), ((guint64 *) buffer)[pos], NULL, &error);
break;
default:
g_assert_not_reached ();
@@ -204,43 +186,57 @@ test_data_array (gpointer buffer, int len,
}
g_assert_no_error (error);
g_assert_cmpint (res, ==, TRUE);
- pos += data_size;
}
-
/* Compare data back */
- pos = 0;
- data = 0;
- while (pos < len)
+ for (pos = 0; pos < len; pos++)
{
- data = TEST_DATA_RETYPE_BUFF(data_type, guint64, ((guchar*)stream_data + pos));
- if (swap)
- {
- switch (data_type)
- {
- case TEST_DATA_BYTE:
- break;
- case TEST_DATA_UINT16:
- case TEST_DATA_INT16:
- data = GUINT16_SWAP_LE_BE((guint16) data);
- break;
- case TEST_DATA_UINT32:
- case TEST_DATA_INT32:
- data = GUINT32_SWAP_LE_BE((guint32) data);
- break;
- case TEST_DATA_UINT64:
- case TEST_DATA_INT64:
- data = GUINT64_SWAP_LE_BE((guint64) data);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
- }
- g_assert_cmpint (data, ==, TEST_DATA_RETYPE_BUFF(data_type, guint64, ((guchar*)buffer + pos)));
- break;
-
- pos += data_size;
+ switch (data_type)
+ {
+ case TEST_DATA_BYTE:
+ /* swapping unnecessary */
+ g_assert_cmpint (buffer[pos], ==, stream_data[pos]);
+ break;
+ case TEST_DATA_UINT16:
+ if (swap)
+ g_assert_cmpint (GUINT16_SWAP_LE_BE (((guint16 *) buffer)[pos]), ==, ((guint16 *) stream_data)[pos]);
+ else
+ g_assert_cmpint (((guint16 *) buffer)[pos], ==, ((guint16 *) stream_data)[pos]);
+ break;
+ case TEST_DATA_INT16:
+ if (swap)
+ g_assert_cmpint ((gint16) GUINT16_SWAP_LE_BE (((gint16 *) buffer)[pos]), ==, ((gint16 *) stream_data)[pos]);
+ else
+ g_assert_cmpint (((gint16 *) buffer)[pos], ==, ((gint16 *) stream_data)[pos]);
+ break;
+ case TEST_DATA_UINT32:
+ if (swap)
+ g_assert_cmpint (GUINT32_SWAP_LE_BE (((guint32 *) buffer)[pos]), ==, ((guint32 *) stream_data)[pos]);
+ else
+ g_assert_cmpint (((guint32 *) buffer)[pos], ==, ((guint32 *) stream_data)[pos]);
+ break;
+ case TEST_DATA_INT32:
+ if (swap)
+ g_assert_cmpint ((gint32) GUINT32_SWAP_LE_BE (((gint32 *) buffer)[pos]), ==, ((gint32 *) stream_data)[pos]);
+ else
+ g_assert_cmpint (((gint32 *) buffer)[pos], ==, ((gint32 *) stream_data)[pos]);
+ break;
+ case TEST_DATA_UINT64:
+ if (swap)
+ g_assert_cmpint (GUINT64_SWAP_LE_BE (((guint64 *) buffer)[pos]), ==, ((guint64 *) stream_data)[pos]);
+ else
+ g_assert_cmpint (((guint64 *) buffer)[pos], ==, ((guint64 *) stream_data)[pos]);
+ break;
+ case TEST_DATA_INT64:
+ if (swap)
+ g_assert_cmpint ((gint64) GUINT64_SWAP_LE_BE (((gint64 *) buffer)[pos]), ==, ((gint64 *) stream_data)[pos]);
+ else
+ g_assert_cmpint (((gint64 *) buffer)[pos], ==, ((gint64 *) stream_data)[pos]);
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
}
g_object_unref (base_stream);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]