summaryrefslogtreecommitdiff
path: root/tests/projects/package/requires_lock/src/main.c
blob: 911b06925c21b86acdd590fae3aba74c5283518f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>

int main(int argc, char** argv) {
    printf("zlib version: %s\n", zlibVersion());
    
    // simple compression test
    const char* source = "Hello, zlib requires lock test!";
    uLong sourceLen = strlen(source) + 1;
    uLong destLen = compressBound(sourceLen);
    Bytef* dest = (Bytef*)malloc(destLen);
    
    if (compress(dest, &destLen, (const Bytef*)source, sourceLen) == Z_OK) {
        printf("Compression successful, compressed size: %lu\n", destLen);
        
        // decompression test
        uLong decompLen = sourceLen;
        Bytef* decomp = (Bytef*)malloc(decompLen);
        if (uncompress(decomp, &decompLen, dest, destLen) == Z_OK) {
            printf("Decompression successful: %s\n", (char*)decomp);
        }
        free(decomp);
    }
    free(dest);
    
    return 0;
}