-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_tmp101.c
More file actions
65 lines (49 loc) · 1.57 KB
/
Copy pathtest_tmp101.c
File metadata and controls
65 lines (49 loc) · 1.57 KB
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
#include <stdarg.h>
#include <stdint.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include "tmp101.h"
static void check_i2c_transmit(void)
{
expect_value(__wrap_i2c_transmit_blocking, address, 0x48);
expect_value(__wrap_i2c_transmit_blocking, offset, 0);
}
static void test_negative_temperature(void **state)
{
will_return(__wrap_i2c_read_blocking, 0b11100111);
will_return(__wrap_i2c_read_blocking, 0b00000000);
check_i2c_transmit();
assert_true(tmp101_get_temperature() == -25);
}
static void test_zero_temperature(void **state)
{
will_return(__wrap_i2c_read_blocking, 0b00000000);
will_return(__wrap_i2c_read_blocking, 0b00000000);
check_i2c_transmit();
assert_true(tmp101_get_temperature() == 0);
}
static void test_positive_temperature(void **state)
{
will_return(__wrap_i2c_read_blocking, 0b01001011);
will_return(__wrap_i2c_read_blocking, 0b00000000);
check_i2c_transmit();
assert_true(tmp101_get_temperature() == 75);
}
static void test_fractional_temperature(void **state)
{
will_return(__wrap_i2c_read_blocking, 0b00000000);
will_return(__wrap_i2c_read_blocking, 0b01000000);
check_i2c_transmit();
assert_true(tmp101_get_temperature() == 0.25);
}
int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(test_positive_temperature),
cmocka_unit_test(test_negative_temperature),
cmocka_unit_test(test_zero_temperature),
cmocka_unit_test(test_fractional_temperature)
};
return cmocka_run_group_tests(tests, NULL, NULL);
}