Skip to content

Commit

Permalink
tests for access to (const) ref data members
Browse files Browse the repository at this point in the history
  • Loading branch information
wlav committed Sep 29, 2021
1 parent 0e0f1a5 commit a4b4458
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
2 changes: 2 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ master: 2.2.0

* Migrated repos to github/wlav
* Properly resolve enum type of class enums
* Get proper shape of ``void*`` and enum arrays
* Fix access to (const) ref data members
* Fix sometimes PCH uninstall issue


Expand Down
4 changes: 4 additions & 0 deletions test/templ_args_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
def ann_adapt(node: 'FPTA::Node&') -> cppyy.gbl.FPTA.EventId:
return cppyy.gbl.FPTA.EventId(node.fData)

def ann_ref_mod(node: 'FPTA::Node&') -> cppyy.gbl.FPTA.EventId:
ev_id = cppyy.gbl.FPTA.EventId(node.fData)
node.fData = 81
return ev_id
24 changes: 24 additions & 0 deletions test/test_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2103,3 +2103,27 @@ def test43_buffer_memory_handling(self):
for i in range(buf1.size):
assert buf1.data1[i] == 1.*i
assert buf1.data2[i] == 2.*i

def test44_const_ref_data(self):
"""Proper indirection for addressing const-ref data"""

import cppyy

cppyy.cppdef("""\
namespace ConstRefData {
struct A {
std::string name;
};
A gA{"Hello, World!"};
struct B {
B() : body1(gA), body2(gA) {}
A body1;
const A& body2;
}; }""")

ns = cppyy.gbl.ConstRefData

b = ns.B()
assert b.body1.name == b.body2.name
1 change: 1 addition & 0 deletions test/test_lowlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ def test04_malloc(self):

for dtype in ["int", "int*", "int**",]:
bar = cppyy.ll.malloc[dtype](4)
assert len(bar) == 4

# variable assignment
foo = ns.Foo[dtype]()
Expand Down
17 changes: 15 additions & 2 deletions test/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,10 +825,15 @@ def adapt(node):
def ann_adapt(node):
return ns.EventId(node.fData)
ann_adapt.__annotations__ = {'node': 'FPTA::Node&', 'return': ns.EventId}
def ann_ref_mod(node):
ev_id = ns.EventId(node.fData)
node.fData = 81
return ev_id
ann_adapt.__annotations__ = {'node': 'FPTA::Node&', 'return': ns.EventId}
else:
oldp = sys.path[:]
sys.path.append('.')
from templ_args_funcs import ann_adapt
from templ_args_funcs import ann_adapt, ann_ref_mod
sys.path = oldp

s = ns.Simulator()
Expand All @@ -845,7 +850,15 @@ def ann_adapt(node):
assert s.Schedule5(ns.Time(1.0), ann_adapt, ns.Node(25)).fId == 25
assert s.Schedule6['FPTA::Node&'](ns.Time(1.0), ann_adapt, ns.Node(88)).fId == 88

def test34_mix_and_match(self):
# verify that the node is correctly modified
tn = ns.Node(25)
assert s.Schedule5(ns.Time(1.0), ann_ref_mod, tn).fId == 25
assert tn.fData == 81
tn = ns.Node(88)
assert s.Schedule6['FPTA::Node&'](ns.Time(1.0), ann_ref_mod, tn).fId == 88
assert tn.fData == 81

def test30_mix_and_match(self):
"""Mix of (non-)templated across inheritance"""

import cppyy
Expand Down

0 comments on commit a4b4458

Please sign in to comment.