/* Cesar project {{{ * * Copyright (C) 2007 Spidcom * * <<>> * * }}} */ /** * \file src/test_utils.c * \brief Utilities tests. * \ingroup test */ #include "common/std.h" #include "lib/test.h" void bits_test_case (test_t t) { test_case_begin (t, "bits"); test_begin (t, "ones") { test_fail_unless (BITS_ONES_COUNT ((u8) 0x00) == 0); test_fail_unless (BITS_ONES_COUNT ((u8) 0x0f) == 4); test_fail_unless (BITS_ONES_COUNT ((u8) 0xf0) == 4); test_fail_unless (BITS_ONES_COUNT ((u8) 0xa5) == 4); test_fail_unless (BITS_ONES_COUNT ((u8) 0xff) == 8); test_fail_unless (BITS_ONES_COUNT ((u16) 0x0000) == 0); test_fail_unless (BITS_ONES_COUNT ((u16) 0x0f0f) == 8); test_fail_unless (BITS_ONES_COUNT ((u16) 0xf0f0) == 8); test_fail_unless (BITS_ONES_COUNT ((u16) 0xa5a5) == 8); test_fail_unless (BITS_ONES_COUNT ((u16) 0xffff) == 16); test_fail_unless (BITS_ONES_COUNT ((u32) 0x00000000) == 0); test_fail_unless (BITS_ONES_COUNT ((u32) 0x0f0f0f0f) == 16); test_fail_unless (BITS_ONES_COUNT ((u32) 0xf0f0f0f0) == 16); test_fail_unless (BITS_ONES_COUNT ((u32) 0xa5a5a5a5) == 16); test_fail_unless (BITS_ONES_COUNT ((u32) 0xffffffff) == 32); test_fail_unless (BITS_ONES_COUNT ((u64) 0x0000000000000000ull) == 0); test_fail_unless (BITS_ONES_COUNT ((u64) 0x0f0f0f0f0f0f0f0full) == 32); test_fail_unless (BITS_ONES_COUNT ((u64) 0xf0f0f0f0f0f0f0f0ull) == 32); test_fail_unless (BITS_ONES_COUNT ((u64) 0xa5a5a5a5a5a5a5a5ull) == 32); test_fail_unless (BITS_ONES_COUNT ((u64) 0xffffffffffffffffull) == 64); } test_end; } void utils_test_suite (test_t t) { test_suite_begin (t, "utils"); bits_test_case (t); } int main (int argc, char **argv) { test_t t; test_init (t, argc, argv); utils_test_suite (t); test_result (t); return test_nb_failed (t) == 0 ? 0 : 1; }