Changeset View
Changeset View
Standalone View
Standalone View
tests/auto/importertest.cpp
Show First 20 Lines • Show All 196 Lines • ▼ Show 20 Line(s) | 191 | { | |||
---|---|---|---|---|---|
197 | NEW_ROW("PICT0001.JPG", "2009-10-24T22:50:49", "{date}_{time}.{ext}", "2009-10-24_22-50-49.JPG"); | 197 | NEW_ROW("PICT0001.JPG", "2009-10-24T22:50:49", "{date}_{time}.{ext}", "2009-10-24_22-50-49.JPG"); | ||
198 | NEW_ROW("PICT0001.JPG", "2009-10-24T22:50:49", "{date}_{time}.{ext.lower}", "2009-10-24_22-50-49.jpg"); | 198 | NEW_ROW("PICT0001.JPG", "2009-10-24T22:50:49", "{date}_{time}.{ext.lower}", "2009-10-24_22-50-49.jpg"); | ||
199 | NEW_ROW("2009.10.24.JPG", "2009-10-24T22:50:49", "{date}_{time}.{ext.lower}", "2009-10-24_22-50-49.jpg"); | 199 | NEW_ROW("2009.10.24.JPG", "2009-10-24T22:50:49", "{date}_{time}.{ext.lower}", "2009-10-24_22-50-49.jpg"); | ||
200 | NEW_ROW("PICT0001.JPG", "2009-10-24T22:50:49", "{name}.{ext}", "PICT0001.JPG"); | 200 | NEW_ROW("PICT0001.JPG", "2009-10-24T22:50:49", "{name}.{ext}", "PICT0001.JPG"); | ||
201 | NEW_ROW("PICT0001.JPG", "2009-10-24T22:50:49", "{name.lower}.{ext.lower}", "pict0001.jpg"); | 201 | NEW_ROW("PICT0001.JPG", "2009-10-24T22:50:49", "{name.lower}.{ext.lower}", "pict0001.jpg"); | ||
202 | NEW_ROW("iLikeCurlies", "2009-10-24T22:50:49", "{{{name}}", "{iLikeCurlies}"); | 202 | NEW_ROW("iLikeCurlies", "2009-10-24T22:50:49", "{{{name}}", "{iLikeCurlies}"); | ||
203 | NEW_ROW("UnknownKeyword", "2009-10-24T22:50:49", "foo{unknown}bar", "foobar"); | 203 | NEW_ROW("UnknownKeyword", "2009-10-24T22:50:49", "foo{unknown}bar", "foobar"); | ||
204 | NEW_ROW("MissingClosingCurly", "2009-10-24T22:50:49", "foo{date", "foo"); | 204 | NEW_ROW("MissingClosingCurly", "2009-10-24T22:50:49", "foo{date", "foo"); | ||
205 | NEW_ROW("PICT0001.JPG", "2009-10-24T22:50:49", "{date}/{name}.{ext}", "2009-10-24/PICT0001.JPG"); | ||||
205 | } | 206 | } | ||
206 | 207 | | |||
207 | void ImporterTest::testAutoRenameFormat() | 208 | void ImporterTest::testAutoRenameFormat() | ||
208 | { | 209 | { | ||
209 | QStringList dates = QStringList() | 210 | QStringList dates = QStringList() | ||
210 | << "1979-02-23_10-20-00" | 211 | << "1979-02-23_10-20-00" | ||
211 | << "2006-04-01_11-30-15" | 212 | << "2006-04-01_11-30-15" | ||
212 | << "2009-10-01_21-15-27"; | 213 | << "2009-10-01_21-15-27"; | ||
214 | QStringList dates2 = QStringList() | ||||
215 | << "1979-02-23/10-20-00" | ||||
216 | << "2006-04-01/11-30-15" | ||||
217 | << "2009-10-01/21-15-27"; | ||||
213 | QCOMPARE(dates.count(), mDocumentList.count()); | 218 | QCOMPARE(dates.count(), mDocumentList.count()); | ||
219 | QCOMPARE(dates2.count(), mDocumentList.count()); | ||||
214 | 220 | | |||
215 | QUrl destUrl = QUrl::fromLocalFile(mTempDir->path() + "/foo"); | 221 | QUrl destUrl = QUrl::fromLocalFile(mTempDir->path() + "/foo"); | ||
216 | 222 | | |||
217 | Importer importer(nullptr); | 223 | Importer importer(nullptr); | ||
218 | importer.setAutoRenameFormat("{date}_{time}.{ext}"); | 224 | importer.setAutoRenameFormat("{date}_{time}.{ext}"); | ||
219 | QList<QUrl> list = mDocumentList; | 225 | QList<QUrl> list = mDocumentList; | ||
220 | 226 | | |||
221 | QEventLoop loop; | 227 | QEventLoop loop; | ||
222 | connect(&importer, &Importer::importFinished, &loop, &QEventLoop::quit); | 228 | connect(&importer, &Importer::importFinished, &loop, &QEventLoop::quit); | ||
223 | importer.start(list, destUrl); | 229 | importer.start(list, destUrl); | ||
224 | loop.exec(); | 230 | loop.exec(); | ||
225 | 231 | | |||
226 | QCOMPARE(importer.importedUrlList().count(), list.count()); | 232 | QCOMPARE(importer.importedUrlList().count(), list.count()); | ||
227 | QCOMPARE(importer.importedUrlList(), list); | 233 | QCOMPARE(importer.importedUrlList(), list); | ||
228 | 234 | | |||
229 | for (int pos = 0; pos < dates.count(); ++pos) { | 235 | for (int pos = 0; pos < dates.count(); ++pos) { | ||
230 | QUrl src = list[pos]; | 236 | QUrl src = list[pos]; | ||
231 | QUrl dst = destUrl; | 237 | QUrl dst = destUrl; | ||
232 | dst.setPath(dst.path() + '/' + dates[pos] + ".jpg"); | 238 | dst.setPath(dst.path() + '/' + dates[pos] + ".jpg"); | ||
233 | QVERIFY(FileUtils::contentsAreIdentical(src, dst)); | 239 | QVERIFY(FileUtils::contentsAreIdentical(src, dst)); | ||
234 | } | 240 | } | ||
241 | | ||||
242 | // Test again with slashes in AutoRenameFormat | ||||
243 | importer.setAutoRenameFormat("{date}/{time}.{ext}"); | ||||
244 | importer.start(list, destUrl); | ||||
245 | loop.exec(); | ||||
246 | | ||||
247 | QCOMPARE(importer.importedUrlList().count(), list.count()); | ||||
248 | QCOMPARE(importer.importedUrlList(), list); | ||||
249 | | ||||
250 | for (int pos = 0; pos < dates2.count(); ++pos) { | ||||
251 | QUrl src = list[pos]; | ||||
252 | QUrl dst = destUrl; | ||||
253 | dst.setPath(dst.path() + '/' + dates2[pos] + ".jpg"); | ||||
254 | QVERIFY(FileUtils::contentsAreIdentical(src, dst)); | ||||
255 | } | ||||
235 | } | 256 | } | ||
236 | 257 | | |||
237 | void ImporterTest::testReadOnlyDestination() | 258 | void ImporterTest::testReadOnlyDestination() | ||
238 | { | 259 | { | ||
239 | QUrl destUrl = QUrl::fromLocalFile(mTempDir->path() + "/foo"); | 260 | QUrl destUrl = QUrl::fromLocalFile(mTempDir->path() + "/foo"); | ||
240 | chmod(QFile::encodeName(mTempDir->path()), 0555); | 261 | chmod(QFile::encodeName(mTempDir->path()), 0555); | ||
241 | 262 | | |||
242 | Importer importer(nullptr); | 263 | Importer importer(nullptr); | ||
243 | QSignalSpy errorSpy(&importer, SIGNAL(error(QString))); | 264 | QSignalSpy errorSpy(&importer, SIGNAL(error(QString))); | ||
244 | importer.start(mDocumentList, destUrl); | 265 | importer.start(mDocumentList, destUrl); | ||
245 | 266 | | |||
246 | QCOMPARE(errorSpy.count(), 1); | 267 | QCOMPARE(errorSpy.count(), 1); | ||
247 | QVERIFY(importer.importedUrlList().isEmpty()); | 268 | QVERIFY(importer.importedUrlList().isEmpty()); | ||
248 | } | 269 | } |