File: test_assert_set.c

package info (click to toggle)
cmocka 2.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,372 kB
  • sloc: ansic: 13,134; xml: 226; makefile: 23
file content (137 lines) | stat: -rw-r--r-- 3,920 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "config.h"

#include <cmocka.h>
#include <cmocka_private.h>

static void test_assert_int_in_set_8(void **state)
{
    int8_t set[] = {1, 2, 3, INT8_MAX};

    (void)state; /* unused */

    assert_int_in_set(1, set, ARRAY_SIZE(set));
}

static void test_assert_int_in_set_16(void **state)
{
    int16_t set[] = {1, 2, 3, INT16_MAX};

    (void)state; /* unused */

    assert_int_in_set(INT16_MAX, set, ARRAY_SIZE(set));
}

static void test_assert_int_in_set_32(void **state)
{
    int32_t set[] = {INT32_MIN, -2, -1, 0, 1, 2, 3, INT32_MAX};

    (void)state; /* unused */

    assert_int_in_set(INT32_MIN, set, ARRAY_SIZE(set));
    assert_int_in_set(-1, set, ARRAY_SIZE(set));
    assert_int_in_set(0, set, ARRAY_SIZE(set));
    assert_int_in_set(1, set, ARRAY_SIZE(set));
    assert_int_in_set(INT32_MAX, set, ARRAY_SIZE(set));
}

static void test_assert_int_in_set_64(void **state)
{
    int64_t set[] = {1, 2, 3, INT64_MAX};

    (void)state; /* unused */

    assert_int_in_set(INT64_MAX, set, ARRAY_SIZE(set));
}

static void test_assert_int_not_in_set_32(void **state)
{
    int32_t set[] = {INT32_MIN + 1, -2, -1, 0, 1, 2, 3, INT32_MAX - 1};

    (void)state; /* unused */

    assert_int_not_in_set(INT32_MIN, set, ARRAY_SIZE(set));
    assert_int_not_in_set(-3, set, ARRAY_SIZE(set));
    assert_int_not_in_set(4, set, ARRAY_SIZE(set));
    assert_int_not_in_set(INT32_MAX, set, ARRAY_SIZE(set));
}


static void test_assert_int_not_in_set_64(void **state)
{
    int64_t set[] = {INT64_MIN + 1, -2, -1, 0, 1, 2, 3, INT64_MAX - 1};

    (void)state; /* unused */

    assert_int_not_in_set(INT64_MIN, set, ARRAY_SIZE(set));
    assert_int_not_in_set(-3, set, ARRAY_SIZE(set));
    assert_int_not_in_set(4, set, ARRAY_SIZE(set));
    assert_int_not_in_set(INT64_MAX, set, ARRAY_SIZE(set));
}

static void test_assert_uint_in_set_32(void **state)
{
    uint32_t set[] = {0, 1, 2, 3, UINT32_MAX};

    (void)state; /* unused */

    assert_int_in_set(0, set, ARRAY_SIZE(set));
    assert_int_in_set(1, set, ARRAY_SIZE(set));
    assert_int_in_set(UINT32_MAX, set, ARRAY_SIZE(set));
}

static void test_assert_uint_in_set_64(void **state)
{
    uint64_t set[] = {1, 2, 3, UINT64_MAX};

    (void)state; /* unused */

    assert_int_in_set(UINT64_MAX, set, ARRAY_SIZE(set));
}

static void test_assert_uint_not_in_set_64(void **state)
{
    uint64_t set[] = {0, 1, 2, 3, UINT64_MAX - 1};

    (void)state; /* unused */

    assert_uint_not_in_set(UINT64_MAX, set, ARRAY_SIZE(set));
    assert_uint_not_in_set(4, set, ARRAY_SIZE(set));
}

static void test_assert_float_in_set(void **state)
{
    double set[] = {3.14, 2.718, 42.0, 1.618};
    (void)state; /* unused */

    assert_float_in_set(3.14, set, ARRAY_SIZE(set), 0.01);
    assert_float_in_set(2.7, set, ARRAY_SIZE(set), 0.1);
    assert_float_in_set(2.718, set, ARRAY_SIZE(set), 0.001);
    assert_float_in_set(42.0, set, ARRAY_SIZE(set), 0.01);
}

static void test_assert_float_not_in_set(void **state)
{
    double set[] = {3.14, 2.718, 42.0, 1.618};
    (void)state; /* unused */

    assert_float_not_in_set(3.145, set, ARRAY_SIZE(set), 0.001);
    assert_float_not_in_set(0.83462, set, ARRAY_SIZE(set), 0.001);
}

int main(void) {
    const struct CMUnitTest set_tests[] = {
        cmocka_unit_test(test_assert_int_in_set_8),
        cmocka_unit_test(test_assert_int_in_set_16),
        cmocka_unit_test(test_assert_int_in_set_32),
        cmocka_unit_test(test_assert_int_in_set_64),
        cmocka_unit_test(test_assert_int_not_in_set_32),
        cmocka_unit_test(test_assert_int_not_in_set_64),
        cmocka_unit_test(test_assert_uint_in_set_32),
        cmocka_unit_test(test_assert_uint_in_set_64),
        cmocka_unit_test(test_assert_uint_not_in_set_64),
        cmocka_unit_test(test_assert_float_in_set),
        cmocka_unit_test(test_assert_float_not_in_set),
    };

    return cmocka_run_group_tests(set_tests, NULL, NULL);
}