crc32.cpp

00001 //
00002 // This program is free software; you can redistribute it and/or modify
00003 // it under the terms of the GNU General Public License as published by
00004 // the Free Software Foundation; either version 2 of the License, or
00005 // (at your option) any later version.
00006 //
00007 // This program is distributed in the hope that it will be useful,
00008 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 // GNU General Public License for more details.
00011 //
00012 // You should have received a copy of the GNU General Public License
00013 // along with this program; if not, write to the Free Software
00014 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00015 //
00016 // As a special exception to the GNU General Public License, permission is
00017 // granted for additional uses of the text contained in its release
00018 // of Common C++.
00019 //
00020 // The exception is that, if you link the Common C++ library with other
00021 // files to produce an executable, this does not by itself cause the
00022 // resulting executable to be covered by the GNU General Public License.
00023 // Your use of that executable is in no way restricted on account of
00024 // linking the Common C++ library code into it.
00025 //
00026 // This exception does not however invalidate any other reasons why
00027 // the executable file might be covered by the GNU General Public License.
00028 //
00029 // This exception applies only to the code released under the
00030 // name Common C++.  If you copy code from other releases into a copy of
00031 // Common C++, as the General Public License permits, the exception does
00032 // not apply to the code that you add in this way.  To avoid misleading
00033 // anyone as to the status of such modified files, you must delete
00034 // this exception notice from them.
00035 //
00036 // If you write modifications of your own for Common C++, it is your choice
00037 // whether to permit this exception to apply to your modifications.
00038 // If you do not wish that, delete this exception notice.
00039 
00040 #include <cc++/common.h>
00041 
00042 #ifdef  CCXX_NAMESPACES
00043 using namespace std;
00044 using namespace ost;
00045 #endif
00046 
00047 
00048 int main(int argc, char *argv[])
00049  {
00050    unsigned char test[44];
00051    unsigned char buf[4];
00052    unsigned long crc;
00053    int i;
00054 
00055    cout << "CRC32 Algorithm Test\n\n";
00056 
00057    cout << "AAL-5 Test #1 - 40 Octets filled with \"0\" - ";
00058    cout << "CRC32 = 0x864d7f99\n";
00059 
00060    for (i = 0; i < 40; i++)
00061           test[i] = 0x0;
00062    test[40] = test[41] = test[42] = 0x0;
00063    test[43] = 0x28;
00064 
00065    CRC32Digest crc1;
00066    crc1.putDigest(test, 44);
00067    crc1.getDigest(buf);
00068    crc = *(unsigned long *)buf;
00069    cout << "Test #1 CRC32 = " << hex << crc << "\n\n";
00070    if (crc == 0x864d7f99)
00071           cout << "Test #1 PASSED\n\n\n";
00072    else
00073           cout << "Test #1 FAILED\n\n\n";
00074 
00075 
00076    cout << "AAL-5 Test #2 - 40 Octets filled with \"1\" - ";
00077    cout << "CRC32 = 0xc55e457a\n";
00078 
00079    for (i = 0; i < 40; i++)
00080           test[i] = 0xFF;
00081    test[40] = test[41] = test[42] = 0x0;
00082    test[43] = 0x28;
00083 
00084    CRC32Digest crc2;
00085    crc2.putDigest(test, 44);
00086    crc2.getDigest(buf);
00087    crc = *(unsigned long *)buf;
00088    cout << "Test #2 CRC32 = " << hex << crc << "\n\n";
00089    if (crc == 0xc55e457a)
00090           cout << "Test #2 PASSED\n\n\n";
00091    else
00092           cout << "Test #2 FAILED\n\n\n";
00093 
00094    cout << "AAL-5 Test #3 - 40 Octets counting 1 to 40 - ";
00095    cout << "CRC32 = 0xbf671ed0\n";
00096 
00097    for (i = 0; i < 40; i++)
00098           test[i] = i+1;
00099    test[40] = test[41] = test[42] = 0x0;
00100    test[43] = 0x28;
00101 
00102    CRC32Digest crc3;
00103    crc3.putDigest(test, 44);
00104    crc3.getDigest(buf);
00105    crc = *(unsigned long *)buf;
00106    cout << "Test #3 CRC32 = " << hex << crc << "\n\n";
00107    if (crc == 0xbf671ed0)
00108           cout << "Test #3 PASSED\n\n\n";
00109    else
00110           cout << "Test #3 FAILED\n\n\n";
00111 
00112 }

Generated on Fri Feb 23 09:55:13 2007 for GNU CommonC++ by  doxygen 1.5.1