File indexing completed on 2024-04-28 08:45:14

0001 /*
0002     SPDX-FileCopyrightText: 2017-2019 Nicolas Carion <french.ebook.lover@gmail.com>
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 #include <cmath>
0011 #include <iostream>
0012 #include <tuple>
0013 #include <unordered_set>
0014 
0015 #include "core.h"
0016 #include "definitions.h"
0017 #include "effects/effectsrepository.hpp"
0018 #include "effects/effectstack/model/effectitemmodel.hpp"
0019 #include "effects/effectstack/model/effectstackmodel.hpp"
0020 
0021 QString anEffect;
0022 TEST_CASE("Effects stack", "[Effects]")
0023 {
0024     // Create timeline
0025     auto binModel = pCore->projectItemModel();
0026     std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
0027 
0028     // Here we do some trickery to enable testing.
0029     // We mock the project class so that the undoStack function returns our undoStack
0030     KdenliveDoc document(undoStack);
0031 
0032     pCore->projectManager()->m_project = &document;
0033     QDateTime documentDate = QDateTime::currentDateTime();
0034     pCore->projectManager()->updateTimeline(false, QString(), QString(), documentDate, 0);
0035     auto timeline = document.getTimeline(document.uuid());
0036     pCore->projectManager()->m_activeTimelineModel = timeline;
0037     pCore->projectManager()->testSetActiveDocument(&document, timeline);
0038 
0039     // Create a request
0040     int tid1;
0041     REQUIRE(timeline->requestTrackInsertion(-1, tid1));
0042 
0043     // Create clip
0044     QString binId = createProducer(pCore->getProjectProfile(), "red", binModel);
0045     int cid1;
0046     REQUIRE(timeline->requestClipInsertion(binId, tid1, 100, cid1));
0047     std::shared_ptr<ProjectClip> clip = binModel->getClipByBinID(binId);
0048 
0049     auto model = clip->m_effectStack;
0050 
0051     REQUIRE(model->checkConsistency());
0052     REQUIRE(model->rowCount() == 0);
0053 
0054     // Check whether repo works
0055     QVector<QPair<QString, QString>> effects = EffectsRepository::get()->getNames();
0056     REQUIRE(!effects.isEmpty());
0057 
0058     anEffect = QStringLiteral("sepia"); // effects.first().first;
0059 
0060     REQUIRE(!anEffect.isEmpty());
0061 
0062     SECTION("Create and delete effects")
0063     {
0064         REQUIRE(model->appendEffect(anEffect));
0065         REQUIRE(model->checkConsistency());
0066         REQUIRE(model->rowCount() == 1);
0067 
0068         REQUIRE(model->appendEffect(anEffect));
0069         REQUIRE(model->checkConsistency());
0070         REQUIRE(model->rowCount() == 2);
0071 
0072         undoStack->undo();
0073         REQUIRE(model->checkConsistency());
0074         REQUIRE(model->rowCount() == 1);
0075     }
0076 
0077     SECTION("Create cut with fade in")
0078     {
0079         auto clipModel = timeline->getClipPtr(cid1)->m_effectStack;
0080         REQUIRE(clipModel->rowCount() == 0);
0081         clipModel->appendEffect("fade_from_black");
0082         REQUIRE(clipModel->checkConsistency());
0083         REQUIRE(clipModel->rowCount() == 1);
0084 
0085         int l = timeline->getClipPlaytime(cid1);
0086         REQUIRE(TimelineFunctions::requestClipCut(timeline, cid1, 100 + l - 10));
0087         int splitted = timeline->getClipByPosition(tid1, 100 + l - 9);
0088         auto splitModel = timeline->getClipPtr(splitted)->m_effectStack;
0089         REQUIRE(clipModel->rowCount() == 1);
0090         REQUIRE(splitModel->rowCount() == 0);
0091     }
0092 
0093     SECTION("Create cut with fade out")
0094     {
0095         auto clipModel = timeline->getClipPtr(cid1)->m_effectStack;
0096         REQUIRE(clipModel->rowCount() == 0);
0097         clipModel->appendEffect("fade_to_black");
0098         REQUIRE(clipModel->checkConsistency());
0099         REQUIRE(clipModel->rowCount() == 1);
0100 
0101         int l = timeline->getClipPlaytime(cid1);
0102         REQUIRE(TimelineFunctions::requestClipCut(timeline, cid1, 100 + l - 10));
0103         int splitted = timeline->getClipByPosition(tid1, 100 + l - 9);
0104         auto splitModel = timeline->getClipPtr(splitted)->m_effectStack;
0105         REQUIRE(clipModel->rowCount() == 0);
0106         REQUIRE(splitModel->rowCount() == 1);
0107     }
0108     timeline.reset();
0109     clip.reset();
0110     pCore->projectManager()->closeCurrentDocument(false, false);
0111 }