Get rid of CppUnit boilerplate in wxRect unit test
No real changes, just clean up the test.
This commit is contained in:
parent
540d2c2d39
commit
1a22adb80d
1 changed files with 21 additions and 60 deletions
|
|
@ -22,64 +22,34 @@
|
|||
#include "asserthelper.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// test class
|
||||
// tests
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class RectTestCase : public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
RectTestCase() { }
|
||||
|
||||
private:
|
||||
CPPUNIT_TEST_SUITE( RectTestCase );
|
||||
CPPUNIT_TEST( CentreIn );
|
||||
CPPUNIT_TEST( InflateDeflate );
|
||||
CPPUNIT_TEST( Operators );
|
||||
CPPUNIT_TEST( Union );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void CentreIn();
|
||||
void InflateDeflate();
|
||||
void Operators();
|
||||
void Union();
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(RectTestCase);
|
||||
};
|
||||
|
||||
// register in the unnamed registry so that these tests are run by default
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION( RectTestCase );
|
||||
|
||||
// also include in its own registry so that these tests can be run alone
|
||||
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RectTestCase, "RectTestCase" );
|
||||
|
||||
void RectTestCase::CentreIn()
|
||||
TEST_CASE("wxRect::CentreIn", "[rect]")
|
||||
{
|
||||
typedef wxRect R;
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( R(45, 45, 10, 10),
|
||||
R(0, 0, 10, 10).CentreIn(R(0, 0, 100, 100)));
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( R(-5, -5, 20, 20),
|
||||
R(0, 0, 20, 20).CentreIn(R(0, 0, 10, 10)));
|
||||
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) );
|
||||
}
|
||||
|
||||
void RectTestCase::InflateDeflate()
|
||||
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);
|
||||
|
||||
CPPUNIT_ASSERT(r1.Inflate( 10, 10)==wxRect( 0, 0, 40, 60));
|
||||
CPPUNIT_ASSERT(r1.Inflate( 20, 30)==wxRect(-10, -20, 60, 100));
|
||||
CPPUNIT_ASSERT(r1.Inflate(-10, -10)==wxRect( 20, 20, 0, 20));
|
||||
CPPUNIT_ASSERT(r1.Inflate(-15, -15)==wxRect( 20, 25, 0, 10));
|
||||
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));
|
||||
|
||||
CPPUNIT_ASSERT(r1.Inflate( 10, 10)==r1.Deflate(-10, -10));
|
||||
CPPUNIT_ASSERT(r1.Inflate( 20, 30)==r1.Deflate(-20, -30));
|
||||
CPPUNIT_ASSERT(r1.Inflate(-10, -10)==r1.Deflate( 10, 10));
|
||||
CPPUNIT_ASSERT(r1.Inflate(-15, -15)==r1.Deflate( 15, 15));
|
||||
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));
|
||||
}
|
||||
|
||||
void RectTestCase::Operators()
|
||||
TEST_CASE("wxRect::Operators", "[rect]")
|
||||
{
|
||||
// test + operator which works like Union but does not ignore empty rectangles
|
||||
static const struct RectData
|
||||
|
|
@ -106,25 +76,20 @@ void RectTestCase::Operators()
|
|||
{
|
||||
const RectData& data = s_rects[n];
|
||||
|
||||
CPPUNIT_ASSERT(
|
||||
( data.GetFirst() + data.GetSecond() ) == data.GetResult()
|
||||
);
|
||||
|
||||
CPPUNIT_ASSERT(
|
||||
( data.GetSecond() + data.GetFirst() ) == data.GetResult()
|
||||
);
|
||||
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;
|
||||
CPPUNIT_ASSERT(wxRect(1, 2, 2, 4) == r1);
|
||||
CHECK(wxRect(1, 2, 2, 4) == r1);
|
||||
|
||||
CPPUNIT_ASSERT( (r1 * wxRect()).IsEmpty() );
|
||||
CHECK( (r1 * wxRect()).IsEmpty() );
|
||||
}
|
||||
|
||||
void RectTestCase::Union()
|
||||
TEST_CASE("wxRect::Union", "[rect]")
|
||||
{
|
||||
static const struct RectData
|
||||
{
|
||||
|
|
@ -150,12 +115,8 @@ void RectTestCase::Union()
|
|||
{
|
||||
const RectData& data = s_rects[n];
|
||||
|
||||
CPPUNIT_ASSERT(
|
||||
data.GetFirst().Union(data.GetSecond()) == data.GetResult()
|
||||
);
|
||||
CHECK( data.GetFirst().Union(data.GetSecond()) == data.GetResult() );
|
||||
|
||||
CPPUNIT_ASSERT(
|
||||
data.GetSecond().Union(data.GetFirst()) == data.GetResult()
|
||||
);
|
||||
CHECK( data.GetSecond().Union(data.GetFirst()) == data.GetResult() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue