| 1 |
import py |
| 2 |
from pypy.conftest import option |
| 3 |
from pypy.module._rawffi.tracker import Tracker |
| 4 |
|
| 5 |
|
| 6 |
class AppTestTracker: |
| 7 |
spaceconfig = dict(usemodules=['_rawffi', 'struct']) |
| 8 |
|
| 9 |
def setup_class(cls): |
| 10 |
|
| 11 |
|
| 12 |
if option.runappdirect: |
| 13 |
try: |
| 14 |
import _rawffi |
| 15 |
_rawffi._num_of_allocated_objects() |
| 16 |
except (ImportError, RuntimeError) as e: |
| 17 |
py.test.skip(str(e)) |
| 18 |
|
| 19 |
Tracker.DO_TRACING = True |
| 20 |
|
| 21 |
def test_array(self): |
| 22 |
import _rawffi |
| 23 |
oldnum = _rawffi._num_of_allocated_objects() |
| 24 |
a = _rawffi.Array('c')(3) |
| 25 |
assert _rawffi._num_of_allocated_objects() - oldnum == 1 |
| 26 |
a.free() |
| 27 |
assert _rawffi._num_of_allocated_objects() - oldnum == 0 |
| 28 |
|
| 29 |
def test_structure(self): |
| 30 |
import _rawffi |
| 31 |
oldnum = _rawffi._num_of_allocated_objects() |
| 32 |
s = _rawffi.Structure([('a', 'i'), ('b', 'i')])() |
| 33 |
assert _rawffi._num_of_allocated_objects() - oldnum == 1 |
| 34 |
s.free() |
| 35 |
assert _rawffi._num_of_allocated_objects() - oldnum == 0 |
| 36 |
|
| 37 |
def test_callback(self): |
| 38 |
import _rawffi |
| 39 |
oldnum = _rawffi._num_of_allocated_objects() |
| 40 |
c = _rawffi.CallbackPtr(lambda : 3, [], 'i') |
| 41 |
assert _rawffi._num_of_allocated_objects() - oldnum== 1 |
| 42 |
c.free() |
| 43 |
assert _rawffi._num_of_allocated_objects() - oldnum== 0 |
| 44 |
|
| 45 |
def teardown_class(cls): |
| 46 |
Tracker.DO_TRACING = False |
| 47 |
|