Nested class tests.
authorRobert Bradshaw <robertwb@gmail.com>
Tue, 30 Oct 2012 08:07:48 +0000 (01:07 -0700)
committerRobert Bradshaw <robertwb@gmail.com>
Tue, 30 Oct 2012 08:07:48 +0000 (01:07 -0700)
tests/run/cpp_nested_classes.pyx [new file with mode: 0644]
tests/run/cpp_nested_classes_support.cpp [new file with mode: 0644]

diff --git a/tests/run/cpp_nested_classes.pyx b/tests/run/cpp_nested_classes.pyx
new file mode 100644 (file)
index 0000000..1c77a7c
--- /dev/null
@@ -0,0 +1,23 @@
+# tag: cpp
+
+cdef extern from "cpp_nested_classes_support.cpp":
+    cdef cppclass A:
+        cppclass B:
+            int square(int)
+            cppclass C:
+                int cube(int)
+        B* createB()
+
+def test():
+    """
+    >>> test()
+    """
+    cdef A a
+    cdef A.B b
+    assert b.square(3) == 9
+    cdef A.B.C c
+    assert c.cube(3) == 27
+    
+    cdef A.B *b_ptr = a.createB()
+    assert b_ptr.square(4) == 16
+    del b_ptr
diff --git a/tests/run/cpp_nested_classes_support.cpp b/tests/run/cpp_nested_classes_support.cpp
new file mode 100644 (file)
index 0000000..cbc6ffb
--- /dev/null
@@ -0,0 +1,14 @@
+class A {
+public:
+  class B {
+  public:
+    int square(int x) { return x * x; }
+    class C {
+        public:
+        int cube(int x) { return x * x * x; }
+    };
+  };
+  B* createB() {
+    return new B();
+  }
+};