00001 #include <KoPoint.h>
00002 #include <kdebug.h>
00003 #include <kglobal.h>
00004 #include <stdlib.h>
00005 #include <math.h>
00006
00007 bool check( QString txt, bool res, bool expected )
00008 {
00009 if ( res == expected ) {
00010 kDebug() << txt << " : checking '" << res << "' against expected value '" << expected << "'... " << "ok" << endl;
00011 } else {
00012 kDebug() << txt << " : checking '" << res << "' against expected value '" << expected << "'... " << "KO !" << endl;
00013 exit( 1 );
00014 }
00015 return true;
00016 }
00017
00018 bool check( QString txt, double res, double expected )
00019 {
00020 if ( qAbs(res - expected) < 0.000001 ) {
00021 kDebug() << txt << " : checking '" << res << "' against expected value '" << expected << "'... " << "ok" << endl;
00022 } else {
00023 kDebug() << txt << " : checking '" << res << "' against expected value '" << expected << "'... " << "KO !" << endl;
00024 exit( 1 );
00025 }
00026 return true;
00027 }
00028
00029 int main()
00030 {
00031 KoPoint p0;
00032 check( "KoPoint() is null", p0.isNull(), true );
00033 KoPoint p1( 10.1, 20.2 );
00034 check( "KoPoint(...) is not null", p1.isNull(), false );
00035 check( "KoPoint::x()", p1.x(), 10.1 );
00036 check( "KoPoint::y()", p1.y(), 20.2 );
00037 p1.setX( 2.1 );
00038 p1.setY( 3.2 );
00039 check( "KoPoint::setX()", p1.x(), 2.1 );
00040 check( "KoPoint::setY()", p1.y(), 3.2 );
00041
00042 KoPoint p2( QPoint( -30, -40 ) );
00043 check( "KoPoint(const QPoint&)", p2.x(), -30.0 );
00044 check( "KoPoint(const QPoint&)", p2.y(), -40.0 );
00045 p2.rx() = 1.5;
00046 p2.ry() = 2.5;
00047 check( "KoPoint::rx()", p2.x(), 1.5 );
00048 check( "KoPoint::ry()", p2.y(), 2.5 );
00049 p2.setCoords( -1.6, -1.7 );
00050 check( "KoPoint::setCoords(double, double)", p2.x(), -1.6 );
00051 check( "KoPoint::setCoords(double, double)", p2.y(), -1.7 );
00052
00053 check( "KoPoint::operator==(const KoPoint&)", p1 == p1, true );
00054 check( "KoPoint::operator!=(const KoPoint&)", p1 != p2, true );
00055
00056 KoPoint p4( 10.2, 20.2 );
00057 KoPoint p5( 30.4, 40.4 );
00058 p4 += p5;
00059 check( "KoPoint::operator+=(const KoPoint&)", p4.x(), 40.6 );
00060 check( "KoPoint::operator+=(const KoPoint&)", p4.y(), 60.6 );
00061 p4 -= p5;
00062 check( "KoPoint::operator-=(const KoPoint&)", p4.x(), 10.2 );
00063 check( "KoPoint::operator-=(const KoPoint&)", p4.y(), 20.2 );
00064 p4 *= 2.0;
00065 check( "KoPoint::operator*=(double)", p4.x(), 20.4 );
00066 check( "KoPoint::operator*=(double)", p4.y(), 40.4 );
00067 p4 = p5;
00068 check( "KoPoint::operator=(const KoPoint&)", p4.x(), 30.4 );
00069 check( "KoPoint::operator=(const KoPoint&)", p4.y(), 40.4 );
00070
00071
00072
00073
00074 KoPoint p6( 1.0, 2.0 );
00075 check( "KoPoint::isNear()", p6.isNear( p6, 0 ), true );
00076 check( "KoPoint::isNear()", p6.isNear( KoPoint( 2, 10 ), 1 ), false );
00077 check( "KoPoint::isNear()", p6.isNear( KoPoint( 2, 1 ), 1 ), true );
00078
00079 KoPoint p7( 10, 10 );
00080 check( "KoPoint::getAngle()",
00081 fmod( KoPoint::getAngle( p7, p7 * -1 ) + 10*360.0, 360.0 ), 45.0 );
00082
00083
00084
00085
00086
00087 kDebug() << endl << "Test OK !" << endl;
00088 }
00089