LZO: update from 2.06 to 2.08
[tomato.git] / release / src / router / lzo / tests / chksum.c
blobc22afba805df1ed64eaa322eda9aa872b09cf630
1 /* chksum.c -- compute a checksum
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer
6 All Rights Reserved.
8 The LZO library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The LZO library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the LZO library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
25 http://www.oberhumer.com/opensource/lzo/
29 #include "lzo/lzoconf.h"
31 /* utility layer */
32 #define WANT_LZO_MALLOC 1
33 #include "examples/portab.h"
36 /*************************************************************************
38 **************************************************************************/
40 int main(int argc, char *argv[])
42 lzo_bytep block;
43 lzo_uint block_size;
44 lzo_uint32_t adler, crc;
46 if (argc < 0 && argv == NULL) /* avoid warning about unused args */
47 return 0;
49 if (lzo_init() != LZO_E_OK)
51 printf("lzo_init() failed !!!\n");
52 return 4;
55 /* prepare the block */
56 block_size = 128 * 1024L;
57 block = (lzo_bytep) lzo_malloc(block_size);
58 if (block == NULL)
60 printf("out of memory\n");
61 return 3;
63 lzo_memset(block, 0, block_size);
65 /* adler32 checksum */
66 adler = lzo_adler32(0, NULL, 0);
67 adler = lzo_adler32(adler, block, block_size);
68 if (adler != 0x001e0001UL)
70 printf("adler32 checksum error !!! (0x%08lx)\n", (long) adler);
71 return 2;
74 /* crc32 checksum */
75 crc = lzo_crc32(0, NULL, 0);
76 crc = lzo_crc32(crc, block, block_size);
77 if (crc != 0x7ee8cdcdUL)
79 printf("crc32 checksum error !!! (0x%08lx)\n", (long) crc);
80 return 1;
83 lzo_free(block);
84 printf("Checksum test passed.\n");
85 return 0;
89 /* vim:set ts=4 sw=4 et: */