Sophie

Sophie

distrib > Mandriva > 2007.0 > i586 > by-pkgid > ad1ba1135a9c9eeffc2e538163e00373 > files > 835

libCommonC++2_1.4-devel-1.4.1-1mdv2007.0.i586.rpm

\section{crc32.cpp}


\footnotesize\begin{verbatim}1 //  
2 // This program is free software; you can redistribute it and/or modify
3 // it under the terms of the GNU General Public License as published by
4 // the Free Software Foundation; either version 2 of the License, or
5 // (at your option) any later version.
6 // 
7 // This program is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 // GNU General Public License for more details.
11 //
12 // You should have received a copy of the GNU General Public License
13 // along with this program; if not, write to the Free Software 
14 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15 // 
16 // As a special exception to the GNU General Public License, permission is 
17 // granted for additional uses of the text contained in its release 
18 // of Common C++.
19 // 
20 // The exception is that, if you link the Common C++ library with other
21 // files to produce an executable, this does not by itself cause the
22 // resulting executable to be covered by the GNU General Public License.
23 // Your use of that executable is in no way restricted on account of
24 // linking the Common C++ library code into it.
25 //
26 // This exception does not however invalidate any other reasons why
27 // the executable file might be covered by the GNU General Public License.
28 //
29 // This exception applies only to the code released under the 
30 // name Common C++.  If you copy code from other releases into a copy of
31 // Common C++, as the General Public License permits, the exception does
32 // not apply to the code that you add in this way.  To avoid misleading
33 // anyone as to the status of such modified files, you must delete
34 // this exception notice from them.
35 //
36 // If you write modifications of your own for Common C++, it is your choice
37 // whether to permit this exception to apply to your modifications.
38 // If you do not wish that, delete this exception notice.
39 
40 #include <cc++/common.h>
41 
42 #ifdef  CCXX_NAMESPACES
43 using namespace std;
44 using namespace ost;
45 #endif
46 
47 
48 int main(int argc, char *argv[])
49  {
50    unsigned char test[44];
51    unsigned char buf[4];
52    unsigned long crc;
53    int i;
54    
55    cout << "CRC32 Algorithm Test\n\n";
56    
57    cout << "AAL-5 Test #1 - 40 Octets filled with \"0\" - ";
58    cout << "CRC32 = 0x864d7f99\n";
59 
60    for (i = 0; i < 40; i++)
61       test[i] = 0x0;
62    test[40] = test[41] = test[42] = 0x0;
63    test[43] = 0x28;
64    
65    CRC32Digest crc1;
66    crc1.putDigest(test, 44);
67    crc1.getDigest(buf);
68    crc = *(unsigned long *)buf;
69    cout << "Test #1 CRC32 = " << hex << crc << "\n\n";
70    if (crc == 0x864d7f99)
71       cout << "Test #1 PASSED\n\n\n";
72    else
73       cout << "Test #1 FAILED\n\n\n";
74    
75 
76    cout << "AAL-5 Test #2 - 40 Octets filled with \"1\" - ";
77    cout << "CRC32 = 0xc55e457a\n";
78 
79    for (i = 0; i < 40; i++)
80       test[i] = 0xFF;
81    test[40] = test[41] = test[42] = 0x0;
82    test[43] = 0x28;
83    
84    CRC32Digest crc2;
85    crc2.putDigest(test, 44);
86    crc2.getDigest(buf);
87    crc = *(unsigned long *)buf;
88    cout << "Test #2 CRC32 = " << hex << crc << "\n\n";
89    if (crc == 0xc55e457a)
90       cout << "Test #2 PASSED\n\n\n";
91    else
92       cout << "Test #2 FAILED\n\n\n";
93 
94    cout << "AAL-5 Test #3 - 40 Octets counting 1 to 40 - ";
95    cout << "CRC32 = 0xbf671ed0\n";
96 
97    for (i = 0; i < 40; i++)
98       test[i] = i+1;
99    test[40] = test[41] = test[42] = 0x0;
100    test[43] = 0x28;
101    
102    CRC32Digest crc3;
103    crc3.putDigest(test, 44);
104    crc3.getDigest(buf);
105    crc = *(unsigned long *)buf;
106    cout << "Test #3 CRC32 = " << hex << crc << "\n\n";
107    if (crc == 0xbf671ed0)
108       cout << "Test #3 PASSED\n\n\n";
109    else
110       cout << "Test #3 FAILED\n\n\n";
111 
112 }
\end{verbatim}
\normalsize