From 49c02e0388644b2f05af5a0bf53d5ea570eef2a1 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Sat, 4 Feb 2023 16:12:52 +0100 Subject: [PATCH] test: add UnReplace test --- src/test/playermanagertest.cpp | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/test/playermanagertest.cpp b/src/test/playermanagertest.cpp index 6b7faedb2633..adaf235091a8 100644 --- a/src/test/playermanagertest.cpp +++ b/src/test/playermanagertest.cpp @@ -198,3 +198,41 @@ TEST_F(PlayerManagerTest, UnEjectInvalidTrackIdTest) { deck1->slotEjectTrack(1.0); ASSERT_EQ(nullptr, deck1->getLoadedTrack()); } + +TEST_F(PlayerManagerTest, UnReplaceTest) { + // Trigger eject twice within 500 ms to undo track replacement + auto deck1 = m_pPlayerManager->getDeck(1); + // Load a track + TrackPointer pTrack1 = getOrAddTrackByLocation(getTestDir().filePath(kTrackLocationTest1)); + ASSERT_NE(nullptr, pTrack1); + TrackId testId1 = pTrack1->getId(); + ASSERT_TRUE(testId1.isValid()); + deck1->slotLoadTrack(pTrack1, false); + m_pEngine->process(1024); + while (!deck1->getEngineDeck()->getEngineBuffer()->isTrackLoaded()) { + QTest::qSleep(100); // millis + } + ASSERT_NE(nullptr, deck1->getLoadedTrack()); + + // Load another track. + TrackPointer pTrack2 = getOrAddTrackByLocation(getTestDir().filePath(kTrackLocationTest2)); + ASSERT_NE(nullptr, pTrack2); + deck1->slotLoadTrack(pTrack2, false); + m_pEngine->process(1024); + while (!deck1->getEngineDeck()->getEngineBuffer()->isTrackLoaded()) { + QTest::qSleep(100); // millis + } + ASSERT_NE(nullptr, deck1->getLoadedTrack()); + + // Eject. Make sure eject does not trigger 'unreplace': + // sleep for longer than 500 ms 'unreplace' period so this is not registered as double-click + QTest::qSleep(500); // millis + deck1->slotEjectTrack(1.0); + ASSERT_EQ(nullptr, deck1->getLoadedTrack()); + + // Eject again, assume this is reached faster than 500 ms after first eject + deck1->slotEjectTrack(1.0); + // First track should be reloaded + ASSERT_NE(nullptr, deck1->getLoadedTrack()); + ASSERT_EQ(testId1, deck1->getLoadedTrack()->getId()); +}