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