~unity-team/nux/nux.armel-fixes

« back to all changes in this revision

Viewing changes to tests/gtest-nux-axisdecelerationanimation.cpp

  • Committer: Tarmac
  • Author(s): Daniel d'Andrada
  • Date: 2012-10-04 15:58:52 UTC
  • mfrom: (682.1.10 flickable)
  • Revision ID: tarmac-20121004155852-h5qlr2bc4szpr8jz
New: KineticScrollView

+ InputArea::SetTrackChildMouseEvents() and EVENT_MOUSE_CANCEL. Fixes: . Approved by Jay Taoko, Eleni Maria Stea, Nick Dedekind, Michi Henning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2012 - Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License, as
 
6
 * published by the  Free Software Foundation; either version 2.1 or 3.0
 
7
 * of the License.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful, but
 
10
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
11
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
12
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 
13
 * License for more details.
 
14
 *
 
15
 * You should have received a copy of both the GNU Lesser General Public
 
16
 * License along with this program. If not, see <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Daniel d'Andrada <daniel.dandrada@canonical.com>
 
19
 */
 
20
 
 
21
#include <gtest/gtest.h>
 
22
#include <Nux/KineticScrolling/AxisDecelerationAnimation.h>
 
23
 
 
24
using namespace nux;
 
25
 
 
26
TEST(AxisDecelerationAnimation, ComesToAHalt)
 
27
{
 
28
  AxisDecelerationAnimation animation;
 
29
  float min_pos = 0.0f;
 
30
  float max_pos = 100.0f;
 
31
  float start_pos = 10.0f;
 
32
 
 
33
  animation.SetMinimumPosition(min_pos);
 
34
  animation.SetMaximumPosition(max_pos);
 
35
  animation.SetStartPosition(start_pos);
 
36
  animation.SetStartVelocity(100.0f);
 
37
  animation.SetOvershootBoundsEnabled(false);
 
38
 
 
39
  animation.Start();
 
40
 
 
41
  float last_pos = start_pos;
 
42
  float last_movement = 0.0f;
 
43
  for (int i = 0; i < 1000 && animation.IsActive(); ++i)
 
44
  {
 
45
    animation.Update(16);
 
46
 
 
47
    /* Check that it's moving along the velocity direction */
 
48
    ASSERT_TRUE(animation.GetPosition() > last_pos);
 
49
 
 
50
    float movement = animation.GetPosition() - last_pos;
 
51
 
 
52
    if (i > 0)
 
53
    {
 
54
      /* Check that it's decelerating */
 
55
      ASSERT_TRUE(movement - last_movement);
 
56
    }
 
57
 
 
58
    last_pos = animation.GetPosition();
 
59
    last_movement = movement;
 
60
  }
 
61
 
 
62
  /* Check that it came to a halt */
 
63
  ASSERT_FALSE(animation.IsActive());
 
64
}
 
65
 
 
66
TEST(AxisDecelerationAnimation, StopAtBounds)
 
67
{
 
68
  AxisDecelerationAnimation animation;
 
69
  float min_pos = 0.0f;
 
70
  float max_pos = 100.0f;
 
71
  float start_pos = 50.0f;
 
72
 
 
73
  animation.SetMinimumPosition(min_pos);
 
74
  animation.SetMaximumPosition(max_pos);
 
75
 
 
76
  /* test different velocities on both directions */
 
77
  std::vector<int> velocities;
 
78
  for (int i = 1; i <= 100; ++i)
 
79
  {
 
80
    velocities.push_back(i);
 
81
  }
 
82
  for (int i = -1; i >= -100; --i)
 
83
  {
 
84
    velocities.push_back(i);
 
85
  }
 
86
 
 
87
  for (size_t i = 0; i < velocities.size(); ++i)
 
88
  {
 
89
    animation.SetStartPosition(start_pos);
 
90
    animation.SetStartVelocity(velocities[i]);
 
91
    animation.Start();
 
92
 
 
93
    for (int j = 0; j < 1000 && animation.IsActive(); ++j)
 
94
    {
 
95
      animation.Update(16);
 
96
    }
 
97
    ASSERT_FALSE(animation.IsActive());
 
98
 
 
99
    ASSERT_LE(animation.GetPosition(), max_pos);
 
100
    ASSERT_GE(animation.GetPosition(), min_pos);
 
101
  }
 
102
}