1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef STUBS_H
8 #define STUBS_H
9 
10 #include <stdbool.h>
11 #include <stdint.h>
12 
13 #include <zephyr/fff.h>
14 #include <zephyr/net/lwm2m.h>
15 #include <zephyr/ztest.h>
16 #include <zephyr/net/tls_credentials.h>
17 
18 #include "lwm2m_message_handling.h"
19 
20 #define ZSOCK_POLLIN  1
21 #define ZSOCK_POLLOUT 4
22 
23 void set_socket_events(short events);
24 void clear_socket_events(void);
25 
26 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_rd_client_pause);
27 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_rd_client_resume);
28 DECLARE_FAKE_VALUE_FUNC(struct lwm2m_message *, find_msg, struct coap_pending *,
29 			struct coap_reply *);
30 DECLARE_FAKE_VOID_FUNC(coap_pending_clear, struct coap_pending *);
31 DECLARE_FAKE_VALUE_FUNC(size_t, coap_pendings_count, struct coap_pending *, size_t);
32 DECLARE_FAKE_VOID_FUNC(lwm2m_reset_message, struct lwm2m_message *, bool);
33 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_send_message_async, struct lwm2m_message *);
34 DECLARE_FAKE_VOID_FUNC(lwm2m_registry_lock);
35 DECLARE_FAKE_VOID_FUNC(lwm2m_registry_unlock);
36 DECLARE_FAKE_VALUE_FUNC(bool, coap_pending_cycle, struct coap_pending *);
37 DECLARE_FAKE_VALUE_FUNC(int, generate_notify_message, struct lwm2m_ctx *, struct observe_node *,
38 			void *);
39 DECLARE_FAKE_VALUE_FUNC(int64_t, engine_observe_shedule_next_event, struct observe_node *, uint16_t,
40 			const int64_t);
41 DECLARE_FAKE_VALUE_FUNC(int, handle_request, struct coap_packet *, struct lwm2m_message *);
42 DECLARE_FAKE_VOID_FUNC(lwm2m_udp_receive, struct lwm2m_ctx *, uint8_t *, uint16_t,
43 		       struct sockaddr *);
44 DECLARE_FAKE_VALUE_FUNC(bool, lwm2m_rd_client_is_registred, struct lwm2m_ctx *);
45 DECLARE_FAKE_VOID_FUNC(lwm2m_engine_context_close, struct lwm2m_ctx *);
46 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_get_res_buf, const struct lwm2m_obj_path *, void **, uint16_t *,
47 			uint16_t *, uint8_t *);
48 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_parse_peerinfo, char *, struct lwm2m_ctx *, bool);
49 DECLARE_FAKE_VALUE_FUNC(int, tls_credential_add, sec_tag_t, enum tls_credential_type, const void *,
50 			size_t);
51 DECLARE_FAKE_VALUE_FUNC(int, tls_credential_delete, sec_tag_t, enum tls_credential_type);
52 DECLARE_FAKE_VALUE_FUNC(struct lwm2m_engine_obj_field *, lwm2m_get_engine_obj_field,
53 			struct lwm2m_engine_obj *, int);
54 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_get_bool, const struct lwm2m_obj_path *, bool *);
55 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_delete_obj_inst, uint16_t, uint16_t);
56 DECLARE_FAKE_VOID_FUNC(lwm2m_clear_block_contexts);
57 DECLARE_FAKE_VALUE_FUNC(int, z_impl_zsock_connect, int, const struct sockaddr *, socklen_t);
58 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_security_mode, struct lwm2m_ctx *);
59 DECLARE_FAKE_VALUE_FUNC(int, z_impl_zsock_setsockopt, int, int, int, const void *, socklen_t);
60 DECLARE_FAKE_VOID_FUNC(engine_update_tx_time);
61 DECLARE_FAKE_VALUE_FUNC(bool, coap_block_has_more, struct coap_packet *);
62 
63 #define DO_FOREACH_FAKE(FUNC)                                                                      \
64 	do {                                                                                       \
65 		FUNC(lwm2m_rd_client_pause)                                                        \
66 		FUNC(lwm2m_rd_client_resume)                                                       \
67 		FUNC(find_msg)                                                                     \
68 		FUNC(coap_pending_clear)                                                           \
69 		FUNC(coap_pendings_count)                                                          \
70 		FUNC(lwm2m_reset_message)                                                          \
71 		FUNC(lwm2m_send_message_async)                                                     \
72 		FUNC(lwm2m_registry_lock)                                                          \
73 		FUNC(lwm2m_registry_unlock)                                                        \
74 		FUNC(coap_pending_cycle)                                                           \
75 		FUNC(generate_notify_message)                                                      \
76 		FUNC(engine_observe_shedule_next_event)                                            \
77 		FUNC(handle_request)                                                               \
78 		FUNC(lwm2m_udp_receive)                                                            \
79 		FUNC(lwm2m_rd_client_is_registred)                                                 \
80 		FUNC(lwm2m_engine_context_close)                                                   \
81 		FUNC(lwm2m_get_res_buf)                                                            \
82 		FUNC(lwm2m_parse_peerinfo)                                                         \
83 		FUNC(tls_credential_add)                                                           \
84 		FUNC(tls_credential_delete)                                                        \
85 		FUNC(lwm2m_get_engine_obj_field)                                                   \
86 		FUNC(lwm2m_get_bool)                                                               \
87 		FUNC(lwm2m_delete_obj_inst)                                                        \
88 		FUNC(lwm2m_clear_block_contexts)                                                   \
89 		FUNC(z_impl_zsock_connect)                                                         \
90 		FUNC(lwm2m_security_mode)                                                          \
91 		FUNC(z_impl_zsock_setsockopt)                                                      \
92 		FUNC(engine_update_tx_time)                                                        \
93 		FUNC(coap_block_has_more)							   \
94 	} while (0)
95 
96 #endif /* STUBS_H */
97