Commit 382ec1a0 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Add test for regression issue #1494

parent 6146c1b8
Pipeline #211316 passed with stage
in 7 minutes and 12 seconds
......@@ -478,14 +478,16 @@ bool Core::setCurrentProfile(const QString &profilePath)
// inform render widget
m_timecode.setFormat(profileFromRepository->fps());
profileChanged();
emit m_mainWindow->updateRenderWidgetProfile();
m_monitorManager->resetProfiles();
emit m_monitorManager->updatePreviewScaling();
if (m_guiConstructed && m_mainWindow->hasTimeline() && m_mainWindow->getCurrentTimeline()->model()) {
m_mainWindow->getCurrentTimeline()->model()->updateProfile(getProjectProfile());
m_mainWindow->getCurrentTimeline()->model()->updateFieldOrderFilter(getCurrentProfile());
checkProfileValidity();
emit m_mainWindow->getCurrentTimeline()->controller()->frameFormatChanged();
if (m_guiConstructed) {
emit m_mainWindow->updateRenderWidgetProfile();
m_monitorManager->resetProfiles();
emit m_monitorManager->updatePreviewScaling();
if (m_mainWindow->hasTimeline() && m_mainWindow->getCurrentTimeline()->model()) {
m_mainWindow->getCurrentTimeline()->model()->updateProfile(getProjectProfile());
m_mainWindow->getCurrentTimeline()->model()->updateFieldOrderFilter(getCurrentProfile());
checkProfileValidity();
emit m_mainWindow->getCurrentTimeline()->controller()->frameFormatChanged();
}
}
return true;
}
......
......@@ -133,6 +133,17 @@ KdenliveDoc::KdenliveDoc(const QUrl &url, QDomDocument& newDom, QString projectF
updateClipsCount();
}
KdenliveDoc::KdenliveDoc(MainWindow *parent)
: QObject(parent)
, uuid(QUuid::createUuid())
, m_autosave(nullptr)
, m_clipsCount(0)
, m_modified(false)
, m_documentOpenStatus(CleanProject)
{
initializeProperties();
}
DocOpenResult KdenliveDoc::Open(const QUrl &url, const QString &projectFolder, QUndoGroup *undoGroup,
bool recoverCorruption, MainWindow *parent)
{
......
......@@ -93,6 +93,8 @@ public:
/** @brief Open an existing Kdenlive project, returning nothing if the project cannot be opened. */
static DocOpenResult Open(const QUrl &url, const QString &projectFolder, QUndoGroup *undoGroup,
bool recoverCorruption, MainWindow *parent = nullptr);
/** @brief Create a dummy project, used for testing. */
KdenliveDoc(MainWindow *parent = nullptr);
~KdenliveDoc() override;
friend class LoadJob;
/** @brief Get current document's producer. */
......
......@@ -270,8 +270,7 @@ void ProjectManager::testSetActiveDocument(KdenliveDoc *doc, std::shared_ptr<Tim
bool ProjectManager::testSaveFileAs(const QString &outputFileName)
{
QString saveFolder = QFileInfo(outputFileName).absolutePath();
QMap<QString, QString> docProperties;
docProperties.insert(QStringLiteral("version"), QString::number(m_project->getDocumentVersion()));
QMap<QString, QString> docProperties = m_project->documentProperties();
docProperties.insert(QStringLiteral("timelineHash"), m_mainTimelineModel->timelineHash().toHex());
pCore->projectItemModel()->saveDocumentProperties(docProperties, QMap<QString, QString>(), m_project->getGuideModel());
QString scene = m_mainTimelineModel->sceneList(saveFolder);
......
......@@ -27,7 +27,8 @@ TEST_CASE("Save File", "[SF]")
SECTION("Simple insert and save")
{
// Create document
Mock<KdenliveDoc> docMock;
KdenliveDoc document(nullptr);
Mock<KdenliveDoc> docMock(document);
// When(Method(docMock, getDocumentProperty)).AlwaysDo([](const QString &name, const QString &defaultValue) {
// Q_UNUSED(name) Q_UNUSED(defaultValue)
// qDebug() << "Intercepted call";
......@@ -43,8 +44,7 @@ TEST_CASE("Save File", "[SF]")
ProjectManager &mocked = pmMock.get();
pCore->m_projectManager = &mocked;
pCore->m_projectManager->m_project = &mockedDoc;
pCore->m_projectManager->m_project->m_guideModel = guideModel;
mockedDoc.m_guideModel = guideModel;
// We also mock timeline object to spy few functions and mock others
TimelineItemModel tim(&profile_file, undoStack);
......@@ -110,7 +110,8 @@ TEST_CASE("Save File", "[SF]")
SECTION("Reopen and check in/out points")
{
// Create new document
Mock<KdenliveDoc> docMock;
KdenliveDoc document(nullptr);
Mock<KdenliveDoc> docMock(document);
KdenliveDoc &mockedDoc = docMock.get();
// We mock the project class so that the undoStack function returns our undoStack, and our mocked document
......@@ -121,8 +122,7 @@ TEST_CASE("Save File", "[SF]")
ProjectManager &mocked = pmMock.get();
pCore->m_projectManager = &mocked;
pCore->m_projectManager->m_project = &mockedDoc;
pCore->m_projectManager->m_project->m_guideModel = guideModel;
mockedDoc.m_guideModel = guideModel;
// We also mock timeline object to spy few functions and mock others
TimelineItemModel tim(&profile_file, undoStack);
......@@ -174,7 +174,8 @@ TEST_CASE("Save File", "[SF]")
SECTION("Open a file with AV clips")
{
// Create new document
Mock<KdenliveDoc> docMock;
KdenliveDoc document(nullptr);
Mock<KdenliveDoc> docMock(document);
KdenliveDoc &mockedDoc = docMock.get();
// We mock the project class so that the undoStack function returns our undoStack, and our mocked document
......@@ -190,8 +191,7 @@ TEST_CASE("Save File", "[SF]")
ProjectManager &mocked = pmMock.get();
pCore->m_projectManager = &mocked;
pCore->m_projectManager->m_project = &mockedDoc;
pCore->m_projectManager->m_project->m_guideModel = guideModel;
mockedDoc.m_guideModel = guideModel;
// We also mock timeline object to spy few functions and mock others
TimelineItemModel tim(&profile_file, undoStack);
......@@ -266,7 +266,8 @@ TEST_CASE("Non-BMP Unicode", "[NONBMP]")
{
// Create document
Mock<KdenliveDoc> docMock;
KdenliveDoc document(nullptr);
Mock<KdenliveDoc> docMock(document);
// When(Method(docMock, getDocumentProperty)).AlwaysDo([](const QString &name, const QString &defaultValue) {
// Q_UNUSED(name) Q_UNUSED(defaultValue)
// qDebug() << "Intercepted call";
......@@ -282,8 +283,7 @@ TEST_CASE("Non-BMP Unicode", "[NONBMP]")
ProjectManager &mocked = pmMock.get();
pCore->m_projectManager = &mocked;
pCore->m_projectManager->m_project = &mockedDoc;
pCore->m_projectManager->m_project->m_guideModel = guideModel;
mockedDoc.m_guideModel = guideModel;
// We also mock timeline object to spy few functions and mock others
TimelineItemModel tim(&profile_file, undoStack);
......@@ -361,6 +361,73 @@ TEST_CASE("Non-BMP Unicode", "[NONBMP]")
REQUIRE(xmldata != nullptr);
CHECK(clipname->text().contains(emojiTestString));
}
SECTION("Save project and check profile")
{
// Create document
KdenliveDoc document(nullptr);
Mock<KdenliveDoc> docMock(document);
// When(Method(docMock, getDocumentProperty)).AlwaysDo([](const QString &name, const QString &defaultValue) {
// Q_UNUSED(name) Q_UNUSED(defaultValue)
// qDebug() << "Intercepted call";
// return QStringLiteral("dummyId");
// });
KdenliveDoc &mockedDoc = docMock.get();
// We mock the project class so that the undoStack function returns our undoStack, and our mocked document
Mock<ProjectManager> pmMock;
When(Method(pmMock, undoStack)).AlwaysReturn(undoStack);
When(Method(pmMock, cacheDir)).AlwaysReturn(QDir(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)));
When(Method(pmMock, current)).AlwaysReturn(&mockedDoc);
ProjectManager &mocked = pmMock.get();
pCore->m_projectManager = &mocked;
mockedDoc.m_guideModel = guideModel;
pCore->setCurrentProfile("atsc_1080p_25");
// We also mock timeline object to spy few functions and mock others
TimelineItemModel tim(&profile_file, undoStack);
Mock<TimelineItemModel> timMock(tim);
auto timeline = std::shared_ptr<TimelineItemModel>(&timMock.get(), [](...) {});
TimelineItemModel::finishConstruct(timeline, guideModel);
mocked.testSetActiveDocument(&mockedDoc, timeline);
QDir dir = QDir::temp();
std::unordered_map<QString, QString> binIdCorresp;
QStringList expandedFolders;
QDomDocument doc = mockedDoc.createEmptyDocument(2, 2);
QScopedPointer<Mlt::Producer> xmlProd(new Mlt::Producer(profile_file, "xml-string", doc.toString().toUtf8()));
Mlt::Service s(*xmlProd);
Mlt::Tractor tractor(s);
binModel->loadBinPlaylist(&tractor, timeline->tractor(), binIdCorresp, expandedFolders, nullptr);
RESET(timMock)
TrackModel::construct(timeline, -1, -1, QString(), true);
TrackModel::construct(timeline, -1, -1, QString(), true);
int tid1 = TrackModel::construct(timeline);
// Setup timeline audio drop info
QMap<int, QString> audioInfo;
audioInfo.insert(1, QStringLiteral("stream1"));
timeline->m_binAudioTargets = audioInfo;
timeline->m_videoTarget = tid1;
mocked.testSaveFileAs(saveFile.fileName());
// open the file and check that it contains the correct profile info
QFile file(saveFile.fileName());
REQUIRE(file.open(QIODevice::ReadOnly));
QByteArray contents = file.readAll();
QString contentCheck("<property name=\"kdenlive:docproperties.profile\">atsc_1080p_25</property>");
if (contents.contains(contentCheck.toUtf8())) {
qDebug() << "File contains test string";
} else {
qDebug() << "File does not contain test string:" << contents;
}
REQUIRE(contents.contains(contentCheck.toUtf8()));
}
binModel->clean();
pCore->m_projectManager = nullptr;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment