Skip to content

Commit 9dbf131

Browse files
committed
Add test for C API function PyUnicode_FromWideChar.
1 parent 3d49968 commit 9dbf131

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

graalpython/com.oracle.graal.python.test/src/tests/cpyext/test_unicode.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -493,10 +493,7 @@ def compile_module(self, name):
493493
(2, bytearray([0x30, 0x20, 0x3C, 0x20]), 2, "‰‼"),
494494
),
495495
code='''PyObject* wrap_PyUnicode_FromKindAndData(int kind, Py_buffer buffer, Py_ssize_t size, PyObject* dummy) {
496-
PyObject* res;
497-
res = PyUnicode_FromKindAndData(kind, (const char *)buffer.buf, size);
498-
Py_XINCREF(res);
499-
return res;
496+
return PyUnicode_FromKindAndData(kind, (const char *)buffer.buf, size);
500497
}
501498
''',
502499
resultspec="O",
@@ -523,3 +520,28 @@ def compile_module(self, name):
523520
cmpfunc=unhandled_error_compare
524521
)
525522

523+
524+
# NOTE: this test assumes that Python uses UTF-8 encoding for source files
525+
test_PyUnicode_FromWideChar = CPyExtFunction(
526+
lambda args: args[3],
527+
lambda: (
528+
(4, bytearray([0xA2, 0x0E, 0x02, 0x00]), 1, "𠺢"),
529+
(4, bytearray([0xA2, 0x0E, 0x02, 0x00, 0x4C, 0x0F, 0x02, 0x00]), 2, "𠺢𠽌"),
530+
(2, bytearray([0x30, 0x20]), 1, "‰"),
531+
(2, bytearray([0x30, 0x20, 0x3C, 0x20]), 2, "‰‼"),
532+
),
533+
code='''PyObject* wrap_PyUnicode_FromWideChar(int expectedWcharSize, Py_buffer buffer, Py_ssize_t size, PyObject* dummy) {
534+
if (SIZEOF_WCHAR_T == expectedWcharSize) {
535+
return PyUnicode_FromWideChar((const wchar_t *) buffer.buf, size);
536+
}
537+
return dummy;
538+
}
539+
''',
540+
resultspec="O",
541+
argspec='iy*nO',
542+
arguments=["int expectedWcharSize", "Py_buffer buffer", "Py_ssize_t size", "PyObject* dummy"],
543+
callfunction="wrap_PyUnicode_FromWideChar",
544+
cmpfunc=unhandled_error_compare
545+
)
546+
547+

0 commit comments

Comments
 (0)