Remove trailing whitespace.
[cython.git] / tests / run / cpp_classes.pyx
1 __doc__ = u"""
2     >>> test_new_del()
3     (2, 2)
4     >>> test_rect_area(3, 4)
5     12.0
6     >>> test_square_area(15)
7     (225.0, 225.0)
8 """
9
10 cdef extern from "shapes.h" namespace "shapes":
11
12     cdef cppclass Shape:
13         float area()
14
15     cdef cppclass Circle(Shape):
16         int radius
17         Circle(int)
18
19     cdef cppclass Rectangle(Shape):
20         int width
21         int height
22         Rectangle()
23         Rectangle(int, int)
24
25     cdef cppclass Square(Rectangle):
26         int side
27         Square(int)
28
29     int constructor_count, destructor_count
30
31 def test_new_del():
32     cdef Rectangle *rect = new Rectangle(10, 20)
33     cdef Circle *circ = new Circle(15)
34     del rect, circ
35     return constructor_count, destructor_count
36
37 def test_rect_area(w, h):
38     cdef Rectangle *rect = new Rectangle(w, h)
39     try:
40         return rect.area()
41     finally:
42         del rect
43
44 def test_square_area(w):
45     cdef Square *sqr = new Square(w)
46     cdef Rectangle *rect = sqr
47     try:
48         return rect.area(), sqr.area()
49     finally:
50         del sqr
51
52 cdef double get_area(Rectangle s):
53     return s.area()
54
55 def test_value_call(int w):
56     """
57     >>> test_value_call(5)
58     (25.0, 25.0)
59     """
60     cdef Square *sqr = new Square(w)
61     cdef Rectangle *rect = sqr
62     try:
63         return get_area(sqr[0]), get_area(rect[0])
64     finally:
65         del sqr