MCPcopy Create free account
hub / github.com/aguinet/dragonffi / test_array_ptr

Method test_array_ptr

bindings/python/tests/test_array_ptr.py:21–41  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

19
20class ArrayPtrTest(DFFITest):
21 def test_array_ptr(self):
22 CU = self.FFI.compile('''
23#include <stdio.h>
24typedef int int2[2];
25void foo(char* buf, size_t n, int2* ar)
26{
27 snprintf(buf, n, "%d %d", ar[0][0], ar[0][1]);
28}
29 ''&#x27;)
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
43if __name__ == '__main__':
44 unittest.main()

Callers

nothing calls this directly

Calls 3

cstr_from_arrayMethod · 0.80
compileMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected