From 3904be6b0f17a80ebc220d70d80e77c74cef75c5 Mon Sep 17 00:00:00 2001
From: David Cermak <cermak@espressif.com>
Date: Mon, 10 Feb 2020 21:36:31 +0100
Subject: [PATCH] ESP-NETIF: add unit test for get/set hostname API

---
 components/esp_netif/test/test_esp_netif.c | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/components/esp_netif/test/test_esp_netif.c b/components/esp_netif/test/test_esp_netif.c
index be1c99798c..a3d8447099 100644
--- a/components/esp_netif/test/test_esp_netif.c
+++ b/components/esp_netif/test/test_esp_netif.c
@@ -225,3 +225,31 @@ TEST_CASE("esp_netif: create custom wifi interfaces", "[esp_netif][leaks=0]")
     esp_netif_destroy(sta);
 }
 
+
+TEST_CASE("esp_netif: get/set hostname", "[esp_netif]")
+{
+    const char *hostname;
+    esp_netif_config_t cfg = ESP_NETIF_DEFAULT_WIFI_STA();
+
+    test_case_uses_tcpip();
+    esp_netif_t *esp_netif = esp_netif_new(&cfg);
+
+    // specific hostname not set yet, get_hostname should fail
+    TEST_ASSERT_NOT_EQUAL(ESP_OK, esp_netif_get_hostname(esp_netif, &hostname));
+
+    TEST_ASSERT_NOT_NULL(esp_netif);
+    esp_netif_attach_wifi_station(esp_netif);
+
+    esp_netif_action_start(esp_netif, NULL, 0, NULL);
+
+    // specific hostname not set yet, but if started, get_hostname to return default config value
+    TEST_ASSERT_EQUAL(ESP_OK, esp_netif_get_hostname(esp_netif, &hostname));
+    TEST_ASSERT_EQUAL_STRING(hostname, CONFIG_LWIP_LOCAL_HOSTNAME);
+
+    // specific hostname set and get
+    TEST_ASSERT_EQUAL(ESP_OK, esp_netif_set_hostname(esp_netif, "new_name"));
+    TEST_ASSERT_EQUAL(ESP_OK, esp_netif_get_hostname(esp_netif, &hostname));
+    TEST_ASSERT_EQUAL_STRING(hostname, "new_name");
+
+    esp_netif_destroy(esp_netif);
+}