Test files for cpp classes.
authorDanilo Freitas <dsurviver@gmail.com>
Tue, 7 Jul 2009 08:39:50 +0000 (01:39 -0700)
committerDanilo Freitas <dsurviver@gmail.com>
Tue, 7 Jul 2009 08:39:50 +0000 (01:39 -0700)
tests/run/cpp_classes.pyx [new file with mode: 0644]
tests/run/shapes.cpp [new file with mode: 0644]
tests/run/shapes.h [new file with mode: 0644]

diff --git a/tests/run/cpp_classes.pyx b/tests/run/cpp_classes.pyx
new file mode 100644 (file)
index 0000000..2bdbcae
--- /dev/null
@@ -0,0 +1,18 @@
+cdef extern from "shapes.h" namespace shapes:
+
+    cdef cppclass Shape:
+        area()
+    
+    cdef cppclass Rectangle(Shape):
+        int width
+        int height
+        __init__(int, int)
+    
+    cdef cppclass Square(Shape):
+        int side
+        __init__(int)
+
+cdef Rectangle *rect = new Rectangle(10, 20)
+cdef Square *sqr = new Square(15)
+
+del rect, sqr
diff --git a/tests/run/shapes.cpp b/tests/run/shapes.cpp
new file mode 100644 (file)
index 0000000..11f6e2f
--- /dev/null
@@ -0,0 +1,15 @@
+#include "shapes.h"
+
+using namespace shapes;
+
+Rectangle::Rectangle(int width, int height)
+{
+    this->width = width;
+    this->height = height;
+}
+
+Square::Square(int side)
+{
+    this->side = side;
+}
+
diff --git a/tests/run/shapes.h b/tests/run/shapes.h
new file mode 100644 (file)
index 0000000..54c31f0
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef SHAPES_H
+#define SHAPES_H
+
+namespace shapes {
+
+    class Shape
+    {
+    public:
+        virtual float area() = 0;
+        virtual ~Shape() { }
+    };
+    
+    class Rectangle : public Shape
+    {
+    public:
+        Rectangle(int width, int height);
+        float area() { return width * height; }
+        int width;
+        int height;
+    };
+    
+    class Square : public Shape
+    {
+    public:
+        Square(int side);
+        float area() { return side * side; }
+        int side;
+    };
+
+}
+#endif