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
|
/*
SPDX-FileCopyrightText: 2022 Jean-Baptiste Mardelle <jb@kdenlive.org>
SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "catch.hpp"
#include "test_utils.hpp"
// test specific headers
#include "doc/docundostack.hpp"
#include "doc/kdenlivedoc.h"
#include "core.h"
#include "definitions.h"
using namespace fakeit;
TEST_CASE("Cut undo/redo", "[MoveClips]")
{
// Create timeline
auto binModel = pCore->projectItemModel();
binModel->clean();
std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
// Create document
KdenliveDoc document(undoStack);
pCore->projectManager()->testSetDocument(&document);
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
QDateTime documentDate = QDateTime::currentDateTime();
KdenliveTests::updateTimeline(false, QString(), QString(), documentDate, 0);
auto timeline = document.getTimeline(document.uuid());
pCore->projectManager()->testSetActiveTimeline(timeline);
// Create a request
int tid1 = timeline->getTrackIndexFromPosition(1);
int tid2 = timeline->getTrackIndexFromPosition(2);
int tid3 = timeline->getTrackIndexFromPosition(3);
// Create clip with audio (40 frames long)
// QString binId = createAVProducer(*pCore->getProjectProfile(), binModel);
QString binId = KdenliveTests::createProducerWithSound(pCore->getProjectProfile(), binModel, 100);
QString binId2 = KdenliveTests::createProducer(pCore->getProjectProfile(), "red", binModel, 100, false);
// Setup insert stream data
QMap<int, QString> audioInfo;
audioInfo.insert(1, QStringLiteral("stream1"));
KdenliveTests::setAudioTargets(timeline, audioInfo);
// Create AV clip 1
int cid1;
int cid2;
int cid3;
int cid4;
int cid5;
REQUIRE(timeline->requestClipInsertion(binId, tid2, 100, cid1));
cid2 = timeline->getClipSplitPartner(cid1);
REQUIRE(timeline->requestClipInsertion(binId2, tid3, 100, cid5));
SECTION("Ensure all clip instances on a track use the same producer")
{
REQUIRE(timeline->getItemTrackId(cid2) == tid1);
REQUIRE(timeline->getItemTrackId(cid1) == tid2);
Mlt::Producer prod1 = *(KdenliveTests::getClipPtr(timeline, cid1));
Mlt::Producer prod2 = *(KdenliveTests::getClipPtr(timeline, cid2));
// Clips on different tracks should not use the same producer
REQUIRE(!prod1.same_clip(prod2));
// Split clip
REQUIRE(TimelineFunctions::requestClipCut(timeline, cid1, 110));
cid3 = timeline->getClipByPosition(tid2, 111);
cid4 = timeline->getClipSplitPartner(cid3);
REQUIRE(timeline->getItemTrackId(cid4) == tid1);
REQUIRE(timeline->getItemTrackId(cid3) == tid2);
Mlt::Producer prod3 = *(KdenliveTests::getClipPtr(timeline, cid3));
Mlt::Producer prod4 = *(KdenliveTests::getClipPtr(timeline, cid4));
// Clips on different tracks should not use the same producer
REQUIRE(!prod3.same_clip(prod4));
// Clips on same track should use the same producer
REQUIRE(prod1.same_clip(prod3));
REQUIRE(prod2.same_clip(prod4));
// Undo and redo cut, then ensure the producers are still correct
undoStack->undo();
undoStack->redo();
prod3 = *(KdenliveTests::getClipPtr(timeline, cid3));
prod4 = *(KdenliveTests::getClipPtr(timeline, cid4));
// Clips on different tracks should not use the same producer
REQUIRE(!prod3.same_clip(prod4));
// Clips on same track should use the same producer
REQUIRE(prod1.same_clip(prod3));
REQUIRE(prod2.same_clip(prod4));
// Undo cut
undoStack->undo();
}
SECTION("Ensure selected group cut works")
{
// Set selection
timeline->requestSetSelection({cid1, cid5});
// Split clip
REQUIRE(TimelineFunctions::requestClipCut(timeline, cid1, 110));
// Undo and redo cut, then ensure the producers are still correct
undoStack->undo();
undoStack->redo();
undoStack->undo();
}
pCore->projectManager()->closeCurrentDocument(false, false);
}
|