From 164ae885add6ef01cb08f04c2de21eb2639c8b7e Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Tue, 7 Jul 2009 02:19:08 -0700 Subject: [PATCH] make sure constructor/destructors are being called --- tests/run/cpp_classes.pyx | 4 ++++ tests/run/shapes.h | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/run/cpp_classes.pyx b/tests/run/cpp_classes.pyx index d56be4e4..056ae81e 100644 --- a/tests/run/cpp_classes.pyx +++ b/tests/run/cpp_classes.pyx @@ -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) diff --git a/tests/run/shapes.h b/tests/run/shapes.h index 19dd2fce..3106d01c 100644 --- a/tests/run/shapes.h +++ b/tests/run/shapes.h @@ -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 -- 2.26.2