Geometry operators tests.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31007 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
90f7243727
commit
3e8f9a4980
110
tests/geometry/point.cpp
Normal file
110
tests/geometry/point.cpp
Normal file
@ -0,0 +1,110 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/geometry/point.cpp
|
||||
// Purpose: wxPoint unit test
|
||||
// Author: Wlodzimierz ABX Skiba
|
||||
// Created: 2004-12-14
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2004 wxWindows
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/gdicmn.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class PointTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
PointTestCase() { }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( PointTestCase );
|
||||
CPPUNIT_TEST( Operators );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Operators();
|
||||
|
||||
DECLARE_NO_COPY_CLASS(PointTestCase)
|
||||
};
|
||||
|
||||
class RealPointTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
RealPointTestCase() { }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( RealPointTestCase );
|
||||
CPPUNIT_TEST( Operators );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Operators();
|
||||
|
||||
DECLARE_NO_COPY_CLASS(RealPointTestCase)
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( PointTestCase );
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( RealPointTestCase );
|
||||
|
||||
// also include in it's own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( PointTestCase, "PointTestCase" );
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RealPointTestCase, "RealPointTestCase" );
|
||||
|
||||
void PointTestCase::Operators()
|
||||
{
|
||||
wxPoint p1(1,2);
|
||||
wxPoint p2(6,3);
|
||||
wxPoint p3(7,5);
|
||||
wxPoint p4(5,1);
|
||||
wxPoint p5 = p2 + p1;
|
||||
wxPoint p6 = p2 - p1;
|
||||
CPPUNIT_ASSERT( p3.x == p5.x && p3.y == p5.y );
|
||||
CPPUNIT_ASSERT( p4.x == p6.x && p4.y == p6.y );
|
||||
CPPUNIT_ASSERT( p3 == p5 );
|
||||
CPPUNIT_ASSERT( p4 == p6 );
|
||||
CPPUNIT_ASSERT( p3 != p4 );
|
||||
p5 = p2; p5 += p1;
|
||||
p6 = p2; p6 -= p1;
|
||||
CPPUNIT_ASSERT( p3 == p5 );
|
||||
CPPUNIT_ASSERT( p4 == p6 );
|
||||
wxSize s(p1.x,p1.y);
|
||||
p5 = p2; p5 = p2 + s;
|
||||
p6 = p2; p6 = p2 - s;
|
||||
CPPUNIT_ASSERT( p3 == p5 );
|
||||
CPPUNIT_ASSERT( p4 == p6 );
|
||||
p5 = p2; p5 += s;
|
||||
p6 = p2; p6 -= s;
|
||||
CPPUNIT_ASSERT( p3 == p5 );
|
||||
CPPUNIT_ASSERT( p4 == p6 );
|
||||
}
|
||||
|
||||
void RealPointTestCase::Operators()
|
||||
{
|
||||
const double EPSILON = 0.00001;
|
||||
wxRealPoint p1(1.2,3.4);
|
||||
wxRealPoint p2(8.7,5.4);
|
||||
wxRealPoint p3(9.9,8.8);
|
||||
wxRealPoint p4(7.5,2.0);
|
||||
wxRealPoint p5 = p2 + p1;
|
||||
wxRealPoint p6 = p2 - p1;
|
||||
/*
|
||||
CPPUNIT_ASSERT( p3 == p5 );
|
||||
CPPUNIT_ASSERT( p4 == p6 );
|
||||
CPPUNIT_ASSERT( p3 != p4 );
|
||||
*/
|
||||
CPPUNIT_ASSERT( fabs( p3.x - p5.x ) < EPSILON && fabs( p3.y - p5.y ) < EPSILON );
|
||||
CPPUNIT_ASSERT( fabs( p4.x - p6.x ) < EPSILON && fabs( p4.y - p6.y ) < EPSILON );
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2004-12-11
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2004 wxWindows
|
||||
// Copyright: (c) 2004 wxWindows
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -18,10 +18,9 @@
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/gdicmn.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/gdicmn.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -33,9 +32,11 @@ public:
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( RectTestCase );
|
||||
CPPUNIT_TEST( Operators );
|
||||
CPPUNIT_TEST( Union );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Operators();
|
||||
void Union();
|
||||
|
||||
DECLARE_NO_COPY_CLASS(RectTestCase)
|
||||
@ -47,6 +48,43 @@ CPPUNIT_TEST_SUITE_REGISTRATION( RectTestCase );
|
||||
// also include in it's own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RectTestCase, "RectTestCase" );
|
||||
|
||||
void RectTestCase::Operators()
|
||||
{
|
||||
// test + operator which works like Union but does not ignore empty rectangles
|
||||
static const struct RectData
|
||||
{
|
||||
int x1, y1, w1, h1;
|
||||
int x2, y2, w2, h2;
|
||||
int x, y, w, h;
|
||||
|
||||
wxRect GetFirst() const { return wxRect(x1, y1, w1, h1); }
|
||||
wxRect GetSecond() const { return wxRect(x2, y2, w2, h2); }
|
||||
wxRect GetResult() const { return wxRect(x, y, w, h); }
|
||||
} s_rects[] =
|
||||
{
|
||||
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
{ 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 2, 2 },
|
||||
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
|
||||
{ 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 4, 4 },
|
||||
{ 1, 1, 2, 2, 4, 4, 1, 1, 1, 1, 4, 4 },
|
||||
{ 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 6, 6 },
|
||||
{ 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4 }
|
||||
};
|
||||
|
||||
for ( size_t n = 0; n < WXSIZEOF(s_rects); n++ )
|
||||
{
|
||||
const RectData& data = s_rects[n];
|
||||
|
||||
CPPUNIT_ASSERT(
|
||||
( data.GetFirst() + data.GetSecond() ) == data.GetResult()
|
||||
);
|
||||
|
||||
CPPUNIT_ASSERT(
|
||||
( data.GetSecond() + data.GetFirst() ) == data.GetResult()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void RectTestCase::Union()
|
||||
{
|
||||
static const struct RectData
|
||||
@ -66,7 +104,7 @@ void RectTestCase::Union()
|
||||
{ 1, 1, 1, 1, 4, 4, 1, 1, 1, 1, 4, 4 },
|
||||
{ 1, 1, 2, 2, 4, 4, 1, 1, 1, 1, 4, 4 },
|
||||
{ 2, 2, 2, 2, 4, 4, 4, 4, 2, 2, 6, 6 },
|
||||
{ 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4 },
|
||||
{ 1, 1, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4 }
|
||||
};
|
||||
|
||||
for ( size_t n = 0; n < WXSIZEOF(s_rects); n++ )
|
||||
@ -82,4 +120,3 @@ void RectTestCase::Union()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
76
tests/geometry/size.cpp
Normal file
76
tests/geometry/size.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/geometry/size.cpp
|
||||
// Purpose: wxSize unit test
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2004-12-14
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 2004 wxWindows
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/gdicmn.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class SizeTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SizeTestCase() { }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( SizeTestCase );
|
||||
CPPUNIT_TEST( Operators );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Operators();
|
||||
|
||||
DECLARE_NO_COPY_CLASS(SizeTestCase)
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( SizeTestCase );
|
||||
|
||||
// also include in it's own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SizeTestCase, "SizeTestCase" );
|
||||
|
||||
void SizeTestCase::Operators()
|
||||
{
|
||||
wxSize s1(1,2);
|
||||
wxSize s2(3,4);
|
||||
wxSize s3;
|
||||
|
||||
s3 = s1 + s2;
|
||||
CPPUNIT_ASSERT( s3.GetWidth()==4 && s3.GetHeight()==6 );
|
||||
s3 = s2 - s1;
|
||||
CPPUNIT_ASSERT( s3.GetWidth()==2 && s3.GetHeight()==2 );
|
||||
s3 = s1 * 2;
|
||||
CPPUNIT_ASSERT( s3.GetWidth()==2 && s3.GetHeight()==4 );
|
||||
s3 = s3 / 2;
|
||||
CPPUNIT_ASSERT( s3.GetWidth()==1 && s3.GetHeight()==2 );
|
||||
|
||||
s3 = s2;
|
||||
CPPUNIT_ASSERT( s3 != s1 );
|
||||
s3 = s1;
|
||||
CPPUNIT_ASSERT( s3 == s1 );
|
||||
s3 += s2;
|
||||
CPPUNIT_ASSERT( s3.GetWidth()==4 && s3.GetHeight()==6 );
|
||||
s3 -= s2;
|
||||
CPPUNIT_ASSERT( s3 == s1 );
|
||||
s3 *= 2;
|
||||
CPPUNIT_ASSERT( s3.GetWidth()==2 && s3.GetHeight()==4 );
|
||||
s3 /= 2;
|
||||
CPPUNIT_ASSERT( s3 == s1 );
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
<template id="wx_test">
|
||||
<cppflags>$(CPPUNIT_CFLAGS)</cppflags>
|
||||
<ldflags>$(CPPUNIT_LIBS)</ldflags>
|
||||
|
||||
|
||||
<if cond="WX_DISABLE_PRECOMP_HEADERS=='0'">
|
||||
<if cond="FORMAT!='autoconf' and TOOLKIT=='MSW'">
|
||||
<sources>dummy.cpp</sources>
|
||||
@ -55,7 +55,7 @@
|
||||
<wx-lib>net</wx-lib>
|
||||
<wx-lib>base</wx-lib>
|
||||
</exe>
|
||||
|
||||
|
||||
|
||||
<exe id="test_gui" template="wx_sample,wx_test"
|
||||
template_append="wx_append"
|
||||
@ -63,10 +63,12 @@
|
||||
|
||||
<!-- link against GUI libraries, but be a console app: -->
|
||||
<app-type>console</app-type>
|
||||
|
||||
|
||||
<sources>
|
||||
test.cpp
|
||||
geometry/rect.cpp
|
||||
geometry/size.cpp
|
||||
geometry/point.cpp
|
||||
</sources>
|
||||
<wx-lib>core</wx-lib>
|
||||
<wx-lib>base</wx-lib>
|
||||
|
Loading…
Reference in New Issue
Block a user