Imported Upstream version 2.7
[ossec-hids.git] / src / os_zlib / zlib-test.c
1 /* @(#) $Id: ./src/os_zlib/zlib-test.c, 2011/09/08 dcid Exp $
2  */
3
4 /* Copyright (C) 2009 Trend Micro Inc.
5  * All rights reserved.
6  *
7  * This program is a free software; you can redistribute it
8  * and/or modify it under the terms of the GNU General Public
9  * License (version 2) as published by the FSF - Free Software
10  * Foundation
11  */
12
13
14 #include "shared.h"
15 #include "os_zlib.h"
16
17 #ifndef ARGV0
18   #define ARGV0   "zlib-test"
19 #endif
20
21 /* Zlib test */
22 int main(int argc, char **argv)
23 {
24     int ret, srcsize, dstsize = 2010;
25     char dst[2048];
26     char dst2[2048];
27
28     memset(dst, 0, 2048);
29     memset(dst2, 0, 2048);
30
31     if(argc < 2)
32     {
33         printf("%s: string\n", argv[0]);
34         exit(1);
35     }
36
37     srcsize = strlen(argv[1]);
38     if(srcsize > 2000)
39     {
40         printf("%s: string too large\n", argv[0]);
41         exit(1);
42
43     }
44
45     if((ret = os_compress(argv[1], dst, srcsize, dstsize)))
46     {
47         printf("Compressed, from %d->%d\n",srcsize, ret);
48     }
49     else
50     {
51         printf("FAILED compressing.\n");
52         exit(1);
53     }
54
55     /* Setting new srcsize for decompression */
56     srcsize = ret;
57
58     if((ret = os_uncompress(dst, dst2, srcsize, dstsize)))
59     {
60         printf("Uncompressed ok. String: '%s', size %d->%d\n",
61                                         dst2, srcsize, ret);
62     }
63     else
64     {
65         printf("FAILED uncompressing.\n");
66         exit(1);
67     }
68
69     return(0);
70 }