Unit test for the move assignment operator and move constructor in FPoint, FSize and FRect

This commit is contained in:
Markus Gans 2019-07-31 23:57:35 +02:00
parent 92c120b79e
commit 0e12be93cc
11 changed files with 139 additions and 29 deletions

View File

@ -1,3 +1,7 @@
2019-07-31 Markus Gans <guru.mail@muenster.de>
* Unit test for the move assignment operator and move constructor
in FPoint, FSize and FRect
2019-07-28 Markus Gans <guru.mail@muenster.de>
* FreeBSD can now change the frequency and duration
of the pc speaker signal

View File

@ -44,8 +44,9 @@ FPoint& FPoint::operator = (const FPoint& p)
//----------------------------------------------------------------------
FPoint& FPoint::operator = (FPoint&& p)
{
xpos = std::move(p.xpos);
ypos = std::move(p.ypos);
xpos = p.xpos;
ypos = p.ypos;
p.xpos = p.ypos = 0;
return *this;
}

View File

@ -299,20 +299,22 @@ FRect FRect::combined (const FRect& r) const
//----------------------------------------------------------------------
FRect& FRect::operator = (const FRect& r)
{
X1 = r.getX1();
Y1 = r.getY1();
X2 = r.getX2();
Y2 = r.getY2();
X1 = r.X1;
Y1 = r.Y1;
X2 = r.X2;
Y2 = r.Y2;
return *this;
}
//----------------------------------------------------------------------
FRect& FRect::operator = (FRect&& r)
{
X1 = std::move(r.getX1());
Y1 = std::move(r.getY1());
X2 = std::move(r.getX2());
Y2 = std::move(r.getY2());
X1 = r.X1;
Y1 = r.Y1;
X2 = r.X2;
Y2 = r.Y2;
r.X1 = r.Y1 = 0;
r.X2 = r.Y2 = -1;
return *this;
}

View File

@ -44,8 +44,9 @@ FSize& FSize::operator = (const FSize& s)
//----------------------------------------------------------------------
FSize& FSize::operator = (FSize&& s)
{
width = std::move(s.width);
height = std::move(s.height);
width = s.width;
height = s.height;
s.width = s.height = 0; std::cerr << " move operator\n";
return *this;
}

View File

@ -53,6 +53,7 @@ class FPoint
// Constructors
FPoint () = default;
FPoint (const FPoint&); // copy constructor
FPoint (FPoint&&); // move constructor
FPoint (int, int);
// Destructor
@ -103,6 +104,12 @@ inline FPoint::FPoint (const FPoint& p) // copy constructor
, ypos(p.ypos)
{ }
//----------------------------------------------------------------------
inline FPoint::FPoint (FPoint&& p) // move constructor
: xpos(p.xpos)
, ypos(p.ypos)
{ p.xpos = p.ypos = 0; }
//----------------------------------------------------------------------
inline FPoint::FPoint (int x, int y)
: xpos(x)

View File

@ -61,6 +61,7 @@ class FRect
// Constructors
FRect () = default;
FRect (const FRect&); // copy constructor
FRect (FRect&&); // move constructor
FRect (int, int, std::size_t, std::size_t);
FRect (const FPoint&, const FSize&);
FRect (const FPoint&, const FPoint&);
@ -153,6 +154,17 @@ inline FRect::FRect (const FRect& r) // copy constructor
, Y2(r.Y2)
{ }
//----------------------------------------------------------------------
inline FRect::FRect (FRect&& r) // move constructor
: X1(r.X1)
, Y1(r.Y1)
, X2(r.X2)
, Y2(r.Y2)
{
r.X1 = r.Y1 = 0;
r.X2 = r.Y2 = -1;
}
//----------------------------------------------------------------------
inline FRect::FRect (int x, int y, std::size_t width, std::size_t height)
: X1(x)

View File

