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

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("Show/hide tracks", "[HideTracks]")
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     // Audio tracks
0035     int tid1 = timeline->getTrackIndexFromPosition(0);
0036     int tid2 = timeline->getTrackIndexFromPosition(1);
0037     // Video tracks
0038     int tid3 = timeline->getTrackIndexFromPosition(2);
0039     int tid4 = timeline->getTrackIndexFromPosition(3);
0040 
0041     // Create clip with audio (100 frames long)
0042     QString binId = createProducerWithSound(pCore->getProjectProfile(), binModel, 100);
0043     // Create color clip (50 frames long)
0044     QString binId2 = createProducer(pCore->getProjectProfile(), "red", binModel, 50, false);
0045 
0046     // Setup insert stream data
0047     QMap<int, QString> audioInfo;
0048     audioInfo.insert(1, QStringLiteral("stream1"));
0049     timeline->m_binAudioTargets = audioInfo;
0050 
0051     int cid1;
0052     int cid2;
0053     int cid3;
0054     int cid4;
0055 
0056     // Create AV clip 1
0057     REQUIRE(timeline->requestClipInsertion(binId, tid3, 10, cid1));
0058     cid2 = timeline->getClipSplitPartner(cid1);
0059 
0060     // Remove video part
0061     timeline->m_groups->ungroupItem(cid2, undo, redo);
0062     timeline->requestItemDeletion(cid1);
0063 
0064     SECTION("Disable, enable audio track and check length")
0065     {
0066         REQUIRE(timeline->duration() == 110);
0067         timeline->setTrackProperty(tid2, QStringLiteral("hide"), "3");
0068         REQUIRE(timeline->duration() == 0);
0069         timeline->setTrackProperty(tid2, QStringLiteral("hide"), "1");
0070         REQUIRE(timeline->duration() == 110);
0071     }
0072 
0073     SECTION("Disable, add clip, enable audio track and check length")
0074     {
0075         REQUIRE(timeline->duration() == 110);
0076         timeline->setTrackProperty(tid2, QStringLiteral("hide"), "3");
0077         REQUIRE(timeline->duration() == 0);
0078         REQUIRE(timeline->requestClipInsertion(binId2, tid4, 10, cid1));
0079         REQUIRE(timeline->duration() == 60);
0080         timeline->setTrackProperty(tid2, QStringLiteral("hide"), "1");
0081         REQUIRE(timeline->duration() == 110);
0082         timeline->setTrackProperty(tid4, QStringLiteral("hide"), "3");
0083         REQUIRE(timeline->duration() == 110);
0084         timeline->setTrackProperty(tid4, QStringLiteral("hide"), "2");
0085         REQUIRE(timeline->duration() == 110);
0086         timeline->setTrackProperty(tid2, QStringLiteral("hide"), "3");
0087         REQUIRE(timeline->duration() == 60);
0088     }
0089 
0090     pCore->projectManager()->closeCurrentDocument(false, false);
0091 }