diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2016-11-20 17:08:55 +0100 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2016-11-21 11:56:40 +0100 |
commit | d698869964053ddf53971b6dc787af477beae139 (patch) | |
tree | 9dd69574190a588b8df4a329ea104432bdbbba18 | |
parent | f71891e787612c085b2bb844f8b1a5ab07c74e24 (diff) | |
download | gnutls-d698869964053ddf53971b6dc787af477beae139.tar.gz |
tests: enhanced str-unicode with GNUTLS_UTF8_IGNORE_ERRS flag
That is, enhanced to check the tolerable variant of gnutls_utf8_password_normalize()
-rw-r--r-- | tests/str-unicode.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tests/str-unicode.c b/tests/str-unicode.c index 274fb6e956..5602ec30d5 100644 --- a/tests/str-unicode.c +++ b/tests/str-unicode.c @@ -49,6 +49,21 @@ static void fname(void **glob_state) \ gnutls_free(out.data); \ } +#define INVALID_MATCH_FUNC(fname, password, normalized) \ +static void inv_##fname(void **glob_state) \ +{ \ + gnutls_datum_t out; \ + int ret = gnutls_utf8_password_normalize((uint8_t*)password, strlen(password), &out, GNUTLS_UTF8_IGNORE_ERRS); \ + if (normalized == NULL) { \ + assert_int_not_equal(ret, 0); \ + return; \ + } else { \ + assert_int_equal(ret, 0); \ + } \ + assert_int_equal(strcmp((char*)out.data, (char*)normalized), 0); \ + gnutls_free(out.data); \ +} + MATCH_FUNC(test_ascii, "correct horse battery staple", "correct horse battery staple"); MATCH_FUNC(test_capitals, "Correct Horse Battery Staple", "Correct Horse Battery Staple"); MATCH_FUNC(test_multilang, "\xCF\x80\xC3\x9F\xC3\xA5", "πßå"); @@ -57,6 +72,10 @@ MATCH_FUNC(test_space_replacement, "foo bar", "foo bar"); MATCH_FUNC(test_invalid, "my cat is a \x09by", NULL); MATCH_FUNC(test_normalization1, "char \x49\xCC\x87", "char \xC4\xB0"); +INVALID_MATCH_FUNC(test_ascii, "correct horse battery staple", "correct horse battery staple"); +INVALID_MATCH_FUNC(test_special_char, "\x4A\x61\x63\x6B\x20\x6F\x66\x20\xE2\x99\xA6\x73", "Jack of ♦s"); +INVALID_MATCH_FUNC(test_invalid, "my cat is a \x09by", "my cat is a \x09by"); + int main(void) { const struct CMUnitTest tests[] = { @@ -66,7 +85,10 @@ int main(void) cmocka_unit_test(test_special_char), cmocka_unit_test(test_space_replacement), cmocka_unit_test(test_invalid), - cmocka_unit_test(test_normalization1) + cmocka_unit_test(test_normalization1), + cmocka_unit_test(inv_test_ascii), + cmocka_unit_test(inv_test_special_char), + cmocka_unit_test(inv_test_invalid) }; return cmocka_run_group_tests(tests, NULL, NULL); } |