TEST_F(TrackExporterTest, SimpleListExport) { // Create a simple list of trackpointers and export them. QFileInfo fileinfo1(m_testDataDir.filePath("cover-test.ogg")); TrackPointer track1(TrackInfoObject::newTemporary(fileinfo1)); QFileInfo fileinfo2(m_testDataDir.filePath("cover-test.flac")); TrackPointer track2(TrackInfoObject::newTemporary(fileinfo2)); QFileInfo fileinfo3(m_testDataDir.filePath("cover-test.m4a")); TrackPointer track3(TrackInfoObject::newTemporary(fileinfo3)); // An initializer list would be prettier here, but it doesn't compile // on MSVC or OSX. QList<TrackPointer> tracks; tracks.append(track1); tracks.append(track2); tracks.append(track3); TrackExportWorker worker(m_exportDir.canonicalPath(), tracks); m_answerer.reset(new FakeOverwriteAnswerer(&worker)); worker.run(); EXPECT_TRUE(worker.wait(10000)); EXPECT_EQ(3, m_answerer->currentProgress()); EXPECT_EQ(3, m_answerer->currentProgressCount()); // The destination folder should have all the files. EXPECT_TRUE(QFileInfo(m_exportDir.filePath("cover-test.ogg")).exists()); EXPECT_TRUE(QFileInfo(m_exportDir.filePath("cover-test.flac")).exists()); EXPECT_TRUE(QFileInfo(m_exportDir.filePath("cover-test.m4a")).exists()); }
DuplicateDialog::DuplicateDialog(const QList<QString> &pathlist, QString dir, QWidget *parent) : QDialog(parent), ui(new Ui::DuplicateDialog) { ui->setupUi(this); QGridLayout *layout = new QGridLayout(this); bool matchNames = true; qint64 filesize = 0; for(int i = 0; i < pathlist.size(); ++i) { if(i != 0) { QFileInfo fileinfo1(dir + pathlist[i]); QFileInfo fileinfo2(dir + pathlist[i - 1]); if(fileinfo1.fileName() != fileinfo2.fileName()) matchNames = false; } else filesize = QFileInfo(dir + pathlist[i]).size(); QLabel *label = new QLabel(pathlist[i], this); layout->addWidget(label, i, 0); QPushButton *button = new QPushButton("Remove", this); button->setStatusTip(dir + pathlist[i]); //qDebug() << "DuplicateDialog" << i << dir + pathlist[i]; connect(button, SIGNAL(clicked()), this, SLOT(remove_clicked())); layout->addWidget(button, i, 1); } layout->addWidget(new QLabel("Size: " + QString::number(filesize), this)); if(matchNames) layout->addWidget(new QLabel("All files have the same name", this)); setLayout(layout); }
TEST_F(TrackExporterTest, OverwriteSkip) { // Export a tracklist with two existing tracks -- overwrite one and skip // the other. QFileInfo fileinfo1(m_testDataDir.filePath("cover-test.ogg")); const qint64 fileSize1 = fileinfo1.size(); TrackPointer track1(Track::newTemporary(fileinfo1)); QFileInfo fileinfo2(m_testDataDir.filePath("cover-test.m4a")); TrackPointer track2(Track::newTemporary(fileinfo2)); // Create empty versions at the destination so we can see if we actually // overwrote or skipped. QFile file1(m_exportDir.filePath("cover-test.ogg")); ASSERT_TRUE(file1.open(QIODevice::WriteOnly)); file1.close(); QFile file2(m_exportDir.filePath("cover-test.m4a")); ASSERT_TRUE(file2.open(QIODevice::WriteOnly)); file2.close(); // Set up the worker and answerer. QList<TrackPointer> tracks; tracks.append(track1); tracks.append(track2); TrackExportWorker worker(m_exportDir.canonicalPath(), tracks); m_answerer.reset(new FakeOverwriteAnswerer(&worker)); m_answerer->setAnswer(QFileInfo(file1).canonicalFilePath(), TrackExportWorker::OverwriteAnswer::OVERWRITE); m_answerer->setAnswer(QFileInfo(file2).canonicalFilePath(), TrackExportWorker::OverwriteAnswer::SKIP); worker.run(); EXPECT_TRUE(worker.wait(10000)); EXPECT_EQ(2, m_answerer->currentProgress()); EXPECT_EQ(2, m_answerer->currentProgressCount()); // The destination folder should have both the files, one skipped and // one written. QFileInfo newfile1(m_exportDir.filePath("cover-test.ogg")); EXPECT_TRUE(newfile1.exists()); EXPECT_EQ(fileSize1, newfile1.size()); QFileInfo newfile2(m_exportDir.filePath("cover-test.m4a")); EXPECT_TRUE(newfile2.exists()); EXPECT_EQ(0, newfile2.size()); }
TEST_F(TrackExporterTest, Cancel) { // Export a tracklist with two existing tracks, but cancel before we do // anything. QFileInfo fileinfo1(m_testDataDir.filePath("cover-test.ogg")); TrackPointer track1(TrackInfoObject::newTemporary(fileinfo1)); QFileInfo fileinfo2(m_testDataDir.filePath("cover-test.m4a")); TrackPointer track2(TrackInfoObject::newTemporary(fileinfo2)); // Create empty version at the destination so we can see if we actually // canceled. QFile file2(m_exportDir.filePath("cover-test.m4a")); ASSERT_TRUE(file2.open(QIODevice::WriteOnly)); file2.close(); // Set up the worker and answerer. QList<TrackPointer> tracks; tracks.append(track1); tracks.append(track2); TrackExportWorker worker(m_exportDir.canonicalPath(), tracks); m_answerer.reset(new FakeOverwriteAnswerer(&worker)); m_answerer->setAnswer(QFileInfo(file2).canonicalFilePath(), TrackExportWorker::OverwriteAnswer::CANCEL); worker.run(); EXPECT_TRUE(worker.wait(10000)); EXPECT_EQ(-1, m_answerer->currentProgress()); EXPECT_EQ(-1, m_answerer->currentProgressCount()); // Both files should have been skipped because we canceled the process, // so the .ogg shouldn't exist at all. QFileInfo newfile1(m_exportDir.filePath("cover-test.ogg")); EXPECT_FALSE(newfile1.exists()); QFileInfo newfile2(m_exportDir.filePath("cover-test.m4a")); EXPECT_TRUE(newfile2.exists()); EXPECT_EQ(0, newfile2.size()); }
TEST_F(TrackExporterTest, MungeFilename) { // Create a track list with a duplicate track in a different location, // see that the name gets munged. QFileInfo fileinfo1(m_testDataDir.filePath("cover-test.ogg")); TrackPointer track1(TrackInfoObject::newTemporary(fileinfo1)); // Create a file with the same name in a different place. Its filename // should be munged and the file still copied. QDir tempPath(QDir::tempPath()); QFile file2(tempPath.filePath("cover-test.ogg")); QFileInfo fileinfo2(file2); ASSERT_TRUE(file2.open(QIODevice::WriteOnly)); file2.close(); TrackPointer track2(TrackInfoObject::newTemporary(fileinfo2)); // Set up the worker and answerer. QList<TrackPointer> tracks; tracks.append(track1); tracks.append(track2); TrackExportWorker worker(m_exportDir.canonicalPath(), tracks); m_answerer.reset(new FakeOverwriteAnswerer(&worker)); worker.run(); EXPECT_TRUE(worker.wait(10000)); EXPECT_EQ(2, m_answerer->currentProgress()); EXPECT_EQ(2, m_answerer->currentProgressCount()); QFileInfo newfile1(m_exportDir.filePath("cover-test.ogg")); EXPECT_TRUE(newfile1.exists()); QFileInfo newfile2(m_exportDir.filePath("cover-test-0001.ogg")); EXPECT_TRUE(newfile2.exists()); // Remove the track we created. tempPath.remove("cover-test.ogg"); }