File tree Expand file tree Collapse file tree 5 files changed +73
-17
lines changed
components/mdns/tests/host_unit_test/unity Expand file tree Collapse file tree 5 files changed +73
-17
lines changed Original file line number Diff line number Diff line change 98
98
cmake -DUNIT_TESTS=test_receiver ..
99
99
cmake --build .
100
100
ctest --extra-verbose
101
+ cd ..
102
+ mkdir build3 && cd build3
103
+ cmake -DUNIT_TESTS=test_sender ..
104
+ cmake --build .
105
+ ctest --extra-verbose
101
106
102
107
103
108
fuzz_test :
Original file line number Diff line number Diff line change 7
7
#include "unity.h"
8
8
#include "create_test_packet.h"
9
9
#include "unity_main.h"
10
+ #include "mock_mdns_pcb.h"
11
+ #include "mock_mdns_send.h"
12
+ #include "create_test_packet.h"
10
13
11
14
static void test_mdns_hostname_queries (void )
12
15
{
@@ -58,6 +61,23 @@ static void test_mdns_with_answers(void)
58
61
59
62
}
60
63
64
+ static void mdns_priv_create_answer_from_parsed_packet_Callback (mdns_parsed_packet_t * parsed_packet , int cmock_num_calls )
65
+ {
66
+ printf ("callback\n" );
67
+ }
68
+
69
+ void setup_cmock (void )
70
+ {
71
+ mdns_priv_probe_all_pcbs_CMockIgnore ();
72
+ mdns_priv_pcb_announce_CMockIgnore ();
73
+ mdns_priv_pcb_send_bye_service_CMockIgnore ();
74
+ mdns_priv_pcb_check_probing_services_CMockIgnore ();
75
+ mdns_priv_pcb_is_after_probing_IgnoreAndReturn (true);
76
+
77
+ _mdns_clear_tx_queue_head_CMockIgnore ();
78
+ _mdns_remove_scheduled_service_packets_CMockIgnore ();
79
+ mdns_priv_create_answer_from_parsed_packet_Stub (mdns_priv_create_answer_from_parsed_packet_Callback );
80
+ }
61
81
62
82
void run_unity_tests (void )
63
83
{
Original file line number Diff line number Diff line change
1
+ /*
2
+ * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3
+ *
4
+ * SPDX-License-Identifier: Unlicense OR CC0-1.0
5
+ */
6
+
7
+ #include "unity.h"
8
+ #include "unity_main.h"
9
+ #include "mock_mdns_pcb.h"
10
+ #include "mdns_send.h"
11
+
12
+ void setup_cmock (void )
13
+ {
14
+ mdns_priv_probe_all_pcbs_CMockIgnore ();
15
+ mdns_priv_pcb_announce_CMockIgnore ();
16
+ mdns_priv_pcb_send_bye_service_CMockIgnore ();
17
+ mdns_priv_pcb_check_probing_services_CMockIgnore ();
18
+ mdns_priv_pcb_is_after_probing_IgnoreAndReturn (true);
19
+ }
20
+
21
+
22
+
23
+ // Example of a more complex test with answers and additional records
24
+ static void test_dispatch_tx_packet (void )
25
+ {
26
+ mdns_tx_packet_t p = {};
27
+ _mdns_dispatch_tx_packet (& p );
28
+ }
29
+
30
+
31
+ void run_unity_tests (void )
32
+ {
33
+ UNITY_BEGIN ();
34
+
35
+ // Run hostname queries test
36
+ RUN_TEST (test_dispatch_tx_packet );
37
+
38
+
39
+ UNITY_END ();
40
+ }
Original file line number Diff line number Diff line change
1
+ # Testing mDNS sender, need to mock pbb
2
+ set (MOCK_FILES
3
+ "mdns_pcb"
4
+ )
5
+
6
+ list (APPEND SOURCES unity/${UNIT_TESTS}/test_sender.c )
Original file line number Diff line number Diff line change 12
12
#include "mdns_receive.h"
13
13
#include "mdns_responder.h"
14
14
#include "mdns_mem_caps.h"
15
- #include "mock_mdns_pcb.h"
16
- #include "mock_mdns_send.h"
17
- #include "create_test_packet.h"
18
15
19
16
void setUp (void )
20
17
{
@@ -132,24 +129,12 @@ void test_mdns_receive_from_file(const char* filename)
132
129
133
130
134
131
void run_unity_tests (void );
135
-
136
- void mdns_priv_create_answer_from_parsed_packet_Callback (mdns_parsed_packet_t * parsed_packet , int cmock_num_calls )
137
- {
138
- printf ("callback\n" );
139
- }
132
+ void setup_cmock (void );
140
133
141
134
int main (int argc , char * * argv )
142
135
{
143
136
if (argc >= 2 && strcmp (argv [1 ], "--test" ) == 0 ) {
144
- mdns_priv_probe_all_pcbs_CMockIgnore ();
145
- mdns_priv_pcb_announce_CMockIgnore ();
146
- mdns_priv_pcb_send_bye_service_CMockIgnore ();
147
- mdns_priv_pcb_check_probing_services_CMockIgnore ();
148
- mdns_priv_pcb_is_after_probing_IgnoreAndReturn (true);
149
-
150
- _mdns_clear_tx_queue_head_CMockIgnore ();
151
- _mdns_remove_scheduled_service_packets_CMockIgnore ();
152
- mdns_priv_create_answer_from_parsed_packet_Stub (mdns_priv_create_answer_from_parsed_packet_Callback );
137
+ setup_cmock ();
153
138
154
139
init_responder ();
155
140
run_unity_tests ();
You can’t perform that action at this time.
0 commit comments