diff options
Diffstat (limited to 'tests/run/cpp_nested_classes.pyx')
-rw-r--r-- | tests/run/cpp_nested_classes.pyx | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/run/cpp_nested_classes.pyx b/tests/run/cpp_nested_classes.pyx index b50f79936..8877c0440 100644 --- a/tests/run/cpp_nested_classes.pyx +++ b/tests/run/cpp_nested_classes.pyx @@ -25,6 +25,22 @@ cdef extern from "cpp_nested_classes_support.h": cdef cppclass SpecializedTypedClass(TypedClass[double]): pass +cdef cppclass AA: + cppclass BB: + int square(int x): + return x * x + cppclass CC: + int cube(int x): + return x * x * x + BB* createB(): + return new BB() + ctypedef int my_int + @staticmethod + my_int negate(my_int x): + return -x + +cdef cppclass DD(AA): + ctypedef int my_other_int ctypedef A AliasA1 ctypedef AliasA1 AliasA2 @@ -44,6 +60,27 @@ def test_nested_classes(): assert b_ptr.square(4) == 16 del b_ptr +def test_nested_defined_classes(): + """ + >>> test_nested_defined_classes() + """ + cdef AA a + cdef AA.BB b + assert b.square(3) == 9 + cdef AA.BB.CC c + assert c.cube(3) == 27 + + cdef AA.BB *b_ptr = a.createB() + assert b_ptr.square(4) == 16 + del b_ptr + +def test_nested_inherited_classes(): + """ + >>> test_nested_inherited_classes() + """ + cdef DD.BB b + assert b.square(3) == 9 + def test_nested_typedef(py_x): """ >>> test_nested_typedef(5) @@ -51,6 +88,13 @@ def test_nested_typedef(py_x): cdef A.my_int x = py_x assert A.negate(x) == -py_x +def test_nested_defined_typedef(py_x): + """ + >>> test_nested_typedef(5) + """ + cdef AA.my_int x = py_x + assert AA.negate(x) == -py_x + def test_typedef_for_nested(py_x): """ >>> test_typedef_for_nested(5) |