00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <config.h>
00025
00026 #ifdef DBUS_BUILD_TESTS
00027 #include "dbus-marshal-byteswap.h"
00028 #include "dbus-test.h"
00029 #include <stdio.h>
00030
00031 static void
00032 do_byteswap_test (int byte_order)
00033 {
00034 int sequence;
00035 DBusString signature;
00036 DBusString body;
00037 int opposite_order;
00038
00039 if (!_dbus_string_init (&signature) || !_dbus_string_init (&body))
00040 _dbus_assert_not_reached ("oom");
00041
00042 opposite_order = byte_order == DBUS_LITTLE_ENDIAN ? DBUS_BIG_ENDIAN : DBUS_LITTLE_ENDIAN;
00043
00044 sequence = 0;
00045 while (dbus_internal_do_not_use_generate_bodies (sequence,
00046 byte_order,
00047 &signature, &body))
00048 {
00049 DBusString copy;
00050 DBusTypeReader body_reader;
00051 DBusTypeReader copy_reader;
00052
00053 if (!_dbus_string_init (©))
00054 _dbus_assert_not_reached ("oom");
00055
00056 if (!_dbus_string_copy (&body, 0, ©, 0))
00057 _dbus_assert_not_reached ("oom");
00058
00059 _dbus_marshal_byteswap (&signature, 0,
00060 byte_order,
00061 opposite_order,
00062 ©, 0);
00063
00064 _dbus_type_reader_init (&body_reader, byte_order, &signature, 0,
00065 &body, 0);
00066 _dbus_type_reader_init (©_reader, opposite_order, &signature, 0,
00067 ©, 0);
00068
00069 if (!_dbus_type_reader_equal_values (&body_reader, ©_reader))
00070 {
00071 _dbus_verbose_bytes_of_string (&signature, 0,
00072 _dbus_string_get_length (&signature));
00073 _dbus_verbose_bytes_of_string (&body, 0,
00074 _dbus_string_get_length (&body));
00075 _dbus_verbose_bytes_of_string (©, 0,
00076 _dbus_string_get_length (©));
00077
00078 _dbus_warn ("Byte-swapped data did not have same values as original data\n");
00079 _dbus_assert_not_reached ("test failed");
00080 }
00081
00082 _dbus_string_free (©);
00083
00084 _dbus_string_set_length (&signature, 0);
00085 _dbus_string_set_length (&body, 0);
00086 ++sequence;
00087 }
00088
00089 _dbus_string_free (&signature);
00090 _dbus_string_free (&body);
00091
00092 printf (" %d blocks swapped from order '%c' to '%c'\n",
00093 sequence, byte_order, opposite_order);
00094 }
00095
00096 dbus_bool_t
00097 _dbus_marshal_byteswap_test (void)
00098 {
00099 do_byteswap_test (DBUS_LITTLE_ENDIAN);
00100 do_byteswap_test (DBUS_BIG_ENDIAN);
00101
00102 return TRUE;
00103 }
00104
00105 #endif