Merge lp:~brandontschaefer/unity/lp.1199050-fix into lp:unity

Proposed by Brandon Schaefer
Status: Merged
Approved by: Stephen M. Webb
Approved revision: no longer in the source branch.
Merged at revision: 3418
Proposed branch: lp:~brandontschaefer/unity/lp.1199050-fix
Merge into: lp:unity
Diff against target: 77 lines (+42/-1)
2 files modified
launcher/PointerBarrier.cpp (+4/-1)
tests/test_pointer_barrier.cpp (+38/-0)
To merge this branch: bzr merge lp:~brandontschaefer/unity/lp.1199050-fix
Reviewer Review Type Date Requested Status
Stephen M. Webb (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+173845@code.launchpad.net

Commit message

Don't calculate the velocity if dtime is 0. This way we don't get a huge velocity on the initial barrier hit.

Description of the change

=== Problem ===
When we got an event we had to calculate the velocity of the event. If dtime was 0, I was assuming it was ok to just use 1. The problem is this would create a huge number when it was ever 0. Causing the barrier to break waay to easy, causing the launcher to not reveal as easy as it use to.

=== Fix ===
If dtime is 0, just return the velocity as 1, instead of calculating the velc and only dividing by 1...

=== Tests ===
Test we don't break the barrier if we have 0 dtime
Test we break the barrier if we have greater then 0 dtime and the velc is greater then the threshold.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Stephen M. Webb (bregma) wrote :

Righteous catch.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/PointerBarrier.cpp'
2--- launcher/PointerBarrier.cpp 2013-02-23 00:54:10 +0000
3+++ launcher/PointerBarrier.cpp 2013-07-09 23:59:25 +0000
4@@ -117,8 +117,11 @@
5 dx = event->dx;
6 dy = event->dy;
7
8+ millis = event->dtime;
9+
10 // Sometimes dtime is 0, if so we don't want to divide by zero!
11- millis = event->dtime ?: 1;
12+ if (!millis)
13+ return 1;
14
15 speed = sqrt(dx * dx + dy * dy) / millis * 1000;
16
17
18=== modified file 'tests/test_pointer_barrier.cpp'
19--- tests/test_pointer_barrier.cpp 2013-02-25 20:00:25 +0000
20+++ tests/test_pointer_barrier.cpp 2013-07-09 23:59:25 +0000
21@@ -20,6 +20,9 @@
22 */
23
24 #include <gtest/gtest.h>
25+#include <gmock/gmock.h>
26+using namespace testing;
27+
28 #include <limits>
29
30 #include "test_utils.h"
31@@ -34,6 +37,8 @@
32 {
33 public:
34 bool HandleBarrierEvent(XIBarrierEvent* b_ev) { return PointerBarrierWrapper::HandleBarrierEvent(b_ev); }
35+
36+ MOCK_METHOD1(ReleaseBarrier, void(int));
37 };
38
39 XIBarrierEvent GetGenericEvent (unsigned int id)
40@@ -162,4 +167,37 @@
41 EXPECT_EQ(events_recived, 2);
42 }
43
44+TEST(TestPointerBarrier, DontReleaseBarrierOnEmptyDTime)
45+{
46+ MockPointerBarrier pb;
47+ pb.threshold = 1000;
48+ XIBarrierEvent ev = GetGenericEvent(0xabba);
49+ ev.dtime = 0;
50+
51+ {
52+ InSequence sequence;
53+ EXPECT_CALL(pb, ReleaseBarrier(0xabba)).Times(0);
54+ }
55+
56+ EXPECT_TRUE(pb.HandleBarrierEvent(&ev));
57+
58+ Utils::WaitForTimeoutMSec(pb.smoothing());
59+}
60+
61+TEST(TestPointerBarrier, ReleaseBarrierIfOverThreshold)
62+{
63+ MockPointerBarrier pb;
64+ pb.threshold = 500;
65+ XIBarrierEvent ev = GetGenericEvent(0xabba);
66+
67+ {
68+ InSequence sequence;
69+ EXPECT_CALL(pb, ReleaseBarrier(0xabba)).Times(1);
70+ }
71+
72+ EXPECT_TRUE(pb.HandleBarrierEvent(&ev));
73+
74+ Utils::WaitForTimeoutMSec(pb.smoothing());
75+}
76+
77 }