1 /*
2  * Copyright (c) 2023 Codecoup
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef MOCKS_GATT_EXPECTS_H_
8 #define MOCKS_GATT_EXPECTS_H_
9 
10 #include <zephyr/bluetooth/gatt.h>
11 #include <zephyr/ztest_assert.h>
12 
13 #include "gatt.h"
14 #include "expects_util.h"
15 
16 #define expect_bt_gatt_notify_cb_called_once(_conn, _uuid, _attr, _data, _len)                     \
17 do {                                                                                               \
18 	const char *func_name = "bt_gatt_notify_cb";                                               \
19 	struct bt_gatt_notify_params *params;                                                      \
20 												   \
21 	IF_NOT_EMPTY(_conn, (                                                                      \
22 		     zassert_equal_ptr(_conn, mock_bt_gatt_notify_cb_fake.arg0_val,                \
23 				       "'%s()' was called with incorrect '%s' value",              \
24 				       func_name, "conn");))                                       \
25 												   \
26 	params = mock_bt_gatt_notify_cb_fake.arg1_val;                                             \
27 												   \
28 	/* params->uuid is optional */                                                             \
29 	if (params->uuid) {                                                                        \
30 		IF_NOT_EMPTY(_uuid, (                                                              \
31 			     zassert_true(bt_uuid_cmp(_uuid, params->uuid) == 0,                   \
32 					  "'%s()' was called with incorrect '%s' value",           \
33 					  func_name, "params->uuid");))                            \
34 	} else {                                                                                   \
35 		IF_NOT_EMPTY(_attr, (                                                              \
36 			     zassert_equal_ptr(_attr, params->attr,                                \
37 					       "'%s()' was called with incorrect '%s' value",      \
38 					       func_name, "params->attr");))                       \
39 	}                                                                                          \
40 												   \
41 	/* assert if _data is valid, but _len is empty */                                          \
42 	IF_EMPTY(_len, (IF_NOT_EMPTY(_data, (zassert_unreachable();))))                            \
43 												   \
44 	IF_NOT_EMPTY(_len, (                                                                       \
45 		     zassert_equal(_len, params->len,                                              \
46 				   "'%s()' was called with incorrect '%s' value",                  \
47 				   func_name, "params->len");                                      \
48 		     expect_data(func_name, "params->data", _data, params->data, _len);))          \
49 } while (0)
50 
expect_bt_gatt_notify_cb_not_called(void)51 static inline void expect_bt_gatt_notify_cb_not_called(void)
52 {
53 	const char *func_name = "bt_gatt_notify_cb";
54 
55 	zassert_equal(0, mock_bt_gatt_notify_cb_fake.call_count,
56 		      "'%s()' was called unexpectedly", func_name);
57 }
58 
59 #endif /* MOCKS_GATT_EXPECTS_H_ */
60