Subversion Repositories QNX 8.QNX8 IFS tool

Rev

Blame | Last modification | View Log | Download | RSS feed

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