| 1 | import py, os, sys |
| 2 | from pypy.module._cppyy import interp_cppyy, executor |
| 3 | |
| 4 | |
| 5 | class AppTestREGRESSION: |
| 6 | spaceconfig = dict(usemodules=['_cppyy', '_rawffi', 'itertools']) |
| 7 | |
| 8 | def setup_class(cls): |
| 9 | cls.w_example01 = cls.space.appexec([], """(): |
| 10 | import ctypes, _cppyy |
| 11 | _cppyy._post_import_startup()""") |
| 12 | |
| 13 | def test01_dir(self): |
| 14 | """These dir() methods used to crash.""" |
| 15 | |
| 16 | import _cppyy as cppyy |
| 17 | |
| 18 | cppyy.gbl.gInterpreter.Declare("namespace cppyy_regression_test { void iii() {}; }") |
| 19 | |
| 20 | assert not 'iii' in cppyy.gbl.cppyy_regression_test.__dict__ |
| 21 | assert not '__abstractmethods__' in dir(cppyy.gbl.cppyy_regression_test) |
| 22 | assert '__class__' in dir(cppyy.gbl.cppyy_regression_test) |
| 23 | assert 'iii' in dir(cppyy.gbl.cppyy_regression_test) |
| 24 | |
| 25 | assert not 'iii' in cppyy.gbl.cppyy_regression_test.__dict__ |
| 26 | assert cppyy.gbl.cppyy_regression_test.iii |
| 27 | assert 'iii' in cppyy.gbl.cppyy_regression_test.__dict__ |
| 28 | |
| 29 | def test02_default_template_arguments(self): |
| 30 | """Calling a templated method on a templated class with all defaults used to crash.""" |
| 31 | |
| 32 | import _cppyy as cppyy |
| 33 | |
| 34 | cppyy.gbl.gInterpreter.Declare(""" |
| 35 | template<typename T> |
| 36 | class AllDefault { |
| 37 | public: |
| 38 | AllDefault(int val) : m_t(val) {} |
| 39 | template<int aap=1, int noot=2> |
| 40 | int do_stuff() { return m_t+aap+noot; } |
| 41 | |
| 42 | public: |
| 43 | T m_t; |
| 44 | };""") |
| 45 | |
| 46 | a = cppyy.gbl.AllDefault[int](24) |
| 47 | a.m_t = 21; |
| 48 | assert a.do_stuff() == 24 |