Max | 5c18e26 | 2016-02-05 13:55:38 +0100 | [diff] [blame] | 1 | #include <inttypes.h> |
| 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <stdint.h> |
| 5 | #include <string.h> |
| 6 | #include <time.h> |
| 7 | #include <stdbool.h> |
| 8 | #include <errno.h> |
| 9 | |
| 10 | #include <osmocom/core/utils.h> |
| 11 | #include <osmocom/core/bits.h> |
| 12 | #include <osmocom/core/bitcomp.h> |
| 13 | |
| 14 | static char lol[1024]; // for pretty-printing |
| 15 | |
| 16 | int main(int argc, char **argv) |
| 17 | { |
| 18 | srand(time(NULL)); |
| 19 | |
| 20 | struct bitvec bv, out; |
| 21 | uint8_t i = 20, test[i], data[i]; |
| 22 | |
| 23 | bv.data_len = i; |
| 24 | bv.data = test; |
| 25 | out.data_len = i; |
| 26 | out.data = data; |
| 27 | bitvec_zero(&bv); |
| 28 | bitvec_zero(&out); |
| 29 | |
| 30 | printf("\nrunning static tests...\n"); |
| 31 | |
| 32 | printf("\nTEST1:\n 00110111 01000111 10000001 1111\n"); |
| 33 | bitvec_zero(&bv); |
| 34 | bitvec_set_uint(&bv, 0x374781F, 28); bitvec_to_string_r(&bv, lol); printf("%s", lol); |
| 35 | |
| 36 | printf("\nEncoded:\n%d", osmo_t4_encode(&bv)); bitvec_to_string_r(&bv, lol); printf("%s", lol); |
| 37 | printf(" [%d]\nExpected:\n0 11011110 10001000 01110101 01100101 100 [35]\n", bv.cur_bit); |
| 38 | |
| 39 | bitvec_zero(&bv); |
| 40 | bitvec_set_uint(&bv, 0xDE887565, 32); |
| 41 | bitvec_set_uint(&bv, 4, 3); |
| 42 | bitvec_to_string_r(&bv, lol); |
| 43 | printf(" %s [%d]\n", lol, bv.cur_bit); |
Max | 5c18e26 | 2016-02-05 13:55:38 +0100 | [diff] [blame] | 44 | |
| 45 | printf("\nTEST2:\n 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 11111111 00000000 00\n"); |
| 46 | bitvec_zero(&bv); |
| 47 | bitvec_set_uint(&bv, 0xFFFFFFFF, 32); |
| 48 | bitvec_set_uint(&bv, 0xFFFFFFFF, 32); |
| 49 | bitvec_set_uint(&bv, 0xFFFFFC00, 26); bitvec_to_string_r(&bv, lol); printf("%s", lol); |
| 50 | printf("\nEncoded:\n%d", osmo_t4_encode(&bv)); bitvec_to_string_r(&bv, lol); printf("%s", lol); |
| 51 | printf(" [%d]\nExpected:\n1 11011101 01000001 00 [18]\n", bv.cur_bit); |
| 52 | |
Max | 5c18e26 | 2016-02-05 13:55:38 +0100 | [diff] [blame] | 53 | return 0; |
| 54 | } |