summaryrefslogtreecommitdiff
path: root/tests/run/cpp_nested_classes.pyx
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run/cpp_nested_classes.pyx')
-rw-r--r--tests/run/cpp_nested_classes.pyx91
1 files changed, 90 insertions, 1 deletions
diff --git a/tests/run/cpp_nested_classes.pyx b/tests/run/cpp_nested_classes.pyx
index 6008b2379..50a453901 100644
--- a/tests/run/cpp_nested_classes.pyx
+++ b/tests/run/cpp_nested_classes.pyx
@@ -1,4 +1,4 @@
-# tag: cpp
+# tag: cpp, no-cpp-locals
cdef extern from "cpp_nested_classes_support.h":
cdef cppclass A:
@@ -25,6 +25,26 @@ 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
+
def test_nested_classes():
"""
@@ -40,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)
@@ -47,6 +88,27 @@ 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)
+ """
+ cdef AliasA1.my_int x = py_x
+ assert A.negate(x) == -py_x
+
+def test_typedef_for_nested_deep(py_x):
+ """
+ >>> test_typedef_for_nested_deep(5)
+ """
+ cdef AliasA2.my_int x = py_x
+ assert A.negate(x) == -py_x
+
def test_typed_nested_typedef(x):
"""
>>> test_typed_nested_typedef(4)
@@ -123,3 +185,30 @@ def test_nested_sub_struct(x):
assert s.int_value == x
s.typed_value = x
return s.typed_value
+
+cimport cpp_nested_names
+cimport libcpp.string
+from cython.operator cimport dereference as deref, preincrement as inc
+
+def test_nested_names():
+ """
+ >>> test_nested_names()
+ Nested
+ NestedNested
+ C
+ y
+ t
+ h
+ o
+ n
+ """
+ cdef cpp_nested_names.Outer.Nested n = cpp_nested_names.Outer.get()
+ cdef cpp_nested_names.Outer.Nested.NestedNested nn = n.get()
+ print(n.get_str().decode('ascii'))
+ print(nn.get_str().decode('ascii'))
+
+ cdef libcpp.string.string s = "Cython"
+ cdef libcpp.string.string.iterator i = s.begin()
+ while i != s.end():
+ print(chr(deref(i)))
+ inc(i)