Commit 66168f55 authored by Nicolas Carion's avatar Nicolas Carion

tests for bin/timeline consistency

parent a1b0d9b6
......@@ -1219,6 +1219,7 @@ void ProjectClip::setBinEffectsEnabled(bool enabled)
void ProjectClip::registerTimelineClip(std::weak_ptr<TimelineModel> timeline, int clipId)
{
Q_ASSERT(m_registeredClips.count(clipId) == 0);
Q_ASSERT(!timeline.expired());
m_registeredClips[clipId] = std::move(timeline);
}
......
......@@ -57,6 +57,7 @@ class ProjectClip : public AbstractProjectItem, public ClipController
Q_OBJECT
public:
friend bool TimelineModel::checkConsistency(); // for testing
/**
* @brief Constructor; used when loading a project and the producer is already available.
*/
......
......@@ -558,3 +558,15 @@ bool ProjectItemModel::requestCleanup()
pCore->pushUndo(undo, redo, i18n("Clean Project"));
return true;
}
std::vector<QString> ProjectItemModel::getAllClipIds() const
{
std::vector<QString> result;
for (const auto &clip : m_allItems) {
auto c = std::static_pointer_cast<AbstractProjectItem>(clip.second.lock());
if (c->itemType() == AbstractProjectItem::ClipItem) {
result.push_back(c->clipId());
}
}
return result;
}
......@@ -73,6 +73,9 @@ public:
/** @brief Deletes all element and start a fresh model */
void clean();
/** @brief Returns the id of all the clips (excluding folders) */
std::vector<QString> getAllClipIds() const;
/** @brief Convenience method to access root folder */
std::shared_ptr<ProjectFolder> getRootFolder() const;
......
......@@ -74,6 +74,7 @@ void ClipModel::registerClipToBin()
if (!binClip) {
qDebug() << "Error : Bin clip for id: " << m_binClipId << " NOT AVAILABLE!!!";
}
qDebug() << "REGISTRATION " << m_id << "ptr count"<<m_parent.use_count();
binClip->registerTimelineClip(m_parent, m_id);
}
......
......@@ -21,6 +21,8 @@
#include "timelinemodel.hpp"
#include "assets/model/assetparametermodel.hpp"
#include "bin/projectitemmodel.h"
#include "bin/projectclip.h"
#include "clipmodel.hpp"
#include "compositionmodel.hpp"
#include "core.h"
......@@ -89,6 +91,9 @@ TimelineModel::~TimelineModel()
for (auto tracks : all_ids) {
deregisterTrack_lambda(tracks, false)();
}
for (const auto & clip : m_allClips) {
clip.second->deregisterClipToBin();
}
}
int TimelineModel::getTracksCount() const
......@@ -1492,14 +1497,72 @@ bool TimelineModel::unplantComposition(int compoId)
bool TimelineModel::checkConsistency()
{
for (const auto &track : m_iteratorTable) {
if (!(*track.second)->checkConsistency()) {
qDebug() << "Constistency check failed for track" << track.first;
for (const auto &tck : m_iteratorTable) {
auto track = (*tck.second);
//Check parent/children link for tracks
if (auto ptr = track->m_parent.lock()) {
if (ptr.get() != this) {
qDebug() << "Wrong parent for track" << tck.first;
return false;
}
} else {
qDebug() << "NULL parent for track" << tck.first;
return false;
}
// check consistency of track
if (!track->checkConsistency()) {
qDebug() << "Constistency check failed for track" << tck.first;
return false;
}
}
//Check parent/children link for clips
for (const auto &cp : m_allClips) {
auto clip = (cp.second);
//Check parent/children link for tracks
if (auto ptr = clip->m_parent.lock()) {
if (ptr.get() != this) {
qDebug() << "Wrong parent for clip" << cp.first;
return false;
}
} else {
qDebug() << "NULL parent for clip" << cp.first;
return false;
}
}
// We now check consistenty of the compositions. For that, we list all compositions of the tractor, and see if we have a matching one in our
// We check consistency with bin model
auto binClips = pCore->projectItemModel()->getAllClipIds();
// First step: all clips referenced by the bin model exist and are inserted
for (const auto &binClip : binClips) {
auto projClip = pCore->projectItemModel()->getClipByBinID(binClip);
for (const auto &insertedClip : projClip->m_registeredClips) {
if (auto ptr = insertedClip.second.lock()) {
if (ptr.get() == this) { // check we are talking of this timeline
if (!isClip(insertedClip.first)) {
qDebug() << "Bin model registers a bad clip ID" << insertedClip.first;
return false;
}
}
} else {
qDebug() << "Bin model registers a clip in a NULL timeline" << insertedClip.first;
return false;
}
}
}
// Second step: all clips are referenced
for (const auto &clip : m_allClips) {
auto binId = clip.second->m_binClipId;
auto projClip = pCore->projectItemModel()->getClipByBinID(binId);
if (projClip->m_registeredClips.count(clip.first) == 0) {
qDebug() << "Clip " << clip.first << "not registered in bin";
return false;
}
}
// We now check consistency of the compositions. For that, we list all compositions of the tractor, and see if we have a matching one in our
// m_allCompositions
std::unordered_set<int> remaining_compo;
for (const auto &compo : m_allCompositions) {
......
......@@ -543,9 +543,11 @@ protected:
/* @brief Unplant the composition with given Id */
bool unplantComposition(int compoId);
public:
/* @brief Debugging function that checks consistency with Mlt objects */
bool checkConsistency();
protected:
/* @brief Refresh project monitor if cursor was inside range */
void checkRefresh(int start, int end);
......
......@@ -232,6 +232,7 @@ TEST_CASE("Basic creation/deletion of a clip", "[ClipModel]")
TEST_CASE("Clip manipulation", "[ClipModel]")
{
auto binModel = pCore->projectItemModel();
binModel->clean();
std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);
std::shared_ptr<MarkerListModel> guideModel = std::make_shared<MarkerListModel>(undoStack);
......
Markdown is supported
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