3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 04:32:37 +01:00

unit: add tests for util_get_{domain,username}

test-ssid-to-utf8 was hijacked and renamed to test-util, and
two tests were added for the new utility functions.
This commit is contained in:
James Prestwood 2019-04-08 11:15:21 -07:00 committed by Denis Kenzior
parent 1e337259ce
commit 27f7a523b4
2 changed files with 44 additions and 4 deletions

View File

@ -312,7 +312,7 @@ unit_tests = unit/test-cmac-aes \
unit/test-hmac-md5 unit/test-hmac-sha1 unit/test-hmac-sha256 \
unit/test-prf-sha1 unit/test-kdf-sha256 \
unit/test-crypto unit/test-eapol unit/test-mpdu \
unit/test-ie unit/test-ssid-to-utf8 unit/test-ssid-security \
unit/test-ie unit/test-util unit/test-ssid-security \
unit/test-arc4 unit/test-wsc unit/test-eap-mschapv2 \
unit/test-eap-sim unit/test-sae
@ -399,9 +399,9 @@ unit_test_eapol_SOURCES = unit/test-eapol.c \
unit_test_eapol_LDADD = $(ell_ldadd)
unit_test_eapol_DEPENDENCIES = ell/unit/test_data
unit_test_ssid_to_utf8_SOURCES = src/util.h src/util.c \
unit/test-ssid-to-utf8.c
unit_test_ssid_to_utf8_LDADD = $(ell_ldadd)
unit_test_util_SOURCES = src/util.h src/util.c \
unit/test-util.c
unit_test_util_LDADD = $(ell_ldadd)
unit_test_ssid_security_SOURCES = unit/test-ssid-security.c src/ie.h src/ie.c \
src/common.h src/common.c

View File

@ -77,11 +77,51 @@ static void ssid_to_utf8(const void *data)
}
static const char ms_id[] = "domain\\user";
static const char id[] = "user@domain";
static const char no_separator[] = "username";
static void get_domain_test(const void *data)
{
const char *test;
test = util_get_domain(ms_id);
assert(strcmp(test, "domain") == 0);
test = util_get_domain(id);
assert(strcmp(test, "domain") == 0);
test = util_get_domain(no_separator);
assert(strcmp(test, "username") == 0);
}
static void get_username_test(const void *data)
{
const char *test;
test = util_get_username(ms_id);
assert(strcmp(test, "user") == 0);
test = util_get_username(id);
assert(strcmp(test, "user") == 0);
test = util_get_username(no_separator);
assert(strcmp(test, "username") == 0);
}
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
l_test_add("/util/ssid_to_utf8/", ssid_to_utf8, ssid_samples);
l_test_add("/util/get_domain/", get_domain_test, NULL);
l_test_add("/util/get_username/", get_username_test, NULL);
return l_test_run();
}