2007-07-14 02:44:01 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
2005-01-27 23:39:26 +00:00
|
|
|
/* dbus-marshal-byteswap-util.c Would be in dbus-marshal-byteswap.c but tests/bus only
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2005 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Academic Free License version 2.1
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2009-07-10 19:32:38 -04:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-01-27 23:39:26 +00:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2018-09-28 16:36:49 +01:00
|
|
|
#include "misc-internals.h"
|
|
|
|
|
|
2013-06-28 16:25:54 +08:00
|
|
|
#ifdef DBUS_ENABLE_EMBEDDED_TESTS
|
2018-09-28 16:36:49 +01:00
|
|
|
#include "dbus/dbus-marshal-byteswap.h"
|
|
|
|
|
#include "dbus/dbus-test.h"
|
2017-11-14 14:09:59 +00:00
|
|
|
#include <dbus/dbus-test-tap.h>
|
2005-01-27 23:39:26 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2018-09-28 16:36:49 +01:00
|
|
|
#include "dbus-marshal-recursive-util.h"
|
|
|
|
|
|
2005-01-27 23:39:26 +00:00
|
|
|
static void
|
|
|
|
|
do_byteswap_test (int byte_order)
|
|
|
|
|
{
|
|
|
|
|
int sequence;
|
|
|
|
|
DBusString signature;
|
|
|
|
|
DBusString body;
|
|
|
|
|
int opposite_order;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (&signature) || !_dbus_string_init (&body))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("oom");
|
2005-01-27 23:39:26 +00:00
|
|
|
|
|
|
|
|
opposite_order = byte_order == DBUS_LITTLE_ENDIAN ? DBUS_BIG_ENDIAN : DBUS_LITTLE_ENDIAN;
|
2018-12-17 11:34:41 +00:00
|
|
|
|
2005-01-27 23:39:26 +00:00
|
|
|
sequence = 0;
|
2018-07-23 17:29:56 +01:00
|
|
|
while (_dbus_test_generate_bodies (sequence, byte_order, &signature, &body))
|
2005-01-27 23:39:26 +00:00
|
|
|
{
|
|
|
|
|
DBusString copy;
|
|
|
|
|
DBusTypeReader body_reader;
|
|
|
|
|
DBusTypeReader copy_reader;
|
|
|
|
|
|
|
|
|
|
if (!_dbus_string_init (©))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("oom");
|
2005-01-27 23:39:26 +00:00
|
|
|
|
|
|
|
|
if (!_dbus_string_copy (&body, 0, ©, 0))
|
2017-11-14 14:17:53 +00:00
|
|
|
_dbus_test_fatal ("oom");
|
2005-01-27 23:39:26 +00:00
|
|
|
|
|
|
|
|
_dbus_marshal_byteswap (&signature, 0,
|
|
|
|
|
byte_order,
|
|
|
|
|
opposite_order,
|
|
|
|
|
©, 0);
|
|
|
|
|
|
|
|
|
|
_dbus_type_reader_init (&body_reader, byte_order, &signature, 0,
|
|
|
|
|
&body, 0);
|
|
|
|
|
_dbus_type_reader_init (©_reader, opposite_order, &signature, 0,
|
|
|
|
|
©, 0);
|
2018-12-17 11:34:41 +00:00
|
|
|
|
2005-01-27 23:39:26 +00:00
|
|
|
if (!_dbus_type_reader_equal_values (&body_reader, ©_reader))
|
|
|
|
|
{
|
|
|
|
|
_dbus_verbose_bytes_of_string (&signature, 0,
|
|
|
|
|
_dbus_string_get_length (&signature));
|
|
|
|
|
_dbus_verbose_bytes_of_string (&body, 0,
|
|
|
|
|
_dbus_string_get_length (&body));
|
|
|
|
|
_dbus_verbose_bytes_of_string (©, 0,
|
|
|
|
|
_dbus_string_get_length (©));
|
|
|
|
|
|
2017-11-14 14:13:45 +00:00
|
|
|
_dbus_test_fatal ("Byte-swapped data did not have same values as original data");
|
2005-01-27 23:39:26 +00:00
|
|
|
}
|
2018-12-17 11:34:41 +00:00
|
|
|
|
2005-01-27 23:39:26 +00:00
|
|
|
_dbus_string_free (©);
|
2018-12-17 11:34:41 +00:00
|
|
|
|
2005-01-27 23:39:26 +00:00
|
|
|
_dbus_string_set_length (&signature, 0);
|
|
|
|
|
_dbus_string_set_length (&body, 0);
|
|
|
|
|
++sequence;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_dbus_string_free (&signature);
|
|
|
|
|
_dbus_string_free (&body);
|
|
|
|
|
|
2017-11-14 14:09:59 +00:00
|
|
|
_dbus_test_diag (" %d blocks swapped from order '%c' to '%c'",
|
2005-01-27 23:39:26 +00:00
|
|
|
sequence, byte_order, opposite_order);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_bool_t
|
2018-09-03 12:18:39 -07:00
|
|
|
_dbus_marshal_byteswap_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
|
2005-01-27 23:39:26 +00:00
|
|
|
{
|
|
|
|
|
do_byteswap_test (DBUS_LITTLE_ENDIAN);
|
|
|
|
|
do_byteswap_test (DBUS_BIG_ENDIAN);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-28 16:25:54 +08:00
|
|
|
#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
|