|
1 | 1 | #include <scratchcpp/target.h> |
| 2 | +#include <scratchcpp/sprite.h> |
2 | 3 | #include <scratchcpp/variable.h> |
3 | 4 | #include <scratchcpp/list.h> |
4 | 5 | #include <scratchcpp/block.h> |
|
8 | 9 | #include <scratch/sound_p.h> |
9 | 10 | #include <enginemock.h> |
10 | 11 | #include <targetmock.h> |
| 12 | +#include <spritehandlermock.h> |
11 | 13 | #include <graphicseffectmock.h> |
12 | 14 | #include <audiooutputmock.h> |
13 | 15 | #include <audioplayermock.h> |
@@ -580,6 +582,48 @@ TEST(TargetTest, FastBoundingRect) |
580 | 582 | ASSERT_EQ(rect.bottom(), 0); |
581 | 583 | } |
582 | 584 |
|
| 585 | +TEST(TargetTest, TouchingEdge) |
| 586 | +{ |
| 587 | + Target target; |
| 588 | + EngineMock engine; |
| 589 | + EXPECT_CALL(engine, stageWidth()).WillRepeatedly(Return(480)); |
| 590 | + EXPECT_CALL(engine, stageHeight()).WillRepeatedly(Return(360)); |
| 591 | + ASSERT_FALSE(target.touchingEdge()); |
| 592 | + target.setEngine(&engine); |
| 593 | + ASSERT_FALSE(target.touchingEdge()); |
| 594 | + |
| 595 | + Sprite sprite; |
| 596 | + sprite.setEngine(&engine); |
| 597 | + ASSERT_FALSE(sprite.touchingEdge()); |
| 598 | + |
| 599 | + SpriteHandlerMock iface; |
| 600 | + EXPECT_CALL(iface, init); |
| 601 | + sprite.setInterface(&iface); |
| 602 | + |
| 603 | + EXPECT_CALL(iface, boundingRect).WillOnce(Return(Rect(-100, 100, 100, -100))); |
| 604 | + ASSERT_FALSE(sprite.touchingEdge()); |
| 605 | + EXPECT_CALL(iface, boundingRect).WillOnce(Return(Rect(-240, 100, 100, -100))); |
| 606 | + ASSERT_FALSE(sprite.touchingEdge()); |
| 607 | + EXPECT_CALL(iface, boundingRect).WillOnce(Return(Rect(-240.1, 100, 100, -100))); |
| 608 | + ASSERT_TRUE(sprite.touchingEdge()); |
| 609 | + EXPECT_CALL(iface, boundingRect).WillOnce(Return(Rect(-240, 180, 100, -100))); |
| 610 | + ASSERT_FALSE(sprite.touchingEdge()); |
| 611 | + EXPECT_CALL(iface, boundingRect).WillOnce(Return(Rect(-240, 180.1, 100, -100))); |
| 612 | + ASSERT_TRUE(sprite.touchingEdge()); |
| 613 | + EXPECT_CALL(iface, boundingRect).WillOnce(Return(Rect(-240, 180, 240, -100))); |
| 614 | + ASSERT_FALSE(sprite.touchingEdge()); |
| 615 | + EXPECT_CALL(iface, boundingRect).WillOnce(Return(Rect(-240, 180, 240.1, -100))); |
| 616 | + ASSERT_TRUE(sprite.touchingEdge()); |
| 617 | + EXPECT_CALL(iface, boundingRect).WillOnce(Return(Rect(-240, 180, 240, -180))); |
| 618 | + ASSERT_FALSE(sprite.touchingEdge()); |
| 619 | + EXPECT_CALL(iface, boundingRect).WillOnce(Return(Rect(-240, 180, 240, -180.1))); |
| 620 | + ASSERT_TRUE(sprite.touchingEdge()); |
| 621 | + EXPECT_CALL(iface, boundingRect).WillOnce(Return(Rect(-242, 183, 240, -100))); |
| 622 | + ASSERT_TRUE(sprite.touchingEdge()); |
| 623 | + EXPECT_CALL(iface, boundingRect).WillOnce(Return(Rect(-242, 183, 280, -690))); |
| 624 | + ASSERT_TRUE(sprite.touchingEdge()); |
| 625 | +} |
| 626 | + |
583 | 627 | TEST(TargetTest, GraphicsEffects) |
584 | 628 | { |
585 | 629 | Target target; |
|
0 commit comments