add int64 to test suites, fix minor bug where marshaling assumed that DBusOctets8 was aligned when passed in as a function argument

This commit is contained in:
Havoc Pennington 2005-01-01 02:35:09 +00:00
parent 394d57c765
commit bb8f518d07
3 changed files with 116 additions and 6 deletions

View file

@ -194,6 +194,20 @@ pack_4_octets (dbus_uint32_t value,
*((dbus_uint32_t*)(data)) = DBUS_UINT32_TO_BE (value);
}
static void
swap_8_octets (DBusOctets8 *value,
int byte_order)
{
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
{
#ifdef DBUS_HAVE_INT64
value->u = DBUS_UINT64_SWAP_LE_BE (value->u);
#else
swap_bytes ((unsigned char *)value, 8);
#endif
}
}
static void
pack_8_octets (DBusOctets8 value,
int byte_order,
@ -208,8 +222,7 @@ pack_8_octets (DBusOctets8 value,
*((dbus_uint64_t*)(data)) = DBUS_UINT64_TO_BE (value.u);
#else
memcpy (data, &value, 8);
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
swap_bytes ((unsigned char *)data, 8);
swap_8_octets ((DBusOctets8*)data, byte_order);
#endif
}
@ -483,10 +496,9 @@ marshal_8_octets (DBusString *str,
DBusOctets8 value)
{
_dbus_assert (sizeof (value) == 8);
if (byte_order != DBUS_COMPILER_BYTE_ORDER)
pack_8_octets (value, byte_order, (unsigned char*) &value); /* pack into self, swapping as we go */
swap_8_octets (&value, byte_order);
return _dbus_string_insert_8_aligned (str, insert_at,
(const unsigned char *)&value);
}

View file

@ -1434,6 +1434,14 @@ static dbus_bool_t int32_read_value (TestTypeNode *node,
DataBlock *block,
DBusTypeReader *reader,
int seed);
static dbus_bool_t int64_write_value (TestTypeNode *node,
DataBlock *block,
DBusTypeWriter *writer,
int seed);
static dbus_bool_t int64_read_value (TestTypeNode *node,
DataBlock *block,
DBusTypeReader *reader,
int seed);
static dbus_bool_t struct_1_write_value (TestTypeNode *node,
DataBlock *block,
DBusTypeWriter *writer,
@ -1504,6 +1512,26 @@ static const TestTypeNodeClass uint32_class = {
NULL
};
static const TestTypeNodeClass int64_class = {
DBUS_TYPE_INT64,
sizeof (TestTypeNode),
NULL,
NULL,
int64_write_value,
int64_read_value,
NULL
};
static const TestTypeNodeClass uint64_class = {
DBUS_TYPE_UINT64,
sizeof (TestTypeNode),
NULL,
NULL,
int64_write_value, /* recycle from int64 */
int64_read_value, /* recycle from int64 */
NULL
};
static const TestTypeNodeClass struct_1_class = {
DBUS_TYPE_STRUCT,
sizeof (TestTypeNodeContainer),
@ -1557,7 +1585,9 @@ static const TestTypeNodeClass array_2_class = {
static const TestTypeNodeClass* const
basic_nodes[] = {
&int32_class,
&uint32_class
&uint32_class,
&int64_class,
&uint64_class
};
#define N_BASICS (_DBUS_N_ELEMENTS (basic_nodes))
@ -1736,9 +1766,17 @@ run_test_nodes_in_one_configuration (TestTypeNode **nodes,
nid.n_nodes = n_nodes;
nid.byte_order = byte_order;
/* FIXME put the OOM testing back once we debug everything and are willing to
* wait for it to run ;-)
*/
#if 0
_dbus_test_oom_handling ("running test node",
run_test_nodes_iteration,
&nid);
#else
if (!run_test_nodes_iteration (&nid))
_dbus_assert_not_reached ("no memory");
#endif
data_block_free (&block);
}
@ -2216,6 +2254,64 @@ int32_read_value (TestTypeNode *node,
return TRUE;
}
#ifdef DBUS_HAVE_INT64
static dbus_int64_t
int64_from_seed (int seed)
{
dbus_int32_t v32;
dbus_int64_t v;
v32 = int32_from_seed (seed);
v = (((dbus_int64_t)v32) << 32) | (~v32);
return v;
}
#endif
static dbus_bool_t
int64_write_value (TestTypeNode *node,
DataBlock *block,
DBusTypeWriter *writer,
int seed)
{
#ifdef DBUS_HAVE_INT64
/* also used for uint64 */
dbus_int64_t v;
v = int64_from_seed (seed);
return _dbus_type_writer_write_basic (writer,
node->klass->typecode,
&v);
#else
return TRUE;
#endif
}
static dbus_bool_t
int64_read_value (TestTypeNode *node,
DataBlock *block,
DBusTypeReader *reader,
int seed)
{
#ifdef DBUS_HAVE_INT64
/* also used for uint64 */
dbus_int64_t v;
check_expected_type (reader, node->klass->typecode);
_dbus_type_reader_read_basic (reader,
(dbus_int64_t*) &v);
_dbus_assert (v == int64_from_seed (seed));
return TRUE;
#else
return TRUE;
#endif
}
static dbus_bool_t
struct_N_write_value (TestTypeNode *node,
DataBlock *block,

View file

@ -1148,6 +1148,8 @@ _dbus_string_insert_8_aligned (DBusString *str,
if (!align_insert_point_then_open_gap (str, &insert_at, 8, 8))
return FALSE;
_dbus_assert (_DBUS_ALIGN_VALUE (insert_at, 8) == (unsigned) insert_at);
ASSIGN_8_OCTETS (real->str + insert_at, octets);
return TRUE;