1 /*
2  * Copyright (c) 2022 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/bluetooth/buf.h>
9 #include "mocks/net_buf.h"
10 #include "mocks/net_buf_expects.h"
11 
expect_single_call_net_buf_alloc(struct net_buf_pool * pool,k_timeout_t * timeout)12 void expect_single_call_net_buf_alloc(struct net_buf_pool *pool, k_timeout_t *timeout)
13 {
14 	const char *func_name = "net_buf_alloc_fixed";
15 
16 	zassert_equal(net_buf_alloc_fixed_fake.call_count, 1, "'%s()' was called more than once",
17 		      func_name);
18 
19 	zassert_equal_ptr(net_buf_alloc_fixed_fake.arg0_val, pool,
20 			  "'%s()' was called with incorrect '%s' value", func_name, "pool");
21 
22 	zassert_mem_equal(&net_buf_alloc_fixed_fake.arg1_val, timeout, sizeof(k_timeout_t),
23 			  "'%s()' was called with incorrect '%s' value", func_name, "timeout");
24 }
25 
expect_not_called_net_buf_alloc(void)26 void expect_not_called_net_buf_alloc(void)
27 {
28 	const char *func_name = "net_buf_alloc_fixed";
29 
30 	zassert_equal(net_buf_alloc_fixed_fake.call_count, 0, "'%s()' was called unexpectedly",
31 		      func_name);
32 }
33 
expect_single_call_net_buf_reserve(struct net_buf * buf)34 void expect_single_call_net_buf_reserve(struct net_buf *buf)
35 {
36 	const char *func_name = "net_buf_simple_reserve";
37 
38 	zassert_equal(net_buf_simple_reserve_fake.call_count, 1, "'%s()' was called more than once",
39 		      func_name);
40 
41 	zassert_equal_ptr(net_buf_simple_reserve_fake.arg0_val, &buf->b,
42 			  "'%s()' was called with incorrect '%s' value", func_name, "buf");
43 
44 	zassert_equal(net_buf_simple_reserve_fake.arg1_val, BT_BUF_RESERVE,
45 		      "'%s()' was called with incorrect '%s' value", func_name, "reserve");
46 }
47 
expect_not_called_net_buf_reserve(void)48 void expect_not_called_net_buf_reserve(void)
49 {
50 	const char *func_name = "net_buf_simple_reserve";
51 
52 	zassert_equal(net_buf_simple_reserve_fake.call_count, 0, "'%s()' was called unexpectedly",
53 		      func_name);
54 }
55 
expect_single_call_net_buf_ref(struct net_buf * buf)56 void expect_single_call_net_buf_ref(struct net_buf *buf)
57 {
58 	const char *func_name = "net_buf_ref";
59 
60 	zassert_equal(net_buf_ref_fake.call_count, 1, "'%s()' was called more than once",
61 		      func_name);
62 
63 	zassert_equal_ptr(net_buf_ref_fake.arg0_val, buf,
64 			  "'%s()' was called with incorrect '%s' value", func_name, "buf");
65 }
66 
expect_not_called_net_buf_ref(void)67 void expect_not_called_net_buf_ref(void)
68 {
69 	const char *func_name = "net_buf_ref";
70 
71 	zassert_equal(net_buf_ref_fake.call_count, 0, "'%s()' was called unexpectedly",
72 		      func_name);
73 }
74