Commit 814bf013 authored by Nicolas Carion's avatar Nicolas Carion
Browse files

enable fuzzing on more functions

parent c0afe32d
Pipeline #1641 passed with stage
in 14 minutes and 33 seconds
......@@ -127,7 +127,8 @@ void EffectsRepository::parseCustomAssetFile(const QString &file_name, std::unor
continue;
}
if (customAssets.count(result.id) > 0) {
qDebug() << "Warning: duplicate custom definition of effect" << result.id << "found. Only last one will be considered";
qDebug() << "Warning: duplicate custom definition of effect" << result.id << "found. Only last one will be considered. Duplicate found in"
<< file_name;
}
result.xml = currentEffect;
......
......@@ -21,6 +21,7 @@
#include "logger.hpp"
#include "bin/projectitemmodel.h"
#include "timeline2/model/timelinefunctions.hpp"
#include "timeline2/model/timelinemodel.hpp"
#include <QString>
#include <fstream>
......@@ -75,6 +76,11 @@ void Logger::init()
incr_ind(incr_ind);
}
for (const auto &m : rttr::type::get<TimelineFunctions>().get_methods()) {
translation_table[m.get_name().to_string()] = cur_ind;
incr_ind(incr_ind);
}
for (const auto &i : translation_table) {
back_translation_table[i.second] = i.first;
}
......
......@@ -131,6 +131,13 @@ protected:
Logger::log(this, __FUNCTION__, {__VA_ARGS__}); \
}
/// Same as TRACE, but called from a static function
#define TRACE_STATIC(ptr, ...) \
LogGuard __guard; \
if (__guard.hasGuard()) { \
Logger::log(ptr.get(), __FUNCTION__, {__VA_ARGS__}); \
}
/// See Logger::log_res
#define TRACE_RES(res) \
if (__guard.hasGuard()) { \
......
......@@ -30,6 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "doc/kdenlivedoc.h"
#include "effects/effectstack/model/effectstackmodel.hpp"
#include "groupsmodel.hpp"
#include "logger.hpp"
#include "timelineitemmodel.hpp"
#include "trackmodel.hpp"
#include "transitions/transitionsrepository.hpp"
......@@ -40,6 +41,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <klocalizedstring.h>
#include <unordered_map>
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wsign-conversion"
#pragma GCC diagnostic ignored "-Wfloat-equal"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wpedantic"
#include <rttr/registration>
#pragma GCC diagnostic pop
RTTR_REGISTRATION
{
using namespace rttr;
registration::class_<TimelineFunctions>("TimelineFunctions")
.method("requestClipCut", select_overload<bool(std::shared_ptr<TimelineItemModel>, int, int)>(&TimelineFunctions::requestClipCut))(
parameter_names("timeline", "clipId", "position"));
}
bool TimelineFunctions::cloneClip(const std::shared_ptr<TimelineItemModel> &timeline, int clipId, int &newId, PlaylistState::ClipState state, Fun &undo,
Fun &redo)
{
......@@ -131,10 +149,12 @@ bool TimelineFunctions::requestClipCut(std::shared_ptr<TimelineItemModel> timeli
{
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
TRACE_STATIC(timeline, clipId, position);
bool result = TimelineFunctions::requestClipCut(timeline, clipId, position, undo, redo);
if (result) {
pCore->pushUndo(undo, redo, i18n("Cut clip"));
}
TRACE_RES(result);
return result;
}
......
......@@ -82,7 +82,20 @@ RTTR_REGISTRATION
.method("requestClearSelection", select_overload<void(bool)>(&TimelineModel::requestClearSelection))(parameter_names("onDeletion"))
.method("requestAddToSelection", &TimelineModel::requestAddToSelection)(parameter_names("itemId", "clear"))
.method("requestRemoveFromSelection", &TimelineModel::requestRemoveFromSelection)(parameter_names("itemId"))
.method("requestSetSelection", select_overload<bool(const std::unordered_set<int> &)>(&TimelineModel::requestSetSelection))(parameter_names("itemIds"));
.method("requestSetSelection", select_overload<bool(const std::unordered_set<int> &)>(&TimelineModel::requestSetSelection))(parameter_names("itemIds"))
.method("requestFakeClipMove", select_overload<bool(int, int, int, bool, bool, bool)>(&TimelineModel::requestFakeClipMove))(
parameter_names("clipId", "trackId", "position", "updateView", "logUndo", "invalidateTimeline"))
.method("requestFakeGroupMove", select_overload<bool(int, int, int, int, bool, bool)>(&TimelineModel::requestFakeGroupMove))
// (parameter_names("clipId", "groupId", "delta_track", "delta_pos", "updateView" "logUndo"))
.method("suggestClipMove", &TimelineModel::suggestClipMove)(parameter_names("clipId", "trackId", "position", "cursorPosition", "snapDistance"))
.method("suggestCompositionMove",
&TimelineModel::suggestCompositionMove)(parameter_names("compoId", "trackId", "position", "cursorPosition", "snapDistance"))
.method("addSnap", &TimelineModel::addSnap)(parameter_names("pos"))
.method("removeSnap", &TimelineModel::addSnap)(parameter_names("pos"))
// .method("requestCompositionInsertion", select_overload<bool(const QString &, int, int, int, std::unique_ptr<Mlt::Properties>, int &, bool)>(
// &TimelineModel::requestCompositionInsertion))(
// parameter_names("transitionId", "trackId", "position", "length", "transProps", "id", "logUndo"))
.method("requestClipTimeWarp", select_overload<bool(int, double)>(&TimelineModel::requestClipTimeWarp))(parameter_names("clipId", "speed"));
}
int TimelineModel::next_id = 0;
......@@ -461,7 +474,7 @@ bool TimelineModel::normalEdit() const
return m_editMode == TimelineMode::NormalEdit;
}
bool TimelineModel::fakeClipMove(int clipId, int trackId, int position, bool updateView, bool invalidateTimeline, Fun &undo, Fun &redo)
bool TimelineModel::requestFakeClipMove(int clipId, int trackId, int position, bool updateView, bool invalidateTimeline, Fun &undo, Fun &redo)
{
Q_UNUSED(updateView);
Q_UNUSED(invalidateTimeline);
......@@ -560,8 +573,10 @@ bool TimelineModel::requestClipMove(int clipId, int trackId, int position, bool
bool TimelineModel::requestFakeClipMove(int clipId, int trackId, int position, bool updateView, bool logUndo, bool invalidateTimeline)
{
QWriteLocker locker(&m_lock);
TRACE(clipId, trackId, position, updateView, logUndo, invalidateTimeline)
Q_ASSERT(m_allClips.count(clipId) > 0);
if (m_allClips[clipId]->getPosition() == position && getClipTrackId(clipId) == trackId) {
TRACE_RES(true);
return true;
}
if (m_groups->isInGroup(clipId)) {
......@@ -572,14 +587,17 @@ bool TimelineModel::requestFakeClipMove(int clipId, int trackId, int position, b
int track_pos2 = getTrackPosition(current_trackId);
int delta_track = track_pos1 - track_pos2;
int delta_pos = position - m_allClips[clipId]->getPosition();
return requestFakeGroupMove(clipId, groupId, delta_track, delta_pos, updateView, logUndo);
bool res = requestFakeGroupMove(clipId, groupId, delta_track, delta_pos, updateView, logUndo);
TRACE_RES(res);
return res;
}
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
bool res = fakeClipMove(clipId, trackId, position, updateView, invalidateTimeline, undo, redo);
bool res = requestFakeClipMove(clipId, trackId, position, updateView, invalidateTimeline, undo, redo);
if (res && logUndo) {
PUSH_UNDO(undo, redo, i18n("Move clip"));
}
TRACE_RES(res);
return res;
}
......@@ -648,10 +666,10 @@ int TimelineModel::suggestItemMove(int itemId, int trackId, int position, int cu
return suggestCompositionMove(itemId, trackId, position, cursorPosition, snapDistance);
}
int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int cursorPosition, int snapDistance, bool allowViewUpdate)
int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int cursorPosition, int snapDistance)
{
Q_UNUSED(allowViewUpdate);
QWriteLocker locker(&m_lock);
TRACE(clipId, trackId, position, cursorPosition, snapDistance);
Q_ASSERT(isClip(clipId));
Q_ASSERT(isTrack(trackId));
int currentPos = getClipPosition(clipId);
......@@ -661,6 +679,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int cu
trackId = sourceTrackId;
}
if (currentPos == position && sourceTrackId == trackId) {
TRACE_RES(position);
return position;
}
bool after = position > currentPos;
......@@ -681,8 +700,8 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int cu
}
}
int snapped = requestBestSnapPos(position, m_allClips[clipId]->getPlaytime(), m_editMode == TimelineMode::NormalEdit ? ignored_pts : std::vector<int>(),
cursorPosition, snapDistance);
int snapped = getBestSnapPos(position, m_allClips[clipId]->getPlaytime(), m_editMode == TimelineMode::NormalEdit ? ignored_pts : std::vector<int>(),
cursorPosition, snapDistance);
// qDebug() << "Starting suggestion " << clipId << position << currentPos << "snapped to " << snapped;
if (snapped >= 0) {
position = snapped;
......@@ -695,6 +714,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int cu
possible = requestClipMoveAttempt(clipId, trackId, position);
}*/
if (possible) {
TRACE_RES(position);
return position;
}
// Find best possible move
......@@ -707,6 +727,7 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int cu
if (!possible) {
qDebug() << "CANNOT MOVE CLIP : " << clipId << " ON TK: " << trackId << ", AT POS: " << position;
} else {
TRACE_RES(position);
return position;
}
}
......@@ -720,9 +741,11 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int cu
position = currentPos - blank_length;
}
} else {
TRACE_RES(currentPos);
return currentPos;
}
possible = requestClipMove(clipId, trackId, position, true, false, false);
TRACE_RES(possible ? position : currentPos);
return possible ? position : currentPos;
}
// find best pos for groups
......@@ -778,15 +801,18 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int cu
int updatedPos = currentPos + (after ? blank_length : -blank_length);
possible = requestClipMove(clipId, trackId, updatedPos, true, false, false);
if (possible) {
TRACE_RES(updatedPos);
return updatedPos;
}
}
TRACE_RES(currentPos);
return currentPos;
}
int TimelineModel::suggestCompositionMove(int compoId, int trackId, int position, int cursorPosition, int snapDistance)
{
QWriteLocker locker(&m_lock);
TRACE(compoId, trackId, position, cursorPosition, snapDistance);
Q_ASSERT(isComposition(compoId));
Q_ASSERT(isTrack(trackId));
int currentPos = getCompositionPosition(compoId);
......@@ -796,6 +822,7 @@ int TimelineModel::suggestCompositionMove(int compoId, int trackId, int position
trackId = currentTrack;
}
if (currentPos == position && currentTrack == trackId) {
TRACE_RES(position);
return position;
}
......@@ -820,7 +847,7 @@ int TimelineModel::suggestCompositionMove(int compoId, int trackId, int position
ignored_pts.push_back(out);
}
int snapped = requestBestSnapPos(position, m_allCompositions[compoId]->getPlaytime(), ignored_pts, cursorPosition, snapDistance);
int snapped = getBestSnapPos(position, m_allCompositions[compoId]->getPlaytime(), ignored_pts, cursorPosition, snapDistance);
qDebug() << "Starting suggestion " << compoId << position << currentPos << "snapped to " << snapped;
if (snapped >= 0) {
position = snapped;
......@@ -830,6 +857,7 @@ int TimelineModel::suggestCompositionMove(int compoId, int trackId, int position
bool possible = requestCompositionMove(compoId, trackId, position, true, false);
qDebug() << "Original move success" << possible;
if (possible) {
TRACE_RES(position);
return position;
}
/*bool after = position > currentPos;
......@@ -842,6 +870,7 @@ int TimelineModel::suggestCompositionMove(int compoId, int trackId, int position
return currentPos - blank_length;
}
return position;*/
TRACE_RES(currentPos);
return currentPos;
}
......@@ -1151,12 +1180,14 @@ std::unordered_set<int> TimelineModel::getItemsInRange(int trackId, int start, i
bool TimelineModel::requestFakeGroupMove(int clipId, int groupId, int delta_track, int delta_pos, bool updateView, bool logUndo)
{
TRACE(clipId, groupId, delta_track, delta_pos, updateView, logUndo);
std::function<bool(void)> undo = []() { return true; };
std::function<bool(void)> redo = []() { return true; };
bool res = requestFakeGroupMove(clipId, groupId, delta_track, delta_pos, updateView, logUndo, undo, redo);
if (res && logUndo) {
PUSH_UNDO(undo, redo, i18n("Move group"));
}
TRACE_RES(res);
return res;
}
......@@ -2064,7 +2095,7 @@ int TimelineModel::suggestSnapPoint(int pos, int snapDistance)
return (qAbs(snapped - pos) < snapDistance ? snapped : pos);
}
int TimelineModel::requestBestSnapPos(int pos, int length, const std::vector<int> &pts, int cursorPosition, int snapDistance)
int TimelineModel::getBestSnapPos(int pos, int length, const std::vector<int> &pts, int cursorPosition, int snapDistance)
{
if (!pts.empty()) {
m_snaps->ignore(pts);
......@@ -2088,23 +2119,25 @@ int TimelineModel::requestBestSnapPos(int pos, int length, const std::vector<int
return -1;
}
int TimelineModel::requestNextSnapPos(int pos)
int TimelineModel::getNextSnapPos(int pos)
{
return m_snaps->getNextPoint(pos);
}
int TimelineModel::requestPreviousSnapPos(int pos)
int TimelineModel::getPreviousSnapPos(int pos)
{
return m_snaps->getPreviousPoint(pos);
}
void TimelineModel::addSnap(int pos)
{
TRACE(pos);
return m_snaps->addPoint(pos);
}
void TimelineModel::removeSnap(int pos)
{
TRACE(pos);
return m_snaps->removePoint(pos);
}
......@@ -2120,12 +2153,14 @@ bool TimelineModel::requestCompositionInsertion(const QString &transitionId, int
int &id, bool logUndo)
{
QWriteLocker locker(&m_lock);
// TRACE(transitionId, trackId, position, length, transProps.get(), id, logUndo);
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool result = requestCompositionInsertion(transitionId, trackId, -1, position, length, std::move(transProps), id, undo, redo, logUndo);
if (result && logUndo) {
PUSH_UNDO(undo, redo, i18n("Insert Composition"));
}
// TRACE_RES(result);
return result;
}
......@@ -2781,6 +2816,8 @@ bool TimelineModel::requestClipTimeWarp(int clipId, double speed, Fun &undo, Fun
bool TimelineModel::requestClipTimeWarp(int clipId, double speed)
{
QWriteLocker locker(&m_lock);
TRACE(clipId, speed);
Fun undo = []() { return true; };
Fun redo = []() { return true; };
// Get main clip info
......@@ -2797,17 +2834,18 @@ bool TimelineModel::requestClipTimeWarp(int clipId, double speed)
} else {
pCore->displayMessage(i18n("Change speed failed"), ErrorMessage);
undo();
TRACE_RES(false);
return false;
}
} else {
// If clip is not inserted on a track, we just change the producer
m_allClips[clipId]->useTimewarpProducer(speed, undo, redo);
result = m_allClips[clipId]->useTimewarpProducer(speed, undo, redo);
}
if (result) {
PUSH_UNDO(undo, redo, i18n("Change clip speed"));
return true;
}
return false;
TRACE_RES(result);
return result;
}
const QString TimelineModel::getTrackTagById(int trackId) const
......
......@@ -345,7 +345,7 @@ public:
bool requestCompositionMove(int transid, int trackId, int compositionTrack, int position, bool updateView, bool finalMove, Fun &undo, Fun &redo);
/* When timeline edit mode is insert or overwrite, we fake the move (as it will overlap existing clips, and only process the real move on drop */
bool fakeClipMove(int clipId, int trackId, int position, bool updateView, bool invalidateTimeline, Fun &undo, Fun &redo);
bool requestFakeClipMove(int clipId, int trackId, int position, bool updateView, bool invalidateTimeline, Fun &undo, Fun &redo);
bool requestFakeClipMove(int clipId, int trackId, int position, bool updateView, bool logUndo, bool invalidateTimeline);
bool requestFakeGroupMove(int clipId, int groupId, int delta_track, int delta_pos, bool updateView = true, bool logUndo = true);
bool requestFakeGroupMove(int clipId, int groupId, int delta_track, int delta_pos, bool updateView, bool finalMove, Fun &undo, Fun &redo,
......@@ -362,7 +362,7 @@ public:
@param dontRefreshMasterClip when false, no view refresh is attempted
*/
Q_INVOKABLE int suggestItemMove(int itemId, int trackId, int position, int cursorPosition, int snapDistance = -1);
Q_INVOKABLE int suggestClipMove(int clipId, int trackId, int position, int cursorPosition, int snapDistance = -1, bool allowViewUpdate = true);
Q_INVOKABLE int suggestClipMove(int clipId, int trackId, int position, int cursorPosition, int snapDistance = -1);
Q_INVOKABLE int suggestCompositionMove(int compoId, int trackId, int position, int cursorPosition, int snapDistance = -1);
/* @brief Request clip insertion at given position. This action is undoable
......@@ -380,6 +380,8 @@ public:
/* Same function, but accumulates undo and redo*/
bool requestClipInsertion(const QString &binClipId, int trackId, int position, int &id, bool logUndo, bool refreshView, bool useTargets, Fun &undo,
Fun &redo);
protected:
/* @brief Creates a new clip instance without inserting it.
This action is undoable, returns true on success
@param binClipId: Bin id of the clip to insert
......@@ -388,6 +390,7 @@ public:
*/
bool requestClipCreation(const QString &binClipId, int &id, PlaylistState::ClipState state, double speed, Fun &undo, Fun &redo);
public:
/* @brief Deletes the given clip or composition from the timeline This
action is undoable Returns true on success. If it fails, nothing is
modified. If the clip/composition is in a group, the call is deferred to
......@@ -498,6 +501,7 @@ public:
*/
void setUndoStack(std::weak_ptr<DocUndoStack> undo_stack);
protected:
/* @brief Requests the best snapped position for a clip
@param pos is the clip's requested position
@param length is the clip's duration
......@@ -505,17 +509,18 @@ public:
@param snapDistance the maximum distance for a snap result, -1 for no snapping
@returns best snap position or -1 if no snap point is near
*/
int requestBestSnapPos(int pos, int length, const std::vector<int> &pts = std::vector<int>(), int cursorPosition = 0, int snapDistance = -1);
int getBestSnapPos(int pos, int length, const std::vector<int> &pts = std::vector<int>(), int cursorPosition = 0, int snapDistance = -1);
public:
/* @brief Requests the next snapped point
@param pos is the current position
*/
int requestNextSnapPos(int pos);
int getNextSnapPos(int pos);
/* @brief Requests the previous snapped point
@param pos is the current position
*/
int requestPreviousSnapPos(int pos);
int getPreviousSnapPos(int pos);
/* @brief Add a new snap point
@param pos is the current position
......
......@@ -494,12 +494,12 @@ void TimelineController::deleteTrack(int tid)
void TimelineController::gotoNextSnap()
{
setPosition(m_model->requestNextSnapPos(timelinePosition()));
setPosition(m_model->getNextSnapPos(timelinePosition()));
}
void TimelineController::gotoPreviousSnap()
{
setPosition(m_model->requestPreviousSnapPos(timelinePosition()));
setPosition(m_model->getPreviousSnapPos(timelinePosition()));
}
void TimelineController::groupSelection()
......
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