initial commit
Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
113
libs/wxWidgets-3.3.1/tests/geometry/point.cpp
Normal file
113
libs/wxWidgets-3.3.1/tests/geometry/point.cpp
Normal file
@@ -0,0 +1,113 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/geometry/point.cpp
|
||||
// Purpose: wxPoint unit test
|
||||
// Author: Wlodzimierz ABX Skiba
|
||||
// Created: 2004-12-14
|
||||
// Copyright: (c) 2004 wxWindows
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/gdicmn.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/math.h"
|
||||
|
||||
TEST_CASE("wxPoint::Operators", "[point]")
|
||||
{
|
||||
wxPoint p1(1,2);
|
||||
wxPoint p2(6,3);
|
||||
wxPoint p3(7,5);
|
||||
wxPoint p4(5,1);
|
||||
wxPoint p5 = p2 + p1;
|
||||
wxPoint p6 = p2 - p1;
|
||||
CHECK( p3.x == p5.x );
|
||||
CHECK( p3.y == p5.y );
|
||||
CHECK( p4.x == p6.x );
|
||||
CHECK( p4.y == p6.y );
|
||||
CHECK( p3 == p5 );
|
||||
CHECK( p4 == p6 );
|
||||
CHECK( p3 != p4 );
|
||||
p5 = p2; p5 += p1;
|
||||
p6 = p2; p6 -= p1;
|
||||
CHECK( p3 == p5 );
|
||||
CHECK( p4 == p6 );
|
||||
wxSize s(p1.x,p1.y);
|
||||
p5 = p2; p5 = p2 + s;
|
||||
p6 = p2; p6 = p2 - s;
|
||||
CHECK( p3 == p5 );
|
||||
CHECK( p4 == p6 );
|
||||
p5 = p2; p5 = s + p2;
|
||||
p6 = p2; p6 = s - p2;
|
||||
CHECK( p3 == p5 );
|
||||
CHECK( p4 == -p6 );
|
||||
p5 = p2; p5 += s;
|
||||
p6 = p2; p6 -= s;
|
||||
CHECK( p3 == p5 );
|
||||
CHECK( p4 == p6 );
|
||||
|
||||
// Test arithmetic compound assignment operators with scalars
|
||||
wxPoint p7(3, 5);
|
||||
p7 /= 2; // chosen to check results truncate
|
||||
CHECK( p7.x == 1 );
|
||||
CHECK( p7.y == 2 );
|
||||
p7 *= 2;
|
||||
CHECK( p7.x == 2 );
|
||||
CHECK( p7.y == 4 );
|
||||
p7 *= 3.2; // chosen so that x and y rounds down and up respectively
|
||||
CHECK( p7.x == 6 );
|
||||
CHECK( p7.y == 13 );
|
||||
p7 /= 1.1; // chosen so that x and y rounds up and down respectively
|
||||
CHECK( p7.x == 5 );
|
||||
CHECK( p7.y == 12 );
|
||||
|
||||
// Test arithmetic compound assignment operators with wxSizes
|
||||
wxSize s1(2, 3);
|
||||
p7 += s1;
|
||||
CHECK( p7.x == 7 );
|
||||
CHECK( p7.y == 15 );
|
||||
wxSize s2(3, 4);
|
||||
p7 -= s2;
|
||||
CHECK( p7.x == 4 );
|
||||
CHECK( p7.y == 11 );
|
||||
}
|
||||
|
||||
TEST_CASE("wxRealPoint::Operators", "[point]")
|
||||
{
|
||||
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;
|
||||
CHECK( p3.x == Approx(p5.x) );
|
||||
CHECK( p3.y == Approx(p5.y) );
|
||||
CHECK( p4.x == Approx(p6.x) );
|
||||
CHECK( p4.y == Approx(p6.y) );
|
||||
CHECK( p3.x != Approx(p4.x) );
|
||||
|
||||
// Test arithmetic compound assignment operators with scalars
|
||||
wxRealPoint p7(3.0, 5.0);
|
||||
p7 /= 2.0;
|
||||
CHECK( p7.x == Approx(1.5) );
|
||||
CHECK( p7.y == Approx(2.5) );
|
||||
p7 *= 3.0;
|
||||
CHECK( p7.x == Approx(4.5) );
|
||||
CHECK( p7.y == Approx(7.5) );
|
||||
|
||||
// Test arithmetic compound assignment operators with wxSizes
|
||||
wxSize s1(2, 3);
|
||||
p7 += s1;
|
||||
CHECK( p7.x == Approx(6.5) );
|
||||
CHECK( p7.y == Approx(10.5) );
|
||||
wxSize s2(3, 4);
|
||||
p7 -= s2;
|
||||
CHECK( p7.x == Approx(3.5) );
|
||||
CHECK( p7.y == Approx(6.5) );
|
||||
}
|
||||
126
libs/wxWidgets-3.3.1/tests/geometry/rect.cpp
Normal file
126
libs/wxWidgets-3.3.1/tests/geometry/rect.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/geometry/rect.cpp
|
||||
// Purpose: wxRect unit test
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2004-12-11
|
||||
// Copyright: (c) 2004 wxWindows
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/gdicmn.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/iosfwrap.h"
|
||||
|
||||
#include "asserthelper.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// tests
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
TEST_CASE("wxRect::CentreIn", "[rect]")
|
||||
{
|
||||
typedef wxRect R;
|
||||
|
||||
CHECK( R(0, 0, 10, 10).CentreIn(R(0, 0, 100, 100)) == R(45, 45, 10, 10) );
|
||||
CHECK( R(0, 0, 20, 20).CentreIn(R(0, 0, 10, 10)) == R(-5, -5, 20, 20) );
|
||||
|
||||
R r(-10, -10, 20, 20);
|
||||
r.MakeCenteredIn(R(0, 0, 100, 100), wxHORIZONTAL);
|
||||
CHECK( r == R(40, -10, 20, 20) );
|
||||
}
|
||||
|
||||
TEST_CASE("wxRect::InflateDeflate", "[rect]")
|
||||
{
|
||||
// This is the rectangle from the example in the documentation of wxRect::Inflate().
|
||||
const wxRect r1(10, 10, 20, 40);
|
||||
|
||||
CHECK(r1.Inflate( 10, 10)==wxRect( 0, 0, 40, 60));
|
||||
CHECK(r1.Inflate( 20, 30)==wxRect(-10, -20, 60, 100));
|
||||
CHECK(r1.Inflate(-10, -10)==wxRect( 20, 20, 0, 20));
|
||||
CHECK(r1.Inflate(-15, -15)==wxRect( 20, 25, 0, 10));
|
||||
|
||||
CHECK(r1.Inflate( 10, 10)==r1.Deflate(-10, -10));
|
||||
CHECK(r1.Inflate( 20, 30)==r1.Deflate(-20, -30));
|
||||
CHECK(r1.Inflate(-10, -10)==r1.Deflate( 10, 10));
|
||||
CHECK(r1.Inflate(-15, -15)==r1.Deflate( 15, 15));
|
||||
}
|
||||
|
||||
TEST_CASE("wxRect::Operators", "[rect]")
|
||||
{
|
||||
// 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];
|
||||
|
||||
CHECK( (data.GetFirst() + data.GetSecond()) == data.GetResult() );
|
||||
CHECK( (data.GetSecond() + data.GetFirst()) == data.GetResult() );
|
||||
}
|
||||
|
||||
// test operator*() which returns the intersection of two rectangles
|
||||
wxRect r1 = wxRect(0, 2, 3, 4);
|
||||
wxRect r2 = wxRect(1, 2, 7, 8);
|
||||
r1 *= r2;
|
||||
CHECK(wxRect(1, 2, 2, 4) == r1);
|
||||
|
||||
CHECK( (r1 * wxRect()).IsEmpty() );
|
||||
}
|
||||
|
||||
TEST_CASE("wxRect::Union", "[rect]")
|
||||
{
|
||||
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, 1, 1, 1, 1 },
|
||||
{ 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];
|
||||
|
||||
CHECK( data.GetFirst().Union(data.GetSecond()) == data.GetResult() );
|
||||
|
||||
CHECK( data.GetSecond().Union(data.GetFirst()) == data.GetResult() );
|
||||
}
|
||||
}
|
||||
136
libs/wxWidgets-3.3.1/tests/geometry/region.cpp
Normal file
136
libs/wxWidgets-3.3.1/tests/geometry/region.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/geometry/region.cpp
|
||||
// Purpose: wxRegion unit test
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2011-10-12
|
||||
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/region.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/iosfwrap.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// helper functions
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// This function could be easily added to wxRegionIterator itself, where it
|
||||
// could be implemented far more efficiently as all major platforms store the
|
||||
// number of rectangles anyhow, but as we only use it for debugging purposes,
|
||||
// just keep it here for now.
|
||||
unsigned GetRectsCount(const wxRegion& rgn)
|
||||
{
|
||||
unsigned count = 0;
|
||||
for ( wxRegionIterator iter(rgn); iter.HaveRects(); ++iter )
|
||||
count++;
|
||||
return count;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
// this operator is needed to use CPPUNIT_ASSERT_EQUAL with wxRegions
|
||||
std::ostream& operator<<(std::ostream& os, const wxRegion& rgn)
|
||||
{
|
||||
wxRect r = rgn.GetBox();
|
||||
os << "# rects = " << GetRectsCount(rgn)
|
||||
<< "; bounding box {"
|
||||
<< r.x << ", " << r.y << ", " << r.width << ", " << r.height
|
||||
<< "}";
|
||||
return os;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class RegionTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
RegionTestCase() { }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( RegionTestCase );
|
||||
CPPUNIT_TEST( Validity );
|
||||
CPPUNIT_TEST( Intersect );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void Validity();
|
||||
void Intersect();
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(RegionTestCase);
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( RegionTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RegionTestCase, "RegionTestCase" );
|
||||
|
||||
void RegionTestCase::Validity()
|
||||
{
|
||||
wxRegion r;
|
||||
|
||||
CPPUNIT_ASSERT_MESSAGE
|
||||
(
|
||||
"Default constructed region must be invalid",
|
||||
!r.IsOk()
|
||||
);
|
||||
|
||||
CPPUNIT_ASSERT_MESSAGE
|
||||
(
|
||||
"Invalid region should be empty",
|
||||
r.IsEmpty()
|
||||
);
|
||||
|
||||
// Offsetting an invalid region doesn't make sense.
|
||||
WX_ASSERT_FAILS_WITH_ASSERT( r.Offset(1, 1) );
|
||||
|
||||
CPPUNIT_ASSERT_MESSAGE
|
||||
(
|
||||
"Combining with a valid region should create a valid region",
|
||||
r.Union(0, 0, 10, 10)
|
||||
);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL_MESSAGE
|
||||
(
|
||||
"Union() with invalid region should give the same region",
|
||||
wxRegion(0, 0, 10, 10),
|
||||
r
|
||||
);
|
||||
}
|
||||
|
||||
void RegionTestCase::Intersect()
|
||||
{
|
||||
const wxPoint points1[] = {
|
||||
wxPoint(310, 392),
|
||||
wxPoint(270, 392),
|
||||
wxPoint(270, 421),
|
||||
wxPoint(310, 421)
|
||||
};
|
||||
|
||||
wxRegion region1(WXSIZEOF(points1), points1);
|
||||
|
||||
const wxPoint points2[] = {
|
||||
wxPoint(54, 104),
|
||||
wxPoint(85, 82),
|
||||
wxPoint(68, 58),
|
||||
wxPoint(37, 80)
|
||||
};
|
||||
|
||||
wxRegion region2(4,points2);
|
||||
|
||||
CPPUNIT_ASSERT( region1.Intersect(region2) );
|
||||
CPPUNIT_ASSERT( region1.IsEmpty() );
|
||||
}
|
||||
72
libs/wxWidgets-3.3.1/tests/geometry/size.cpp
Normal file
72
libs/wxWidgets-3.3.1/tests/geometry/size.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/geometry/size.cpp
|
||||
// Purpose: wxSize unit test
|
||||
// Author: Wlodzimierz ABX Skiba
|
||||
// Created: 2004-12-14
|
||||
// Copyright: (c) 2004 wxWindows
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/gdicmn.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "asserthelper.h"
|
||||
|
||||
TEST_CASE("wxSize::Operators", "[size]")
|
||||
{
|
||||
wxSize s1(1,2);
|
||||
wxSize s2(3,4);
|
||||
wxSize s3;
|
||||
|
||||
s3 = s1 + s2;
|
||||
CHECK( s3 == wxSize(4, 6) );
|
||||
s3 = s2 - s1;
|
||||
CHECK( s3 == wxSize(2, 2) );
|
||||
s3 = s1 * 2;
|
||||
CHECK( s3 == wxSize(2, 4) );
|
||||
s3 = 2 * s1;
|
||||
CHECK( s3 == wxSize(2, 4) );
|
||||
s3 = s3 / 2;
|
||||
CHECK( s3 == wxSize(1, 2) );
|
||||
|
||||
s3 = s2;
|
||||
CHECK( s3 != s1 );
|
||||
s3 = s1;
|
||||
CHECK( s3 == s1 );
|
||||
s3 += s2;
|
||||
CHECK( s3 == wxSize(4, 6) );
|
||||
s3 -= s2;
|
||||
CHECK( s3 == s1 );
|
||||
s3 *= 2;
|
||||
CHECK( s3 == wxSize(2, 4) );
|
||||
s3 /= 2;
|
||||
CHECK( s3 == s1 );
|
||||
|
||||
CHECK( wxSize(6, 9) / 1.5 == wxSize(4, 6) );
|
||||
}
|
||||
|
||||
TEST_CASE("wxSize::Functions", "[size]")
|
||||
{
|
||||
CHECK( wxSize(10, 10).IsAtLeast(wxDefaultSize) );
|
||||
CHECK( wxSize(10, 10).IsAtLeast(wxSize()) );
|
||||
CHECK( wxSize(10, 10).IsAtLeast(wxSize(10, 5)) );
|
||||
CHECK( wxSize(10, 10).IsAtLeast(wxSize(10, 10)) );
|
||||
|
||||
CHECK_FALSE( wxSize(10, 10).IsAtLeast(wxSize(11, 10)) );
|
||||
CHECK_FALSE( wxSize(10, 10).IsAtLeast(wxSize(10, 11)) );
|
||||
CHECK_FALSE( wxSize(10, 10).IsAtLeast(wxSize(11, 11)) );
|
||||
CHECK_FALSE( wxDefaultSize.IsAtLeast(wxSize()) );
|
||||
|
||||
CHECK( wxSize().IsEmpty() );
|
||||
CHECK( wxSize(0, 1).IsEmpty() );
|
||||
CHECK( wxSize(1, 0).IsEmpty() );
|
||||
CHECK( wxDefaultSize.IsEmpty() );
|
||||
CHECK_FALSE( wxSize(1, 1).IsEmpty() );
|
||||
}
|
||||
Reference in New Issue
Block a user