1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
|
/*
SPDX-FileCopyrightText: 2018-2022 Jean-Baptiste Mardelle <jb@kdenlive.org>
SPDX-FileCopyrightText: 2022 Eric Jiang
SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "test_utils.hpp"
// test specific headers
#include "bin/binplaylist.hpp"
#include "doc/kdenlivedoc.h"
#include "timeline2/model/builders/meltBuilder.hpp"
#include "xml/xml.hpp"
#include <QTemporaryFile>
#include <QUndoGroup>
using namespace fakeit;
TEST_CASE("Open and Close Sequence", "[OCS]")
{
auto binModel = pCore->projectItemModel();
Q_ASSERT(binModel->clipsCount() == 0);
binModel->clean();
std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
SECTION("Create sequence, add grouped clips, close sequence and reopen")
{
// Create document
pCore->setCurrentProfile(QStringLiteral("dv_pal"));
KdenliveDoc document(undoStack);
Mock<KdenliveDoc> docMock(document);
KdenliveDoc &mockedDoc = docMock.get();
pCore->projectManager()->testSetDocument(&mockedDoc);
QDateTime documentDate = QDateTime::currentDateTime();
KdenliveTests::updateTimeline(false, QString(), QString(), documentDate, 0);
auto timeline = mockedDoc.getTimeline(mockedDoc.uuid());
pCore->projectManager()->testSetActiveTimeline(timeline);
KdenliveTests::resetNextId();
QDir dir = QDir::temp();
QString binId = KdenliveTests::createProducerWithSound(pCore->getProjectProfile(), binModel);
// Create a new sequence clip
std::pair<int, int> tracks = {2, 2};
const QString seqId = ClipCreator::createPlaylistClip(QStringLiteral("Seq 2"), tracks, QStringLiteral("-1"), binModel);
REQUIRE(seqId != QLatin1String("-1"));
timeline.reset();
// Now use the new timeline sequence
QUuid uuid;
QMap<QUuid, QString> allSequences = binModel->getAllSequenceClips();
QMapIterator<QUuid, QString> i(allSequences);
while (i.hasNext()) {
// Find clips with the tag
i.next();
if (i.value() == seqId) {
uuid = i.key();
}
}
timeline = mockedDoc.getTimeline(uuid);
pCore->projectManager()->testSetActiveTimeline(timeline);
// Insert an AV clip
int tid1 = timeline->getTrackIndexFromPosition(2);
// Setup timeline audio drop info
QMap<int, QString> audioInfo;
audioInfo.insert(1, QStringLiteral("stream1"));
KdenliveTests::setAudioTargets(timeline, audioInfo);
KdenliveTests::setVideoTargets(timeline, tid1);
// Insert
int cid1 = -1;
REQUIRE(timeline->requestClipInsertion(binId, tid1, 80, cid1, true, true, false));
// Ensure the clip is grouped (part af an AV group)
REQUIRE(timeline->isInGroup(cid1));
REQUIRE(timeline->getTrackClipsCount(tid1) == 1);
// Add a few guides
timeline->getGuideModel()->addMarker(GenTime(40, pCore->getCurrentFps()), i18n("guide 1"));
timeline->getGuideModel()->addMarker(GenTime(60, pCore->getCurrentFps()), i18n("guide 2"));
REQUIRE(timeline->checkConsistency(timeline->getGuideModel()->getSnapPoints()));
// Now close timeline, the reopen and check the clips, groups and guides are still here
mockedDoc.setModified(true);
pCore->projectManager()->closeTimeline(uuid);
timeline.reset();
// Reopen
pCore->projectManager()->openTimeline(seqId, -1, uuid);
timeline = mockedDoc.getTimeline(uuid);
pCore->projectManager()->testSetActiveTimeline(timeline);
tid1 = timeline->getTrackIndexFromPosition(2);
REQUIRE(timeline->getTrackClipsCount(tid1) == 1);
cid1 = timeline->getClipByStartPosition(tid1, 80);
REQUIRE(cid1 > -1);
REQUIRE(timeline->isInGroup(cid1));
REQUIRE(timeline->getGuideModel()->hasMarker(40));
REQUIRE(timeline->checkConsistency(timeline->getGuideModel()->getSnapPoints()));
pCore->projectManager()->closeCurrentDocument(false, false);
}
}
TEST_CASE("Save File With 2 Sequences", "[SF2]")
{
auto binModel = pCore->projectItemModel();
// Q_ASSERT(binModel->clipsCount() == 0);
binModel->clean();
std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
SECTION("Simple insert and save")
{
// Create document
pCore->setCurrentProfile(QStringLiteral("dv_pal"));
KdenliveDoc document(undoStack);
pCore->projectManager()->testSetDocument(&document);
QDateTime documentDate = QDateTime::currentDateTime();
KdenliveTests::updateTimeline(false, QString(), QString(), documentDate, 0);
auto timeline = document.getTimeline(document.uuid());
pCore->projectManager()->testSetActiveTimeline(timeline);
KdenliveTests::resetNextId();
QDir dir = QDir::temp();
QString binId = KdenliveTests::createProducerWithSound(pCore->getProjectProfile(), binModel);
QString binId2 = KdenliveTests::createProducer(pCore->getProjectProfile(), "red", binModel, 20, false);
int tid1 = timeline->getTrackIndexFromPosition(2);
// Setup timeline audio drop info
QMap<int, QString> audioInfo;
audioInfo.insert(1, QStringLiteral("stream1"));
KdenliveTests::setAudioTargets(timeline, audioInfo);
KdenliveTests::setVideoTargets(timeline, tid1);
// Insert 2 clips (length=20, pos = 80 / 100)
int cid1 = -1;
REQUIRE(timeline->requestClipInsertion(binId2, tid1, 80, cid1, true, true, false));
int l = timeline->getClipPlaytime(cid1);
int cid2 = -1;
REQUIRE(timeline->requestClipInsertion(binId2, tid1, 80 + l, cid2, true, true, false));
// Resize first clip (length=100)
REQUIRE(timeline->requestItemResize(cid1, 100, false) == 100);
// Group the 2 clips
REQUIRE(timeline->requestClipsGroup({cid1, cid2}, true));
auto state = [&]() {
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getTrackClipsCount(tid1) == 2);
REQUIRE(timeline->getClipTrackId(cid1) == tid1);
REQUIRE(timeline->getClipTrackId(cid2) == tid1);
REQUIRE(timeline->getClipPosition(cid1) == 0);
REQUIRE(timeline->getClipPosition(cid2) == 100);
REQUIRE(timeline->getClipPlaytime(cid1) == 100);
REQUIRE(timeline->getClipPlaytime(cid2) == 20);
};
state();
// Add a few guides
timeline->getGuideModel()->addMarker(GenTime(40, pCore->getCurrentFps()), i18n("guide 1"));
timeline->getGuideModel()->addMarker(GenTime(60, pCore->getCurrentFps()), i18n("guide 2"));
timeline->getGuideModel()->addMarker(GenTime(10, pCore->getCurrentFps()), i18n("guide 3"));
REQUIRE(timeline->checkConsistency(timeline->getGuideModel()->getSnapPoints()));
// Add another sequence clip
std::pair<int, int> tracks = {1, 2};
const QString seqId = ClipCreator::createPlaylistClip(QStringLiteral("Seq 2"), tracks, QStringLiteral("-1"), binModel);
REQUIRE(seqId != QLatin1String("-1"));
QUuid uuid;
QMap<QUuid, QString> allSequences = binModel->getAllSequenceClips();
QString firstSeqId = allSequences.value(document.uuid());
QMapIterator<QUuid, QString> i(allSequences);
while (i.hasNext()) {
// Find clips with the tag
i.next();
if (i.value() == seqId) {
uuid = i.key();
}
}
REQUIRE(!uuid.isNull());
// Make last sequence active
timeline.reset();
timeline = document.getTimeline(uuid);
timeline->getGuideModel()->addMarker(GenTime(10, pCore->getCurrentFps()), i18n("guide 4"));
// Save and close
pCore->projectManager()->testSaveFileAs(dir.absoluteFilePath(QStringLiteral("test-nest.kdenlive")));
Q_ASSERT(QFile::exists(dir.absoluteFilePath(QStringLiteral("test-nest.kdenlive"))));
pCore->projectManager()->closeCurrentDocument(false, false);
}
SECTION("Open and check in/out points")
{
// Open document
KdenliveTests::resetNextId();
QString saveFile = QDir::temp().absoluteFilePath(QStringLiteral("test-nest.kdenlive"));
QUrl openURL = QUrl::fromLocalFile(saveFile);
Mock<ProjectManager> pmMock;
When(Method(pmMock, undoStack)).AlwaysReturn(undoStack);
When(Method(pmMock, cacheDir)).AlwaysReturn(QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)));
QUndoGroup *undoGroup = new QUndoGroup();
undoGroup->addStack(undoStack.get());
DocOpenResult openResults = KdenliveDoc::Open(openURL, QDir::temp().path(), undoGroup, false, nullptr);
REQUIRE(openResults.isSuccessful() == true);
std::unique_ptr<KdenliveDoc> openedDoc = openResults.getDocument();
pCore->projectManager()->testSetDocument(openedDoc.get());
const QUuid uuid = openedDoc->uuid();
QDateTime documentDate = QFileInfo(openURL.toLocalFile()).lastModified();
KdenliveTests::updateTimeline(false, QString(), QString(), documentDate, 0);
QMap<QUuid, QString> allSequences = binModel->getAllSequenceClips();
const QString firstSeqId = allSequences.value(uuid);
pCore->projectManager()->openTimeline(firstSeqId, -1, uuid);
std::shared_ptr<TimelineItemModel> timeline = openedDoc->getTimeline(uuid);
// Now reopen all timeline sequences
QList<QUuid> allUuids = allSequences.keys();
allUuids.removeAll(uuid);
pCore->projectManager()->testSetActiveTimeline(timeline);
REQUIRE(timeline->getTracksCount() == 4);
REQUIRE(timeline->checkConsistency(timeline->getGuideModel()->getSnapPoints()));
int tid1 = timeline->getTrackIndexFromPosition(2);
int cid1 = timeline->getClipByStartPosition(tid1, 0);
int cid2 = timeline->getClipByStartPosition(tid1, 100);
REQUIRE(cid1 > -1);
REQUIRE(cid2 > -1);
// Check che clips are still grouped
REQUIRE(timeline->isInGroup(cid1));
REQUIRE(timeline->isInGroup(cid2));
auto state = [&]() {
REQUIRE(timeline->checkConsistency(timeline->getGuideModel()->getSnapPoints()));
REQUIRE(timeline->getTrackClipsCount(tid1) == 2);
REQUIRE(timeline->getClipTrackId(cid1) == tid1);
REQUIRE(timeline->getClipTrackId(cid2) == tid1);
REQUIRE(timeline->getClipPosition(cid1) == 0);
REQUIRE(timeline->getClipPosition(cid2) == 100);
REQUIRE(timeline->getClipPlaytime(cid1) == 100);
REQUIRE(timeline->getClipPlaytime(cid2) == 20);
};
state();
QByteArray updatedHex = timeline->timelineHash().toHex();
const QString hash = openedDoc->getSequenceProperty(uuid, QStringLiteral("timelineHash"));
REQUIRE(updatedHex == hash.toLatin1());
const QString binId1 = timeline->getClipBinId(cid1);
const QUuid secondSequence = allUuids.first();
timeline = openedDoc->getTimeline(secondSequence);
pCore->projectManager()->setActiveTimeline(secondSequence);
REQUIRE(timeline->getTracksCount() == 3);
// Now, add one clip, close sequence and reopen to ensure it is correctly stored as removed
tid1 = timeline->getTrackIndexFromPosition(2);
int cid5 = -1;
int cid6 = -1;
REQUIRE(timeline->requestClipInsertion(binId1, tid1, 330, cid5, true, true, false));
REQUIRE(timeline->requestClipInsertion(binId1, tid1, 120, cid6, true, true, false));
REQUIRE(timeline->getClipPosition(cid5) == 330);
REQUIRE(timeline->getClipPosition(cid6) == 120);
// Group the 2 clips
REQUIRE(timeline->requestClipsGroup({cid5, cid6}, true));
// Close sequence
pCore->projectManager()->closeTimeline(secondSequence, false);
timeline.reset();
// Reopen sequence and check clip is still here
pCore->projectManager()->openTimeline(allSequences.value(secondSequence), -1, secondSequence);
timeline = openedDoc->getTimeline(secondSequence);
tid1 = timeline->getTrackIndexFromPosition(2);
cid5 = timeline->getClipByStartPosition(tid1, 330);
REQUIRE(cid5 > -1);
cid6 = timeline->getClipByStartPosition(tid1, 120);
REQUIRE(cid6 > -1);
REQUIRE(timeline->isInGroup(cid5));
REQUIRE(timeline->isInGroup(cid6));
REQUIRE(timeline->getTrackClipsCount(tid1) == 2);
timeline.reset();
// Save again
QDir dir = QDir::temp();
pCore->projectManager()->testSaveFileAs(dir.absoluteFilePath(QStringLiteral("test-nest.kdenlive")));
pCore->projectManager()->closeCurrentDocument(false, false);
}
SECTION("Reopen and check in/out points")
{
// Create new document
// We mock the project class so that the undoStack function returns our undoStack, and our mocked document
KdenliveTests::resetNextId();
Q_ASSERT(QFile::exists(QDir::temp().absoluteFilePath(QStringLiteral("test-nest.kdenlive"))));
QString saveFile = QDir::temp().absoluteFilePath(QStringLiteral("test-nest.kdenlive"));
QUrl openURL = QUrl::fromLocalFile(saveFile);
Mock<ProjectManager> pmMock;
When(Method(pmMock, undoStack)).AlwaysReturn(undoStack);
When(Method(pmMock, cacheDir)).AlwaysReturn(QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)));
QUndoGroup *undoGroup = new QUndoGroup();
undoGroup->addStack(undoStack.get());
DocOpenResult openResults = KdenliveDoc::Open(openURL, QDir::temp().path(), undoGroup, false, nullptr);
REQUIRE(openResults.isSuccessful() == true);
std::unique_ptr<KdenliveDoc> openedDoc = openResults.getDocument();
pCore->projectManager()->testSetDocument(openedDoc.get());
const QUuid uuid = openedDoc->uuid();
QDateTime documentDate = QFileInfo(openURL.toLocalFile()).lastModified();
KdenliveTests::updateTimeline(false, QString(), QString(), documentDate, 0);
QMap<QUuid, QString> allSequences = binModel->getAllSequenceClips();
const QString firstSeqId = allSequences.value(uuid);
pCore->projectManager()->openTimeline(firstSeqId, -1, uuid);
std::shared_ptr<TimelineItemModel> timeline = openedDoc->getTimeline(uuid);
// Now reopen all timeline sequences
QList<QUuid> allUuids = allSequences.keys();
allUuids.removeAll(uuid);
pCore->projectManager()->testSetActiveTimeline(timeline);
REQUIRE(timeline->getTracksCount() == 4);
REQUIRE(timeline->checkConsistency(timeline->getGuideModel()->getSnapPoints()));
int tid1 = timeline->getTrackIndexFromPosition(2);
int cid1 = timeline->getClipByStartPosition(tid1, 0);
int cid2 = timeline->getClipByStartPosition(tid1, 100);
REQUIRE(cid1 > -1);
REQUIRE(cid2 > -1);
// Check the clips are still grouped
REQUIRE(timeline->isInGroup(cid1));
REQUIRE(timeline->isInGroup(cid2));
auto state = [&]() {
REQUIRE(timeline->checkConsistency(timeline->getGuideModel()->getSnapPoints()));
REQUIRE(timeline->getTrackClipsCount(tid1) == 2);
REQUIRE(timeline->getClipTrackId(cid1) == tid1);
REQUIRE(timeline->getClipTrackId(cid2) == tid1);
REQUIRE(timeline->getClipPosition(cid1) == 0);
REQUIRE(timeline->getClipPosition(cid2) == 100);
REQUIRE(timeline->getClipPlaytime(cid1) == 100);
REQUIRE(timeline->getClipPlaytime(cid2) == 20);
};
state();
QByteArray updatedHex = timeline->timelineHash().toHex();
const QString hash = openedDoc->getSequenceProperty(uuid, QStringLiteral("timelineHash"));
REQUIRE(updatedHex == hash.toLatin1());
const QString binId1 = timeline->getClipBinId(cid1);
const QUuid secondSequence = allUuids.first();
timeline = openedDoc->getTimeline(secondSequence);
pCore->projectManager()->setActiveTimeline(secondSequence);
REQUIRE(timeline->getTracksCount() == 3);
tid1 = timeline->getTrackIndexFromPosition(2);
int cid5 = timeline->getClipByStartPosition(tid1, 330);
REQUIRE(cid5 > -1);
int cid6 = timeline->getClipByStartPosition(tid1, 120);
REQUIRE(cid6 > -1);
REQUIRE(timeline->isInGroup(cid5));
REQUIRE(timeline->isInGroup(cid6));
REQUIRE(timeline->getTrackClipsCount(tid1) == 2);
QDir dir = QDir::temp();
QFile::remove(dir.absoluteFilePath(QStringLiteral("test-nest.kdenlive")));
// binModel->clean();
// pCore->m_projectManager = nullptr;
timeline.reset();
pCore->projectManager()->closeCurrentDocument(false, false);
}
}
TEST_CASE("Save File, Reopen and check for corruption", "[SF3]")
{
auto binModel = pCore->projectItemModel();
binModel->clean();
std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
SECTION("Open and simply save file")
{
QString path = sourcesPath + "/dataset/test-nesting-effects.kdenlive";
Q_ASSERT(QFile::exists(sourcesPath));
QUrl openURL = QUrl::fromLocalFile(path);
QUndoGroup *undoGroup = new QUndoGroup();
undoGroup->addStack(undoStack.get());
DocOpenResult openResults = KdenliveDoc::Open(openURL, QDir::temp().path(), undoGroup, false, nullptr);
REQUIRE(openResults.isSuccessful() == true);
std::unique_ptr<KdenliveDoc> openedDoc = openResults.getDocument();
pCore->projectManager()->testSetDocument(openedDoc.get());
const QUuid uuid = openedDoc->uuid();
QDateTime documentDate = QFileInfo(openURL.toLocalFile()).lastModified();
KdenliveTests::updateTimeline(false, QString(), QString(), documentDate, 0);
QMap<QUuid, QString> allSequences = binModel->getAllSequenceClips();
const QString firstSeqId = allSequences.take(uuid);
pCore->projectManager()->openTimeline(firstSeqId, -1, uuid);
std::shared_ptr<TimelineItemModel> timeline = openedDoc->getTimeline(uuid);
pCore->projectManager()->testSetActiveTimeline(timeline);
// Now reopen all timeline sequences
REQUIRE(openedDoc->checkConsistency());
// Save file
QDir dir = QDir::temp();
pCore->projectManager()->testSaveFileAs(dir.absoluteFilePath(QStringLiteral("test-nest.kdenlive")));
timeline.reset();
pCore->projectManager()->closeCurrentDocument(false, false);
}
SECTION("Reopen and check in/out points")
{
// Create new document
// We mock the project class so that the undoStack function returns our undoStack, and our mocked document
KdenliveTests::resetNextId();
QString saveFile = QDir::temp().absoluteFilePath(QStringLiteral("test-nest.kdenlive"));
QUrl openURL = QUrl::fromLocalFile(saveFile);
Mock<ProjectManager> pmMock;
When(Method(pmMock, undoStack)).AlwaysReturn(undoStack);
When(Method(pmMock, cacheDir)).AlwaysReturn(QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)));
QUndoGroup *undoGroup = new QUndoGroup();
undoGroup->addStack(undoStack.get());
DocOpenResult openResults = KdenliveDoc::Open(openURL, QDir::temp().path(), undoGroup, false, nullptr);
REQUIRE(openResults.isSuccessful() == true);
std::unique_ptr<KdenliveDoc> openedDoc = openResults.getDocument();
pCore->projectManager()->testSetDocument(openedDoc.get());
const QUuid uuid = openedDoc->uuid();
QDateTime documentDate = QFileInfo(openURL.toLocalFile()).lastModified();
KdenliveTests::updateTimeline(false, QString(), QString(), documentDate, 0);
QMap<QUuid, QString> allSequences = binModel->getAllSequenceClips();
const QString firstSeqId = allSequences.take(uuid);
pCore->projectManager()->openTimeline(firstSeqId, -1, uuid);
std::shared_ptr<TimelineItemModel> timeline = openedDoc->getTimeline(uuid);
pCore->projectManager()->testSetActiveTimeline(timeline);
// Now reopen all timeline sequences
QList<QUuid> allUuids = binModel->getAllSequenceClips().keys();
// Collect saved hashes
QMap<QUuid, QString> timelineHashes;
for (auto &u : allUuids) {
timelineHashes.insert(u, openedDoc->getSequenceProperty(u, QStringLiteral("timelineHash")));
}
REQUIRE(openedDoc->checkConsistency());
openedDoc->documentProperties(true);
for (auto &u : allUuids) {
QByteArray updatedHex = openedDoc->getTimeline(u)->timelineHash().toHex();
REQUIRE(updatedHex == timelineHashes.value(u));
}
QDir dir = QDir::temp();
QFile::remove(dir.absoluteFilePath(QStringLiteral("test-nest.kdenlive")));
// binModel->clean();
// pCore->m_projectManager = nullptr;
pCore->projectManager()->closeCurrentDocument(false, false);
}
}
TEST_CASE("Save File And Check Sequence Effects", "[SF2]")
{
auto binModel = pCore->projectItemModel();
Q_ASSERT(binModel->clipsCount() == 0);
binModel->clean();
std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
SECTION("Simple insert, add master effect and save")
{
// Create document
KdenliveDoc document(undoStack);
Mock<KdenliveDoc> docMock(document);
KdenliveDoc &mockedDoc = docMock.get();
pCore->projectManager()->testSetDocument(&mockedDoc);
QDateTime documentDate = QDateTime::currentDateTime();
KdenliveTests::updateTimeline(false, QString(), QString(), documentDate, 0);
auto timeline = mockedDoc.getTimeline(mockedDoc.uuid());
pCore->projectManager()->testSetActiveTimeline(timeline);
KdenliveTests::resetNextId();
QDir dir = QDir::temp();
REQUIRE(timeline->checkConsistency(timeline->getGuideModel()->getSnapPoints()));
// Add another sequence clip
std::pair<int, int> tracks = {1, 2};
const QString seqId = ClipCreator::createPlaylistClip(QStringLiteral("Seq 2"), tracks, QStringLiteral("-1"), binModel);
REQUIRE(seqId != QLatin1String("-1"));
QUuid uuid;
QMap<QUuid, QString> allSequences = binModel->getAllSequenceClips();
QString firstSeqId = allSequences.value(mockedDoc.uuid());
QMapIterator<QUuid, QString> i(allSequences);
while (i.hasNext()) {
// Find clips with the tag
i.next();
if (i.value() == seqId) {
uuid = i.key();
}
}
REQUIRE(!uuid.isNull());
// Make last sequence active
timeline.reset();
timeline = mockedDoc.getTimeline(uuid);
// Add an effect to Bin sequence clip
std::shared_ptr<EffectStackModel> binStack = binModel->getClipEffectStack(seqId.toInt());
REQUIRE(binStack->appendEffect(QStringLiteral("sepia")));
REQUIRE(binStack->checkConsistency());
// Add an effect to master
std::shared_ptr<EffectStackModel> masterStack = timeline->getMasterEffectStackModel();
REQUIRE(masterStack->rowCount() == 1);
REQUIRE(masterStack->appendEffect(QStringLiteral("sepia")));
REQUIRE(masterStack->checkConsistency());
REQUIRE(masterStack->rowCount() == 2);
// Save and close
REQUIRE(pCore->projectManager()->testSaveFileAs(dir.absoluteFilePath(QStringLiteral("test-nest2.kdenlive"))));
pCore->projectManager()->closeCurrentDocument(false, false);
}
SECTION("Open and check that effects are restored")
{
// Create new document
// We mock the project class so that the undoStack function returns our undoStack, and our mocked document
KdenliveTests::resetNextId();
QString saveFile = QDir::temp().absoluteFilePath(QStringLiteral("test-nest2.kdenlive"));
QUrl openURL = QUrl::fromLocalFile(saveFile);
Mock<ProjectManager> pmMock;
When(Method(pmMock, undoStack)).AlwaysReturn(undoStack);
When(Method(pmMock, cacheDir)).AlwaysReturn(QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)));
QUndoGroup *undoGroup = new QUndoGroup();
undoGroup->addStack(undoStack.get());
DocOpenResult openResults = KdenliveDoc::Open(openURL, QDir::temp().path(), undoGroup, false, nullptr);
REQUIRE(openResults.isSuccessful() == true);
std::unique_ptr<KdenliveDoc> openedDoc = openResults.getDocument();
pCore->projectManager()->testSetDocument(openedDoc.get());
const QUuid uuid = openedDoc->uuid();
QDateTime documentDate = QFileInfo(openURL.toLocalFile()).lastModified();
KdenliveTests::updateTimeline(false, QString(), QString(), documentDate, 0);
QMap<QUuid, QString> allSequences = binModel->getAllSequenceClips();
const QString firstSeqId = allSequences.value(uuid);
pCore->projectManager()->openTimeline(firstSeqId, -1, uuid);
std::shared_ptr<TimelineItemModel> timeline = openedDoc->getTimeline(uuid);
// Now reopen all timeline sequences
QList<QUuid> allUuids = allSequences.keys();
allUuids.removeAll(uuid);
QString secondaryId;
for (auto &u : allUuids) {
secondaryId = allSequences.value(u);
pCore->projectManager()->openTimeline(secondaryId, -1, u);
}
pCore->projectManager()->testSetActiveTimeline(timeline);
REQUIRE(timeline->getTracksCount() == 4);
REQUIRE(timeline->checkConsistency(timeline->getGuideModel()->getSnapPoints()));
const QUuid secondSequence = allUuids.first();
timeline = openedDoc->getTimeline(secondSequence);
pCore->projectManager()->setActiveTimeline(secondSequence);
REQUIRE(timeline->getTracksCount() == 3);
std::shared_ptr<EffectStackModel> stack = timeline->getMasterEffectStackModel();
REQUIRE(stack->checkConsistency());
REQUIRE(stack->rowCount() == 2);
std::shared_ptr<EffectStackModel> binStack = binModel->getClipEffectStack(secondaryId.toInt());
REQUIRE(binStack->checkConsistency());
REQUIRE(binStack->rowCount() == 2);
pCore->projectManager()->closeCurrentDocument(false, false);
QFile::remove(QDir::temp().absoluteFilePath(QStringLiteral("test-nest2.kdenlive")));
}
}
TEST_CASE("Check nested sequences on opening", "[NEST]")
{
auto binModel = pCore->projectItemModel();
binModel->clean();
std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
SECTION("Open and simply save file")
{
QString path = sourcesPath + "/dataset/test-nesting.kdenlive";
Q_ASSERT(QFile::exists(sourcesPath));
QUrl openURL = QUrl::fromLocalFile(path);
QUndoGroup *undoGroup = new QUndoGroup();
undoGroup->addStack(undoStack.get());
DocOpenResult openResults = KdenliveDoc::Open(openURL, QDir::temp().path(), undoGroup, false, nullptr);
REQUIRE(openResults.isSuccessful() == true);
std::unique_ptr<KdenliveDoc> openedDoc = openResults.getDocument();
pCore->projectManager()->testSetDocument(openedDoc.get());
const QUuid uuid = openedDoc->uuid();
QDateTime documentDate = QFileInfo(openURL.toLocalFile()).lastModified();
KdenliveTests::updateTimeline(false, QString(), QString(), documentDate, 0);
QMap<QUuid, QString> allSequences = binModel->getAllSequenceClips();
const QString firstSeqId = allSequences.take(uuid);
pCore->projectManager()->openTimeline(firstSeqId, -1, uuid);
std::shared_ptr<TimelineItemModel> timeline1 = openedDoc->getTimeline(uuid);
pCore->projectManager()->testSetActiveTimeline(timeline1);
REQUIRE(openedDoc->checkConsistency());
// Sequence 2 {9228b6f1-e900-4ae9-8591-3cd674dbae98}
std::shared_ptr<TimelineItemModel> timeline2 = openedDoc->getTimeline(QUuid(QStringLiteral("{9228b6f1-e900-4ae9-8591-3cd674dbae98}")));
// Sequence 3 {147c3db9-2050-4453-91bd-4e4ad0033fb5}
std::shared_ptr<TimelineItemModel> timeline3 = openedDoc->getTimeline(QUuid(QStringLiteral("{147c3db9-2050-4453-91bd-4e4ad0033fb5}")));
// Check that each timeline has the correct clipcount
REQUIRE(timeline1->getClipsCount() == 1);
REQUIRE(timeline2->getClipsCount() == 2);
REQUIRE(timeline3->getClipsCount() == 2);
timeline1.reset();
timeline2.reset();
timeline3.reset();
pCore->projectManager()->closeCurrentDocument(false, false);
}
}
|