Skip to content

Commit e8e32ff

Browse files
michal-josef-spacekrurban
authored andcommitted
Add tests for read_MC/UMC/MS
1 parent 94ee31d commit e8e32ff

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

test/unit-testing/bits_test.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,78 @@ bit_read_CMC_tests (void)
13471347
bitfree (&bitchain);
13481348
}
13491349

1350+
static void
1351+
bit_read_MS_tests (void)
1352+
{
1353+
Bit_Chain bitchain = strtobt ("11111111" "01111111");
1354+
unsigned int result = bit_read_MS (&bitchain);
1355+
if (result == 32767)
1356+
ok ("bit_read_MS - 32767");
1357+
else
1358+
fail ("bit_read_MS");
1359+
bitfree (&bitchain);
1360+
1361+
bitchain = strtobt ("11111111" "11111111" "11111111" "01111111");
1362+
result = bit_read_MS (&bitchain);
1363+
if (result == 1073741823)
1364+
ok ("bit_read_MS - 1073741823");
1365+
else
1366+
fail ("bit_read_MS");
1367+
bitfree (&bitchain);
1368+
}
1369+
1370+
static void
1371+
bit_read_UMC_tests (void)
1372+
{
1373+
Bit_Chain bitchain;
1374+
BITCODE_UMC umc;
1375+
1376+
#define test_UMC(s, x) \
1377+
bitchain = strtobt (s); \
1378+
umc = bit_read_UMC (&bitchain); \
1379+
if (umc == x) \
1380+
ok ("bit_read_UMC - " FORMAT_UMC, (BITCODE_UMC)x); \
1381+
else \
1382+
fail ("bit_read_UMC " FORMAT_UMC " != " FORMAT_UMC, umc, (BITCODE_UMC)x); \
1383+
bitfree (&bitchain)
1384+
1385+
test_UMC("00000000", 0x0);
1386+
test_UMC("01111111", 0x7F);
1387+
test_UMC("11100101" "10001110" "00100110", 0x98765);
1388+
test_UMC("11010010" "11101100" "10101001" "11110010" "10010010" "10100010" "00000001", 0x5112E4A7652);
1389+
test_UMC("11111111" "11111111" "11111111" "11111111" "11111111" "11111111" "11111111" "01111111", 0xFFFFFFFFFFFFFF);
1390+
}
1391+
1392+
static void
1393+
bit_read_MC_tests (void)
1394+
{
1395+
Bit_Chain bitchain;
1396+
BITCODE_MC mc;
1397+
1398+
#define test_MC(s, x) \
1399+
bitchain = strtobt (s); \
1400+
mc = bit_read_MC (&bitchain); \
1401+
if (mc == x) \
1402+
ok ("bit_read_MC - %d", (BITCODE_MC)x); \
1403+
else \
1404+
fail ("bit_read_MC " FORMAT_MC " != " FORMAT_MC, mc, (BITCODE_MC)x); \
1405+
bitfree (&bitchain)
1406+
1407+
test_MC("00000000", 0);
1408+
test_MC("00111111", 63);
1409+
test_MC("01111111", -63);
1410+
test_MC("11111111" "00000000", 127);
1411+
test_MC("11111111" "01000000", -127);
1412+
test_MC("11111111" "00111111", 8191);
1413+
test_MC("11111111" "01111111", -8191);
1414+
test_MC("11111111" "11111111" "00000000", 16383);
1415+
test_MC("11111111" "11111111" "01000000", -16383);
1416+
test_MC("11000000" "10111011" "01111000", -925120);
1417+
test_MC("11111111" "11111111" "11111111" "00111111", 134217727);
1418+
test_MC("11111111" "11111111" "11111111" "01111111", -134217727);
1419+
test_MC("11111111" "11111111" "11111111" "11111111", 268435455);
1420+
}
1421+
13501422
static void
13511423
in_hexbin_tests (void)
13521424
{
@@ -1471,6 +1543,9 @@ main (int argc, char const *argv[])
14711543
bit_read_BE_tests ();
14721544
bit_write_BE_tests ();
14731545
bit_read_CMC_tests ();
1546+
bit_read_MS_tests ();
1547+
bit_read_UMC_tests ();
1548+
bit_read_MC_tests ();
14741549
in_hexbin_tests ();
14751550

14761551
// Prepare the testcase

0 commit comments

Comments
 (0)