File: //usr/share/devhelp/books/dbus/api/dbus-marshal-byteswap-util_8c-source.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>D-Bus: dbus-marshal-byteswap-util.c Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.7 -->
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Data Structures</span></a></li>
<li id="current"><a href="files.html"><span>Files</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
</ul></div>
<h1>dbus-marshal-byteswap-util.c</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */</span>
<a name="l00002"></a>00002 <span class="comment">/* dbus-marshal-byteswap-util.c Would be in dbus-marshal-byteswap.c but tests/bus only</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Copyright (C) 2005 Red Hat, Inc.</span>
<a name="l00005"></a>00005 <span class="comment"> *</span>
<a name="l00006"></a>00006 <span class="comment"> * Licensed under the Academic Free License version 2.1</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
<a name="l00009"></a>00009 <span class="comment"> * it under the terms of the GNU General Public License as published by</span>
<a name="l00010"></a>00010 <span class="comment"> * the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00011"></a>00011 <span class="comment"> * (at your option) any later version.</span>
<a name="l00012"></a>00012 <span class="comment"> *</span>
<a name="l00013"></a>00013 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
<a name="l00014"></a>00014 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00015"></a>00015 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<a name="l00016"></a>00016 <span class="comment"> * GNU General Public License for more details.</span>
<a name="l00017"></a>00017 <span class="comment"> *</span>
<a name="l00018"></a>00018 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
<a name="l00019"></a>00019 <span class="comment"> * along with this program; if not, write to the Free Software</span>
<a name="l00020"></a>00020 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
<a name="l00021"></a>00021 <span class="comment"> *</span>
<a name="l00022"></a>00022 <span class="comment"> */</span>
<a name="l00023"></a>00023
<a name="l00024"></a>00024 <span class="preprocessor">#include <config.h></span>
<a name="l00025"></a>00025
<a name="l00026"></a>00026 <span class="preprocessor">#ifdef DBUS_BUILD_TESTS </span>
<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#include "dbus-marshal-byteswap.h"</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include "dbus-test.h"</span>
<a name="l00029"></a>00029 <span class="preprocessor">#include <stdio.h></span>
<a name="l00030"></a>00030
<a name="l00031"></a>00031 <span class="keyword">static</span> <span class="keywordtype">void</span>
<a name="l00032"></a>00032 do_byteswap_test (<span class="keywordtype">int</span> byte_order)
<a name="l00033"></a>00033 {
<a name="l00034"></a>00034 <span class="keywordtype">int</span> sequence;
<a name="l00035"></a>00035 <a class="code" href="structDBusString.html">DBusString</a> signature;
<a name="l00036"></a>00036 <a class="code" href="structDBusString.html">DBusString</a> body;
<a name="l00037"></a>00037 <span class="keywordtype">int</span> opposite_order;
<a name="l00038"></a>00038
<a name="l00039"></a>00039 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#g348252317f7bb8ac43529972945830ae">_dbus_string_init</a> (&signature) || !<a class="code" href="group__DBusString.html#g348252317f7bb8ac43529972945830ae">_dbus_string_init</a> (&body))
<a name="l00040"></a>00040 <a class="code" href="group__DBusInternalsUtils.html#g0c4961ec784874f1b1f3aeccea8d3da1">_dbus_assert_not_reached</a> (<span class="stringliteral">"oom"</span>);
<a name="l00041"></a>00041
<a name="l00042"></a>00042 opposite_order = byte_order == <a class="code" href="group__DBusProtocol.html#gae5e00bf9091a457e5bb3f9a75d982ca">DBUS_LITTLE_ENDIAN</a> ? <a class="code" href="group__DBusProtocol.html#ged8596f854e755344dfbc811a73b0757">DBUS_BIG_ENDIAN</a> : <a class="code" href="group__DBusProtocol.html#gae5e00bf9091a457e5bb3f9a75d982ca">DBUS_LITTLE_ENDIAN</a>;
<a name="l00043"></a>00043
<a name="l00044"></a>00044 sequence = 0;
<a name="l00045"></a>00045 <span class="keywordflow">while</span> (dbus_internal_do_not_use_generate_bodies (sequence,
<a name="l00046"></a>00046 byte_order,
<a name="l00047"></a>00047 &signature, &body))
<a name="l00048"></a>00048 {
<a name="l00049"></a>00049 <a class="code" href="structDBusString.html">DBusString</a> copy;
<a name="l00050"></a>00050 <a class="code" href="structDBusTypeReader.html">DBusTypeReader</a> body_reader;
<a name="l00051"></a>00051 <a class="code" href="structDBusTypeReader.html">DBusTypeReader</a> copy_reader;
<a name="l00052"></a>00052
<a name="l00053"></a>00053 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#g348252317f7bb8ac43529972945830ae">_dbus_string_init</a> (&copy))
<a name="l00054"></a>00054 <a class="code" href="group__DBusInternalsUtils.html#g0c4961ec784874f1b1f3aeccea8d3da1">_dbus_assert_not_reached</a> (<span class="stringliteral">"oom"</span>);
<a name="l00055"></a>00055
<a name="l00056"></a>00056 <span class="keywordflow">if</span> (!<a class="code" href="group__DBusString.html#g3c10f0d1bcaa3b450025b9c6a8b901d7">_dbus_string_copy</a> (&body, 0, &copy, 0))
<a name="l00057"></a>00057 <a class="code" href="group__DBusInternalsUtils.html#g0c4961ec784874f1b1f3aeccea8d3da1">_dbus_assert_not_reached</a> (<span class="stringliteral">"oom"</span>);
<a name="l00058"></a>00058
<a name="l00059"></a>00059 <a class="code" href="group__DBusMarshal.html#g609a4b8c0b65096890766fda73a4c40f">_dbus_marshal_byteswap</a> (&signature, 0,
<a name="l00060"></a>00060 byte_order,
<a name="l00061"></a>00061 opposite_order,
<a name="l00062"></a>00062 &copy, 0);
<a name="l00063"></a>00063
<a name="l00064"></a>00064 <a class="code" href="group__DBusMarshal.html#g35d70cf69b1196518367e3e68e9b2dd2">_dbus_type_reader_init</a> (&body_reader, byte_order, &signature, 0,
<a name="l00065"></a>00065 &body, 0);
<a name="l00066"></a>00066 <a class="code" href="group__DBusMarshal.html#g35d70cf69b1196518367e3e68e9b2dd2">_dbus_type_reader_init</a> (&copy_reader, opposite_order, &signature, 0,
<a name="l00067"></a>00067 &copy, 0);
<a name="l00068"></a>00068
<a name="l00069"></a>00069 <span class="keywordflow">if</span> (!_dbus_type_reader_equal_values (&body_reader, &copy_reader))
<a name="l00070"></a>00070 {
<a name="l00071"></a>00071 <a class="code" href="group__DBusMarshal.html#g3926bb35edf78d114cf0c341fe3258e0">_dbus_verbose_bytes_of_string</a> (&signature, 0,
<a name="l00072"></a>00072 _dbus_string_get_length (&signature));
<a name="l00073"></a>00073 <a class="code" href="group__DBusMarshal.html#g3926bb35edf78d114cf0c341fe3258e0">_dbus_verbose_bytes_of_string</a> (&body, 0,
<a name="l00074"></a>00074 _dbus_string_get_length (&body));
<a name="l00075"></a>00075 <a class="code" href="group__DBusMarshal.html#g3926bb35edf78d114cf0c341fe3258e0">_dbus_verbose_bytes_of_string</a> (&copy, 0,
<a name="l00076"></a>00076 _dbus_string_get_length (&copy));
<a name="l00077"></a>00077
<a name="l00078"></a>00078 <a class="code" href="group__DBusInternalsUtils.html#gbea2c16d6d3fe7c4eb5b9496fc877f84">_dbus_warn</a> (<span class="stringliteral">"Byte-swapped data did not have same values as original data\n"</span>);
<a name="l00079"></a>00079 <a class="code" href="group__DBusInternalsUtils.html#g0c4961ec784874f1b1f3aeccea8d3da1">_dbus_assert_not_reached</a> (<span class="stringliteral">"test failed"</span>);
<a name="l00080"></a>00080 }
<a name="l00081"></a>00081
<a name="l00082"></a>00082 <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&copy);
<a name="l00083"></a>00083
<a name="l00084"></a>00084 <a class="code" href="group__DBusString.html#g08c423b93c28dd746dcb93e0461ab95c">_dbus_string_set_length</a> (&signature, 0);
<a name="l00085"></a>00085 <a class="code" href="group__DBusString.html#g08c423b93c28dd746dcb93e0461ab95c">_dbus_string_set_length</a> (&body, 0);
<a name="l00086"></a>00086 ++sequence;
<a name="l00087"></a>00087 }
<a name="l00088"></a>00088
<a name="l00089"></a>00089 <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&signature);
<a name="l00090"></a>00090 <a class="code" href="group__DBusString.html#g781ca91acda49a834dce7d0ed0eef212">_dbus_string_free</a> (&body);
<a name="l00091"></a>00091
<a name="l00092"></a>00092 printf (<span class="stringliteral">" %d blocks swapped from order '%c' to '%c'\n"</span>,
<a name="l00093"></a>00093 sequence, byte_order, opposite_order);
<a name="l00094"></a>00094 }
<a name="l00095"></a>00095
<a name="l00096"></a>00096 <a class="code" href="group__DBusTypes.html#g39c9cb0f3a2a8ad6f55cc4855d035349">dbus_bool_t</a>
<a name="l00097"></a>00097 _dbus_marshal_byteswap_test (<span class="keywordtype">void</span>)
<a name="l00098"></a>00098 {
<a name="l00099"></a>00099 do_byteswap_test (<a class="code" href="group__DBusProtocol.html#gae5e00bf9091a457e5bb3f9a75d982ca">DBUS_LITTLE_ENDIAN</a>);
<a name="l00100"></a>00100 do_byteswap_test (<a class="code" href="group__DBusProtocol.html#ged8596f854e755344dfbc811a73b0757">DBUS_BIG_ENDIAN</a>);
<a name="l00101"></a>00101
<a name="l00102"></a>00102 <span class="keywordflow">return</span> <a class="code" href="group__DBusMacros.html#ga8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;
<a name="l00103"></a>00103 }
<a name="l00104"></a>00104
<a name="l00105"></a>00105 <span class="preprocessor">#endif </span><span class="comment">/* DBUS_BUILD_TESTS */</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Dec 14 22:26:11 2009 for D-Bus by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
</body>
</html>