Expand and fix cpp tests
authorRobert Bradshaw <robertwb@math.washington.edu>
Tue, 7 Jul 2009 08:50:30 +0000 (01:50 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Tue, 7 Jul 2009 08:50:30 +0000 (01:50 -0700)
tests/run/cpp_classes.pyx

index 2bdbcae4e536d585e747c31460fba9c367b40caf..e0d7e1b26d60b82fcf643188a4dd783267f2e7d4 100644 (file)
@@ -1,7 +1,15 @@
-cdef extern from "shapes.h" namespace shapes:
+__doc__ = u"""
+    >>> test_new_del()
+    >>> test_rect_area(3, 4)
+    12
+    >>> test_square_area(15)
+    225
+"""
+
+cdef extern from "shapes.cpp" namespace shapes:
 
     cdef cppclass Shape:
-        area()
+        float area()
     
     cdef cppclass Rectangle(Shape):
         int width
@@ -12,7 +20,23 @@ cdef extern from "shapes.h" namespace shapes:
         int side
         __init__(int)
 
-cdef Rectangle *rect = new Rectangle(10, 20)
-cdef Square *sqr = new Square(15)
+def test_new_del():
+    cdef Rectangle *rect = new Rectangle(10, 20)
+    cdef Square *sqr = new Square(15)
+    del rect, sqr
+
+def test_rect_area(w, h):
+    cdef Rectangle *rect = new Rectangle(w, h)
+    try:
+        return rect.area()
+    finally:
+        del rect
+
+def test_square_area(w):
+    cdef Square *sqr = new Square(w)
+    cdef Rectangle *rect = sqr
+    try:
+        return rect.area(), sqr.area()
+    finally:
+        del sqr
 
-del rect, sqr