From 58d898ae8610031ce11d7bcc75b839da8196eb6f Mon Sep 17 00:00:00 2001 From: ronso0 Date: Fri, 17 Jan 2025 17:59:04 +0100 Subject: [PATCH] Test: add 'hotcue order by position' keep/remove offsets --- CMakeLists.txt | 1 + src/test/hotcueorderbyposition_test.cpp | 82 +++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/test/hotcueorderbyposition_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7283ed6a7da..f1aeb635520 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2438,6 +2438,7 @@ add_executable( src/test/frametest.cpp src/test/globaltrackcache_test.cpp src/test/hotcuecontrol_test.cpp + src/test/hotcueorderbyposition_test.cpp src/test/imageutils_test.cpp src/test/indexrange_test.cpp src/test/itunesxmlimportertest.cpp diff --git a/src/test/hotcueorderbyposition_test.cpp b/src/test/hotcueorderbyposition_test.cpp new file mode 100644 index 00000000000..ee3001ff611 --- /dev/null +++ b/src/test/hotcueorderbyposition_test.cpp @@ -0,0 +1,82 @@ +// #include "library/coverart.h" +// #include "sources/soundsourceproxy.h" +// #include "test/soundsourceproviderregistration.h" +#include "test/mixxxtest.h" +#include "track/cue.h" +#include "track/track.h" + +// Test for updating track metadata and cover art from files. +class TrackHotcueOrderByPosTest : public MixxxTest { + protected: + static TrackPointer newTestTrack() { + return Track::newTemporary( + QDir(MixxxTest::getOrInitTestDir().filePath(QStringLiteral("track-test-data"))), + "THOBP.mp3"); + } +}; + +TEST_F(TrackHotcueOrderByPosTest, orderHotcuesKeepOffsets) { + auto pTrack = newTestTrack(); + pTrack->markClean(); + + // create hotcues with ascending position but unordered indices + CuePointer pHotcue1 = pTrack->createAndAddCue(mixxx::CueType::HotCue, + 2, + mixxx::audio::FramePos(100), + mixxx::audio::kInvalidFramePos, + mixxx::PredefinedColorPalettes::kDefaultCueColor); + CuePointer pHotcue2 = pTrack->createAndAddCue(mixxx::CueType::HotCue, + 1, + mixxx::audio::FramePos(200), + mixxx::audio::kInvalidFramePos, + mixxx::PredefinedColorPalettes::kDefaultCueColor); + CuePointer pHotcue3 = pTrack->createAndAddCue(mixxx::CueType::HotCue, + 7, + mixxx::audio::FramePos(300), + mixxx::audio::kInvalidFramePos, + mixxx::PredefinedColorPalettes::kDefaultCueColor); + CuePointer pHotcue4 = pTrack->createAndAddCue(mixxx::CueType::HotCue, + 5, + mixxx::audio::FramePos(400), + mixxx::audio::kInvalidFramePos, + mixxx::PredefinedColorPalettes::kDefaultCueColor); + + pTrack->setHotcueIndicesSortedByPosition(); + + // Hotcues indices by position should now be 1 2 5 7 + EXPECT_EQ(pHotcue1->getHotCue(), 1); + EXPECT_EQ(pHotcue2->getHotCue(), 2); + EXPECT_EQ(pHotcue3->getHotCue(), 5); + EXPECT_EQ(pHotcue4->getHotCue(), 7); +} + +TEST_F(TrackHotcueOrderByPosTest, orderHotcuesRemoveOffsets) { + auto pTrack = newTestTrack(); + pTrack->markClean(); + + // create hotcues with ascending position but unordered indices + CuePointer pHotcue1 = pTrack->createAndAddCue(mixxx::CueType::HotCue, + 2, + mixxx::audio::FramePos(100), + mixxx::audio::FramePos::kInvalidValue); + CuePointer pHotcue2 = pTrack->createAndAddCue(mixxx::CueType::HotCue, + 1, + mixxx::audio::FramePos(200), + mixxx::audio::FramePos::kInvalidValue); + CuePointer pHotcue3 = pTrack->createAndAddCue(mixxx::CueType::HotCue, + 7, + mixxx::audio::FramePos(300), + mixxx::audio::FramePos::kInvalidValue); + CuePointer pHotcue4 = pTrack->createAndAddCue(mixxx::CueType::HotCue, + 5, + mixxx::audio::FramePos(400), + mixxx::audio::FramePos::kInvalidValue); + + pTrack->setHotcueIndicesSortedByPosition(true); + + // Hotcues indices by position should now be 1 2 3 4 + EXPECT_EQ(pHotcue1->getHotCue(), 1); + EXPECT_EQ(pHotcue2->getHotCue(), 2); + EXPECT_EQ(pHotcue3->getHotCue(), 3); + EXPECT_EQ(pHotcue4->getHotCue(), 4); +}