make sure constructor/destructors are being called
authorRobert Bradshaw <robertwb@math.washington.edu>
Tue, 7 Jul 2009 09:19:08 +0000 (02:19 -0700)
committerRobert Bradshaw <robertwb@math.washington.edu>
Tue, 7 Jul 2009 09:19:08 +0000 (02:19 -0700)
tests/run/cpp_classes.pyx
tests/run/shapes.h

index d56be4e4e154215df01b2b8ec552fa81d8c40c1a..056ae81e776eddf61438b357def9a438d5fb573c 100644 (file)
@@ -1,5 +1,6 @@
 __doc__ = u"""
     >>> test_new_del()
+    (2, 2)
     >>> test_rect_area(3, 4)
     12.0
     >>> test_square_area(15)
@@ -23,11 +24,14 @@ cdef extern from "shapes.h" namespace shapes:
     cdef cppclass Square(Rectangle):
         int side
         # __init__(int) # need function overloading
+        
+    int constructor_count, destructor_count
 
 def test_new_del():
     cdef Rectangle *rect = new Rectangle(10, 20)
     cdef Circle *circ = new Circle(15)
     del rect, circ
+    return constructor_count, destructor_count
 
 def test_rect_area(w, h):
     cdef Rectangle *rect = new Rectangle(w, h)
index 19dd2fce4a232288cbba338253816a20a95385de..3106d01c0cf35b3ba27d468214cb9b4af78e6581 100644 (file)
@@ -3,11 +3,15 @@
 
 namespace shapes {
     
+    int constructor_count = 0;
+    int destructor_count = 0;
+    
     class Shape
     {
     public:
         virtual float area() = 0;
-        virtual ~Shape() { }
+        Shape() { constructor_count++; } 
+        virtual ~Shape() { destructor_count++; }
     };
 
     class Rectangle : public Shape