From 1ca9c605ae73947db7f5560eb47df91e42795e1a Mon Sep 17 00:00:00 2001 From: Danilo Freitas Date: Tue, 7 Jul 2009 01:39:50 -0700 Subject: [PATCH] Test files for cpp classes. --- tests/run/cpp_classes.pyx | 18 ++++++++++++++++++ tests/run/shapes.cpp | 15 +++++++++++++++ tests/run/shapes.h | 31 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 tests/run/cpp_classes.pyx create mode 100644 tests/run/shapes.cpp create mode 100644 tests/run/shapes.h diff --git a/tests/run/cpp_classes.pyx b/tests/run/cpp_classes.pyx new file mode 100644 index 00000000..2bdbcae4 --- /dev/null +++ b/tests/run/cpp_classes.pyx @@ -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 index 00000000..11f6e2f2 --- /dev/null +++ b/tests/run/shapes.cpp @@ -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 index 00000000..54c31f08 --- /dev/null +++ b/tests/run/shapes.h @@ -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 -- 2.26.2