Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions test/test_lowlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,22 @@ def test15_templated_arrays_gmpxx(self):
g = cppyy.gbl
assert g.test15_templated_arrays_gmpxx.vector.value_type[g.std.vector[g.mpz_class]]

def test16_addressof_nullptr(self):
import cppyy
from cppyy import gbl

cppyy.cppdef(r"""
namespace LLV {
int x = 10;
int *ptr_x = &x;
int *ptr_null = nullptr;
}
""")

assert type(gbl.LLV.ptr_x) == cppyy._backend.LowLevelView
assert type(gbl.LLV.ptr_null) == cppyy._backend.LowLevelView
assert cppyy.addressof(gbl.LLV.ptr_x)
assert cppyy.addressof(gbl.LLV.ptr_null) == 0

class TestMULTIDIMARRAYS:
def setup_class(cls):
Expand Down Expand Up @@ -746,3 +762,32 @@ def test05_char_multidim(self):
for i, v in enumerate(("s1", "s23", "s456")):
assert len(ns.str_array[i]) == 8
assert list(ns.str_array[i])[:len(v)] == list(v)

def test06_3D_custom_struct(self):
import cppyy
from cppyy import gbl

cppyy.cppdef(r"""
constexpr int S = 4;

struct Klass {
static int i;
int k;
Klass() : k(++i) {}
};
int Klass::i = 0;
Klass klasses[S][S + 3][S + 7];

bool consume_klass(Klass* c, int i, int j, int k) {
if (c->k == ((S + 7) * (i * (S + 3) + j) + (k + 1))) return true;
return false;
}
""")

assert gbl.klasses
# assert type(gbl.klasses) == cppyy._backend.LowLevelView # FIXME: https://github.com/compiler-research/CPyCppyy/issues/141

for i in range(gbl.S):
for j in range(gbl.S + 3):
for k in range(gbl.S + 7):
assert gbl.consume_klass(gbl.klasses[i][j][k], i, j, k)
27 changes: 27 additions & 0 deletions test/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,33 @@ def test34_cstring_template_argument(self):
assert ns.stringify["const char*"]("Aap") == "Aap "
assert ns.stringify(ctypes.c_char_p(bytes("Noot", "ascii"))) == "Noot "

def test35_templated_callbacks(self):
import cppyy

cppyy.cppdef(
r"""
std::string foo() { return "foo!";}

std::string bar(int a, float b) {
return "bar(" + std::to_string(a) + ", " + std::to_string(b) + ")";
}

template <typename T, typename U>
std::string baz(T a, U b, std::string c) {
return "baz(" + std::to_string(a) + ", " + std::to_string(b) + ", \"" + c + "\")";
}

template<typename F, typename... Args>
std::string dataframe_define_mock(F callable, Args&&... args) {
return callable(std::forward<Args>(args)...);
}
"""
)

assert cppyy.gbl.dataframe_define_mock(cppyy.gbl.foo) == "foo!"
assert cppyy.gbl.dataframe_define_mock(cppyy.gbl.bar, 42, 11.11) == "bar(42, 11.110000)"
assert cppyy.gbl.dataframe_define_mock(cppyy.gbl.baz["int", "double"], 33, 101.101, "hello") == "baz(33, 101.101000, \"hello\")"


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