Author: Alecsandru Patrascu <alecsandru.patra...@rinftech.com> Branch: ctypes_char_indexing Changeset: r91553:76bf604679cd Date: 2017-05-30 09:58 +0300 http://bitbucket.org/pypy/pypy/changeset/76bf604679cd/
Log: added tests for char_p and unichar_p interpretation diff --git a/pypy/module/test_lib_pypy/ctypes_tests/test_array.py b/pypy/module/test_lib_pypy/ctypes_tests/test_array.py --- a/pypy/module/test_lib_pypy/ctypes_tests/test_array.py +++ b/pypy/module/test_lib_pypy/ctypes_tests/test_array.py @@ -138,4 +138,39 @@ x.y = 3 y[1] = x assert y[1].y == 3 + + def test_output_simple(self): + A = c_char * 10 + TP = POINTER(A) + x = TP(A()) + assert repr(x[0]) != "''" + assert isinstance(repr(x[0]), bytes) + + A = c_wchar * 10 + TP = POINTER(A) + x = TP(A()) + assert repr(x[0]) != "''" + assert isinstance(repr(x[0]), bytes) + + def test_output_complex_test(self): + class Car(Structure): + _fields_ = [("brand", c_char * 10), + ("speed", c_float), + ("owner", c_char * 10)] + + assert Car("abcdefghi", 42.0, "12345").brand == "abcdefghi" + assert Car("abcdefghio", 42.0, "12345").brand == "abcdefghio" + raises(ValueError, Car, "abcdefghiop", 42.0, "12345") + + A = Car._fields_[2][1] + TP = POINTER(A) + x = TP(A()) + assert repr(x[0]) != "''" + assert isinstance(repr(x[0]), bytes) + + c = Car() + c.brand = "abcdex" + c.speed = 42.0 + c.owner = "12345" + assert isinstance(repr(c.brand), bytes) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit