From d5843944cc8ce29085bcdbfc0bd300c102f019af Mon Sep 17 00:00:00 2001 From: Erik Ekman Date: Sat, 27 Feb 2021 12:28:14 +0100 Subject: [PATCH] netif: Add test for netif_find --- test/unit/core/test_netif.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/test/unit/core/test_netif.c b/test/unit/core/test_netif.c index 64063679..35d44714 100644 --- a/test/unit/core/test_netif.c +++ b/test/unit/core/test_netif.c @@ -240,13 +240,42 @@ START_TEST(test_netif_flag_set) } END_TEST +START_TEST(test_netif_find) +{ + struct netif net0; + struct netif net1; + LWIP_UNUSED_ARG(_i); + + /* No netifs available */ + fail_unless(netif_find("ch0") == NULL); + + /* Add netifs with known names */ + fail_unless(netif_add_noaddr(&net0, NULL, testif_init, ethernet_input) == &net0); + net0.num = 0; + fail_unless(netif_add_noaddr(&net1, NULL, testif_init, ethernet_input) == &net1); + net1.num = 1; + + fail_unless(netif_find("ch0") == &net0); + fail_unless(netif_find("CH0") == NULL); + fail_unless(netif_find("ch1") == &net1); + fail_unless(netif_find("ch3") == NULL); + /* atoi failure is not treated as zero */ + fail_unless(netif_find("chX") == NULL); + fail_unless(netif_find("ab0") == NULL); + + netif_remove(&net0); + netif_remove(&net1); +} +END_TEST + /** Create the suite including all tests for this module */ Suite * netif_suite(void) { testfunc tests[] = { TESTFUNC(test_netif_extcallbacks), - TESTFUNC(test_netif_flag_set) + TESTFUNC(test_netif_flag_set), + TESTFUNC(test_netif_find) }; return create_suite("NETIF", tests, sizeof(tests)/sizeof(testfunc), netif_setup, netif_teardown); }