@ -55,6 +55,7 @@ class FSize
// Constructors
FSize () = default;
FSize (const FSize&); // copy constructor
FSize (FSize&&); // move constructor
FSize (std::size_t, std::size_t);
// Destructor
@ -108,7 +109,13 @@ class FSize
inline FSize::FSize (const FSize& s) // copy constructor
: width(s.width)
, height(s.height)
{ }
{ std::cerr << " copy ctor\n";}
//----------------------------------------------------------------------
inline FSize::FSize (FSize&& s) // move constructor
: width(s.width)
, height(s.height)
{ s.width = s.height = 0; std::cerr << " move ctor\n";}
//----------------------------------------------------------------------
inline FSize::FSize (std::size_t w, std::size_t h)

View File

@ -49,6 +49,7 @@ class FPointTest : public CPPUNIT_NS::TestFixture
void classNameTest();
void noArgumentTest();
void copyConstructorTest();
void moveConstructorTest();
void assignmentTest();
void additionAssignmentTest();
void subtractionAssignmentTest();
@ -68,6 +69,7 @@ class FPointTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST (classNameTest);
CPPUNIT_TEST (noArgumentTest);
CPPUNIT_TEST (copyConstructorTest);
CPPUNIT_TEST (moveConstructorTest);
CPPUNIT_TEST (assignmentTest);
CPPUNIT_TEST (additionAssignmentTest);
CPPUNIT_TEST (subtractionAssignmentTest);
@ -110,6 +112,17 @@ void FPointTest::copyConstructorTest()
CPPUNIT_ASSERT ( p2.getY() == 10 );
}
//----------------------------------------------------------------------
void FPointTest::moveConstructorTest()
{
finalcut::FPoint p1 (25,16);
const finalcut::FPoint p2 (std::move(p1));
CPPUNIT_ASSERT ( p1.getX() == 0 );
CPPUNIT_ASSERT ( p1.getY() == 0 );
CPPUNIT_ASSERT ( p2.getX() == 25 );
CPPUNIT_ASSERT ( p2.getY() == 16 );
}
//----------------------------------------------------------------------
void FPointTest::assignmentTest()
{
@ -138,11 +151,19 @@ void FPointTest::assignmentTest()
CPPUNIT_ASSERT ( p2.getX() == 40 );
CPPUNIT_ASSERT ( p2.getY() == 12 );
// Move assignment operator
finalcut::FPoint p3 = std::move(p2);
CPPUNIT_ASSERT ( p2.getX() == 0 );
CPPUNIT_ASSERT ( p2.getY() == 0 );
CPPUNIT_ASSERT ( p2.isOrigin() );
CPPUNIT_ASSERT ( p3.getX() == 40 );
CPPUNIT_ASSERT ( p3.getY() == 12 );
// Value limit
const finalcut::FPoint p3 ( std::numeric_limits<int>::min()
const finalcut::FPoint p4 ( std::numeric_limits<int>::min()
, std::numeric_limits<int>::max() );
CPPUNIT_ASSERT ( p3.getX() == std::numeric_limits<int>::min() );
CPPUNIT_ASSERT ( p3.getY() == std::numeric_limits<int>::max() );
CPPUNIT_ASSERT ( p4.getX() == std::numeric_limits<int>::min() );
CPPUNIT_ASSERT ( p4.getY() == std::numeric_limits<int>::max() );
}
//----------------------------------------------------------------------

View File

@ -47,6 +47,7 @@ class FRectTest : public CPPUNIT_NS::TestFixture
void classNameTest();
void noArgumentTest();
void copyConstructorTest();
void moveConstructorTest();
void assignmentTest();
void equalTest();
void notEqualTest();
@ -69,6 +70,7 @@ class FRectTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST (classNameTest);
CPPUNIT_TEST (noArgumentTest);
CPPUNIT_TEST (copyConstructorTest);
CPPUNIT_TEST (moveConstructorTest);
CPPUNIT_TEST (assignmentTest);
CPPUNIT_TEST (equalTest);
CPPUNIT_TEST (notEqualTest);
@ -107,6 +109,7 @@ void FRectTest::noArgumentTest()
CPPUNIT_ASSERT ( rectangle.isEmpty() );
CPPUNIT_ASSERT ( rectangle.getWidth() == 0 );
CPPUNIT_ASSERT ( rectangle.getHeight() == 0 );
CPPUNIT_ASSERT ( rectangle.getSize() == finalcut::FSize(0, 0) );
CPPUNIT_ASSERT ( rectangle.getPos() == finalcut::FPoint(0, 0) );
CPPUNIT_ASSERT ( rectangle.getUpperLeftPos() == finalcut::FPoint(0, 0) );
CPPUNIT_ASSERT ( rectangle.getUpperRightPos() == finalcut::FPoint(-1, 0) );
@ -126,6 +129,23 @@ void FRectTest::copyConstructorTest()
CPPUNIT_ASSERT ( r2.getHeight() == 10 );
}
//----------------------------------------------------------------------
void FRectTest::moveConstructorTest()
{
finalcut::FRect r1(3, 3, 15, 7);
const finalcut::FRect r2 (std::move(r1));
CPPUNIT_ASSERT ( r1.getX() == 0 );
CPPUNIT_ASSERT ( r1.getY() == 0 );
CPPUNIT_ASSERT ( r1.isEmpty() );
CPPUNIT_ASSERT ( r1.getWidth() == 0 );
CPPUNIT_ASSERT ( r1.getHeight() == 0 );
CPPUNIT_ASSERT ( r2.getX() == 3 );
CPPUNIT_ASSERT ( r2.getY() == 3 );
CPPUNIT_ASSERT ( ! r2.isEmpty() );
CPPUNIT_ASSERT ( r2.getWidth() == 15 );
CPPUNIT_ASSERT ( r2.getHeight() == 7 );
}
//----------------------------------------------------------------------
void FRectTest::assignmentTest()
{
@ -336,6 +356,25 @@ void FRectTest::assignmentTest()
CPPUNIT_ASSERT ( r5.getWidth() == 10 );
CPPUNIT_ASSERT ( r5.getHeight() == 10 );
CPPUNIT_ASSERT ( r5.getSize() == finalcut::FSize(10, 10) );
finalcut::FRect r6;
r6 = std::move(r5); // Move assignment operator
CPPUNIT_ASSERT ( r5.getX1() == 0 );
CPPUNIT_ASSERT ( r5.getY1() == 0 );
CPPUNIT_ASSERT ( r5.getX2() == -1 );
CPPUNIT_ASSERT ( r5.getY2() == -1 );
CPPUNIT_ASSERT ( r5.isEmpty() );
CPPUNIT_ASSERT ( r5.getWidth() == 0 );
CPPUNIT_ASSERT ( r5.getHeight() == 0 );
CPPUNIT_ASSERT ( r5.getSize() == finalcut::FSize(0, 0) );
CPPUNIT_ASSERT ( r5.getPos() == finalcut::FPoint(0, 0) );
CPPUNIT_ASSERT ( r6.getX1() == 2 );
CPPUNIT_ASSERT ( r6.getY1() == 9 );
CPPUNIT_ASSERT ( r6.getX2() == 11 );
CPPUNIT_ASSERT ( r6.getY2() == 18 );
CPPUNIT_ASSERT ( r6.getWidth() == 10 );
CPPUNIT_ASSERT ( r6.getHeight() == 10 );
CPPUNIT_ASSERT ( r6.getSize() == finalcut::FSize(10, 10) );
}
//----------------------------------------------------------------------

