| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
from __future__ import unicode_literals |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
from pypy.module._cffi_backend.newtype import _clean_cache |
| 11 |
|
| 12 |
|
| 13 |
class AppTestUnicodeLiterals: |
| 14 |
spaceconfig = dict(usemodules=('_cffi_backend', )) |
| 15 |
|
| 16 |
def teardown_method(self, meth): |
| 17 |
_clean_cache(self.space) |
| 18 |
|
| 19 |
def test_cast(self): |
| 20 |
from _cffi_backend import FFI |
| 21 |
ffi = FFI() |
| 22 |
assert int(ffi.cast("int", 3.14)) == 3 |
| 23 |
|
| 24 |
def test_new(self): |
| 25 |
from _cffi_backend import FFI |
| 26 |
ffi = FFI() |
| 27 |
assert ffi.new("int[]", [3, 4, 5])[2] == 5 |
| 28 |
|
| 29 |
def test_typeof(self): |
| 30 |
from _cffi_backend import FFI |
| 31 |
ffi = FFI() |
| 32 |
tp = ffi.typeof("int[51]") |
| 33 |
assert tp.length == 51 |
| 34 |
|
| 35 |
def test_sizeof(self): |
| 36 |
from _cffi_backend import FFI |
| 37 |
ffi = FFI() |
| 38 |
assert ffi.sizeof("int[51]") == 51 * 4 |
| 39 |
|
| 40 |
def test_alignof(self): |
| 41 |
from _cffi_backend import FFI |
| 42 |
ffi = FFI() |
| 43 |
assert ffi.alignof("int[51]") == 4 |
| 44 |
|
| 45 |
def test_getctype(self): |
| 46 |
from _cffi_backend import FFI |
| 47 |
ffi = FFI() |
| 48 |
assert ffi.getctype("int**") == "int * *" |
| 49 |
assert type(ffi.getctype("int**")) is str |
| 50 |
|
| 51 |
def test_callback(self): |
| 52 |
from _cffi_backend import FFI |
| 53 |
ffi = FFI() |
| 54 |
cb = ffi.callback("int(int)", |
| 55 |
lambda x: x + 42) |
| 56 |
assert cb(5) == 47 |