diff options
| author | Sam Spilsbury <sam.spilsbury@canonical.com> | 2012-01-02 19:25:03 -0500 |
|---|---|---|
| committer | Tarmac <> | 2012-01-02 19:25:03 -0500 |
| commit | 620886c1aefd1af0c6a8ba0a6360fdddd8cc9bfb (patch) | |
| tree | cc58cb114c177054c76e0c3f61e61ee3400e1c09 /tests | |
| parent | 8d1bfed33dd8fb924afdba90c451549fcaa8b469 (diff) | |
| parent | a4ec575aa4093a382334e494fbdc5c65870d2692 (diff) | |
Adds test for animation code. Fixes: . Appoved by Thomas Voß.
(bzr r1807)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_grabhandle.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/test_grabhandle.cpp b/tests/test_grabhandle.cpp index c3e94aabf..437d32798 100644 --- a/tests/test_grabhandle.cpp +++ b/tests/test_grabhandle.cpp @@ -42,6 +42,31 @@ public: 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 () {}; + + 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. @@ -235,4 +266,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 |
