1 #include <gtest/gtest.h>
2 #include <QtDebug>
3 #include <QScopedPointer>
4
5 #include "control/controlpotmeter.h"
6 #include "control/controlpushbutton.h"
7 #include "preferences/usersettings.h"
8 #include "controllers/softtakeover.h"
9 #include "test/mixxxtest.h"
10 #include "util/memory.h"
11 #include "util/time.h"
12
13 namespace {
14
15 class SoftTakeoverTest : public MixxxTest {
16 protected:
SetUp()17 void SetUp() override {
18 mixxx::Time::setTestMode(true);
19 mixxx::Time::setTestElapsedTime(mixxx::Duration::fromMillis(10));
20 }
21
TearDown()22 void TearDown() override {
23 mixxx::Time::setTestMode(false);
24 }
25 };
26
TEST_F(SoftTakeoverTest,DoesntIgnoreDisabledControl)27 TEST_F(SoftTakeoverTest, DoesntIgnoreDisabledControl) {
28 // Range -1.0 to 1.0
29 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -1.0, 1.0);
30
31 SoftTakeoverCtrl st_control;
32 EXPECT_FALSE(st_control.ignore(co.get(), co->get()));
33 }
34
TEST_F(SoftTakeoverTest,DoesntIgnoreNonPotmeter)35 TEST_F(SoftTakeoverTest, DoesntIgnoreNonPotmeter) {
36 auto co = std::make_unique<ControlPushButton>(ConfigKey("[Channel1]", "test_button"));
37
38 SoftTakeoverCtrl st_control;
39 st_control.enable(co.get());
40
41 // First update is always ignored so this proves the CPB is not enabled for
42 // soft-takeover.
43 EXPECT_FALSE(st_control.ignore(co.get(), 0));
44 }
45
TEST_F(SoftTakeoverTest,IgnoresFirstValue)46 TEST_F(SoftTakeoverTest, IgnoresFirstValue) {
47 // Range -1.0 to 1.0
48 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -1.0, 1.0);
49
50 SoftTakeoverCtrl st_control;
51 st_control.enable(co.get());
52 EXPECT_TRUE(st_control.ignore(co.get(), 5));
53 }
54
TEST_F(SoftTakeoverTest,DoesntIgnoreSameValue)55 TEST_F(SoftTakeoverTest, DoesntIgnoreSameValue) {
56 // Range -1.0 to 1.0
57 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -1.0, 1.0);
58
59 co->set(0.6);
60 SoftTakeoverCtrl st_control;
61 st_control.enable(co.get());
62 // First is always ignored.
63 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(0.6)));
64 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(0.6)));
65 }
66
67 // These are corner cases that allow for quickly flicking/whipping controls
68 // from a standstill when the previous knob value matches the current CO value
TEST_F(SoftTakeoverTest,SuperFastPrevEqCurrent)69 TEST_F(SoftTakeoverTest, SuperFastPrevEqCurrent) {
70 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
71
72 // From the bottom
73 co->set(-250);
74 SoftTakeoverCtrl st_control;
75 st_control.enable(co.get());
76
77 // First is always ignored.
78 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(-250)));
79 // This can happen any time afterwards, so we test 10 seconds
80 mixxx::Time::setTestElapsedTime(mixxx::Duration::fromSeconds(10));
81 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(200)));
82
83 // From the top
84 co->set(250);
85 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(250)));
86 // This can happen any time afterwards, so we test 10 seconds
87 mixxx::Time::setTestElapsedTime(mixxx::Duration::fromSeconds(10));
88 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(-200)));
89 }
90
91 // But when they don't match, this type of thing should be ignored!
92 // FIXME: This fails on the st::ignore() implementation in 2.0.0-rc1
TEST_F(SoftTakeoverTest,DISABLED_SuperFastNotSame)93 TEST_F(SoftTakeoverTest, DISABLED_SuperFastNotSame) {
94 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
95
96 co->set(250);
97 SoftTakeoverCtrl st_control;
98 st_control.enable(co.get());
99
100 // First is always ignored.
101 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(249)));
102 // This can happen any time afterwards, so we test 10 seconds
103 mixxx::Time::setTestElapsedTime(mixxx::Duration::fromSeconds(10));
104 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(-200)));
105 }
106
107 /* The meat of the tests
108 * (See description in SoftTakeover::ignore() )
109 *
110 * The test matrix is given in the accompanying CSV file.
111 * There are 32 possible cases due to five binary possibilities:
112 * - Previous value distance from current (near/far)
113 * - Previous value side of current (less/greater)
114 * - New value distance
115 * - New value side
116 * - New value arrival time (below or above threshold)
117 */
118
119 // ---- Previous Near & less than current
120
TEST_F(SoftTakeoverTest,PrevNearLess_NewNearLess_Soon)121 TEST_F(SoftTakeoverTest, PrevNearLess_NewNearLess_Soon) {
122 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
123
124 co->set(50);
125 SoftTakeoverCtrl st_control;
126 st_control.enable(co.get());
127
128 // First is always ignored.
129 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(40)));
130 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(45)));
131 }
132
TEST_F(SoftTakeoverTest,PrevNearLess_NewNearMore_Soon)133 TEST_F(SoftTakeoverTest, PrevNearLess_NewNearMore_Soon) {
134 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
135
136 co->set(50);
137 SoftTakeoverCtrl st_control;
138 st_control.enable(co.get());
139
140 // First is always ignored.
141 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(40)));
142 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(60)));
143 }
144
TEST_F(SoftTakeoverTest,PrevNearLess_NewFarLess_Soon)145 TEST_F(SoftTakeoverTest, PrevNearLess_NewFarLess_Soon) {
146 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
147
148 co->set(50);
149 SoftTakeoverCtrl st_control;
150 st_control.enable(co.get());
151
152 // First is always ignored.
153 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(40)));
154 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(1)));
155 }
156
TEST_F(SoftTakeoverTest,PrevNearLess_NewFarMore_Soon)157 TEST_F(SoftTakeoverTest, PrevNearLess_NewFarMore_Soon) {
158 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
159
160 co->set(50);
161 SoftTakeoverCtrl st_control;
162 st_control.enable(co.get());
163
164 // First is always ignored.
165 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(40)));
166 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(100)));
167 }
168
TEST_F(SoftTakeoverTest,PrevNearLess_NewNearLess_Late)169 TEST_F(SoftTakeoverTest, PrevNearLess_NewNearLess_Late) {
170 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
171
172 co->set(50);
173 SoftTakeoverCtrl st_control;
174 st_control.enable(co.get());
175
176 // First is always ignored.
177 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(40)));
178 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
179 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(45)));
180 }
181
TEST_F(SoftTakeoverTest,PrevNearLess_NewNearMore_Late)182 TEST_F(SoftTakeoverTest, PrevNearLess_NewNearMore_Late) {
183 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
184
185 co->set(50);
186 SoftTakeoverCtrl st_control;
187 st_control.enable(co.get());
188
189 // First is always ignored.
190 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(40)));
191 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
192 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(60)));
193 }
194
195 // Ignore this case:
196 // Sides prev distance new distance new value arrives Ignore
197 // same close far later TRUE
198 // FIXME: This fails on the st::ignore() implementation in 2.0.0-rc1
TEST_F(SoftTakeoverTest,DISABLED_PrevNearLess_NewFarLess_Late)199 TEST_F(SoftTakeoverTest, DISABLED_PrevNearLess_NewFarLess_Late) {
200 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
201
202 co->set(50);
203 SoftTakeoverCtrl st_control;
204 st_control.enable(co.get());
205
206 // First is always ignored.
207 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(40)));
208 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
209 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(1)));
210 }
211
212 // Ignore this case:
213 // Sides prev distance new distance new value arrives Ignore
214 // opposite close far later TRUE
215 // FIXME: This fails on the st::ignore() implementation in 2.0.0-rc1
TEST_F(SoftTakeoverTest,DISABLED_PrevNearLess_NewFarMore_Late)216 TEST_F(SoftTakeoverTest, DISABLED_PrevNearLess_NewFarMore_Late) {
217 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
218
219 co->set(50);
220 SoftTakeoverCtrl st_control;
221 st_control.enable(co.get());
222
223 // First is always ignored.
224 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(40)));
225 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
226 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(100)));
227 }
228
229 // ---- Previous Near & greater than current
230
TEST_F(SoftTakeoverTest,PrevNearMore_NewNearLess_Soon)231 TEST_F(SoftTakeoverTest, PrevNearMore_NewNearLess_Soon) {
232 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
233
234 co->set(50);
235 SoftTakeoverCtrl st_control;
236 st_control.enable(co.get());
237
238 // First is always ignored.
239 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(55)));
240 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(45)));
241 }
242
TEST_F(SoftTakeoverTest,PrevNearMore_NewNearMore_Soon)243 TEST_F(SoftTakeoverTest, PrevNearMore_NewNearMore_Soon) {
244 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
245
246 co->set(50);
247 SoftTakeoverCtrl st_control;
248 st_control.enable(co.get());
249
250 // First is always ignored.
251 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(55)));
252 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(60)));
253 }
254
TEST_F(SoftTakeoverTest,PrevNearMore_NewFarLess_Soon)255 TEST_F(SoftTakeoverTest, PrevNearMore_NewFarLess_Soon) {
256 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
257
258 co->set(50);
259 SoftTakeoverCtrl st_control;
260 st_control.enable(co.get());
261
262 // First is always ignored.
263 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(55)));
264 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(1)));
265 }
266
TEST_F(SoftTakeoverTest,PrevNearMore_NewFarMore_Soon)267 TEST_F(SoftTakeoverTest, PrevNearMore_NewFarMore_Soon) {
268 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
269
270 co->set(50);
271 SoftTakeoverCtrl st_control;
272 st_control.enable(co.get());
273
274 // First is always ignored.
275 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(55)));
276 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(100)));
277 }
278
TEST_F(SoftTakeoverTest,PrevNearMore_NewNearLess_Late)279 TEST_F(SoftTakeoverTest, PrevNearMore_NewNearLess_Late) {
280 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
281
282 co->set(50);
283 SoftTakeoverCtrl st_control;
284 st_control.enable(co.get());
285
286 // First is always ignored.
287 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(55)));
288 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
289 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(45)));
290 }
291
TEST_F(SoftTakeoverTest,PrevNearMore_NewNearMore_Late)292 TEST_F(SoftTakeoverTest, PrevNearMore_NewNearMore_Late) {
293 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
294
295 co->set(50);
296 SoftTakeoverCtrl st_control;
297 st_control.enable(co.get());
298
299 // First is always ignored.
300 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(55)));
301 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
302 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(60)));
303 }
304
305 // Ignore this case:
306 // Sides prev distance new distance new value arrives Ignore
307 // opposite close far later TRUE
308 // FIXME: This fails on the st::ignore() implementation in 2.0.0-rc1
TEST_F(SoftTakeoverTest,DISABLED_PrevNearMore_NewFarLess_Late)309 TEST_F(SoftTakeoverTest, DISABLED_PrevNearMore_NewFarLess_Late) {
310 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
311
312 co->set(50);
313 SoftTakeoverCtrl st_control;
314 st_control.enable(co.get());
315
316 // First is always ignored.
317 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(55)));
318 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
319 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(1)));
320 }
321
322 // Ignore this case:
323 // Sides prev distance new distance new value arrives Ignore
324 // same close far later TRUE
325 // FIXME: This fails on the st::ignore() implementation in 2.0.0-rc1
TEST_F(SoftTakeoverTest,DISABLED_PrevNearMore_NewFarMore_Late)326 TEST_F(SoftTakeoverTest, DISABLED_PrevNearMore_NewFarMore_Late) {
327 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
328
329 co->set(50);
330 SoftTakeoverCtrl st_control;
331 st_control.enable(co.get());
332
333 // First is always ignored.
334 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(55)));
335 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
336 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(100)));
337 }
338
339 // ---- Previous Far & less than current
340
TEST_F(SoftTakeoverTest,PrevFarLess_NewNearLess_Soon)341 TEST_F(SoftTakeoverTest, PrevFarLess_NewNearLess_Soon) {
342 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
343
344 co->set(50);
345 SoftTakeoverCtrl st_control;
346 st_control.enable(co.get());
347
348 // First is always ignored.
349 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(-50)));
350 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(45)));
351 }
352
TEST_F(SoftTakeoverTest,PrevFarLess_NewNearMore_Soon)353 TEST_F(SoftTakeoverTest, PrevFarLess_NewNearMore_Soon) {
354 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
355
356 co->set(50);
357 SoftTakeoverCtrl st_control;
358 st_control.enable(co.get());
359
360 // First is always ignored.
361 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(-50)));
362 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(60)));
363 }
364
365 // Ignore this case:
366 // Sides prev distance new distance new value arrives Ignore
367 // same far far soon TRUE
368 // FIXME: This fails on the st::ignore() implementation in 2.0.0-rc1
TEST_F(SoftTakeoverTest,DISABLED_PrevFarLess_NewFarLess_Soon)369 TEST_F(SoftTakeoverTest, DISABLED_PrevFarLess_NewFarLess_Soon) {
370 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
371
372 co->set(50);
373 SoftTakeoverCtrl st_control;
374 st_control.enable(co.get());
375
376 // First is always ignored.
377 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(-50)));
378 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(1)));
379 }
380
TEST_F(SoftTakeoverTest,PrevFarLess_NewFarMore_Soon)381 TEST_F(SoftTakeoverTest, PrevFarLess_NewFarMore_Soon) {
382 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
383
384 co->set(50);
385 SoftTakeoverCtrl st_control;
386 st_control.enable(co.get());
387
388 // First is always ignored.
389 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(-50)));
390 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(100)));
391 }
392
TEST_F(SoftTakeoverTest,PrevFarLess_NewNearLess_Late)393 TEST_F(SoftTakeoverTest, PrevFarLess_NewNearLess_Late) {
394 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
395
396 co->set(50);
397 SoftTakeoverCtrl st_control;
398 st_control.enable(co.get());
399
400 // First is always ignored.
401 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(-50)));
402 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
403 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(45)));
404 }
405
TEST_F(SoftTakeoverTest,PrevFarLess_NewNearMore_Late)406 TEST_F(SoftTakeoverTest, PrevFarLess_NewNearMore_Late) {
407 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
408
409 co->set(50);
410 SoftTakeoverCtrl st_control;
411 st_control.enable(co.get());
412
413 // First is always ignored.
414 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(-50)));
415 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
416 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(60)));
417 }
418
419 // Ignore this case:
420 // Sides prev distance new distance new value arrives Ignore
421 // same far far later TRUE
TEST_F(SoftTakeoverTest,PrevFarLess_NewFarLess_Late)422 TEST_F(SoftTakeoverTest, PrevFarLess_NewFarLess_Late) {
423 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
424
425 co->set(50);
426 SoftTakeoverCtrl st_control;
427 st_control.enable(co.get());
428
429 // First is always ignored.
430 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(-50)));
431 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
432 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(1)));
433 }
434
435 // Ignore this case:
436 // Sides prev distance new distance new value arrives Ignore
437 // opposite far far later TRUE
438 // FIXME: This fails on the st::ignore() implementation in 2.0.0-rc1
TEST_F(SoftTakeoverTest,DISABLED_PrevFarLess_NewFarMore_Late)439 TEST_F(SoftTakeoverTest, DISABLED_PrevFarLess_NewFarMore_Late) {
440 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
441
442 co->set(50);
443 SoftTakeoverCtrl st_control;
444 st_control.enable(co.get());
445
446 // First is always ignored.
447 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(-50)));
448 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
449 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(100)));
450 }
451
452 // ---- Previous Far & greater than current
453
TEST_F(SoftTakeoverTest,PrevFarMore_NewNearLess_Soon)454 TEST_F(SoftTakeoverTest, PrevFarMore_NewNearLess_Soon) {
455 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
456
457 co->set(50);
458 SoftTakeoverCtrl st_control;
459 st_control.enable(co.get());
460
461 // First is always ignored.
462 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(120)));
463 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(45)));
464 }
465
TEST_F(SoftTakeoverTest,PrevFarMore_NewNearMore_Soon)466 TEST_F(SoftTakeoverTest, PrevFarMore_NewNearMore_Soon) {
467 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
468
469 co->set(50);
470 SoftTakeoverCtrl st_control;
471 st_control.enable(co.get());
472
473 // First is always ignored.
474 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(120)));
475 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(60)));
476 }
477
TEST_F(SoftTakeoverTest,PrevFarMore_NewFarLess_Soon)478 TEST_F(SoftTakeoverTest, PrevFarMore_NewFarLess_Soon) {
479 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
480
481 co->set(50);
482 SoftTakeoverCtrl st_control;
483 st_control.enable(co.get());
484
485 // First is always ignored.
486 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(120)));
487 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(1)));
488 }
489
490 // Ignore this case:
491 // Sides prev distance new distance new value arrives Ignore
492 // same far far soon TRUE
493 // FIXME: This fails on the st::ignore() implementation in 2.0.0-rc1
TEST_F(SoftTakeoverTest,DISABLED_PrevFarMore_NewFarMore_Soon)494 TEST_F(SoftTakeoverTest, DISABLED_PrevFarMore_NewFarMore_Soon) {
495 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
496
497 co->set(50);
498 SoftTakeoverCtrl st_control;
499 st_control.enable(co.get());
500
501 // First is always ignored.
502 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(120)));
503 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(100)));
504 }
505
TEST_F(SoftTakeoverTest,PrevFarMore_NewNearLess_Late)506 TEST_F(SoftTakeoverTest, PrevFarMore_NewNearLess_Late) {
507 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
508
509 co->set(50);
510 SoftTakeoverCtrl st_control;
511 st_control.enable(co.get());
512
513 // First is always ignored.
514 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(120)));
515 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
516 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(45)));
517 }
518
TEST_F(SoftTakeoverTest,PrevFarMore_NewNearMore_Late)519 TEST_F(SoftTakeoverTest, PrevFarMore_NewNearMore_Late) {
520 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
521
522 co->set(50);
523 SoftTakeoverCtrl st_control;
524 st_control.enable(co.get());
525
526 // First is always ignored.
527 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(120)));
528 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
529 EXPECT_FALSE(st_control.ignore(co.get(), co->getParameterForValue(60)));
530 }
531
532 // Ignore this case:
533 // Sides prev distance new distance new value arrives Ignore
534 // opposite far far later TRUE
535 // FIXME: This fails on the st::ignore() implementation in 2.0.0-rc1
TEST_F(SoftTakeoverTest,DISABLED_PrevFarMore_NewFarLess_Late)536 TEST_F(SoftTakeoverTest, DISABLED_PrevFarMore_NewFarLess_Late) {
537 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
538
539 co->set(50);
540 SoftTakeoverCtrl st_control;
541 st_control.enable(co.get());
542
543 // First is always ignored.
544 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(120)));
545 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
546 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(1)));
547 }
548
549 // Ignore this case:
550 // Sides prev distance new distance new value arrives Ignore
551 // same far far later TRUE
TEST_F(SoftTakeoverTest,PrevFarMore_NewFarMore_Late)552 TEST_F(SoftTakeoverTest, PrevFarMore_NewFarMore_Late) {
553 auto co = std::make_unique<ControlPotmeter>(ConfigKey("[Channel1]", "test_pot"), -250, 250);
554
555 co->set(50);
556 SoftTakeoverCtrl st_control;
557 st_control.enable(co.get());
558
559 // First is always ignored.
560 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(120)));
561 mixxx::Time::setTestElapsedTime(SoftTakeover::TestAccess::getTimeThreshold() * 2);
562 EXPECT_TRUE(st_control.ignore(co.get(), co->getParameterForValue(100)));
563 }
564
565 // For the ignore cases, check that they work correctly with various signed values
566 // TODO
567
568 } // namespace
569