Skip to content

Commit

Permalink
Fix test case on windows
Browse files Browse the repository at this point in the history
This changes the code to make more use of Qt
to handle filepaths on several platforms. We should
also change the API to only accept QDir, QFileInfo
in the future
  • Loading branch information
kain88-de committed Jan 18, 2014
1 parent 47d1859 commit 2012e55
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
15 changes: 11 additions & 4 deletions src/library/dao/directorydao.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ QSet<int> DirectoryDAO::relocateDirectory(const QString& oldFolder,
}

FieldEscaper escaper(m_database);
QString startsWithOldFolder =
escaper.escapeString(escaper.escapeStringForLike(oldFolder % '/', '%') + '%');
// on Windows the absolute path starts with the drive name
// we also need to check for that
QString startsWithOldFolder = escaper.escapeStringForLike(QDir(oldFolder).absolutePath() + "/", '%') + "%";
// Also update information in the track_locations table. This is where mixxx
// gets the location information for a track.
// gets the location information for a track. Put marks around %1 so that this also works on windows
query.prepare(QString("SELECT library.id, track_locations.id, track_locations.location "
"FROM library INNER JOIN track_locations ON "
"track_locations.id = library.location WHERE "
"track_locations.location LIKE %1 ESCAPE '%'")
"track_locations.location LIKE '%1' ESCAPE '%'")
.arg(startsWithOldFolder));
if (!query.exec()) {
LOG_FAILED_QUERY(query) << "coud not relocate path of tracks";
Expand Down Expand Up @@ -144,6 +145,12 @@ QSet<int> DirectoryDAO::relocateDirectory(const QString& oldFolder,
}
}

query.prepare(QString("SELECT location FROM track_locations"));
query.exec();
while (query.next()) {
qDebug() << query.value(0).toString();
}

qDebug() << "Relocated tracks:" << ids.size();

transaction.commit();
Expand Down
21 changes: 13 additions & 8 deletions src/test/directorydoatest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,29 @@ TEST_F(DirectoryDAOTest, getDirTest) {
TEST_F(DirectoryDAOTest, relocateDirTest) {
DirectoryDAO &directoryDao = m_pTrackCollection->getDirectoryDAO();

directoryDao.addDirectory("/Test");
directoryDao.addDirectory("/Test2");
// use a temp dir so that we always use a real existing system path
QString testdir(QDir::tempPath() + "/TestDir");
QString test2(QDir::tempPath() + "/TestDir2");
QString testnew(QDir::tempPath() + "/TestDirNew");

directoryDao.addDirectory(testdir);
directoryDao.addDirectory(test2);
TrackDAO &trackDAO = m_pTrackCollection->getTrackDAO();
// ok now lets create some tracks here
trackDAO.addTracksPrepare();
trackDAO.addTracksAdd(new TrackInfoObject("/Test/a", false), false);
trackDAO.addTracksAdd(new TrackInfoObject("/Test/b", false), false);
trackDAO.addTracksAdd(new TrackInfoObject("/Test2/c", false), false);
trackDAO.addTracksAdd(new TrackInfoObject("/Test2/d", false), false);
trackDAO.addTracksAdd(new TrackInfoObject(testdir + "/a", false), false);
trackDAO.addTracksAdd(new TrackInfoObject(testdir + "/b", false), false);
trackDAO.addTracksAdd(new TrackInfoObject(test2 + "/c", false), false);
trackDAO.addTracksAdd(new TrackInfoObject(test2 + "/d", false), false);
trackDAO.addTracksFinish(false);

QSet<int> ids = directoryDao.relocateDirectory("/Test", "/new");
QSet<int> ids = directoryDao.relocateDirectory(testdir, testnew);
EXPECT_EQ(2, ids.size());

QStringList dirs = directoryDao.getDirs();
ASSERT_EQ(2, dirs.size());
qSort(dirs);
EXPECT_THAT(dirs, ElementsAre(QString("/Test2"), QString("/new")));
EXPECT_THAT(dirs, ElementsAre(test2, testnew));
}

} // namespace

0 comments on commit 2012e55

Please sign in to comment.