File indexing completed on 2024-04-07 04:45:10

0001 /*
0002     SPDX-FileCopyrightText: 2022 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 #include "catch.hpp"
0006 #include "test_utils.hpp"
0007 // test specific headers
0008 #include "doc/docundostack.hpp"
0009 #include "doc/kdenlivedoc.h"
0010 
0011 #include "core.h"
0012 #include "definitions.h"
0013 
0014 using namespace fakeit;
0015 
0016 TEST_CASE("Cut undo/redo", "[MoveClips]")
0017 {
0018     // Create timeline
0019     auto binModel = pCore->projectItemModel();
0020     binModel->clean();
0021     std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
0022 
0023     // Create document
0024     KdenliveDoc document(undoStack);
0025     pCore->projectManager()->m_project = &document;
0026     std::function<bool(void)> undo = []() { return true; };
0027     std::function<bool(void)> redo = []() { return true; };
0028     QDateTime documentDate = QDateTime::currentDateTime();
0029     pCore->projectManager()->updateTimeline(false, QString(), QString(), documentDate, 0);
0030     auto timeline = document.getTimeline(document.uuid());
0031     pCore->projectManager()->m_activeTimelineModel = timeline;
0032     pCore->projectManager()->testSetActiveDocument(&document, timeline);
0033 
0034     // Create a request
0035     int tid3 = timeline->getTrackIndexFromPosition(1);
0036     int tid2 = timeline->getTrackIndexFromPosition(2);
0037 
0038     // Create clip with audio (40 frames long)
0039     // QString binId = createAVProducer(*pCore->getProjectProfile(), binModel);
0040     QString binId = createProducerWithSound(pCore->getProjectProfile(), binModel, 100);
0041 
0042     // Setup insert stream data
0043     QMap<int, QString> audioInfo;
0044     audioInfo.insert(1, QStringLiteral("stream1"));
0045     timeline->m_binAudioTargets = audioInfo;
0046 
0047     // Create AV clip 1
0048     int cid1;
0049     int cid2;
0050     int cid3;
0051     int cid4;
0052 
0053     REQUIRE(timeline->requestClipInsertion(binId, tid2, 100, cid1));
0054     cid2 = timeline->getClipSplitPartner(cid1);
0055 
0056     SECTION("Ensure all clip instances on a track use the same producer")
0057     {
0058         REQUIRE(timeline->getItemTrackId(cid2) == tid3);
0059         REQUIRE(timeline->getItemTrackId(cid1) == tid2);
0060         Mlt::Producer prod1 = *(timeline->getClipPtr(cid1));
0061         Mlt::Producer prod2 = *(timeline->getClipPtr(cid2));
0062         // Clips on different tracks shoud not use the same producer
0063         REQUIRE(!prod1.same_clip(prod2));
0064 
0065         // Split clip
0066         REQUIRE(TimelineFunctions::requestClipCut(timeline, cid1, 110));
0067         cid3 = timeline->getClipByPosition(tid2, 111);
0068         cid4 = timeline->getClipSplitPartner(cid3);
0069         REQUIRE(timeline->getItemTrackId(cid4) == tid3);
0070         REQUIRE(timeline->getItemTrackId(cid3) == tid2);
0071 
0072         Mlt::Producer prod3 = *(timeline->getClipPtr(cid3));
0073         Mlt::Producer prod4 = *(timeline->getClipPtr(cid4));
0074         // Clips on different tracks shoud not use the same producer
0075         REQUIRE(!prod3.same_clip(prod4));
0076         // Clips on same track shoud use the same producer
0077         REQUIRE(prod1.same_clip(prod3));
0078         REQUIRE(prod2.same_clip(prod4));
0079 
0080         // Undo and redo cut, then ensure the producers are still correct
0081         undoStack->undo();
0082         undoStack->redo();
0083 
0084         prod3 = *(timeline->getClipPtr(cid3));
0085         prod4 = *(timeline->getClipPtr(cid4));
0086         // Clips on different tracks shoud not use the same producer
0087         REQUIRE(!prod3.same_clip(prod4));
0088         // Clips on same track shoud use the same producer
0089         REQUIRE(prod1.same_clip(prod3));
0090         REQUIRE(prod2.same_clip(prod4));
0091     }
0092     pCore->projectManager()->closeCurrentDocument(false, false);
0093 }