From f21013a585d84af07f1a3d648cb1c269fabbb8ce Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Tue, 7 Jul 2009 01:50:30 -0700 Subject: [PATCH] Expand and fix cpp tests --- tests/run/cpp_classes.pyx | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/tests/run/cpp_classes.pyx b/tests/run/cpp_classes.pyx index 2bdbcae4..e0d7e1b2 100644 --- a/tests/run/cpp_classes.pyx +++ b/tests/run/cpp_classes.pyx @@ -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 -- 2.26.2