2 * Copyright (C) 2014 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "test_suite.h"
18 #include <bliss_bitpacker.h>
20 static uint16_t bits
[] = { 0, 1, 2, 3, 4, 7, 1, 14, 2, 29, 3, 28, 67};
22 static chunk_t packed_bits
= chunk_from_chars(0x6e, 0x71, 0xe1, 0x74,
25 START_TEST(test_bliss_sign_bitpacker_write
)
28 bliss_bitpacker_t
*packer
;
31 packer
= bliss_bitpacker_create(49);
33 ck_assert(!packer
->write_bits(packer
, 0, 17));
35 for (i
= 0; i
< countof(bits
); i
++)
37 ck_assert(packer
->write_bits(packer
, bits
[i
], 1 + i
/2));
39 buf
= packer
->extract_buf(packer
);
40 ck_assert_int_eq(packer
->get_bits(packer
), 49);
41 ck_assert_chunk_eq(buf
, packed_bits
);
43 packer
->destroy(packer
);
48 START_TEST(test_bliss_sign_bitpacker_read
)
51 bliss_bitpacker_t
*packer
;
54 packer
= bliss_bitpacker_create_from_data(packed_bits
);
56 ck_assert(!packer
->read_bits(packer
, &value
, 17));
58 for (i
= 0; i
< countof(bits
); i
++)
60 ck_assert(packer
->read_bits(packer
, &value
, 1 + i
/2));
61 ck_assert_int_eq(value
, bits
[i
]);
63 ck_assert(!packer
->read_bits(packer
, &value
, 16));
65 packer
->destroy(packer
);
69 START_TEST(test_bliss_sign_bitpacker_fail
)
71 bliss_bitpacker_t
*packer
;
74 packer
= bliss_bitpacker_create(16);
75 ck_assert(!packer
->write_bits(packer
, 0, 17));
76 ck_assert( packer
->write_bits(packer
, 0x7f01, 15));
77 ck_assert(!packer
->write_bits(packer
, 3, 2));
78 packer
->destroy(packer
);
80 packer
= bliss_bitpacker_create_from_data(chunk_from_chars(0x7f, 0x01));
81 ck_assert(!packer
->read_bits(packer
, &value
, 17));
82 ck_assert( packer
->read_bits(packer
, &value
, 15));
83 ck_assert(!packer
->read_bits(packer
, &value
, 2));
84 packer
->destroy(packer
);
88 Suite
*bliss_bitpacker_suite_create()
93 s
= suite_create("bliss_bitpacker");
95 tc
= tcase_create("bitpacker_write");
96 tcase_add_test(tc
, test_bliss_sign_bitpacker_write
);
97 suite_add_tcase(s
, tc
);
99 tc
= tcase_create("bitpacker_read");
100 tcase_add_test(tc
, test_bliss_sign_bitpacker_read
);
101 suite_add_tcase(s
, tc
);
103 tc
= tcase_create("bitpacker_fail");
104 tcase_add_test(tc
, test_bliss_sign_bitpacker_fail
);
105 suite_add_tcase(s
, tc
);