/
test.c
48 lines (35 loc) · 870 Bytes
/
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
#include "pack.h"
#include <stdlib.h>
#include <string.h>
#include <time.h>
/**
* Main entry point for testing the packing code.
* @argc: The argument count.
* @argv: The argument array.
* &returns: Zero on success.
*/
int main(int argc, char **argv)
{
void *ptr;
uint8_t byte, off;
unsigned int i, arr[128], val[128], width[128];
srand(time(NULL));
memset(arr, 0x00, sizeof(arr));
for(i = 0; i < 128; i++) {
width[i] = (unsigned int)rand() % 31 + 1;
val[i] = (unsigned int)rand();
if(width[i] != 32)
val[i] %= (1 << width[i]);
}
ptr = arr;
byte = off = 0;
for(i = 0; i < 128; i++)
pack_uint(&ptr, &byte, &off, val[i], width[i]);
pack_flush(&ptr, &byte, &off);
ptr = arr;
byte = off = 0;
for(i = 0; i < 128; i++)
assert(unpack_uint(&ptr, &byte, &off, width[i]) == val[i]);
fprintf(stderr, "Test OK\n");
return 0;
}