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
=== modified file 'launcher/PointerBarrier.cpp'
--- launcher/PointerBarrier.cpp 2013-02-23 00:54:10 +0000
+++ launcher/PointerBarrier.cpp 2013-07-09 23:59:25 +0000
@@ -117,8 +117,11 @@
117 dx = event->dx;117 dx = event->dx;
118 dy = event->dy;118 dy = event->dy;
119119
120 millis = event->dtime;
121
120 // Sometimes dtime is 0, if so we don't want to divide by zero!122 // Sometimes dtime is 0, if so we don't want to divide by zero!
121 millis = event->dtime ?: 1;123 if (!millis)
124 return 1;
122125
123 speed = sqrt(dx * dx + dy * dy) / millis * 1000;126 speed = sqrt(dx * dx + dy * dy) / millis * 1000;
124127
125128
=== modified file 'tests/test_pointer_barrier.cpp'
--- tests/test_pointer_barrier.cpp 2013-02-25 20:00:25 +0000
+++ tests/test_pointer_barrier.cpp 2013-07-09 23:59:25 +0000
@@ -20,6 +20,9 @@
20 */20 */
2121
22#include <gtest/gtest.h>22#include <gtest/gtest.h>
23#include <gmock/gmock.h>
24using namespace testing;
25
23#include <limits>26#include <limits>
2427
25#include "test_utils.h"28#include "test_utils.h"
@@ -34,6 +37,8 @@
34{37{
35public:38public:
36 bool HandleBarrierEvent(XIBarrierEvent* b_ev) { return PointerBarrierWrapper::HandleBarrierEvent(b_ev); }39 bool HandleBarrierEvent(XIBarrierEvent* b_ev) { return PointerBarrierWrapper::HandleBarrierEvent(b_ev); }
40
41 MOCK_METHOD1(ReleaseBarrier, void(int));
37};42};
3843
39XIBarrierEvent GetGenericEvent (unsigned int id)44XIBarrierEvent GetGenericEvent (unsigned int id)
@@ -162,4 +167,37 @@
162 EXPECT_EQ(events_recived, 2);167 EXPECT_EQ(events_recived, 2);
163}168}
164169
170TEST(TestPointerBarrier, DontReleaseBarrierOnEmptyDTime)
171{
172 MockPointerBarrier pb;
173 pb.threshold = 1000;
174 XIBarrierEvent ev = GetGenericEvent(0xabba);
175 ev.dtime = 0;
176
177 {
178 InSequence sequence;
179 EXPECT_CALL(pb, ReleaseBarrier(0xabba)).Times(0);
180 }
181
182 EXPECT_TRUE(pb.HandleBarrierEvent(&ev));
183
184 Utils::WaitForTimeoutMSec(pb.smoothing());
185}
186
187TEST(TestPointerBarrier, ReleaseBarrierIfOverThreshold)
188{
189 MockPointerBarrier pb;
190 pb.threshold = 500;
191 XIBarrierEvent ev = GetGenericEvent(0xabba);
192
193 {
194 InSequence sequence;
195 EXPECT_CALL(pb, ReleaseBarrier(0xabba)).Times(1);
196 }
197
198 EXPECT_TRUE(pb.HandleBarrierEvent(&ev));
199
200 Utils::WaitForTimeoutMSec(pb.smoothing());
201}
202
165}203}