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    union {
00052            unsigned char buf[4];
00053            uint32 value;
00054    } data;
00055    uint32 crc;
00056    int i;
00057 
00058    cout << "CRC32 Algorithm Test\n\n";
00059 
00060    cout << "AAL-5 Test #1 - 40 Octets filled with \"0\" - ";
00061    cout << "CRC32 = 0x864d7f99\n";
00062 
00063    for (i = 0; i < 40; i++)
00064           test[i] = 0x0;
00065    test[40] = test[41] = test[42] = 0x0;
00066    test[43] = 0x28;
00067 
00068    CRC32Digest crc1;
00069    crc1.putDigest(test, 44);
00070    crc1.getDigest(data.buf);
00071    crc = data.value;
00072    cout << "Test #1 CRC32 = " << hex << crc << "\n\n";
00073    if (crc == 0x864d7f99)
00074           cout << "Test #1 PASSED\n\n\n";
00075    else
00076           cout << "Test #1 FAILED\n\n\n";
00077 
00078 
00079    cout << "AAL-5 Test #2 - 40 Octets filled with \"1\" - ";
00080    cout << "CRC32 = 0xc55e457a\n";
00081 
00082    for (i = 0; i < 40; i++)
00083           test[i] = 0xFF;
00084    test[40] = test[41] = test[42] = 0x0;
00085    test[43] = 0x28;
00086 
00087    CRC32Digest crc2;
00088    crc2.putDigest(test, 44);
00089    crc2.getDigest(data.buf);
00090    crc = data.value;
00091    cout << "Test #2 CRC32 = " << hex << crc << "\n\n";
00092    if (crc == 0xc55e457a)
00093           cout << "Test #2 PASSED\n\n\n";
00094    else
00095           cout << "Test #2 FAILED\n\n\n";
00096 
00097    cout << "AAL-5 Test #3 - 40 Octets counting 1 to 40 - ";
00098    cout << "CRC32 = 0xbf671ed0\n";
00099 
00100    for (i = 0; i < 40; i++)
00101           test[i] = i+1;
00102    test[40] = test[41] = test[42] = 0x0;
00103    test[43] = 0x28;
00104 
00105    CRC32Digest crc3;
00106    crc3.putDigest(test, 44);
00107    crc3.getDigest(data.buf);
00108    crc = data.value;
00109    cout << "Test #3 CRC32 = " << hex << crc << "\n\n";
00110    if (crc == 0xbf671ed0)
00111           cout << "Test #3 PASSED\n\n\n";
00112    else
00113           cout << "Test #3 FAILED\n\n\n";
00114 
00115 }

Generated on Sun Mar 21 21:39:51 2010 for GNU CommonC++ by  doxygen 1.4.7