summaryrefslogtreecommitdiffstats
path: root/tests/bits/bitcomp_test.c
blob: 587dd72b18a028777e01a2bc7a85cfb8539bf813 (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
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
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#include <stdbool.h>
#include <errno.h>

#include <osmocom/core/utils.h>
#include <osmocom/core/bits.h>
#include <osmocom/core/bitcomp.h>

static char lol[1024]; // for pretty-printing

int main(int argc, char **argv)
{
	srand(time(NULL));

	struct bitvec bv, out;
	uint8_t i = 20, test[i], data[i];

	bv.data_len = i;
        bv.data = test;
	out.data_len = i;
	out.data = data;
	bitvec_zero(&bv);
	bitvec_zero(&out);

	printf("\nrunning static tests...\n");

	printf("\nTEST1:\n 00110111 01000111 10000001 1111\n");
	bitvec_zero(&bv);
	bitvec_set_uint(&bv, 0x374781F, 28); bitvec_to_string_r(&bv, lol); printf("%s", lol);

	printf("\nEncoded:\n%d", osmo_t4_encode(&bv)); bitvec_to_string_r(&bv, lol); printf("%s", lol);
	printf(" [%d]\nExpected:\n0 11011110 10001000 01110101 01100101 100 [35]\n", bv.cur_bit);

	bitvec_zero(&bv);
	bitvec_set_uint(&bv, 0xDE887565, 32);
	bitvec_set_uint(&bv, 4, 3);
	bitvec_to_string_r(&bv, lol);
	printf(" %s [%d]\n", lol, bv.cur_bit);

	printf("\nTEST2:\n 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 00000000 00\n");
	bitvec_zero(&bv);
	bitvec_set_uint(&bv, 0xFFFFFFFF, 32);
	bitvec_set_uint(&bv, 0xFFFFFFFF, 32);
	bitvec_set_uint(&bv, 0xFFFFFC00, 26); bitvec_to_string_r(&bv, lol); printf("%s", lol);
	printf("\nEncoded:\n%d", osmo_t4_encode(&bv)); bitvec_to_string_r(&bv, lol); printf("%s", lol);
	printf(" [%d]\nExpected:\n1 11011101 01000001 00 [18]\n", bv.cur_bit);

	return 0;
}