Commits

Armin Rigo  committed 416c671

Properly skip wchar tests if the backend doesn't support them.

  • Participants
  • Parent commits 7cccdc4
  • Branches wchar_t

Comments (0)

Files changed (2)

File cffi/backend_ctypes.py

         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'

File testing/backend_tests.py

         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:
         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")
 
     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")
     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])
         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))