Updates to Tomato RAF including NGINX && PHP
[tomato.git] / release / src / router / lzo / minilzo / testmini.c
blob991f878970ccec6fea3d74f14ae68538b0e64814
1 /* testmini.c -- very simple test program for the miniLZO library
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 2011 Markus Franz Xaver Johannes Oberhumer
6 Copyright (C) 2010 Markus Franz Xaver Johannes Oberhumer
7 Copyright (C) 2009 Markus Franz Xaver Johannes Oberhumer
8 Copyright (C) 2008 Markus Franz Xaver Johannes Oberhumer
9 Copyright (C) 2007 Markus Franz Xaver Johannes Oberhumer
10 Copyright (C) 2006 Markus Franz Xaver Johannes Oberhumer
11 Copyright (C) 2005 Markus Franz Xaver Johannes Oberhumer
12 Copyright (C) 2004 Markus Franz Xaver Johannes Oberhumer
13 Copyright (C) 2003 Markus Franz Xaver Johannes Oberhumer
14 Copyright (C) 2002 Markus Franz Xaver Johannes Oberhumer
15 Copyright (C) 2001 Markus Franz Xaver Johannes Oberhumer
16 Copyright (C) 2000 Markus Franz Xaver Johannes Oberhumer
17 Copyright (C) 1999 Markus Franz Xaver Johannes Oberhumer
18 Copyright (C) 1998 Markus Franz Xaver Johannes Oberhumer
19 Copyright (C) 1997 Markus Franz Xaver Johannes Oberhumer
20 Copyright (C) 1996 Markus Franz Xaver Johannes Oberhumer
21 All Rights Reserved.
23 The LZO library is free software; you can redistribute it and/or
24 modify it under the terms of the GNU General Public License as
25 published by the Free Software Foundation; either version 2 of
26 the License, or (at your option) any later version.
28 The LZO library is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with the LZO library; see the file COPYING.
35 If not, write to the Free Software Foundation, Inc.,
36 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
38 Markus F.X.J. Oberhumer
39 <markus@oberhumer.com>
40 http://www.oberhumer.com/opensource/lzo/
44 #include <stdio.h>
45 #include <stdlib.h>
48 /*************************************************************************
49 // This program shows the basic usage of the LZO library.
50 // We will compress a block of data and decompress again.
52 // For more information, documentation, example programs and other support
53 // files (like Makefiles and build scripts) please download the full LZO
54 // package from
55 // http://www.oberhumer.com/opensource/lzo/
56 **************************************************************************/
58 /* First let's include "minizo.h". */
60 #include "minilzo.h"
63 /* We want to compress the data block at 'in' with length 'IN_LEN' to
64 * the block at 'out'. Because the input block may be incompressible,
65 * we must provide a little more output space in case that compression
66 * is not possible.
69 #if defined(__LZO_STRICT_16BIT)
70 #define IN_LEN (8*1024u)
71 #elif defined(LZO_ARCH_I086) && !defined(LZO_HAVE_MM_HUGE_ARRAY)
72 #define IN_LEN (60*1024u)
73 #else
74 #define IN_LEN (128*1024ul)
75 #endif
76 #define OUT_LEN (IN_LEN + IN_LEN / 16 + 64 + 3)
78 static unsigned char __LZO_MMODEL in [ IN_LEN ];
79 static unsigned char __LZO_MMODEL out [ OUT_LEN ];
82 /* Work-memory needed for compression. Allocate memory in units
83 * of 'lzo_align_t' (instead of 'char') to make sure it is properly aligned.
86 #define HEAP_ALLOC(var,size) \
87 lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo_align_t) ]
89 static HEAP_ALLOC(wrkmem, LZO1X_1_MEM_COMPRESS);
92 /*************************************************************************
94 **************************************************************************/
96 int main(int argc, char *argv[])
98 int r;
99 lzo_uint in_len;
100 lzo_uint out_len;
101 lzo_uint new_len;
103 if (argc < 0 && argv == NULL) /* avoid warning about unused args */
104 return 0;
106 printf("\nLZO real-time data compression library (v%s, %s).\n",
107 lzo_version_string(), lzo_version_date());
108 printf("Copyright (C) 1996-2011 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n");
112 * Step 1: initialize the LZO library
114 if (lzo_init() != LZO_E_OK)
116 printf("internal error - lzo_init() failed !!!\n");
117 printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
118 return 3;
122 * Step 2: prepare the input block that will get compressed.
123 * We just fill it with zeros in this example program,
124 * but you would use your real-world data here.
126 in_len = IN_LEN;
127 lzo_memset(in,0,in_len);
130 * Step 3: compress from 'in' to 'out' with LZO1X-1
132 r = lzo1x_1_compress(in,in_len,out,&out_len,wrkmem);
133 if (r == LZO_E_OK)
134 printf("compressed %lu bytes into %lu bytes\n",
135 (unsigned long) in_len, (unsigned long) out_len);
136 else
138 /* this should NEVER happen */
139 printf("internal error - compression failed: %d\n", r);
140 return 2;
142 /* check for an incompressible block */
143 if (out_len >= in_len)
145 printf("This block contains incompressible data.\n");
146 return 0;
150 * Step 4: decompress again, now going from 'out' to 'in'
152 new_len = in_len;
153 r = lzo1x_decompress(out,out_len,in,&new_len,NULL);
154 if (r == LZO_E_OK && new_len == in_len)
155 printf("decompressed %lu bytes back into %lu bytes\n",
156 (unsigned long) out_len, (unsigned long) in_len);
157 else
159 /* this should NEVER happen */
160 printf("internal error - decompression failed: %d\n", r);
161 return 1;
164 printf("\nminiLZO simple compression test passed.\n");
165 return 0;
169 vi:ts=4:et