Author: Armin Rigo <ar...@tunes.org> Branch: wchar_t Changeset: r610:416c671ede44 Date: 2012-07-09 17:02 +0200 http://bitbucket.org/cffi/cffi/changeset/416c671ede44/
Log: Properly skip wchar tests if the backend doesn't support them. diff --git a/cffi/backend_ctypes.py b/cffi/backend_ctypes.py --- a/cffi/backend_ctypes.py +++ b/cffi/backend_ctypes.py @@ -290,6 +290,8 @@ return CTypesVoid def new_primitive_type(self, name): + if name == 'wchar_t': + raise NotImplementedError(name) ctype = self.PRIMITIVE_TYPES[name] if name == 'char': kind = 'char' diff --git a/testing/backend_tests.py b/testing/backend_tests.py --- a/testing/backend_tests.py +++ b/testing/backend_tests.py @@ -297,8 +297,15 @@ assert [p[i] for i in range(2)] == ['a', 'b'] py.test.raises(IndexError, ffi.new, "char[2]", "abc") + def check_wchar_t(self, ffi): + try: + ffi.cast("wchar_t", 0) + except NotImplementedError: + py.test.skip("NotImplementedError: wchar_t") + def test_wchar_t(self): ffi = FFI(backend=self.Backend()) + self.check_wchar_t(ffi) assert ffi.new("wchar_t", u'x')[0] == u'x' assert ffi.new("wchar_t", unichr(1234))[0] == unichr(1234) if SIZE_OF_WCHAR > 2: @@ -541,7 +548,10 @@ ffi = FFI(backend=self.Backend()) assert str(ffi.new("char", "x")) == "x" assert str(ffi.new("char", "\x00")) == "" - # + + def test_unicode_from_wchar_pointer(self): + ffi = FFI(backend=self.Backend()) + self.check_wchar_t(ffi) assert unicode(ffi.new("wchar_t", u"x")) == u"x" assert unicode(ffi.new("wchar_t", u"\x00")) == u"" x = ffi.new("wchar_t", u"\x00") @@ -566,6 +576,7 @@ def test_string_from_wchar_array(self): ffi = FFI(backend=self.Backend()) + self.check_wchar_t(ffi) assert unicode(ffi.cast("wchar_t", "x")) == u"x" assert unicode(ffi.cast("wchar_t", u"x")) == u"x" x = ffi.cast("wchar_t", "x") @@ -600,6 +611,7 @@ def test_fetch_const_wchar_p_field(self): # 'const' is ignored so far ffi = FFI(backend=self.Backend()) + self.check_wchar_t(ffi) ffi.cdef("struct foo { const wchar_t *name; };") t = ffi.new("const wchar_t[]", u"testing") s = ffi.new("struct foo", [t]) @@ -716,6 +728,10 @@ assert int(p) == 0x80 # "char" is considered unsigned in this case p = ffi.cast("int", "\x81") assert int(p) == 0x81 + + def test_wchar_cast(self): + ffi = FFI(backend=self.Backend()) + self.check_wchar_t(ffi) p = ffi.cast("int", ffi.cast("wchar_t", unichr(1234))) assert int(p) == 1234 p = ffi.cast("long long", ffi.cast("wchar_t", -1)) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit