File indexing completed on 2024-04-21 08:42:52

0001 /*
0002     SPDX-FileCopyrightText: 2018-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 #include "test_utils.hpp"
0007 
0008 QString createProducer(Mlt::Profile &prof, std::string color, std::shared_ptr<ProjectItemModel> binModel, int length, bool limited)
0009 {
0010     std::shared_ptr<Mlt::Producer> producer = std::make_shared<Mlt::Producer>(prof, "color", color.c_str());
0011     producer->set("length", length);
0012     producer->set("out", length - 1);
0013 
0014     REQUIRE(producer->is_valid());
0015 
0016     QString binId = QString::number(binModel->getFreeClipId());
0017     auto binClip = ProjectClip::construct(binId, QIcon(), binModel, producer);
0018     if (limited) {
0019         binClip->forceLimitedDuration();
0020     }
0021     Fun undo = []() { return true; };
0022     Fun redo = []() { return true; };
0023     REQUIRE(binModel->addItem(binClip, binModel->getRootFolder()->clipId(), undo, redo));
0024 
0025     return binId;
0026 }
0027 
0028 QString createProducerWithSound(Mlt::Profile &prof, std::shared_ptr<ProjectItemModel> binModel, int length)
0029 {
0030     // std::shared_ptr<Mlt::Producer> producer = std::make_shared<Mlt::Producer>(prof, QFileInfo(QCoreApplication::applicationDirPath()  +
0031     // "/../../tests/small.mkv").absoluteFilePath().toStdString().c_str()); In case the test system does not have avformat support, we can switch to the
0032     // integrated blipflash producer
0033     std::shared_ptr<Mlt::Producer> producer = std::make_shared<Mlt::Producer>(prof, "blipflash");
0034     REQUIRE(producer->is_valid());
0035 
0036     producer->set("length", length);
0037     producer->set_in_and_out(0, length - 1);
0038     producer->set("kdenlive:duration", length);
0039 
0040     QString binId = QString::number(binModel->getFreeClipId());
0041     auto binClip = ProjectClip::construct(binId, QIcon(), binModel, producer);
0042     binClip->forceLimitedDuration();
0043     Fun undo = []() { return true; };
0044     Fun redo = []() { return true; };
0045     REQUIRE(binModel->addItem(binClip, binModel->getRootFolder()->clipId(), undo, redo));
0046 
0047     return binId;
0048 }
0049 
0050 QString createAVProducer(Mlt::Profile &prof, std::shared_ptr<ProjectItemModel> binModel)
0051 {
0052     std::shared_ptr<Mlt::Producer> producer =
0053         std::make_shared<Mlt::Producer>(prof, QFileInfo(sourcesPath + "/small.mkv").absoluteFilePath().toStdString().c_str());
0054 
0055     // In case the test system does not have avformat support, we can switch to the integrated blipflash producer
0056     int length = -1;
0057     if (!producer || !producer->is_valid()) {
0058         length = 40;
0059         producer.reset(new Mlt::Producer(prof, "blipflash"));
0060         producer->set("length", length);
0061         producer->set_in_and_out(0, length - 1);
0062         producer->set("kdenlive:duration", length);
0063     }
0064     REQUIRE(producer->is_valid());
0065 
0066     QString binId = QString::number(binModel->getFreeClipId());
0067     auto binClip = ProjectClip::construct(binId, QIcon(), binModel, producer);
0068     if (length > -1) {
0069         binClip->forceLimitedDuration();
0070     }
0071     Fun undo = []() { return true; };
0072     Fun redo = []() { return true; };
0073     REQUIRE(binModel->addItem(binClip, binModel->getRootFolder()->clipId(), undo, redo));
0074     return binId;
0075 }
0076 
0077 QString createTextProducer(Mlt::Profile &prof, std::shared_ptr<ProjectItemModel> binModel, const QString &xmldata, const QString &clipname, int length)
0078 {
0079     std::shared_ptr<Mlt::Producer> producer =
0080         std::make_shared<Mlt::Producer>(prof, "kdenlivetitle");
0081 
0082     REQUIRE(producer->is_valid());
0083 
0084     producer->set("length", length);
0085     producer->set_in_and_out(0, length - 1);
0086     producer->set("kdenlive:duration", length);
0087     producer->set_string("kdenlive:clipname", clipname.toLocal8Bit().data());
0088     producer->set_string("xmldata", xmldata.toLocal8Bit().data());
0089 
0090     QString binId = QString::number(binModel->getFreeClipId());
0091     auto binClip = ProjectClip::construct(binId, QIcon(), binModel, producer);
0092     binClip->forceLimitedDuration();
0093     Fun undo = []() { return true; };
0094     Fun redo = []() { return true; };
0095     REQUIRE(binModel->addItem(binClip, binModel->getRootFolder()->clipId(), undo, redo));
0096 
0097     REQUIRE(binClip->clipType() == ClipType::Text);
0098     return binId;
0099 }
0100 
0101 std::unique_ptr<QDomElement> getProperty(const QDomElement &doc, const QString &name) {
0102     QDomNodeList list = doc.elementsByTagName("property");
0103     for (int i = 0; i < list.count(); i++) {
0104         QDomElement e = list.at(i).toElement();
0105         if (e.attribute("name") == name) {
0106             return std::make_unique<QDomElement>(e);
0107         }
0108     }
0109     return nullptr;
0110 }