blob: 25f45ef28c2e813a034fb702cfead8e34a7c346e [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001//
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
43using namespace std;
44using namespace ost;
45#endif
46
47
48int main(int argc, char *argv[])
49 {
50 unsigned char test[44];
51 union {
52 unsigned char buf[4];
53 uint32 value;
54 } data;
55 uint32 crc;
56 int i;
57
58 cout << "CRC32 Algorithm Test\n\n";
59
60 cout << "AAL-5 Test #1 - 40 Octets filled with \"0\" - ";
61 cout << "CRC32 = 0x864d7f99\n";
62
63 for (i = 0; i < 40; i++)
64 test[i] = 0x0;
65 test[40] = test[41] = test[42] = 0x0;
66 test[43] = 0x28;
67
68 CRC32Digest crc1;
69 crc1.putDigest(test, 44);
70 crc1.getDigest(data.buf);
71 crc = data.value;
72 cout << "Test #1 CRC32 = " << hex << crc << "\n\n";
73 if (crc == 0x864d7f99)
74 cout << "Test #1 PASSED\n\n\n";
75 else
76 cout << "Test #1 FAILED\n\n\n";
77
78
79 cout << "AAL-5 Test #2 - 40 Octets filled with \"1\" - ";
80 cout << "CRC32 = 0xc55e457a\n";
81
82 for (i = 0; i < 40; i++)
83 test[i] = 0xFF;
84 test[40] = test[41] = test[42] = 0x0;
85 test[43] = 0x28;
86
87 CRC32Digest crc2;
88 crc2.putDigest(test, 44);
89 crc2.getDigest(data.buf);
90 crc = data.value;
91 cout << "Test #2 CRC32 = " << hex << crc << "\n\n";
92 if (crc == 0xc55e457a)
93 cout << "Test #2 PASSED\n\n\n";
94 else
95 cout << "Test #2 FAILED\n\n\n";
96
97 cout << "AAL-5 Test #3 - 40 Octets counting 1 to 40 - ";
98 cout << "CRC32 = 0xbf671ed0\n";
99
100 for (i = 0; i < 40; i++)
101 test[i] = i+1;
102 test[40] = test[41] = test[42] = 0x0;
103 test[43] = 0x28;
104
105 CRC32Digest crc3;
106 crc3.putDigest(test, 44);
107 crc3.getDigest(data.buf);
108 crc = data.value;
109 cout << "Test #3 CRC32 = " << hex << crc << "\n\n";
110 if (crc == 0xbf671ed0)
111 cout << "Test #3 PASSED\n\n\n";
112 else
113 cout << "Test #3 FAILED\n\n\n";
114
115}