/
bz2.c
35 lines (24 loc) · 1.17 KB
/
bz2.c
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
30
31
32
33
34
35
#include <CUnit/CUnit.h>
#include "../../src/include/general/bzip2.h"
#define BZ2_MAXBUFLEN 1024
char str[] = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et "
"dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex "
"ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu "
"fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
"mollit anim id est laborum.";
void test_comp_decomp(void) {
char *buf;
unsigned int buf_len;
int ret = bzip2_compress(&buf, &buf_len, str, strlen(str));
CU_ASSERT_EQUAL(ret, 1);
CU_ASSERT_EQUAL(buf_len, 302);
char *buf2 = malloc(BZ2_MAXBUFLEN);
unsigned int buf2_len = BZ2_MAXBUFLEN;
ret = bzip2_decompress(buf2, &buf2_len, buf, buf_len);
CU_ASSERT_EQUAL(ret, 1);
CU_ASSERT_EQUAL(buf2_len, strlen(str));
}
void test_bz2_init() {
CU_pSuite suite = CU_add_suite("bz2", NULL, NULL);
CU_add_test(suite, "bz2 comp/decomp works", test_comp_decomp);
}