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_VOID_FUNC(lwm2m_reset_message, struct lwm2m_message *, bool);
32 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_send_message_async, struct lwm2m_message *);
33 DECLARE_FAKE_VOID_FUNC(lwm2m_registry_lock);
34 DECLARE_FAKE_VOID_FUNC(lwm2m_registry_unlock);
35 DECLARE_FAKE_VALUE_FUNC(bool, coap_pending_cycle, struct coap_pending *);
36 DECLARE_FAKE_VALUE_FUNC(int, generate_notify_message, struct lwm2m_ctx *, struct observe_node *,
37 			void *);
38 DECLARE_FAKE_VALUE_FUNC(int64_t, engine_observe_shedule_next_event, struct observe_node *, uint16_t,
39 			const int64_t);
40 DECLARE_FAKE_VALUE_FUNC(int, handle_request, struct coap_packet *, struct lwm2m_message *);
41 DECLARE_FAKE_VOID_FUNC(lwm2m_udp_receive, struct lwm2m_ctx *, uint8_t *, uint16_t,
42 		       struct sockaddr *, udp_request_handler_cb_t);
43 DECLARE_FAKE_VALUE_FUNC(bool, lwm2m_rd_client_is_registred, struct lwm2m_ctx *);
44 DECLARE_FAKE_VOID_FUNC(lwm2m_engine_context_close, struct lwm2m_ctx *);
45 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_get_res_buf, const struct lwm2m_obj_path *, void **, uint16_t *,
46 			uint16_t *, uint8_t *);
47 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_parse_peerinfo, char *, struct lwm2m_ctx *, bool);
48 DECLARE_FAKE_VALUE_FUNC(int, tls_credential_add, sec_tag_t, enum tls_credential_type, const void *,
49 			size_t);
50 DECLARE_FAKE_VALUE_FUNC(int, tls_credential_delete, sec_tag_t, enum tls_credential_type);
51 DECLARE_FAKE_VALUE_FUNC(struct lwm2m_engine_obj_field *, lwm2m_get_engine_obj_field,
52 			struct lwm2m_engine_obj *, int);
53 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_get_bool, const struct lwm2m_obj_path *, bool *);
54 DECLARE_FAKE_VALUE_FUNC(int, lwm2m_delete_obj_inst, uint16_t, uint16_t);
55 DECLARE_FAKE_VOID_FUNC(lwm2m_clear_block_contexts);
56 DECLARE_FAKE_VALUE_FUNC(int, z_impl_zsock_connect, int, const struct sockaddr *, socklen_t);
57 
58 #define DO_FOREACH_FAKE(FUNC)                                                                      \
59 	do {                                                                                       \
60 		FUNC(lwm2m_rd_client_pause)                                                        \
61 		FUNC(lwm2m_rd_client_resume)                                                       \
62 		FUNC(find_msg)                                                                     \
63 		FUNC(coap_pending_clear)                                                           \
64 		FUNC(lwm2m_reset_message)                                                          \
65 		FUNC(lwm2m_send_message_async)                                                     \
66 		FUNC(lwm2m_registry_lock)                                                          \
67 		FUNC(lwm2m_registry_unlock)                                                        \
68 		FUNC(coap_pending_cycle)                                                           \
69 		FUNC(generate_notify_message)                                                      \
70 		FUNC(engine_observe_shedule_next_event)                                            \
71 		FUNC(handle_request)                                                               \
72 		FUNC(lwm2m_udp_receive)                                                            \
73 		FUNC(lwm2m_rd_client_is_registred)                                                 \
74 		FUNC(lwm2m_engine_context_close)                                                   \
75 		FUNC(lwm2m_get_res_buf)                                                            \
76 		FUNC(lwm2m_parse_peerinfo)                                                         \
77 		FUNC(tls_credential_add)                                                           \
78 		FUNC(tls_credential_delete)                                                        \
79 		FUNC(lwm2m_get_engine_obj_field)                                                   \
80 		FUNC(lwm2m_get_bool)                                                               \
81 		FUNC(lwm2m_delete_obj_inst)                                                        \
82 		FUNC(lwm2m_clear_block_contexts)                                                   \
83 		FUNC(z_impl_zsock_connect)                                                         \
84 	} while (0)
85 
86 #endif /* STUBS_H */
87