vlm | 337167e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 1 | #include <per_support.c> |
| 2 | #include <assert.h> |
| 3 | |
| 4 | int |
| 5 | main() { |
| 6 | uint8_t buf[] = { 0xB7, 0x19, 0x2F, 0xEE, 0xAD }; |
| 7 | uint8_t tmpbuf[10]; |
| 8 | int32_t z; |
| 9 | asn_per_data_t pos; |
| 10 | |
| 11 | pos.buffer = buf; |
| 12 | pos.nboff = 0; |
| 13 | pos.nbits = sizeof(buf) * 8; |
| 14 | |
| 15 | z = per_get_few_bits(&pos, 32); |
| 16 | assert(z == -1); |
| 17 | |
| 18 | z = per_get_few_bits(&pos, 0); |
| 19 | assert(z == 0); |
| 20 | assert(pos.nboff == 0); |
| 21 | |
| 22 | z = per_get_few_bits(&pos, 1); |
| 23 | assert(z == 1); |
| 24 | assert(pos.nboff == 1); |
| 25 | |
| 26 | z = per_get_few_bits(&pos, 2); |
| 27 | assert(z == 1); |
| 28 | assert(pos.nboff == 3); |
| 29 | |
| 30 | z = per_get_few_bits(&pos, 2); |
| 31 | assert(z == 2); |
| 32 | assert(pos.nboff == 5); |
| 33 | |
| 34 | z = per_get_few_bits(&pos, 3); |
| 35 | assert(z == 7); |
| 36 | assert(pos.nboff == 8); |
| 37 | assert(pos.nbits == sizeof(buf) * 8); |
| 38 | |
| 39 | z = per_get_few_bits(&pos, 8); |
| 40 | assert(z == 0x19); |
| 41 | assert(pos.nboff == 8); |
| 42 | assert(pos.nbits == (sizeof(buf) - 1) * 8); |
| 43 | |
| 44 | z = per_get_few_bits(&pos, 1); |
| 45 | assert(z == 0); |
| 46 | assert(pos.nboff == 1); |
| 47 | assert(pos.nbits == (sizeof(buf) - 2) * 8); |
| 48 | |
| 49 | z = per_get_few_bits(&pos, 3); |
| 50 | assert(z == 2); |
| 51 | assert(pos.nboff == 4); |
| 52 | assert(pos.nbits == (sizeof(buf) - 2) * 8); |
| 53 | |
| 54 | z = per_get_few_bits(&pos, 8); |
| 55 | assert(z == 254); |
| 56 | assert(pos.nboff == 12); |
| 57 | |
| 58 | pos.buffer = buf; |
| 59 | pos.nboff = 2; |
| 60 | pos.nbits = sizeof(buf) * 8; |
| 61 | z = per_get_few_bits(&pos, 24); |
| 62 | assert(z == 14443711); |
| 63 | |
| 64 | pos.buffer = buf; |
| 65 | pos.nboff = 0; |
| 66 | pos.nbits = sizeof(buf) * 8; |
| 67 | z = per_get_many_bits(&pos, tmpbuf, 0, sizeof(buf) * 8); |
| 68 | assert(z == 0); |
| 69 | assert(buf[0] == tmpbuf[0]); |
| 70 | assert(buf[1] == tmpbuf[1]); |
| 71 | assert(buf[2] == tmpbuf[2]); |
| 72 | assert(buf[3] == tmpbuf[3]); |
| 73 | assert(buf[4] == tmpbuf[4]); |
| 74 | |
| 75 | pos.buffer = buf; |
| 76 | pos.nboff = 1; |
| 77 | pos.nbits = sizeof(buf) * 8; |
| 78 | z = per_get_many_bits(&pos, tmpbuf, 0, sizeof(buf) * 8); |
| 79 | assert(z == -1); |
| 80 | |
| 81 | pos.buffer = buf; |
| 82 | pos.nboff = 1; |
| 83 | pos.nbits = sizeof(buf) * 8; |
| 84 | z = per_get_many_bits(&pos, tmpbuf, 0, sizeof(buf) * 8 - 1); |
| 85 | assert(z == 0); |
| 86 | assert(tmpbuf[0] == 110); |
| 87 | assert(tmpbuf[1] == 50); |
| 88 | assert(tmpbuf[2] == 95); |
| 89 | assert(tmpbuf[3] == 221); |
| 90 | assert(tmpbuf[4] == 90); |
| 91 | |
| 92 | pos.buffer = buf; |
| 93 | pos.nboff = 1; |
| 94 | pos.nbits = sizeof(buf) * 8; |
| 95 | z = per_get_many_bits(&pos, tmpbuf, 1, sizeof(buf) * 8 - 1); |
| 96 | assert(z == 0); |
| 97 | assert(tmpbuf[0] == 55); |
| 98 | assert(tmpbuf[0] != buf[0]); |
| 99 | assert(tmpbuf[1] == buf[1]); |
| 100 | assert(tmpbuf[2] == buf[2]); |
| 101 | assert(tmpbuf[3] == buf[3]); |
| 102 | assert(tmpbuf[4] == buf[4]); |
| 103 | |
| 104 | return 0; |
| 105 | } |