From fcb737024b9672dd73b014a53246252f95628989 Mon Sep 17 00:00:00 2001 From: Mark Donszelmann Date: Fri, 30 Oct 2009 15:37:42 +0100 Subject: Fixed NAR-89 --- src/it/it0015-cpp-executable/pom.xml | 63 ++++++++++++++++++++++ .../src/main/c++/Executable.cpp | 57 ++++++++++++++++++++ .../it0015-cpp-executable/src/main/c++/example.cxx | 28 ++++++++++ .../src/main/include/example.h | 39 ++++++++++++++ 4 files changed, 187 insertions(+) create mode 100644 src/it/it0015-cpp-executable/pom.xml create mode 100644 src/it/it0015-cpp-executable/src/main/c++/Executable.cpp create mode 100644 src/it/it0015-cpp-executable/src/main/c++/example.cxx create mode 100644 src/it/it0015-cpp-executable/src/main/include/example.h (limited to 'src/it') diff --git a/src/it/it0015-cpp-executable/pom.xml b/src/it/it0015-cpp-executable/pom.xml new file mode 100644 index 0000000..84b1f8c --- /dev/null +++ b/src/it/it0015-cpp-executable/pom.xml @@ -0,0 +1,63 @@ + + + + + + 4.0.0 + + + org.apache.maven.its.nar + it-parent + 1.0-SNAPSHOT + ../it-parent/pom.xml + + + it0015-cpp-executable + nar + + Maven NAR C++ Executable Test + 1.0-SNAPSHOT + + Simple c++ test executable + + http://maven.apache.org/ + + + true + + + + integration-test + + + maven-nar-plugin + true + + + + executable + true + + + + + + + diff --git a/src/it/it0015-cpp-executable/src/main/c++/Executable.cpp b/src/it/it0015-cpp-executable/src/main/c++/Executable.cpp new file mode 100644 index 0000000..976ffb8 --- /dev/null +++ b/src/it/it0015-cpp-executable/src/main/c++/Executable.cpp @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include +#include + +extern "C" +int main(int argc, char *argv[]) { + Circle* c = new Circle(10); + Square* s = new Square(10); + + if (Shape::nshapes != 2) return 1; + + c->x = 20; + c->y = 30; + + Shape* shape = s; + shape->x = -10; + shape->y = 5; + + if (c->x != 20.0) return 2; + if (c->y != 30.0) return 3; + if (s->x != -10.0) return 4; + if (s->y != 5.0) return 5; + + Shape* shapes[] = { c, s }; + + if (shapes[0]->area() - 314.1592653589793 > 0.0001) return 6; + if (shapes[0]->perimeter() - 62.83185307179586 > 0.0001) return 7; + if (shapes[1]->area() - 100.0 > 0.0001) return 8; + if (shapes[1]->perimeter() - 40.0 > 0.0001) return 9; + + delete c; + delete s; + + if (Shape::nshapes != 0) return 10; + + return 0; +} + + diff --git a/src/it/it0015-cpp-executable/src/main/c++/example.cxx b/src/it/it0015-cpp-executable/src/main/c++/example.cxx new file mode 100644 index 0000000..1e8e203 --- /dev/null +++ b/src/it/it0015-cpp-executable/src/main/c++/example.cxx @@ -0,0 +1,28 @@ +/* File : example.c */ + +#include "example.h" +#define M_PI 3.14159265358979323846 + +/* Move the shape to a new location */ +void Shape::move(double dx, double dy) { + x += dx; + y += dy; +} + +int Shape::nshapes = 0; + +double Circle::area(void) { + return M_PI*radius*radius; +} + +double Circle::perimeter(void) { + return 2*M_PI*radius; +} + +double Square::area(void) { + return width*width; +} + +double Square::perimeter(void) { + return 4*width; +} diff --git a/src/it/it0015-cpp-executable/src/main/include/example.h b/src/it/it0015-cpp-executable/src/main/include/example.h new file mode 100644 index 0000000..46d9013 --- /dev/null +++ b/src/it/it0015-cpp-executable/src/main/include/example.h @@ -0,0 +1,39 @@ +/* File : example.h */ + +class Shape { +public: + Shape() { + nshapes++; + } + virtual ~Shape() { + nshapes--; + }; + double x, y; + void move(double dx, double dy); + virtual double area(void) = 0; + virtual double perimeter(void) = 0; + static int nshapes; +}; + +class Circle : public Shape { +private: + double radius; +public: + Circle(double r) : radius(r) { }; + virtual double area(void); + virtual double perimeter(void); +}; + +class Square : public Shape { +private: + double width; +public: + Square(double w) : width(w) { }; + virtual double area(void); + virtual double perimeter(void); +}; + + + + + -- cgit v1.2.3