Source

cffi / testing / test_verify.py

Diff from to

testing/test_verify.py

     ffi = FFI()
     ffi.cdef("size_t strlen(const char *s);")
     lib = ffi.verify("#include <string.h>")
-    assert lib.strlen("hi there!") == 9
+    assert lib.strlen(b"hi there!") == 9
 
 def test_strlen_approximate():
     ffi = FFI()
     ffi.cdef("int strlen(char *s);")
     lib = ffi.verify("#include <string.h>")
-    assert lib.strlen("hi there!") == 9
+    assert lib.strlen(b"hi there!") == 9
 
 def test_strlen_array_of_char():
     ffi = FFI()
     ffi.cdef("int strlen(char[]);")
     lib = ffi.verify("#include <string.h>")
-    assert lib.strlen("hello") == 5
+    assert lib.strlen(b"hello") == 5
 
 
 all_integer_types = ['short', 'int', 'long', 'long long',
         ffi.cdef("%s foo(%s);" % (typename, typename))
         lib = ffi.verify("%s foo(%s x) { return x+1; }" % (typename, typename))
         assert lib.foo(42) == 43
-        assert lib.foo(44L) == 45
+        if sys.version < '3':
+            assert lib.foo(long(44)) == 45
         assert lib.foo(ffi.cast(typename, 46)) == 47
         py.test.raises(TypeError, lib.foo, ffi.NULL)
         #
     ffi = FFI()
     ffi.cdef("char foo(char);")
     lib = ffi.verify("char foo(char x) { return x+1; }")
-    assert lib.foo("A") == "B"
+    assert lib.foo(b"A") == b"B"
+    py.test.raises(TypeError, lib.foo, b"bar")
     py.test.raises(TypeError, lib.foo, "bar")
 
 def test_wchar_type():
     ffi.cdef("static char *const PP;")
     lib = ffi.verify('static char *const PP = "testing!";\n')
     assert ffi.typeof(lib.PP) == ffi.typeof("char *")
-    assert str(lib.PP) == "testing!"
+    assert lib.PP.value == b"testing!"
 
 def test_nonfull_enum():
     ffi = FFI()
             return s.a - s.b;
         }
     """)
-    s = ffi.new("struct foo_s *", ['B', 1])
+    s = ffi.new("struct foo_s *", [b'B', 1])
     assert lib.foo(50, s[0]) == ord('A')
 
 def test_autofilled_struct_as_argument():
     """)
     foochar = ffi.cast("char *(*)(void)", lib.fooptr)
     s = foochar()
-    assert str(s) == "foobar"
+    assert s.value == b"foobar"
 
 def test_funcptr_as_argument():
     ffi = FFI()