• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Bitwise comparison</title>
5<link rel="stylesheet" href="../../../boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../../../index.html" title="Boost.Test">
8<link rel="up" href="../extended_comparison.html" title="Extended comparisons support">
9<link rel="prev" href="collections.html" title="Collections comparison">
10<link rel="next" href="../exception_correctness.html" title="Exception correctness">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="collections.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../extended_comparison.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../exception_correctness.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h4 class="title">
27<a name="boost_test.testing_tools.extended_comparison.bitwise"></a><a class="link" href="bitwise.html" title="Bitwise comparison">Bitwise
28        comparison</a>
29</h4></div></div></div>
30<div class="caution"><table border="0" summary="Caution">
31<tr>
32<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../doc/src/images/caution.png"></td>
33<th align="left">Caution</th>
34</tr>
35<tr><td align="left" valign="top"><p>
36            this feature is not available for non C++11 compilers.
37          </p></td></tr>
38</table></div>
39<p>
40          The manipulator <code class="computeroutput"><a class="link" href="../../../boost/test_tools/bitwise.html" title="Struct bitwise">boost::test_tools::bitwise</a></code>
41          can be provided to the <a class="link" href="../../utf_reference/testing_tool_ref/assertion_boost_test_universal_macro.html" title="BOOST_TEST"><code class="computeroutput"><span class="identifier">BOOST_TEST</span></code></a> macro in order to have
42          a bitwise comparison of the operands. In that case, the <span class="emphasis"><em>Unit
43          Test Framework</em></span> indicates the bit indices where the two operands
44          do not match.
45        </p>
46<h6>
47<a name="boost_test.testing_tools.extended_comparison.bitwise.h0"></a>
48          <span class="phrase"><a name="boost_test.testing_tools.extended_comparison.bitwise.example_descr"></a></span><a class="link" href="bitwise.html#boost_test.testing_tools.extended_comparison.bitwise.example_descr">Example:
49          BOOST_TEST bitwise comparison</a>
50        </h6>
51<div class="informaltable"><table class="table">
52<colgroup><col></colgroup>
53<thead><tr><th>
54                  <p>
55                    Code
56                  </p>
57                </th></tr></thead>
58<tbody><tr><td>
59<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">boost_test_bitwise</span>
60<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">included</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
61<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">sstream</span><span class="special">&gt;</span>
62
63<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span><span class="identifier">test_bitwise</span><span class="special">)</span>
64<span class="special">{</span>
65  <span class="keyword">namespace</span> <span class="identifier">tt</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">test_tools</span><span class="special">;</span>
66  <span class="keyword">int</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">0xAB</span><span class="special">;</span>
67  <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="identifier">a</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&amp;</span> <span class="special">~</span><span class="number">1</span><span class="special">),</span> <span class="identifier">tt</span><span class="special">::</span><span class="identifier">bitwise</span><span class="special">()</span> <span class="special">);</span>
68  <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="identifier">a</span> <span class="special">==</span> <span class="identifier">a</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">tt</span><span class="special">::</span><span class="identifier">bitwise</span><span class="special">()</span> <span class="special">);</span>
69  <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="identifier">a</span> <span class="special">!=</span> <span class="identifier">a</span> <span class="special">+</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">tt</span><span class="special">::</span><span class="identifier">bitwise</span><span class="special">()</span> <span class="special">);</span>
70  <span class="keyword">int</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">0x88</span><span class="special">;</span>
71  <span class="identifier">BOOST_TEST</span><span class="special">(</span> <span class="identifier">a</span> <span class="special">==</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">tt</span><span class="special">::</span><span class="identifier">bitwise</span><span class="special">()</span> <span class="special">);</span>
72<span class="special">}</span>
73</pre>
74                </td></tr></tbody>
75</table></div>
76<div class="informaltable"><table class="table">
77<colgroup><col></colgroup>
78<thead><tr><th>
79                  <p>
80                    Output
81                  </p>
82                </th></tr></thead>
83<tbody><tr><td>
84<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="special">./</span><span class="identifier">boost_test_bitwise</span> <span class="special">--</span><span class="identifier">log_level</span><span class="special">=</span><span class="identifier">all</span>
85<span class="identifier">Running</span> <span class="number">1</span> <span class="identifier">test</span> <span class="keyword">case</span><span class="special">...</span>
86<span class="identifier">Entering</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_bitwise"</span>
87<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">13</span><span class="special">):</span> <span class="identifier">Entering</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_bitwise"</span>
88<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">17</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_bitwise"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">==</span> <span class="special">(</span><span class="identifier">a</span> <span class="special">&amp;</span> <span class="special">~</span><span class="number">1</span><span class="special">)</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">171</span> <span class="special">!=</span> <span class="number">170</span><span class="special">].</span> <span class="identifier">Bitwise</span> <span class="identifier">comparison</span> <span class="identifier">failed</span>
89<span class="identifier">Mismatch</span> <span class="identifier">at</span> <span class="identifier">position</span> <span class="number">0</span>
90<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">18</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_bitwise"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">==</span> <span class="identifier">a</span> <span class="special">+</span> <span class="number">1</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">171</span> <span class="special">!=</span> <span class="number">172</span><span class="special">].</span> <span class="identifier">Bitwise</span> <span class="identifier">comparison</span> <span class="identifier">failed</span>
91<span class="identifier">Mismatch</span> <span class="identifier">at</span> <span class="identifier">position</span> <span class="number">0</span>
92<span class="identifier">Mismatch</span> <span class="identifier">at</span> <span class="identifier">position</span> <span class="number">1</span>
93<span class="identifier">Mismatch</span> <span class="identifier">at</span> <span class="identifier">position</span> <span class="number">2</span>
94<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">19</span><span class="special">):</span> <span class="identifier">info</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">!=</span> <span class="identifier">a</span> <span class="special">+</span> <span class="number">1</span> <span class="identifier">has</span> <span class="identifier">passed</span>
95<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">21</span><span class="special">):</span> <span class="identifier">error</span><span class="special">:</span> <span class="identifier">in</span> <span class="string">"test_bitwise"</span><span class="special">:</span> <span class="identifier">check</span> <span class="identifier">a</span> <span class="special">==</span> <span class="identifier">b</span> <span class="identifier">has</span> <span class="identifier">failed</span> <span class="special">[</span><span class="number">171</span> <span class="special">!=</span> <span class="number">136</span><span class="special">].</span> <span class="identifier">Bitwise</span> <span class="identifier">comparison</span> <span class="identifier">failed</span>
96<span class="identifier">Mismatch</span> <span class="identifier">at</span> <span class="identifier">position</span> <span class="number">0</span>
97<span class="identifier">Mismatch</span> <span class="identifier">at</span> <span class="identifier">position</span> <span class="number">1</span>
98<span class="identifier">Mismatch</span> <span class="identifier">at</span> <span class="identifier">position</span> <span class="number">5</span>
99<span class="identifier">test</span><span class="special">.</span><span class="identifier">cpp</span><span class="special">(</span><span class="number">13</span><span class="special">):</span> <span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="keyword">case</span> <span class="string">"test_bitwise"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">627u</span><span class="identifier">s</span>
100<span class="identifier">Leaving</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_bitwise"</span><span class="special">;</span> <span class="identifier">testing</span> <span class="identifier">time</span><span class="special">:</span> <span class="number">772u</span><span class="identifier">s</span>
101
102<span class="special">***</span> <span class="number">3</span> <span class="identifier">failures</span> <span class="identifier">are</span> <span class="identifier">detected</span> <span class="identifier">in</span> <span class="identifier">the</span> <span class="identifier">test</span> <span class="identifier">module</span> <span class="string">"boost_test_bitwise"</span>
103</pre>
104                </td></tr></tbody>
105</table></div>
106<div class="note"><table border="0" summary="Note">
107<tr>
108<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/src/images/note.png"></td>
109<th align="left">Note</th>
110</tr>
111<tr><td align="left" valign="top"><p>
112            the indices start at least significant bit.
113          </p></td></tr>
114</table></div>
115</div>
116<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
117<td align="left"></td>
118<td align="right"><div class="copyright-footer">Copyright © 2001-2020 Boost.Test contributors<p>
119        Distributed under the Boost Software License, Version 1.0. (See accompanying
120        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
121      </p>
122</div></td>
123</tr></table>
124<hr>
125<div class="spirit-nav">
126<a accesskey="p" href="collections.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../extended_comparison.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="../exception_correctness.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
127</div>
128</body>
129</html>
130