#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>

// include, we are testing static methods
#include "bit_utils.c"


/// test few results known as good
static void test_check_fcs(void **state)
{
    (void) state;   // unused

    {
        const uint8_t in[] = {
            0x7f, 0xff, 0x03, 0x00, 0x11, 0x90, 0x03, 0x60,
            0x02, 0x16, 0x00, 0x0a, 0x00, 0x01, 0x01, 0x47,
            0x00, 0x83, 0xf5, 0x00, 0x04, 0xdf, 0xa8, 0x26,
        };
        bool res = check_fcs(in, sizeof(in) * 8);
        assert_int_equal(true, res);
    }

    {
        const uint8_t in[] = {
            0x7f, 0xff, 0x03, 0x00, 0x11, 0x90, 0x13, 0x60,
            0x02, 0x16, 0x00, 0x0a, 0x00, 0x01, 0x01, 0x47,
            0x00, 0x83, 0xf5, 0x00, 0x04, 0xdf, 0x20, 0x87,
        };
        bool res = check_fcs(in, sizeof(in) * 8);
        assert_int_equal(true, res);
    }

    {
        const uint8_t in[] = {
            0x7f, 0xff, 0x03, 0x00, 0x11, 0x90, 0x03, 0x60,
            0x02, 0x16, 0x00, 0x0a, 0x00, 0x01, 0x01, 0x47,
            0x00, 0x83, 0xf5, 0x00, 0x04, 0xe3, 0x47, 0xdd,
        };
        bool res = check_fcs(in, sizeof(in) * 8);
        assert_int_equal(true, res);
    }
}

int main(void)
{
    const UnitTest tests[] = {
        unit_test(test_check_fcs),
    };

    return run_tests(tests);
}
