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

0001 /*
0002     SPDX-FileCopyrightText: 2022 Jean-Baptiste Mardelle <jb@kdenlive.org>
0003     SPDX-FileCopyrightText: 2017-2019 Nicolas Carion <french.ebook.lover@gmail.com>
0004     SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005 */
0006 
0007 #include "test_utils.hpp"
0008 // test specific headers
0009 #include "doc/kdenlivedoc.h"
0010 
0011 static QString getACompo()
0012 {
0013 
0014     // Check whether repo works
0015     QVector<QPair<QString, QString>> transitions = TransitionsRepository::get()->getNames();
0016     REQUIRE(!transitions.isEmpty());
0017 
0018     QString aCompo;
0019     // Look for a compo
0020     for (const auto &trans : qAsConst(transitions)) {
0021         if (TransitionsRepository::get()->isComposition(trans.first)) {
0022             aCompo = trans.first;
0023             break;
0024         }
0025     }
0026     REQUIRE(!aCompo.isEmpty());
0027     return aCompo;
0028 }
0029 
0030 TEST_CASE("Basic creation/deletion of a composition", "[CompositionModel]")
0031 {
0032     QString aCompo = getACompo();
0033 
0034     // Check construction from repo
0035     std::unique_ptr<Mlt::Transition> mlt_transition(TransitionsRepository::get()->getTransition(aCompo));
0036 
0037     REQUIRE(mlt_transition->is_valid());
0038 
0039     std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
0040 
0041     KdenliveDoc document(undoStack);
0042     Mock<KdenliveDoc> docMock(document);
0043     When(Method(docMock, getCacheDir)).AlwaysReturn(QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)));
0044     KdenliveDoc &mockedDoc = docMock.get();
0045 
0046     pCore->projectManager()->m_project = &mockedDoc;
0047     QDateTime documentDate = QDateTime::currentDateTime();
0048     pCore->projectManager()->updateTimeline(false, QString(), QString(), documentDate, 0);
0049     auto timeline = mockedDoc.getTimeline(mockedDoc.uuid());
0050     pCore->projectManager()->m_activeTimelineModel = timeline;
0051     pCore->projectManager()->testSetActiveDocument(&mockedDoc, timeline);
0052 
0053     REQUIRE(timeline->getCompositionsCount() == 0);
0054     int id1 = CompositionModel::construct(timeline, aCompo, QString());
0055     REQUIRE(timeline->getCompositionsCount() == 1);
0056 
0057     int id2 = CompositionModel::construct(timeline, aCompo, QString());
0058     REQUIRE(timeline->getCompositionsCount() == 2);
0059 
0060     int id3 = CompositionModel::construct(timeline, aCompo, QString());
0061     REQUIRE(timeline->getCompositionsCount() == 3);
0062 
0063     // Test deletion
0064     REQUIRE(timeline->requestItemDeletion(id2));
0065     REQUIRE(timeline->getCompositionsCount() == 2);
0066     REQUIRE(timeline->requestItemDeletion(id3));
0067     REQUIRE(timeline->getCompositionsCount() == 1);
0068     REQUIRE(timeline->requestItemDeletion(id1));
0069     REQUIRE(timeline->getCompositionsCount() == 0);
0070     pCore->taskManager.slotCancelJobs();
0071     mockedDoc.closeTimeline(timeline->uuid());
0072     timeline.reset();
0073     pCore->projectItemModel()->clean();
0074 }
0075 
0076 TEST_CASE("Composition manipulation", "[CompositionModel]")
0077 {
0078     std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
0079     KdenliveDoc document(undoStack, {0, 3});
0080     Mock<KdenliveDoc> docMock(document);
0081     When(Method(docMock, getCacheDir)).AlwaysReturn(QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)));
0082     KdenliveDoc &mockedDoc = docMock.get();
0083 
0084     pCore->projectManager()->m_project = &mockedDoc;
0085     QDateTime documentDate = QDateTime::currentDateTime();
0086     pCore->projectManager()->updateTimeline(false, QString(), QString(), documentDate, 0);
0087     auto timeline = mockedDoc.getTimeline(mockedDoc.uuid());
0088     pCore->projectManager()->m_activeTimelineModel = timeline;
0089     pCore->projectManager()->testSetActiveDocument(&mockedDoc, timeline);
0090 
0091     QString aCompo = getACompo();
0092 
0093     int tid1 = timeline->getTrackIndexFromPosition(0);
0094     int tid2 = timeline->getTrackIndexFromPosition(1);
0095     int tid3 = timeline->getTrackIndexFromPosition(2);
0096     int cid2 = CompositionModel::construct(timeline, aCompo, QString());
0097     Q_UNUSED(tid3);
0098     int cid1 = CompositionModel::construct(timeline, aCompo, QString());
0099 
0100     REQUIRE(timeline->getCompositionPlaytime(cid1) == 1);
0101     REQUIRE(timeline->getCompositionPlaytime(cid2) == 1);
0102 
0103     SECTION("Insert a composition in a track and change track")
0104     {
0105         REQUIRE(timeline->checkConsistency());
0106         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 0);
0107         REQUIRE(timeline->getTrackCompositionsCount(tid2) == 0);
0108 
0109         REQUIRE(timeline->getCompositionPlaytime(cid1) == 1);
0110         REQUIRE(timeline->getCompositionPlaytime(cid2) == 1);
0111         REQUIRE(timeline->getCompositionTrackId(cid1) == -1);
0112         REQUIRE(timeline->getCompositionPosition(cid1) == -1);
0113 
0114         int pos = 10;
0115         REQUIRE(timeline->requestCompositionMove(cid1, tid1, pos));
0116         REQUIRE(timeline->checkConsistency());
0117         REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0118         REQUIRE(timeline->getCompositionPosition(cid1) == pos);
0119         REQUIRE(timeline->getCompositionPlaytime(cid1) == 1);
0120         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 1);
0121         REQUIRE(timeline->getTrackCompositionsCount(tid2) == 0);
0122 
0123         pos = 10;
0124         REQUIRE(timeline->requestCompositionMove(cid1, tid2, pos));
0125         REQUIRE(timeline->checkConsistency());
0126         REQUIRE(timeline->getCompositionTrackId(cid1) == tid2);
0127         REQUIRE(timeline->getCompositionPosition(cid1) == pos);
0128         REQUIRE(timeline->getCompositionPlaytime(cid1) == 1);
0129         REQUIRE(timeline->getTrackCompositionsCount(tid2) == 1);
0130         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 0);
0131 
0132         REQUIRE(timeline->requestItemResize(cid1, 10, true) > -1);
0133         REQUIRE(timeline->checkConsistency());
0134         REQUIRE(timeline->getCompositionTrackId(cid1) == tid2);
0135         REQUIRE(timeline->getCompositionPosition(cid1) == pos);
0136         REQUIRE(timeline->getCompositionPlaytime(cid1) == 10);
0137         REQUIRE(timeline->getTrackCompositionsCount(tid2) == 1);
0138         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 0);
0139 
0140         REQUIRE(timeline->requestCompositionMove(cid2, tid2, 0));
0141         REQUIRE(timeline->requestItemResize(cid2, 10, true) > -1);
0142         REQUIRE(timeline->checkConsistency());
0143         REQUIRE(timeline->getCompositionPlaytime(cid2) == 10);
0144 
0145         // Check conflicts
0146         int pos2 = timeline->getCompositionPlaytime(cid1);
0147         REQUIRE(timeline->requestCompositionMove(cid2, tid1, pos2));
0148         REQUIRE(timeline->checkConsistency());
0149         REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0150         REQUIRE(timeline->getCompositionPosition(cid2) == pos2);
0151         REQUIRE(timeline->getTrackCompositionsCount(tid2) == 1);
0152         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 1);
0153 
0154         REQUIRE_FALSE(timeline->requestCompositionMove(cid1, tid1, pos2 + 2));
0155         REQUIRE(timeline->checkConsistency());
0156         REQUIRE(timeline->getTrackCompositionsCount(tid2) == 1);
0157         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 1);
0158         REQUIRE(timeline->getCompositionTrackId(cid1) == tid2);
0159         REQUIRE(timeline->getCompositionPosition(cid1) == pos);
0160         REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0161         REQUIRE(timeline->getCompositionPosition(cid2) == pos2);
0162 
0163         REQUIRE_FALSE(timeline->requestCompositionMove(cid1, tid1, pos2 - 2));
0164         REQUIRE(timeline->checkConsistency());
0165         REQUIRE(timeline->getTrackCompositionsCount(tid2) == 1);
0166         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 1);
0167         REQUIRE(timeline->getCompositionTrackId(cid1) == tid2);
0168         REQUIRE(timeline->getCompositionPosition(cid1) == pos);
0169         REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0170         REQUIRE(timeline->getCompositionPosition(cid2) == pos2);
0171 
0172         REQUIRE(timeline->requestCompositionMove(cid1, tid1, 0));
0173         REQUIRE(timeline->checkConsistency());
0174         REQUIRE(timeline->getTrackCompositionsCount(tid2) == 0);
0175         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
0176         REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0177         REQUIRE(timeline->getCompositionPosition(cid1) == 0);
0178         REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0179         REQUIRE(timeline->getCompositionPosition(cid2) == pos2);
0180     }
0181 
0182     SECTION("Insert consecutive compositions")
0183     {
0184         int length = 12;
0185         REQUIRE(timeline->requestItemResize(cid1, length, true) > -1);
0186         REQUIRE(timeline->requestItemResize(cid2, length, true) > -1);
0187         REQUIRE(timeline->getCompositionPlaytime(cid1) == length);
0188         REQUIRE(timeline->getCompositionPlaytime(cid2) == length);
0189         REQUIRE(timeline->checkConsistency());
0190         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 0);
0191         REQUIRE(timeline->getTrackCompositionsCount(tid2) == 0);
0192 
0193         REQUIRE(timeline->requestCompositionMove(cid1, tid1, 0));
0194         REQUIRE(timeline->checkConsistency());
0195         REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0196         REQUIRE(timeline->getCompositionPosition(cid1) == 0);
0197         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 1);
0198 
0199         REQUIRE(timeline->requestCompositionMove(cid2, tid1, length));
0200         REQUIRE(timeline->checkConsistency());
0201         REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0202         REQUIRE(timeline->getCompositionPosition(cid2) == length);
0203         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
0204     }
0205 
0206     SECTION("Resize orphan composition")
0207     {
0208         int length = 12;
0209         REQUIRE(timeline->requestItemResize(cid1, length, true) > -1);
0210         REQUIRE(timeline->requestItemResize(cid2, length, true) > -1);
0211         REQUIRE(timeline->getCompositionPlaytime(cid1) == length);
0212         REQUIRE(timeline->getCompositionPlaytime(cid2) == length);
0213 
0214         REQUIRE(timeline->getCompositionPlaytime(cid2) == length);
0215         REQUIRE(timeline->requestItemResize(cid2, 5, true) > -1);
0216         auto inOut = std::pair<int, int>{0, 4};
0217         REQUIRE(timeline->m_allCompositions[cid2]->getInOut() == inOut);
0218         REQUIRE(timeline->getCompositionPlaytime(cid2) == 5);
0219         REQUIRE(timeline->requestItemResize(cid2, 10, false) > -1);
0220         REQUIRE(timeline->getCompositionPlaytime(cid2) == 10);
0221         REQUIRE(timeline->requestItemResize(cid2, length + 1, true) > -1);
0222         REQUIRE(timeline->getCompositionPlaytime(cid2) == length + 1);
0223         REQUIRE(timeline->requestItemResize(cid2, 2, false) > -1);
0224         REQUIRE(timeline->getCompositionPlaytime(cid2) == 2);
0225         REQUIRE(timeline->requestItemResize(cid2, length, true) > -1);
0226         REQUIRE(timeline->getCompositionPlaytime(cid2) == length);
0227         REQUIRE(timeline->requestItemResize(cid2, length - 2, true) > -1);
0228         REQUIRE(timeline->getCompositionPlaytime(cid2) == length - 2);
0229         REQUIRE(timeline->requestItemResize(cid2, length - 3, true) > -1);
0230         REQUIRE(timeline->getCompositionPlaytime(cid2) == length - 3);
0231     }
0232 
0233     SECTION("Resize inserted compositions")
0234     {
0235         int length = 12;
0236         REQUIRE(timeline->requestItemResize(cid1, length, true) > -1);
0237         REQUIRE(timeline->requestItemResize(cid2, length, true) > -1);
0238 
0239         REQUIRE(timeline->requestCompositionMove(cid1, tid1, 0));
0240         REQUIRE(timeline->checkConsistency());
0241 
0242         REQUIRE(timeline->requestItemResize(cid1, 5, true) > -1);
0243         REQUIRE(timeline->checkConsistency());
0244         REQUIRE(timeline->getCompositionPlaytime(cid1) == 5);
0245         REQUIRE(timeline->getCompositionPosition(cid1) == 0);
0246 
0247         REQUIRE(timeline->requestCompositionMove(cid2, tid1, 5));
0248         REQUIRE(timeline->checkConsistency());
0249         REQUIRE(timeline->getCompositionPlaytime(cid2) == length);
0250         REQUIRE(timeline->getCompositionPosition(cid2) == 5);
0251 
0252         REQUIRE(timeline->requestItemResize(cid1, 6, true) == -1);
0253         REQUIRE(timeline->requestItemResize(cid1, 6, false) == -1);
0254         REQUIRE(timeline->checkConsistency());
0255 
0256         REQUIRE(timeline->requestItemResize(cid2, length - 5, false) > -1);
0257         REQUIRE(timeline->checkConsistency());
0258         REQUIRE(timeline->getCompositionPosition(cid2) == 10);
0259 
0260         REQUIRE(timeline->requestItemResize(cid1, 10, true) > -1);
0261         REQUIRE(timeline->checkConsistency());
0262         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
0263     }
0264 
0265     SECTION("Change track of resized compositions")
0266     {
0267         int length = 12;
0268         REQUIRE(timeline->requestItemResize(cid1, length, true) > -1);
0269         REQUIRE(timeline->requestItemResize(cid2, length, true) > -1);
0270 
0271         REQUIRE(timeline->requestCompositionMove(cid2, tid1, 5));
0272         REQUIRE(timeline->checkConsistency());
0273         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 1);
0274 
0275         REQUIRE(timeline->requestCompositionMove(cid1, tid2, 10));
0276         REQUIRE(timeline->checkConsistency());
0277         REQUIRE(timeline->getTrackCompositionsCount(tid2) == 1);
0278 
0279         REQUIRE(timeline->requestItemResize(cid1, 5, false) > -1);
0280         REQUIRE(timeline->checkConsistency());
0281 
0282         REQUIRE(timeline->requestCompositionMove(cid1, tid1, 0));
0283         REQUIRE(timeline->checkConsistency());
0284         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
0285         REQUIRE(timeline->getTrackCompositionsCount(tid2) == 0);
0286     }
0287 
0288     SECTION("Composition Move")
0289     {
0290         int length = 12;
0291         REQUIRE(timeline->requestItemResize(cid1, length, true) > -1);
0292         REQUIRE(timeline->requestItemResize(cid2, length, true) > -1);
0293 
0294         REQUIRE(timeline->requestCompositionMove(cid2, tid1, 5));
0295         REQUIRE(timeline->checkConsistency());
0296         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 1);
0297         REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0298         REQUIRE(timeline->getCompositionPosition(cid2) == 5);
0299 
0300         REQUIRE(timeline->requestCompositionMove(cid1, tid1, 5 + length));
0301         auto state = [&]() {
0302             REQUIRE(timeline->checkConsistency());
0303             REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
0304             REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0305             REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0306             REQUIRE(timeline->getCompositionPosition(cid1) == 5 + length);
0307             REQUIRE(timeline->getCompositionPosition(cid2) == 5);
0308         };
0309         state();
0310 
0311         REQUIRE_FALSE(timeline->requestCompositionMove(cid1, tid1, 3 + length));
0312         state();
0313 
0314         REQUIRE_FALSE(timeline->requestCompositionMove(cid1, tid1, 0));
0315         state();
0316 
0317         REQUIRE(timeline->requestCompositionMove(cid2, tid1, 0));
0318         auto state2 = [&]() {
0319             REQUIRE(timeline->checkConsistency());
0320             REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
0321             REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0322             REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0323             REQUIRE(timeline->getCompositionPosition(cid1) == 5 + length);
0324             REQUIRE(timeline->getCompositionPosition(cid2) == 0);
0325         };
0326         state2();
0327 
0328         REQUIRE_FALSE(timeline->requestCompositionMove(cid1, tid1, 0));
0329         state2();
0330 
0331         REQUIRE_FALSE(timeline->requestCompositionMove(cid1, tid1, length - 5));
0332         state2();
0333 
0334         REQUIRE(timeline->requestCompositionMove(cid1, tid1, length));
0335         REQUIRE(timeline->checkConsistency());
0336         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
0337         REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0338         REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0339         REQUIRE(timeline->getCompositionPosition(cid1) == length);
0340         REQUIRE(timeline->getCompositionPosition(cid2) == 0);
0341 
0342         REQUIRE(timeline->requestItemResize(cid2, length - 5, true) > -1);
0343         REQUIRE(timeline->checkConsistency());
0344         REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0345         REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0346         REQUIRE(timeline->getCompositionPosition(cid1) == length);
0347         REQUIRE(timeline->getCompositionPosition(cid2) == 0);
0348 
0349         // REQUIRE(timeline->allowCompositionMove(cid1, tid1, length - 5));
0350         REQUIRE(timeline->requestCompositionMove(cid1, tid1, length - 5));
0351         REQUIRE(timeline->checkConsistency());
0352         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
0353         REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0354         REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0355         REQUIRE(timeline->getCompositionPosition(cid1) == length - 5);
0356         REQUIRE(timeline->getCompositionPosition(cid2) == 0);
0357 
0358         REQUIRE(timeline->requestItemResize(cid2, length - 10, false) > -1);
0359         REQUIRE(timeline->checkConsistency());
0360         REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0361         REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0362         REQUIRE(timeline->getCompositionPosition(cid1) == length - 5);
0363         REQUIRE(timeline->getCompositionPosition(cid2) == 5);
0364 
0365         REQUIRE_FALSE(timeline->requestCompositionMove(cid1, tid1, 0));
0366         REQUIRE(timeline->checkConsistency());
0367         REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0368         REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0369         REQUIRE(timeline->getCompositionPosition(cid1) == length - 5);
0370         REQUIRE(timeline->getCompositionPosition(cid2) == 5);
0371 
0372         REQUIRE(timeline->requestCompositionMove(cid2, tid1, 0));
0373         REQUIRE(timeline->checkConsistency());
0374         REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
0375         REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0376         REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0377         REQUIRE(timeline->getCompositionPosition(cid1) == length - 5);
0378         REQUIRE(timeline->getCompositionPosition(cid2) == 0);
0379     }
0380 
0381     SECTION("Move and resize")
0382     {
0383         int length = 12;
0384         REQUIRE(timeline->requestCompositionMove(cid2, tid2, 0));
0385         REQUIRE(timeline->requestItemResize(cid1, length, true) > -1);
0386         REQUIRE(timeline->requestItemResize(cid2, length, true) > -1);
0387 
0388         REQUIRE(timeline->requestCompositionMove(cid1, tid1, 0));
0389         REQUIRE(timeline->getCompositionPosition(cid1) == 0);
0390         REQUIRE(timeline->requestItemResize(cid1, length - 2, false, 0) > -1);
0391         REQUIRE(timeline->getCompositionPosition(cid1) == 2);
0392         REQUIRE(timeline->requestCompositionMove(cid1, tid1, 0));
0393         auto state = [&]() {
0394             REQUIRE(timeline->checkConsistency());
0395             REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0396             REQUIRE(timeline->getTrackCompositionsCount(tid1) == 1);
0397             REQUIRE(timeline->getCompositionPosition(cid1) == 0);
0398             REQUIRE(timeline->getCompositionPlaytime(cid1) == length - 2);
0399         };
0400         state();
0401 
0402         REQUIRE(timeline->requestItemResize(cid1, length - 4, true) > -1);
0403         REQUIRE(timeline->requestCompositionMove(cid2, tid1, length - 4 + 1));
0404         REQUIRE(timeline->requestItemResize(cid2, length - 2, false) > -1);
0405         REQUIRE(timeline->requestCompositionMove(cid2, tid1, length - 4 + 1));
0406         auto state2 = [&]() {
0407             REQUIRE(timeline->checkConsistency());
0408             REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0409             REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0410             REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
0411             REQUIRE(timeline->getCompositionPosition(cid1) == 0);
0412             REQUIRE(timeline->getCompositionPlaytime(cid1) == length - 4);
0413             REQUIRE(timeline->getCompositionPosition(cid2) == length - 4 + 1);
0414             REQUIRE(timeline->getCompositionPlaytime(cid2) == length - 2);
0415         };
0416         state2();
0417         // the gap between the two clips is 1 frame, we try to resize them by 2 frames
0418         REQUIRE(timeline->requestItemResize(cid1, length - 2, true) == -1);
0419         state2();
0420         REQUIRE(timeline->requestItemResize(cid2, length, false) == -1);
0421         state2();
0422 
0423         REQUIRE(timeline->requestCompositionMove(cid2, tid1, length - 4));
0424         auto state3 = [&]() {
0425             REQUIRE(timeline->checkConsistency());
0426             REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
0427             REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
0428             REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
0429             REQUIRE(timeline->getCompositionPosition(cid1) == 0);
0430             REQUIRE(timeline->getCompositionPlaytime(cid1) == length - 4);
0431             REQUIRE(timeline->getCompositionPosition(cid2) == length - 4);
0432             REQUIRE(timeline->getCompositionPlaytime(cid2) == length - 2);
0433         };
0434         state3();
0435 
0436         // Now the gap is 0 frames, the resize should still fail
0437         REQUIRE(timeline->requestItemResize(cid1, length - 2, true) == -1);
0438         state3();
0439         REQUIRE(timeline->requestItemResize(cid2, length, false) == -1);
0440         state3();
0441 
0442         // We move cid1 out of the way
0443         REQUIRE(timeline->requestCompositionMove(cid1, tid2, 0));
0444         // now resize should work
0445         REQUIRE(timeline->requestItemResize(cid1, length - 2, true) > -1);
0446         REQUIRE(timeline->requestItemResize(cid2, length, false) > -1);
0447     }
0448     pCore->taskManager.slotCancelJobs();
0449     mockedDoc.closeTimeline(timeline->uuid());
0450     timeline.reset();
0451     pCore->projectItemModel()->clean();
0452 }