(self)
| 19 | |
| 20 | class ArrayPtrTest(DFFITest): |
| 21 | def test_array_ptr(self): |
| 22 | CU = self.FFI.compile(''' |
| 23 | #include <stdio.h> |
| 24 | typedef int int2[2]; |
| 25 | void foo(char* buf, size_t n, int2* ar) |
| 26 | { |
| 27 | snprintf(buf, n, "%d %d", ar[0][0], ar[0][1]); |
| 28 | } |
| 29 | ''') |
| 30 | |
| 31 | v = CU.types.int2() |
| 32 | v.set(0, 1) |
| 33 | v.set(1, 2) |
| 34 | buf = self.FFI.arrayType(self.FFI.CharTy, 128)() |
| 35 | CU.funcs.foo(pydffi.ptr(buf), 128, pydffi.ptr(v)) |
| 36 | self.assertEqual(self.cstr_from_array(buf), b"1 2") |
| 37 | |
| 38 | v[0] = 10 |
| 39 | v[1] = 20 |
| 40 | CU.funcs.foo(pydffi.ptr(buf), 128, pydffi.ptr(v)) |
| 41 | self.assertEqual(self.cstr_from_array(buf), b"10 20") |
| 42 | |
| 43 | if __name__ == '__main__': |
| 44 | unittest.main() |
nothing calls this directly
no test coverage detected