Bug 587434 – regression tests fail

make this test not only compile, but also run successfully with mad
CFLAGS.
This commit is contained in:
Benjamin Otte 2009-06-30 20:33:19 +02:00
parent 80561f9718
commit d589da7e86

View File

@ -109,33 +109,19 @@ enum TestDataType {
TEST_DATA_UINT64 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 static void
test_data_array (gpointer buffer, int len, test_data_array (guchar *buffer, gsize len,
enum TestDataType data_type, GDataStreamByteOrder byte_order) enum TestDataType data_type, GDataStreamByteOrder byte_order)
{ {
GOutputStream *stream; GOutputStream *stream;
GOutputStream *base_stream; GOutputStream *base_stream;
gpointer stream_data; guchar *stream_data;
GError *error = NULL; GError *error = NULL;
int pos; guint pos;
int data_size = 1;
GDataStreamByteOrder native; GDataStreamByteOrder native;
gboolean swap; gboolean swap;
gboolean res; gboolean res;
guint64 data;
/* create objects */ /* create objects */
stream_data = g_malloc0 (len); 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)); 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); 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) switch (data_type)
{ {
case TEST_DATA_BYTE: case TEST_DATA_BYTE:
data_size = 1;
break; break;
case TEST_DATA_INT16: case TEST_DATA_INT16:
case TEST_DATA_UINT16: case TEST_DATA_UINT16:
data_size = 2; g_assert_cmpint (len % 2, ==, 0);
break;
case TEST_DATA_INT32: case TEST_DATA_INT32:
case TEST_DATA_UINT32: case TEST_DATA_UINT32:
data_size = 4; g_assert_cmpint (len % 4, ==, 0);
break;
case TEST_DATA_INT64: case TEST_DATA_INT64:
case TEST_DATA_UINT64: case TEST_DATA_UINT64:
data_size = 8; g_assert_cmpint (len % 8, ==, 0);
len /= 8;
break; break;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
break; 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 */ /* Write data to the file */
pos = 0; for (pos = 0; pos < len; pos++)
while (pos < len)
{ {
switch (data_type) switch (data_type)
{ {
case TEST_DATA_BYTE: 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; break;
case TEST_DATA_INT16: 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; break;
case TEST_DATA_UINT16: 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; break;
case TEST_DATA_INT32: 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; break;
case TEST_DATA_UINT32: 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; break;
case TEST_DATA_INT64: 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; break;
case TEST_DATA_UINT64: 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; break;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
@ -204,44 +186,58 @@ test_data_array (gpointer buffer, int len,
} }
g_assert_no_error (error); g_assert_no_error (error);
g_assert_cmpint (res, ==, TRUE); g_assert_cmpint (res, ==, TRUE);
pos += data_size;
} }
/* Compare data back */ /* Compare data back */
pos = 0; for (pos = 0; pos < len; pos++)
data = 0;
while (pos < len)
{
data = TEST_DATA_RETYPE_BUFF(data_type, guint64, ((guchar*)stream_data + pos));
if (swap)
{ {
switch (data_type) switch (data_type)
{ {
case TEST_DATA_BYTE: case TEST_DATA_BYTE:
/* swapping unnecessary */
g_assert_cmpint (buffer[pos], ==, stream_data[pos]);
break; break;
case TEST_DATA_UINT16: 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: case TEST_DATA_INT16:
data = GUINT16_SWAP_LE_BE((guint16) data); 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; break;
case TEST_DATA_UINT32: 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: case TEST_DATA_INT32:
data = GUINT32_SWAP_LE_BE((guint32) data); 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; break;
case TEST_DATA_UINT64: 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: case TEST_DATA_INT64:
data = GUINT64_SWAP_LE_BE((guint64) data); 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; break;
default: default:
g_assert_not_reached (); g_assert_not_reached ();
break; break;
} }
} }
g_assert_cmpint (data, ==, TEST_DATA_RETYPE_BUFF(data_type, guint64, ((guchar*)buffer + pos)));
break;
pos += data_size;
}
g_object_unref (base_stream); g_object_unref (base_stream);
g_object_unref (stream); g_object_unref (stream);