-
Notifications
You must be signed in to change notification settings - Fork 2
/
rle_test.c
58 lines (51 loc) · 1.3 KB
/
rle_test.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <string.h>
#include <sys/uio.h>
#include "describe/describe.h"
#include "rle.h"
// TODO: varint
// TODO: grow buffer or add fn for decoded length
int
main(){
describe("rle_encode()") {
it("should compress runs") {
struct iovec iov[] = {
{
.iov_base = "hello",
.iov_len = 5
},
{
.iov_base = "hello",
.iov_len = 5
},
{
.iov_base = "hello",
.iov_len = 5
},
{
.iov_base = "foo",
.iov_len = 3
},
{
.iov_base = "foo",
.iov_len = 3
},
{
.iov_base = "bar",
.iov_len = 3
}
};
char buf[256];
size_t len = rle_encode(iov, 6, buf);
assert(len == 17);
struct iovec out[6] = {{0}};
rle_decode(buf, 17, out);
assert(strncmp("hello", out[0].iov_base, out[0].iov_len) == 0);
assert(strncmp("hello", out[1].iov_base, out[1].iov_len) == 0);
assert(strncmp("hello", out[2].iov_base, out[2].iov_len) == 0);
assert(strncmp("foo", out[3].iov_base, out[3].iov_len) == 0);
assert(strncmp("foo", out[4].iov_base, out[4].iov_len) == 0);
assert(strncmp("bar", out[5].iov_base, out[5].iov_len) == 0);
}
}
return assert_failures();
}