View File

@ -49,6 +49,7 @@ class FSizeTest : public CPPUNIT_NS::TestFixture
void classNameTest();
void noArgumentTest();
void copyConstructorTest();
void moveConstructorTest();
void assignmentTest();
void additionAssignmentTest();
void subtractionAssignmentTest();
@ -71,6 +72,7 @@ class FSizeTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST (classNameTest);
CPPUNIT_TEST (noArgumentTest);
CPPUNIT_TEST (copyConstructorTest);
CPPUNIT_TEST (moveConstructorTest);
CPPUNIT_TEST (assignmentTest);
CPPUNIT_TEST (additionAssignmentTest);
CPPUNIT_TEST (subtractionAssignmentTest);
@ -116,6 +118,18 @@ void FSizeTest::copyConstructorTest()
CPPUNIT_ASSERT ( s2.getHeight() == 80 );
}
//----------------------------------------------------------------------
void FSizeTest::moveConstructorTest()
{
finalcut::FSize s1 (120, 36);
const finalcut::FSize s2 (std::move(s1));
CPPUNIT_ASSERT ( s1.getWidth() == 0 );
CPPUNIT_ASSERT ( s1.getHeight() == 0 );
CPPUNIT_ASSERT ( s1.isEmpty() );
CPPUNIT_ASSERT ( s2.getWidth() == 120 );
CPPUNIT_ASSERT ( s2.getHeight() == 36 );
}
//----------------------------------------------------------------------
void FSizeTest::assignmentTest()
{
@ -145,11 +159,20 @@ void FSizeTest::assignmentTest()
CPPUNIT_ASSERT ( s2.getWidth() == 5 );
CPPUNIT_ASSERT ( s2.getHeight() == 4 );
// Move assignment operator
finalcut::FSize s3;
s3 = std::move(s2);
CPPUNIT_ASSERT ( s2.getWidth() == 0 );
CPPUNIT_ASSERT ( s2.getHeight() == 0 );
CPPUNIT_ASSERT ( s2.isEmpty() );
CPPUNIT_ASSERT ( s3.getWidth() == 5 );
CPPUNIT_ASSERT ( s3.getHeight() == 4 );
// Value limit
const finalcut::FSize s3 ( std::numeric_limits<std::size_t>::min()
const finalcut::FSize s4 ( std::numeric_limits<std::size_t>::min()
, std::numeric_limits<std::size_t>::max() );
CPPUNIT_ASSERT ( s3.getWidth() == std::numeric_limits<std::size_t>::min() );
CPPUNIT_ASSERT ( s3.getHeight() == std::numeric_limits<std::size_t>::max() );
CPPUNIT_ASSERT ( s4.getWidth() == std::numeric_limits<std::size_t>::min() );
CPPUNIT_ASSERT ( s4.getHeight() == std::numeric_limits<std::size_t>::max() );
}
//----------------------------------------------------------------------

View File

@ -684,15 +684,6 @@ void ftermfreebsdTest::freebsdConsoleTest()
freebsd.restoreCursorStyle();
CPPUNIT_ASSERT ( freebsd.getCursorStyle() == finalcut::fc::blink_cursor );
for (std::size_t i = 0; i <= finalcut::fc::lastCharItem; i++)
if ( finalcut::fc::character[i][finalcut::fc::PC] < 0x1c )
std::cerr << i << ":" << finalcut::fc::character[i][finalcut::fc::PC] << ", ";
for (std::size_t i = 0; i <= finalcut::fc::lastCharItem; i++)
if ( finalcut::fc::character[i][finalcut::fc::PC] < 0x1c )
std::cerr << i << ":" << finalcut::fc::character[i][finalcut::fc::ASCII] << ", ";
CPPUNIT_ASSERT ( finalcut::fc::character[2][finalcut::fc::PC] == 21 );
CPPUNIT_ASSERT ( finalcut::fc::character[3][finalcut::fc::PC] == 8 );
CPPUNIT_ASSERT ( finalcut::fc::character[4][finalcut::fc::PC] == 10 );
@ -711,8 +702,8 @@ void ftermfreebsdTest::freebsdConsoleTest()
CPPUNIT_ASSERT ( finalcut::fc::character[59][finalcut::fc::PC] == 16 );
CPPUNIT_ASSERT ( finalcut::fc::character[60][finalcut::fc::PC] == 17 );
CPPUNIT_ASSERT ( finalcut::fc::character[105][finalcut::fc::PC] == 4 );
freebsd.initCharMap (finalcut::fc::character);
term_detection->detect();
CPPUNIT_ASSERT ( finalcut::fc::character[2][finalcut::fc::PC] == 36 );
CPPUNIT_ASSERT ( finalcut::fc::character[3][finalcut::fc::PC] == 42 );
@ -733,6 +724,8 @@ void ftermfreebsdTest::freebsdConsoleTest()
CPPUNIT_ASSERT ( finalcut::fc::character[60][finalcut::fc::PC] == 60 );
CPPUNIT_ASSERT ( finalcut::fc::character[105][finalcut::fc::PC] == 42 );
term_detection->detect();
#if DEBUG
const finalcut::FString& sec_da = \
finalcut::FTerm::getFTermDebugData().getSecDAString();