diff options
author | Beat Bolli <dev@drbeat.li> | 2021-02-14 23:47:57 +0100 |
---|---|---|
committer | Pauli <ppzgs1@gmail.com> | 2021-03-18 14:12:48 +1000 |
commit | d07d8057991712261323c05bb022d000a01404d0 (patch) | |
tree | 2eff21a354bb2c98608540953bf7f8d541022220 /test/asn1_internal_test.c | |
parent | eb27d75788e7d53a2a43aacc25f23c2856b4065d (diff) |
Add tests for the limited Unicode code point range
Signed-off-by: Beat Bolli <dev@drbeat.li>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14185)
Diffstat (limited to 'test/asn1_internal_test.c')
-rw-r--r-- | test/asn1_internal_test.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/asn1_internal_test.c b/test/asn1_internal_test.c index e77299a7c8..cf201a5a26 100644 --- a/test/asn1_internal_test.c +++ b/test/asn1_internal_test.c @@ -107,9 +107,50 @@ static int test_standard_methods(void) return 0; } +/********************************************************************** + * + * Tests of the Unicode code point range + * + ***/ + +static int test_unicode(const unsigned char *univ, size_t len, int expected) +{ + const unsigned char *end = univ + len; + int ok = 1; + + for (; univ < end; univ += 4) { + if (!TEST_int_eq(ASN1_mbstring_copy(NULL, univ, 4, MBSTRING_UNIV, + B_ASN1_UTF8STRING), + expected)) + ok = 0; + } + return ok; +} + +static int test_unicode_range(void) +{ + const unsigned char univ_ok[] = "\0\0\0\0" + "\0\0\xd7\xff" + "\0\0\xe0\x00" + "\0\x10\xff\xff"; + const unsigned char univ_bad[] = "\0\0\xd8\x00" + "\0\0\xdf\xff" + "\0\x11\x00\x00" + "\x80\x00\x00\x00" + "\xff\xff\xff\xff"; + int ok = 1; + + if (!test_unicode(univ_ok, sizeof univ_ok - 1, V_ASN1_UTF8STRING)) + ok = 0; + if (!test_unicode(univ_bad, sizeof univ_bad - 1, -1)) + ok = 0; + return ok; +} + int setup_tests(void) { ADD_TEST(test_tbl_standard); ADD_TEST(test_standard_methods); + ADD_TEST(test_unicode_range); return 1; } |