diff --git a/test/test_lowlevel.py b/test/test_lowlevel.py index 90066281..1618e1cd 100644 --- a/test/test_lowlevel.py +++ b/test/test_lowlevel.py @@ -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): @@ -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) diff --git a/test/test_templates.py b/test/test_templates.py index 2b2f3c3b..8d7158f8 100644 --- a/test/test_templates.py +++ b/test/test_templates.py @@ -1162,6 +1162,59 @@ 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 + std::string baz(T a, U b, std::string c) { + return "baz(" + std::to_string(a) + ", " + std::to_string(b) + ", \"" + c + "\")"; + } + + template + std::string dataframe_define_mock(F callable, Args&&... args) { + return callable(std::forward(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\")" + + def test37_enum_template_argument_function(self): + import cppyy + from cppyy import gbl + + cppyy.cppdef( + r""" + enum What { NO, YES }; + + template + struct EE { + What w = E; + }; + + template + What get() { + return E; + } + """ + ) + + assert gbl.EE[gbl.What.NO]().w == 0 + assert gbl.EE[gbl.What.YES]().w == 1 + + assert gbl.get[gbl.What.NO]() == 0 + assert gbl.get[gbl.What.YES]() == 1 + @mark.skipif((IS_MAC and IS_CLING), reason="setup class fails with OS X cling") class TestTEMPLATED_TYPEDEFS: