1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-marshal-byteswap-util.c Would be in dbus-marshal-byteswap.c but tests/bus only
4 * Copyright (C) 2005 Red Hat, Inc.
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #ifdef DBUS_BUILD_TESTS
27 #include "dbus-marshal-byteswap.h"
28 #include "dbus-test.h"
32 do_byteswap_test (int byte_order)
39 if (!_dbus_string_init (&signature) || !_dbus_string_init (&body))
40 _dbus_assert_not_reached ("oom");
42 opposite_order = byte_order == DBUS_LITTLE_ENDIAN ? DBUS_BIG_ENDIAN : DBUS_LITTLE_ENDIAN;
45 while (dbus_internal_do_not_use_generate_bodies (sequence,
50 DBusTypeReader body_reader;
51 DBusTypeReader copy_reader;
53 if (!_dbus_string_init (©))
54 _dbus_assert_not_reached ("oom");
56 if (!_dbus_string_copy (&body, 0, ©, 0))
57 _dbus_assert_not_reached ("oom");
59 _dbus_marshal_byteswap (&signature, 0,
64 _dbus_type_reader_init (&body_reader, byte_order, &signature, 0,
66 _dbus_type_reader_init (©_reader, opposite_order, &signature, 0,
69 if (!_dbus_type_reader_equal_values (&body_reader, ©_reader))
71 _dbus_verbose_bytes_of_string (&signature, 0,
72 _dbus_string_get_length (&signature));
73 _dbus_verbose_bytes_of_string (&body, 0,
74 _dbus_string_get_length (&body));
75 _dbus_verbose_bytes_of_string (©, 0,
76 _dbus_string_get_length (©));
78 _dbus_warn ("Byte-swapped data did not have same values as original data\n");
79 _dbus_assert_not_reached ("test failed");
82 _dbus_string_free (©);
84 _dbus_string_set_length (&signature, 0);
85 _dbus_string_set_length (&body, 0);
89 _dbus_string_free (&signature);
90 _dbus_string_free (&body);
92 printf (" %d blocks swapped from order '%c' to '%c'\n",
93 sequence, byte_order, opposite_order);
97 _dbus_marshal_byteswap_test (void)
99 do_byteswap_test (DBUS_LITTLE_ENDIAN);
100 do_byteswap_test (DBUS_BIG_ENDIAN);
105 #endif /* DBUS_BUILD_TESTS */