summaryrefslogtreecommitdiff
path: root/tests
diff options
authorSam Spilsbury <sam.spilsbury@canonical.com>2011-12-22 16:42:53 +0800
committerSam Spilsbury <sam.spilsbury@canonical.com>2011-12-22 16:42:53 +0800
commit6b4d7fa0d5be6a03e928feba27397336fd10a060 (patch)
treee2802c51e274f75e21c088003e5c059442f3f168 /tests
parent9d1c2a3dc7af716de1c4d8cd0d4abb9a8253546e (diff)
Added tests for animation code
(bzr r1794.6.1)
Diffstat (limited to 'tests')
-rw-r--r--tests/test_grabhandle.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/test_grabhandle.cpp b/tests/test_grabhandle.cpp
index e191bd156..b700bac2e 100644
--- a/tests/test_grabhandle.cpp
+++ b/tests/test_grabhandle.cpp
@@ -42,6 +42,31 @@ public:
virtual GrabHandle::Impl * create (const GrabHandle::Ptr &h);
};
+class MockAnimationGrabHandleImpl : public unity::MT::GrabHandle::Impl
+{
+public:
+ MockAnimationGrabHandleImpl () : unity::MT::GrabHandle::Impl ()
+ {
+ EXPECT_CALL (*this, damage (_)).Times (AtLeast (unity::MT::FADE_MSEC * 2));
+ EXPECT_CALL (*this, show ()).Times (AtLeast (1));
+ EXPECT_CALL (*this, hide ()).Times (AtLeast (1));
+ }
+
+ MOCK_METHOD0 (show, void ());
+ MOCK_METHOD0 (hide, void ());
+ MOCK_CONST_METHOD3 (buttonPress, void (int, int, unsigned int));
+ MOCK_METHOD3 (lockPosition, void (int, int, unsigned int));
+ MOCK_METHOD1 (damage, void (const nux::Geometry &));
+};
+
+class MockAnimationGrabHandleImplFactory : public unity::MT::GrabHandle::ImplFactory
+{
+public:
+ MockAnimationGrabHandleImplFactory () : ImplFactory () {};
+
+ virtual GrabHandle::Impl * create (const GrabHandle::Ptr &h);
+};
+
class MockShowHideGrabHandleImpl : public unity::MT::GrabHandle::Impl
{
public:
@@ -108,6 +133,12 @@ MockShowHideGrabHandleImplFactory::create (const GrabHandle::Ptr &h)
return new MockShowHideGrabHandleImpl ();
}
+GrabHandle::Impl *
+MockAnimationGrabHandleImplFactory::create (const GrabHandle::Ptr &h)
+{
+ return new MockAnimationGrabHandleImpl ();
+}
+
namespace {
// The fixture for testing class UnityMTGrabHandleTest.
@@ -244,4 +275,85 @@ TEST_F(UnityMTGrabHandleTest, TestShowHide)
group->hide ();
}
+TEST_F(UnityMTGrabHandleTest, TestAnimations)
+{
+ int opacity = 0;
+ unity::MT::GrabHandle::ImplFactory::SetDefault (new MockAnimationGrabHandleImplFactory ());
+ unity::MT::Texture::Factory::SetDefault (new MockGrabHandleTextureFactory ());
+
+ unity::MT::FADE_MSEC = 10;
+
+ std::vector <TextureSize> textures;
+
+ for (unsigned int i = 0; i < unity::MT::NUM_HANDLES; i++)
+ textures.push_back (TextureSize (MockGrabHandleTextureFactory::Default ()->create (), nux::Geometry (0, 0, 100, 100)));
+
+ GrabHandleGroup::Ptr group = GrabHandleGroup::create (window, textures);
+
+ group->show ();
+ for (unsigned int i = 0; i < unity::MT::FADE_MSEC; i++)
+ {
+ group->animate (1);
+ EXPECT_TRUE (group->needsAnimate ());
+ EXPECT_TRUE (group->visible ());
+ opacity += ((1 /
+ static_cast <float> (unity::MT::FADE_MSEC)) *
+ std::numeric_limits <unsigned short>::max ());
+ opacity = std::min (opacity, static_cast <int> (std::numeric_limits <unsigned short>::max ()));
+ EXPECT_EQ (group->opacity (), opacity);
+ group->forEachHandle ([&](const unity::MT::GrabHandle::Ptr &h)
+ {
+ h->damage (nux::Geometry (h->x (),
+ h->y (),
+ h->width (),
+ h->height ()));
+ });
+ }
+
+ group->animate (1);
+ group->forEachHandle ([&](const unity::MT::GrabHandle::Ptr &h)
+ {
+ h->damage (nux::Geometry (h->x (),
+ h->y (),
+ h->width (),
+ h->height ()));
+ });
+ EXPECT_FALSE (group->needsAnimate ());
+ EXPECT_EQ (group->opacity (), std::numeric_limits <unsigned short>::max ());
+
+ opacity = group->opacity ();
+
+ group->hide ();
+ for (unsigned int i = 0; i < unity::MT::FADE_MSEC - 1; i++)
+ {
+ group->animate (1);
+ EXPECT_TRUE (group->needsAnimate ());
+ EXPECT_TRUE (group->visible ());
+ opacity -= ((1 /
+ static_cast <float> (unity::MT::FADE_MSEC)) *
+ std::numeric_limits <unsigned short>::max ());
+ opacity = std::max (opacity, 0);
+ EXPECT_EQ (group->opacity (), opacity);
+ group->forEachHandle ([&](const unity::MT::GrabHandle::Ptr &h)
+ {
+ h->damage (nux::Geometry (h->x (),
+ h->y (),
+ h->width (),
+ h->height ()));
+ });
+ }
+
+ group->animate (1);
+ group->forEachHandle ([&](const unity::MT::GrabHandle::Ptr &h)
+ {
+ h->damage (nux::Geometry (h->x (),
+ h->y (),
+ h->width (),
+ h->height ()));
+ });
+ EXPECT_FALSE (group->needsAnimate ());
+ EXPECT_EQ (group->opacity (), 0);
+
+}
+
} // namespace