UsingLibQhull_test.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (c) 2008-2011 C.B. Barber. All rights reserved.
00004 ** $Id: //main/2011/qhull/src/qhulltest/UsingLibQhull_test.cpp#2 $$Change: 1342 $
00005 ** $DateTime: 2011/03/07 21:55:47 $$Author: bbarber $
00006 **
00007 ****************************************************************************/
00008 
00009 //pre-compiled headers
00010 #include <iostream>
00011 #include "../road/RoadTest.h" // QT_VERSION
00012 
00013 #include "UsingLibQhull.h"
00014 #include "QhullError.h"
00015 #include "Qhull.h"
00016 
00017 using std::cout;
00018 using std::endl;
00019 using std::string;
00020 
00021 namespace orgQhull {
00022 
00025 class UsingLibQhull_test : public RoadTest
00026 {
00027     Q_OBJECT
00028 
00029 #//Test slots
00030 private slots:
00031     void cleanup();
00032     void t_classMembers();
00033     void t_globalPoints();
00034     void t_UsingLibQhull();
00035     void t_methods();
00036     void t_cleanuptestcase();
00037 };//UsingLibQhull_test
00038 
00039 void
00040 add_UsingLibQhull_test()
00041 {
00042     new UsingLibQhull_test();
00043 }
00044 
00045 //Executed after each testcase
00046 void UsingLibQhull_test::
00047 cleanup()
00048 {
00049     UsingLibQhull::checkQhullMemoryEmpty();
00050     RoadTest::cleanup();
00051 }
00052 
00053 void UsingLibQhull_test::
00054 t_classMembers()
00055 {
00056     {
00057         //checkQhullMemoryEmpty tested by cleanup()
00058         QCOMPARE(UsingLibQhull::globalMachineEpsilon()+1.0, 1.0);
00059         RboxPoints r10("10");
00060         Qhull q(r10,"v");  // voronoi diagram of 10 points
00061         UsingLibQhull::unsetGlobalAngleEpsilon();
00062         UsingLibQhull::unsetGlobalDistanceEpsilon();
00063         cout << "MachineEpsilon " << UsingLibQhull::globalMachineEpsilon()
00064             << " angleEpsilon " << UsingLibQhull::globalAngleEpsilon()
00065             << " distanceEpsilon " << UsingLibQhull::globalDistanceEpsilon()
00066             << endl;
00067         QCOMPARE(UsingLibQhull::currentAngleEpsilon()+1.0, 1.0);
00068         QVERIFY(UsingLibQhull::currentAngleEpsilon() > UsingLibQhull::globalMachineEpsilon());
00069         QCOMPARE(UsingLibQhull::currentDistanceEpsilon()+1.0, 1.0);
00070         QVERIFY(UsingLibQhull::currentDistanceEpsilon() >= UsingLibQhull::currentAngleEpsilon());
00071         QCOMPARE(UsingLibQhull::currentQhull().runId(), q.runId());
00072         QCOMPARE(UsingLibQhull::globalAngleEpsilon()+1.0, UsingLibQhull::currentAngleEpsilon()+1.0);
00073         QCOMPARE(UsingLibQhull::currentVertexDimension(), q.dimension());
00074         QCOMPARE(UsingLibQhull::globalDistanceEpsilon()+1.0, UsingLibQhull::currentDistanceEpsilon()+1.0);
00075         UsingLibQhull::setGlobalAngleEpsilon(1.0);
00076         UsingLibQhull::setGlobalDistanceEpsilon(1.0);
00077         cout << " Global angleEpsilon " << UsingLibQhull::globalAngleEpsilon()
00078             << " distanceEpsilon " << UsingLibQhull::globalDistanceEpsilon()
00079             << endl;
00080         QCOMPARE(UsingLibQhull::globalAngleEpsilon(), UsingLibQhull::globalDistanceEpsilon());
00081         QVERIFY(UsingLibQhull::currentAngleEpsilon() != UsingLibQhull::globalAngleEpsilon());
00082         UsingLibQhull::setGlobalVertexDimension(3);
00083         QCOMPARE(UsingLibQhull::globalVertexDimension(), UsingLibQhull::currentVertexDimension());
00084         UsingLibQhull::setGlobalVertexDimension(2);
00085         QCOMPARE(UsingLibQhull::globalVertexDimension(), 2);
00086         QCOMPARE(UsingLibQhull::currentVertexDimension(), q.dimension());
00087         QVERIFY(UsingLibQhull::currentDistanceEpsilon() != UsingLibQhull::globalDistanceEpsilon());
00088         UsingLibQhull::unsetGlobalAngleEpsilon();
00089         UsingLibQhull::unsetGlobalVertexDimension();
00090         UsingLibQhull::unsetGlobalDistanceEpsilon();
00091         QCOMPARE(UsingLibQhull::currentAngleEpsilon()+1.0, UsingLibQhull::globalAngleEpsilon()+1.0);
00092         QCOMPARE(UsingLibQhull::globalVertexDimension(), UsingLibQhull::currentVertexDimension());
00093         QCOMPARE(UsingLibQhull::currentDistanceEpsilon()+1.0, UsingLibQhull::globalDistanceEpsilon()+1.0);
00094         UsingLibQhull::setGlobals();
00095     }
00096     QCOMPARE(UsingLibQhull::globalAngleEpsilon()+1.0, 1.0);
00097     QCOMPARE(UsingLibQhull::globalVertexDimension(), 4); // 'v'.  VertexDimension is only used for QhullVertex where dim>15
00098     QCOMPARE(UsingLibQhull::globalDistanceEpsilon()+1.0, 1.0);
00099     UsingLibQhull::unsetGlobals();
00100     try{
00101         cout << UsingLibQhull::globalVertexDimension();
00102         QFAIL("Did not throw error for undefined dimension.");
00103     }catch(const std::exception &e){
00104         cout << "INFO     Caught error -- " << e.what() << endl;
00105     }
00106 }//t_classMembers
00107 
00108 void UsingLibQhull_test::
00109 t_globalPoints()
00110 {
00111     const coordT *r10PointsBegin;
00112     {
00113         RboxPoints r10("10");
00114         Qhull q(r10,"v");  // voronoi diagram of 10 points
00115         UsingLibQhull::unsetGlobalPoints();
00116         int dimension;
00117         const coordT *pointsEnd;
00118         const coordT *pointsBegin= UsingLibQhull::globalPoints(&dimension, &pointsEnd);
00119         cout << "pointsBegin " << pointsBegin
00120             << " pointsEnd " << pointsEnd
00121             << " dimension " << dimension
00122             << endl;
00123         int dimension2;
00124         const coordT *pointsEnd2;
00125         const coordT *pointsBegin2= UsingLibQhull::currentPoints(&dimension2, &pointsEnd2);
00126         QCOMPARE(pointsBegin2, pointsBegin);
00127         QCOMPARE(pointsEnd2, pointsEnd);
00128         QCOMPARE(dimension2, dimension);
00129         coordT c[]= { 1.0,2.0, 3.0,4.0, 5.0,6.0 };
00130         UsingLibQhull::setGlobalPoints(2, c, c+3*2);
00131         pointsBegin= UsingLibQhull::globalPoints(&dimension, &pointsEnd);
00132         QCOMPARE(pointsBegin, c);
00133         QCOMPARE(pointsEnd[-1], 6.0);
00134         QCOMPARE(dimension, 2);
00135         UsingLibQhull::unsetGlobalPoints();
00136         pointsBegin= UsingLibQhull::globalPoints(&dimension, &pointsEnd);
00137         QCOMPARE(pointsBegin, pointsBegin2);
00138         QCOMPARE(pointsEnd, pointsEnd2);
00139         QCOMPARE(dimension, dimension2);
00140         UsingLibQhull::setGlobals();
00141         r10PointsBegin= pointsBegin;
00142     }
00143     int dimension3;
00144     const coordT *pointsEnd3;
00145     const coordT *pointsBegin3= UsingLibQhull::currentPoints(&dimension3, &pointsEnd3);
00146     QCOMPARE(pointsBegin3, r10PointsBegin); // Memory was freed
00147     QCOMPARE(pointsEnd3, r10PointsBegin+10*4);
00148     QCOMPARE(dimension3, 4);
00149     UsingLibQhull::unsetGlobals();
00150     try{
00151         pointsBegin3= UsingLibQhull::globalPoints(&dimension3, &pointsEnd3);
00152         QFAIL("Did not throw error for undefined global points.");
00153     }catch(const std::exception &e){
00154         cout << "INFO     Caught error -- " << e.what() << endl;
00155     }
00156 }//t_globalPoints
00157 
00158 void UsingLibQhull_test::
00159 t_UsingLibQhull()
00160 {
00161     {
00162         Qhull q;
00163         UsingLibQhull uq(&q); // Normally created in a method using 'this'
00164 
00165         try{
00166             Qhull q2; // If qh_QHpointer, QhullQh() calls usinlibqhull()
00167             UsingLibQhull uq2(&q2);
00168             QFAIL("UsingLibQhull did not fail.");
00169         }catch (const std::exception &e) {
00170             cout << "INFO   : Caught " << e.what();
00171         }
00172     }
00173     Qhull q3;
00174     UsingLibQhull uq3(&q3);
00175     // UsingLibQhull uq4; // Default constructors disabled.
00176 }//t_UsingLibQhull
00177 
00178 void UsingLibQhull_test::
00179 t_methods()
00180 {
00181     Qhull q;
00182     UsingLibQhull u(&q); // Normally created in a method using 'this'
00183     QVERIFY(u.defined());
00184     u.maybeThrowQhullMessage(0);  // Nothing thrown
00185     try{
00186         u.maybeThrowQhullMessage(1);
00187         QFAIL("maybeThrowQhullMessage(1) did not fail.");
00188     }catch (const std::exception &e) {
00189         cout << "INFO   : Caught " << e.what();
00190     }
00191     // Can not check checkRunId() in maybeThrowQhullMessage().  Requires another thread.
00192     u.maybeThrowQhullMessage(2, UsingLibQhull::NOthrow);
00193     try{
00194         throw QhullError(10054, "Report previous NOthrow error");
00195     }catch (const std::exception &e) {
00196         cout << "INFO   : " << e.what();
00197     }
00198 }//t_methods
00199 
00200 // Executed after last test
00201 void UsingLibQhull_test::
00202 t_cleanuptestcase()
00203 {
00204     UsingLibQhull::unsetGlobals();
00205 }//t_cleanuptestcase
00206 
00207 }//orgQhull
00208 
00209 #include "moc/UsingLibQhull_test.moc"
00210 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


libqhull
Author(s): Robert Krug
autogenerated on Tue Jun 18 2013 12:38:50