Fix Get() for null Points and Rects, add tests for it

This commit is contained in:
Dmitry Marakasov 2014-02-21 23:46:37 +04:00
parent 8e6bf5fc2f
commit 5a61a8f51b
3 changed files with 6 additions and 4 deletions

View File

@ -51,11 +51,11 @@ bool Point::operator!=(const Point& other) const {
}
SDL_Point* Point::Get() {
return &point_;
return valid_ ? &point_ : nullptr;
}
const SDL_Point* Point::Get() const {
return &point_;
return valid_ ? &point_ : nullptr;
}
bool Point::IsNull() const {

View File

@ -54,11 +54,11 @@ bool Rect::operator!=(const Rect& other) const {
}
SDL_Rect* Rect::Get() {
return &rect_;
return valid_ ? &rect_ : nullptr;
}
const SDL_Rect* Rect::Get() const {
return &rect_;
return valid_ ? &rect_ : nullptr;
}
Rect Rect::FromCenter(int cx, int cy, int w, int h) {

View File

@ -33,6 +33,7 @@ BEGIN_TEST()
EXPECT_TRUE(p != Point(1,2));
EXPECT_TRUE(p == Point::Null());
EXPECT_TRUE(p.IsNull());
EXPECT_TRUE(p.Get() == nullptr);
}
{
@ -114,6 +115,7 @@ BEGIN_TEST()
EXPECT_TRUE(r != Rect(1,2,3,4));
EXPECT_TRUE(r == Rect::Null());
EXPECT_TRUE(r.IsNull());
EXPECT_TRUE(r.Get() == nullptr);
}
{