| 1 |
import py, os, sys |
| 2 |
from .support import setup_make, soext |
| 3 |
|
| 4 |
currpath = py.path.local(__file__).dirpath() |
| 5 |
test_dct = str(currpath.join("cpp11featuresDict"))+soext |
| 6 |
|
| 7 |
def setup_module(mod): |
| 8 |
setup_make("cpp11features") |
| 9 |
|
| 10 |
|
| 11 |
class AppTestCPP11FEATURES: |
| 12 |
spaceconfig = dict(usemodules=['_cppyy', '_rawffi', 'itertools']) |
| 13 |
|
| 14 |
def setup_class(cls): |
| 15 |
cls.w_test_dct = cls.space.newtext(test_dct) |
| 16 |
cls.w_example01 = cls.space.appexec([], """(): |
| 17 |
import ctypes, _cppyy |
| 18 |
_cppyy._post_import_startup() |
| 19 |
return ctypes.CDLL(%r, ctypes.RTLD_GLOBAL)""" % (test_dct, )) |
| 20 |
|
| 21 |
def test01_shared_ptr(self): |
| 22 |
"""Usage and access of std::shared_ptr<>""" |
| 23 |
|
| 24 |
import _cppyy |
| 25 |
TestSharedPtr = _cppyy.gbl.TestSharedPtr |
| 26 |
create_shared_ptr_instance = _cppyy.gbl.create_shared_ptr_instance |
| 27 |
|
| 28 |
|
| 29 |
assert TestSharedPtr.s_counter == 0 |
| 30 |
|
| 31 |
ptr1 = create_shared_ptr_instance() |
| 32 |
assert ptr1 |
| 33 |
assert not not ptr1 |
| 34 |
assert TestSharedPtr.s_counter == 1 |
| 35 |
|
| 36 |
ptr2 = create_shared_ptr_instance() |
| 37 |
assert ptr2 |
| 38 |
assert not not ptr2 |
| 39 |
assert TestSharedPtr.s_counter == 2 |
| 40 |
|
| 41 |
del ptr2 |
| 42 |
import gc; gc.collect() |
| 43 |
assert TestSharedPtr.s_counter == 1 |
| 44 |
|
| 45 |
del ptr1 |
| 46 |
gc.collect() |
| 47 |
assert TestSharedPtr.s_counter == 0 |
| 48 |
|
| 49 |
def test02_nullptr(self): |
| 50 |
"""Allow the programmer to pass NULL in certain cases""" |
| 51 |
|
| 52 |
import _cppyy |
| 53 |
|
| 54 |
|
| 55 |
nullptr = _cppyy.nullptr |
| 56 |
assert not hasattr(_cppyy.gbl, 'nullptr') |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
def test03_move(self): |
| 61 |
"""Move construction, assignment, and methods""" |
| 62 |
|
| 63 |
import _cppyy |
| 64 |
|
| 65 |
def moveit(T): |
| 66 |
std = _cppyy.gbl.std |
| 67 |
|
| 68 |
|
| 69 |
i1 = T() |
| 70 |
assert T.s_move_counter == 0 |
| 71 |
|
| 72 |
i2 = T(i1) |
| 73 |
assert T.s_move_counter == 0 |
| 74 |
|
| 75 |
i3 = T(std.move(T())) |
| 76 |
|
| 77 |
assert T.s_move_counter == 1 |
| 78 |
|
| 79 |
i4 = T(std.move(i1)) |
| 80 |
assert T.s_move_counter == 2 |
| 81 |
|
| 82 |
|
| 83 |
i4.__assign__(i2) |
| 84 |
assert T.s_move_counter == 2 |
| 85 |
|
| 86 |
i4.__assign__(std.move(T())) |
| 87 |
assert T.s_move_counter == 3 |
| 88 |
|
| 89 |
i4.__assign__(std.move(i2)) |
| 90 |
assert T.s_move_counter == 4 |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
moveit(_cppyy.gbl.TestMoving1) |
| 95 |
moveit(_cppyy.gbl.TestMoving2) |