Skip to content

Commit 465fb20

Browse files
1 parent 53e0589 commit 465fb20

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

test/test_lowlevel.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,22 @@ def test15_templated_arrays_gmpxx(self):
517517
g = cppyy.gbl
518518
assert g.test15_templated_arrays_gmpxx.vector.value_type[g.std.vector[g.mpz_class]]
519519

520+
def test16_addressof_nullptr(self):
521+
import cppyy
522+
from cppyy import gbl
523+
524+
cppyy.cppdef(r"""
525+
namespace LLV {
526+
int x = 10;
527+
int *ptr_x = &x;
528+
int *ptr_null = nullptr;
529+
}
530+
""")
531+
532+
assert type(gbl.LLV.ptr_x) == cppyy._backend.LowLevelView
533+
assert type(gbl.LLV.ptr_null) == cppyy._backend.LowLevelView
534+
assert cppyy.addressof(gbl.LLV.ptr_x)
535+
assert cppyy.addressof(gbl.LLV.ptr_null) == 0
520536

521537
class TestMULTIDIMARRAYS:
522538
def setup_class(cls):
@@ -746,3 +762,32 @@ def test05_char_multidim(self):
746762
for i, v in enumerate(("s1", "s23", "s456")):
747763
assert len(ns.str_array[i]) == 8
748764
assert list(ns.str_array[i])[:len(v)] == list(v)
765+
766+
def test06_3D_custom_struct(self):
767+
import cppyy
768+
from cppyy import gbl
769+
770+
cppyy.cppdef(r"""
771+
constexpr int S = 4;
772+
773+
struct Klass {
774+
static int i;
775+
int k;
776+
Klass() : k(++i) {}
777+
};
778+
int Klass::i = 0;
779+
Klass klasses[S][S + 3][S + 7];
780+
781+
bool consume_klass(Klass* c, int i, int j, int k) {
782+
if (c->k == ((S + 7) * (i * (S + 3) + j) + (k + 1))) return true;
783+
return false;
784+
}
785+
""")
786+
787+
assert gbl.klasses
788+
# assert type(gbl.klasses) == cppyy._backend.LowLevelView # FIXME: https://github.com/compiler-research/CPyCppyy/issues/141
789+
790+
for i in range(gbl.S):
791+
for j in range(gbl.S + 3):
792+
for k in range(gbl.S + 7):
793+
assert gbl.consume_klass(gbl.klasses[i][j][k], i, j, k)

test/test_templates.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,33 @@ def test34_cstring_template_argument(self):
11621162
assert ns.stringify["const char*"]("Aap") == "Aap "
11631163
assert ns.stringify(ctypes.c_char_p(bytes("Noot", "ascii"))) == "Noot "
11641164

1165+
def test35_templated_callbacks(self):
1166+
import cppyy
1167+
1168+
cppyy.cppdef(
1169+
r"""
1170+
std::string foo() { return "foo!";}
1171+
1172+
std::string bar(int a, float b) {
1173+
return "bar(" + std::to_string(a) + ", " + std::to_string(b) + ")";
1174+
}
1175+
1176+
template <typename T, typename U>
1177+
std::string baz(T a, U b, std::string c) {
1178+
return "baz(" + std::to_string(a) + ", " + std::to_string(b) + ", \"" + c + "\")";
1179+
}
1180+
1181+
template<typename F, typename... Args>
1182+
std::string dataframe_define_mock(F callable, Args&&... args) {
1183+
return callable(std::forward<Args>(args)...);
1184+
}
1185+
"""
1186+
)
1187+
1188+
assert cppyy.gbl.dataframe_define_mock(cppyy.gbl.foo) == "foo!"
1189+
assert cppyy.gbl.dataframe_define_mock(cppyy.gbl.bar, 42, 11.11) == "bar(42, 11.110000)"
1190+
assert cppyy.gbl.dataframe_define_mock(cppyy.gbl.baz["int", "double"], 33, 101.101, "hello") == "baz(33, 101.101000, \"hello\")"
1191+
11651192

11661193
@mark.skipif((IS_MAC and IS_CLING), reason="setup class fails with OS X cling")
11671194
class TestTEMPLATED_TYPEDEFS:

0 commit comments

Comments
 (0)