<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <meta name="generator" content="Doxygen 1.8.5"/> <title>GNU CommonC++: crc32.cpp</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="dynsections.js"></script> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div, it is closed by doxygen! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">GNU CommonC++ </div> </td> </tr> </tbody> </table> </div> <!-- end header part --> <!-- Generated by Doxygen 1.8.5 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="examples.html"><span>Examples</span></a></li> </ul> </div> </div><!-- top --> <div class="header"> <div class="headertitle"> <div class="title">crc32.cpp</div> </div> </div><!--header--> <div class="contents"> <div class="fragment"><div class="line"><span class="comment">//</span></div> <div class="line"><span class="comment">// This program is free software; you can redistribute it and/or modify</span></div> <div class="line"><span class="comment">// it under the terms of the GNU General Public License as published by</span></div> <div class="line"><span class="comment">// the Free Software Foundation; either version 2 of the License, or</span></div> <div class="line"><span class="comment">// (at your option) any later version.</span></div> <div class="line"><span class="comment">//</span></div> <div class="line"><span class="comment">// This program is distributed in the hope that it will be useful,</span></div> <div class="line"><span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div> <div class="line"><span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></div> <div class="line"><span class="comment">// GNU General Public License for more details.</span></div> <div class="line"><span class="comment">//</span></div> <div class="line"><span class="comment">// You should have received a copy of the GNU General Public License</span></div> <div class="line"><span class="comment">// along with this program; if not, write to the Free Software</span></div> <div class="line"><span class="comment">// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.</span></div> <div class="line"><span class="comment">//</span></div> <div class="line"><span class="comment">// As a special exception to the GNU General Public License, permission is</span></div> <div class="line"><span class="comment">// granted for additional uses of the text contained in its release</span></div> <div class="line"><span class="comment">// of Common C++.</span></div> <div class="line"><span class="comment">//</span></div> <div class="line"><span class="comment">// The exception is that, if you link the Common C++ library with other</span></div> <div class="line"><span class="comment">// files to produce an executable, this does not by itself cause the</span></div> <div class="line"><span class="comment">// resulting executable to be covered by the GNU General Public License.</span></div> <div class="line"><span class="comment">// Your use of that executable is in no way restricted on account of</span></div> <div class="line"><span class="comment">// linking the Common C++ library code into it.</span></div> <div class="line"><span class="comment">//</span></div> <div class="line"><span class="comment">// This exception does not however invalidate any other reasons why</span></div> <div class="line"><span class="comment">// the executable file might be covered by the GNU General Public License.</span></div> <div class="line"><span class="comment">//</span></div> <div class="line"><span class="comment">// This exception applies only to the code released under the</span></div> <div class="line"><span class="comment">// name Common C++. If you copy code from other releases into a copy of</span></div> <div class="line"><span class="comment">// Common C++, as the General Public License permits, the exception does</span></div> <div class="line"><span class="comment">// not apply to the code that you add in this way. To avoid misleading</span></div> <div class="line"><span class="comment">// anyone as to the status of such modified files, you must delete</span></div> <div class="line"><span class="comment">// this exception notice from them.</span></div> <div class="line"><span class="comment">//</span></div> <div class="line"><span class="comment">// If you write modifications of your own for Common C++, it is your choice</span></div> <div class="line"><span class="comment">// whether to permit this exception to apply to your modifications.</span></div> <div class="line"><span class="comment">// If you do not wish that, delete this exception notice.</span></div> <div class="line"></div> <div class="line"><span class="preprocessor">#include <<a class="code" href="common_8h.html">cc++/common.h</a>></span></div> <div class="line"></div> <div class="line"><span class="preprocessor">#ifdef CCXX_NAMESPACES</span></div> <div class="line"><span class="preprocessor"></span><span class="keyword">using namespace </span>std;</div> <div class="line"><span class="keyword">using namespace </span>ost;</div> <div class="line"><span class="preprocessor">#endif</span></div> <div class="line"><span class="preprocessor"></span></div> <div class="line"></div> <div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])</div> <div class="line"> {</div> <div class="line"> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> test[44];</div> <div class="line"> <span class="keyword">union </span>{</div> <div class="line"> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[4];</div> <div class="line"> <a class="code" href="config_8h.html#a945d766905ae60477daf7c8846d80f9b">uint32</a> value;</div> <div class="line"> } data;</div> <div class="line"> <a class="code" href="config_8h.html#a945d766905ae60477daf7c8846d80f9b">uint32</a> crc;</div> <div class="line"> <span class="keywordtype">int</span> i;</div> <div class="line"></div> <div class="line"> cout << <span class="stringliteral">"CRC32 Algorithm Test\n\n"</span>;</div> <div class="line"></div> <div class="line"> cout << <span class="stringliteral">"AAL-5 Test #1 - 40 Octets filled with \"0\" - "</span>;</div> <div class="line"> cout << <span class="stringliteral">"CRC32 = 0x864d7f99\n"</span>;</div> <div class="line"></div> <div class="line"> <span class="keywordflow">for</span> (i = 0; i < 40; i++)</div> <div class="line"> test[i] = 0x0;</div> <div class="line"> test[40] = test[41] = test[42] = 0x0;</div> <div class="line"> test[43] = 0x28;</div> <div class="line"></div> <div class="line"> <a name="_a0"></a><a class="code" href="classost_1_1_c_r_c32_digest.html">CRC32Digest</a> crc1;</div> <div class="line"> crc1.<a name="a1"></a><a class="code" href="classost_1_1_c_r_c32_digest.html#a2eaff9b0e5fa824b8f16c69b673b3174">putDigest</a>(test, 44);</div> <div class="line"> crc1.<a name="a2"></a><a class="code" href="classost_1_1_c_r_c32_digest.html#a979761cf1d4d54c376a3b41f713da91a">getDigest</a>(data.buf);</div> <div class="line"> crc = data.value;</div> <div class="line"> cout << <span class="stringliteral">"Test #1 CRC32 = "</span> << hex << crc << <span class="stringliteral">"\n\n"</span>;</div> <div class="line"> <span class="keywordflow">if</span> (crc == 0x864d7f99)</div> <div class="line"> cout << <span class="stringliteral">"Test #1 PASSED\n\n\n"</span>;</div> <div class="line"> <span class="keywordflow">else</span></div> <div class="line"> cout << <span class="stringliteral">"Test #1 FAILED\n\n\n"</span>;</div> <div class="line"></div> <div class="line"></div> <div class="line"> cout << <span class="stringliteral">"AAL-5 Test #2 - 40 Octets filled with \"1\" - "</span>;</div> <div class="line"> cout << <span class="stringliteral">"CRC32 = 0xc55e457a\n"</span>;</div> <div class="line"></div> <div class="line"> <span class="keywordflow">for</span> (i = 0; i < 40; i++)</div> <div class="line"> test[i] = 0xFF;</div> <div class="line"> test[40] = test[41] = test[42] = 0x0;</div> <div class="line"> test[43] = 0x28;</div> <div class="line"></div> <div class="line"> <a class="code" href="classost_1_1_c_r_c32_digest.html">CRC32Digest</a> crc2;</div> <div class="line"> crc2.<a class="code" href="classost_1_1_c_r_c32_digest.html#a2eaff9b0e5fa824b8f16c69b673b3174">putDigest</a>(test, 44);</div> <div class="line"> crc2.<a class="code" href="classost_1_1_c_r_c32_digest.html#a979761cf1d4d54c376a3b41f713da91a">getDigest</a>(data.buf);</div> <div class="line"> crc = data.value;</div> <div class="line"> cout << <span class="stringliteral">"Test #2 CRC32 = "</span> << hex << crc << <span class="stringliteral">"\n\n"</span>;</div> <div class="line"> <span class="keywordflow">if</span> (crc == 0xc55e457a)</div> <div class="line"> cout << <span class="stringliteral">"Test #2 PASSED\n\n\n"</span>;</div> <div class="line"> <span class="keywordflow">else</span></div> <div class="line"> cout << <span class="stringliteral">"Test #2 FAILED\n\n\n"</span>;</div> <div class="line"></div> <div class="line"> cout << <span class="stringliteral">"AAL-5 Test #3 - 40 Octets counting 1 to 40 - "</span>;</div> <div class="line"> cout << <span class="stringliteral">"CRC32 = 0xbf671ed0\n"</span>;</div> <div class="line"></div> <div class="line"> <span class="keywordflow">for</span> (i = 0; i < 40; i++)</div> <div class="line"> test[i] = i+1;</div> <div class="line"> test[40] = test[41] = test[42] = 0x0;</div> <div class="line"> test[43] = 0x28;</div> <div class="line"></div> <div class="line"> <a class="code" href="classost_1_1_c_r_c32_digest.html">CRC32Digest</a> crc3;</div> <div class="line"> crc3.<a class="code" href="classost_1_1_c_r_c32_digest.html#a2eaff9b0e5fa824b8f16c69b673b3174">putDigest</a>(test, 44);</div> <div class="line"> crc3.<a class="code" href="classost_1_1_c_r_c32_digest.html#a979761cf1d4d54c376a3b41f713da91a">getDigest</a>(data.buf);</div> <div class="line"> crc = data.value;</div> <div class="line"> cout << <span class="stringliteral">"Test #3 CRC32 = "</span> << hex << crc << <span class="stringliteral">"\n\n"</span>;</div> <div class="line"> <span class="keywordflow">if</span> (crc == 0xbf671ed0)</div> <div class="line"> cout << <span class="stringliteral">"Test #3 PASSED\n\n\n"</span>;</div> <div class="line"> <span class="keywordflow">else</span></div> <div class="line"> cout << <span class="stringliteral">"Test #3 FAILED\n\n\n"</span>;</div> <div class="line"></div> <div class="line">}</div> </div><!-- fragment --> </div><!-- contents --> <!-- start footer part --> <hr class="footer"/><address class="footer"><small> Generated on Thu Oct 17 2013 23:24:56 for GNU CommonC++ by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.8.5 </small></address> </body> </html>