Add tests for the limited Unicode code point range
authorBeat Bolli <dev@drbeat.li>
Sun, 14 Feb 2021 22:47:57 +0000 (23:47 +0100)
committerPauli <ppzgs1@gmail.com>
Thu, 18 Mar 2021 04:12:48 +0000 (14:12 +1000)
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)

test/asn1_internal_test.c

index e77299a7c8e38e1c3797d0a1da16de1cc28090e3..cf201a5a267066fa90d1fc211020f80e31c3ddf2 100644 (file)
@@ -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;
 }