11/*
2- * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
1313#include "esp32_mock.h"
1414#include "mdns.h"
1515#include "mdns_private.h"
16+ #include "mdns_utils.h"
17+ #include "mdns_querier.h"
1618
1719//
1820// Global stuctures containing packet payload, search
@@ -23,20 +25,21 @@ mdns_search_once_t *search = NULL;
2325//
2426// Dependency injected test functions
2527void mdns_test_execute_action (void * action );
26- mdns_srv_item_t * mdns_test_mdns_get_service_item (const char * service , const char * proto );
2728mdns_search_once_t * mdns_test_search_init (const char * name , const char * service , const char * proto , uint16_t type , uint32_t timeout , uint8_t max_results );
2829esp_err_t mdns_test_send_search_action (mdns_action_type_t type , mdns_search_once_t * search );
2930void mdns_test_search_free (mdns_search_once_t * search );
31+
3032void mdns_test_init_di (void );
33+ void mdns_querier_test_init_di (void );
3134extern mdns_server_t * _mdns_server ;
3235
3336//
3437// mdns function wrappers for mdns setup in test mode
3538static int mdns_test_hostname_set (const char * mdns_hostname )
3639{
3740 for (int i = 0 ; i < MDNS_MAX_INTERFACES ; i ++ ) {
38- _mdns_server -> interfaces [i ].pcbs [MDNS_IP_PROTOCOL_V4 ].state = PCB_RUNNING ; // mark the PCB running to exercise mdns in fully operational mode
39- _mdns_server -> interfaces [i ].pcbs [MDNS_IP_PROTOCOL_V6 ].state = PCB_RUNNING ;
41+ // _mdns_server->interfaces[i].pcbs[MDNS_IP_PROTOCOL_V4].state = PCB_RUNNING; // mark the PCB running to exercise mdns in fully operational mode
42+ // _mdns_server->interfaces[i].pcbs[MDNS_IP_PROTOCOL_V6].state = PCB_RUNNING;
4043 }
4144 int ret = mdns_hostname_set (mdns_hostname );
4245 mdns_action_t * a = NULL ;
@@ -78,32 +81,22 @@ static int mdns_test_service_txt_set(const char *service, const char *proto, ui
7881static int mdns_test_sub_service_add (const char * sub_name , const char * service_name , const char * proto , uint32_t port )
7982{
8083 if (mdns_service_add (NULL , service_name , proto , port , NULL , 0 )) {
81- // This is expected failure as the service thread is not running
84+ return ESP_FAIL ;
8285 }
83- mdns_action_t * a = NULL ;
84- GetLastItem (& a );
85- mdns_test_execute_action (a );
8686
87- if (mdns_test_mdns_get_service_item (service_name , proto ) == NULL ) {
87+ if (_mdns_get_service_item (service_name , proto , NULL ) == NULL ) {
8888 return ESP_FAIL ;
8989 }
90- int ret = mdns_service_subtype_add_for_host (NULL , service_name , proto , NULL , sub_name );
91- a = NULL ;
92- GetLastItem (& a );
93- mdns_test_execute_action (a );
94- return ret ;
90+ return mdns_service_subtype_add_for_host (NULL , service_name , proto , NULL , sub_name );
9591}
9692
9793static int mdns_test_service_add (const char * service_name , const char * proto , uint32_t port )
9894{
9995 if (mdns_service_add (NULL , service_name , proto , port , NULL , 0 )) {
100- // This is expected failure as the service thread is not running
96+ return ESP_FAIL ;
10197 }
102- mdns_action_t * a = NULL ;
103- GetLastItem (& a );
104- mdns_test_execute_action (a );
10598
106- if (mdns_test_mdns_get_service_item (service_name , proto ) == NULL ) {
99+ if (_mdns_get_service_item (service_name , proto , NULL ) == NULL ) {
107100 return ESP_FAIL ;
108101 }
109102 return ESP_OK ;
@@ -161,6 +154,7 @@ int main(int argc, char **argv)
161154
162155 // Init depencency injected methods
163156 mdns_test_init_di ();
157+ mdns_querier_test_init_di ();
164158
165159 if (mdns_init ()) {
166160 abort ();
@@ -266,9 +260,6 @@ int main(int argc, char **argv)
266260 }
267261#ifndef MDNS_NO_SERVICES
268262 mdns_service_remove_all ();
269- mdns_action_t * a = NULL ;
270- GetLastItem (& a );
271- mdns_test_execute_action (a );
272263#endif
273264 ForceTaskDelete ();
274265 mdns_free ();
0 commit comments