summaryrefslogtreecommitdiff
path: root/cesar/lib/test/utils/src/test_utils.c
blob: 23ef0307cf15cf00d59ca7e1c4cbc59da5581d12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \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;
}