Skip to content
Merged
28 changes: 13 additions & 15 deletions LoopLibCore/sources/pdfdiff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
#include "pdfjobscheduler.h"
#include "pdfpainter.h"

#include <QCryptographicHash>
#include <QUuid>
#include <QXmlStreamWriter>

#include "pdfdbgheap.h"

Expand Down Expand Up @@ -90,7 +92,6 @@ PDFDiff::PDFDiff(QObject* parent) :
m_cancelled(false),
m_textAnalysisAlgorithm(PDFDocumentTextFlowFactory::Algorithm::Layout)
{

}

PDFDiff::~PDFDiff()
Expand Down Expand Up @@ -152,7 +153,7 @@ void PDFDiff::start()
spec.operationId = QStringLiteral("pdf.diff");

m_activeJobId = pdf::PDFJobScheduler::global().submit(spec, [this](pdf::PDFJobContext& context)
{
{
if (context.isCancellationRequested())
{
m_cancelled = true;
Expand Down Expand Up @@ -259,7 +260,7 @@ void PDFDiff::stepProgress()
struct PDFDiffPageContext
{
PDFInteger pageIndex = 0;
std::array<uint8_t, 64> pageHash = { };
std::array<uint8_t, 64> pageHash = {};
PDFPrecompiledPage::GraphicPieceInfos graphicPieces;
PDFDocumentTextFlow text;
};
Expand Down Expand Up @@ -377,13 +378,13 @@ void PDFDiff::performSteps(const std::vector<PDFInteger>& leftPages,
std::vector<PDFDiffPageContext> rightPreparedPages;

PDFDiffHelper::PageSequence pageSequence;
std::map<size_t, size_t> pageMatches; // Indices are real page indices, not indices to page contexts
std::map<size_t, size_t> pageMatches; // Indices are real page indices, not indices to page contexts

auto createDiffPageContext = [](auto pageIndex)
{
PDFDiffPageContext context;
context.pageIndex = pageIndex;
return context;
PDFDiffPageContext context;
context.pageIndex = pageIndex;
return context;
};
std::transform(leftPages.cbegin(), leftPages.cend(), std::back_inserter(leftPreparedPages), createDiffPageContext);
std::transform(rightPages.cbegin(), rightPages.cend(), std::back_inserter(rightPreparedPages), createDiffPageContext);
Expand Down Expand Up @@ -731,7 +732,7 @@ void PDFDiff::performCompare(const std::vector<PDFDiffPageContext>& leftPrepared
compareCharacters);
algorithm.perform();
PDFAlgorithmLongestCommonSubsequenceBase::Sequence sequence = algorithm.getSequence();
PDFAlgorithmLongestCommonSubsequenceBase::markSequence(sequence, { }, { });
PDFAlgorithmLongestCommonSubsequenceBase::markSequence(sequence, {}, {});
PDFAlgorithmLongestCommonSubsequenceBase::SequenceItemRanges modifiedRanges = PDFAlgorithmLongestCommonSubsequenceBase::getModifiedRanges(sequence);

// Merge modified sequences separated by just space
Expand Down Expand Up @@ -813,9 +814,9 @@ void PDFDiff::performCompare(const std::vector<PDFDiffPageContext>& leftPrepared
pageIndex1 = textItem->pageIndex;
}

if (static_cast< std::size_t >( textCompareItem.charIndex ) + textCompareItem.charCount <= textItem->characterBoundingRects.size())
if (static_cast<std::size_t>(textCompareItem.charIndex) + textCompareItem.charCount <= textItem->characterBoundingRects.size())
{
const size_t startIndex = textCompareItem.charIndex;
const size_t startIndex = textCompareItem.charIndex;
const size_t endIndex = startIndex + textCompareItem.charCount;

for (size_t i = startIndex; i < endIndex; ++i)
Expand All @@ -841,9 +842,9 @@ void PDFDiff::performCompare(const std::vector<PDFDiffPageContext>& leftPrepared
pageIndex2 = textItem->pageIndex;
}

if (static_cast< std::size_t >(textCompareItem.charIndex) + textCompareItem.charCount <= textItem->characterBoundingRects.size())
if (static_cast<std::size_t>(textCompareItem.charIndex) + textCompareItem.charCount <= textItem->characterBoundingRects.size())
{
const size_t startIndex = textCompareItem.charIndex;
const size_t startIndex = textCompareItem.charIndex;
const size_t endIndex = startIndex + textCompareItem.charCount;

for (size_t i = startIndex; i < endIndex; ++i)
Expand Down Expand Up @@ -973,7 +974,6 @@ void PDFDiff::setTextAnalysisAlgorithm(PDFDocumentTextFlowFactory::Algorithm tex
PDFDiffResult::PDFDiffResult() :
m_result(true)
{

}

void PDFDiffResult::addPageMoved(PDFInteger pageIndex1, PDFInteger pageIndex2)
Expand Down Expand Up @@ -1839,12 +1839,10 @@ PDFDiffResultNavigator::PDFDiffResultNavigator(QObject* parent) :
m_diffResult(nullptr),
m_currentIndex(0)
{

}

PDFDiffResultNavigator::~PDFDiffResultNavigator()
{

}

void PDFDiffResultNavigator::setResult(const PDFDiffResult* diffResult)
Expand Down
51 changes: 25 additions & 26 deletions LoopLibCore/sources/pdfdiff.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ class LOOPLIBCORESHARED_EXPORT PDFDiffResult

enum class Type : uint32_t
{
Invalid = 0x0000,
PageMoved = 0x0001,
PageAdded = 0x0002,
PageRemoved = 0x0004,
RemovedTextCharContent = 0x0008,
RemovedVectorGraphicContent = 0x0010,
RemovedImageContent = 0x0020,
RemovedShadingContent = 0x0040,
AddedTextCharContent = 0x0080,
AddedVectorGraphicContent = 0x0100,
AddedImageContent = 0x0200,
AddedShadingContent = 0x0400,
TextReplaced = 0x0800,
TextAdded = 0x1000,
TextRemoved = 0x2000,
Invalid = 0x0000,
PageMoved = 0x0001,
PageAdded = 0x0002,
PageRemoved = 0x0004,
RemovedTextCharContent = 0x0008,
RemovedVectorGraphicContent = 0x0010,
RemovedImageContent = 0x0020,
RemovedShadingContent = 0x0040,
AddedTextCharContent = 0x0080,
AddedVectorGraphicContent = 0x0100,
AddedImageContent = 0x0200,
AddedShadingContent = 0x0400,
TextReplaced = 0x0800,
TextAdded = 0x1000,
TextRemoved = 0x2000,
};

struct PageSequenceItem
Expand Down Expand Up @@ -232,7 +232,7 @@ class LOOPLIBCORESHARED_EXPORT PDFDiffResult
void addRectRight(Difference& difference, QRectF rect);

Differences m_differences;
RectInfos m_rects; ///< Rectangles with page indices
RectInfos m_rects; ///< Rectangles with page indices
PDFOperationResult m_result;
QStringList m_strings;
uint32_t m_typeFlags = 0;
Expand Down Expand Up @@ -300,14 +300,14 @@ class LOOPLIBCORESHARED_EXPORT PDFDiff : public QObject

enum Option
{
None = 0x0000,
Asynchronous = 0x0001, ///< Compare document asynchronously
PC_Text = 0x0002, ///< Use text to compare pages (determine, which pages correspond to each other)
PC_VectorGraphics = 0x0004, ///< Use vector graphics to compare pages (determine, which pages correspond to each other)
PC_Images = 0x0008, ///< Use images to compare pages (determine, which pages correspond to each other)
PC_Mesh = 0x0010, ///< Use mesh to compare pages (determine, which pages correspond to each other)
CompareTextsAsVector = 0x0020, ///< Compare texts as vector graphics
CompareWords = 0x0040, ///< Compare words, not just characters
None = 0x0000,
Asynchronous = 0x0001, ///< Compare document asynchronously
PC_Text = 0x0002, ///< Use text to compare pages (determine, which pages correspond to each other)
PC_VectorGraphics = 0x0004, ///< Use vector graphics to compare pages (determine, which pages correspond to each other)
PC_Images = 0x0008, ///< Use images to compare pages (determine, which pages correspond to each other)
PC_Mesh = 0x0010, ///< Use mesh to compare pages (determine, which pages correspond to each other)
CompareTextsAsVector = 0x0020, ///< Compare texts as vector graphics
CompareWords = 0x0040, ///< Compare words, not just characters
};
Q_DECLARE_FLAGS(Options, Option)

Expand Down Expand Up @@ -356,7 +356,6 @@ class LOOPLIBCORESHARED_EXPORT PDFDiff : public QObject
void comparationFinished();

private:

enum Steps
{
StepExtractContentLeftDocument,
Expand Down Expand Up @@ -409,4 +408,4 @@ class LOOPLIBCORESHARED_EXPORT PDFDiff : public QObject

} // namespace pdf

#endif // PDFDIFF_H
#endif // PDFDIFF_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"schema_kind": "loop-lifecycle-trace",
"schema_version": 1,
"seed": 539363361,
"initial_artifact_digest": "161a1beb41c008069762349ccae021ac2276deb2314aed2cdcb746a485f4dbcf",
"commands": [
{
"index": 0,
"kind": "open",
"argument": "9073021129658994722"
},
{
"index": 1,
"kind": "save-reopen",
"argument": "5643642477061534660"
}
],
"expected_invariants": [
"source-immutable",
"cancel-is-terminal",
"stale-results-rejected",
"history-append-only"
],
"observed_result": "rollback-history-mutated",
"shrink_history": [
64,
2
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"schema_kind": "loop-lifecycle-trace",
"schema_version": 1,
"seed": 539363361,
"initial_artifact_digest": "161a1beb41c008069762349ccae021ac2276deb2314aed2cdcb746a485f4dbcf",
"commands": [
{
"index": 0,
"kind": "open",
"argument": "9073021129658994722"
}
],
"expected_invariants": [
"source-immutable",
"cancel-is-terminal",
"stale-results-rejected",
"history-append-only"
],
"observed_result": "source-overwritten",
"shrink_history": [
64,
1
]
}
24 changes: 24 additions & 0 deletions UnitTests/testdata/lifecycle/failure-stale-result-minimized.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"schema_kind": "loop-lifecycle-trace",
"schema_version": 1,
"seed": 539363361,
"initial_artifact_digest": "161a1beb41c008069762349ccae021ac2276deb2314aed2cdcb746a485f4dbcf",
"commands": [
{
"index": 0,
"kind": "open",
"argument": "9073021129658994722"
}
],
"expected_invariants": [
"source-immutable",
"cancel-is-terminal",
"stale-results-rejected",
"history-append-only"
],
"observed_result": "stale-result-accepted",
"shrink_history": [
64,
1
]
}
59 changes: 59 additions & 0 deletions UnitTests/testdata/lifecycle/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"schema_kind": "loop-lifecycle-corpus",
"schema_version": 1,
"max_commands": 64,
"initial_artifact_digest": "161a1beb41c008069762349ccae021ac2276deb2314aed2cdcb746a485f4dbcf",
"passing_traces": [
{
"seed": 539363361,
"trace_file": "seed-20260821.json",
"command_count": 64,
"sha256": "3e1f42af36600a36a81e67fa57fcd580db12bbfe99f7dd539d592a5cde1f70ed",
"observed_result": "invariants-held"
},
{
"seed": 539363585,
"trace_file": "seed-20260901.json",
"command_count": 64,
"sha256": "1a86d6679ee11d4bd8fd66aa2fb90ac41b0d6a70c1d0efa0d798158ca5488fb6",
"observed_result": "invariants-held"
},
{
"seed": 539363590,
"trace_file": "seed-20260906.json",
"command_count": 64,
"sha256": "d5d2ae6d4dbee887dd454cbe262938bbd78f8d286a5d802e784e1eecde436d19",
"observed_result": "invariants-held"
},
{
"seed": 539365889,
"trace_file": "seed-20261201.json",
"command_count": 64,
"sha256": "13c6207cfaea9553f3a62d59a91b6b1fe22c3fae2c46405cc6309e5d9bc3cd67",
"observed_result": "invariants-held"
}
],
"failure_traces": [
{
"trace_file": "failure-stale-result-minimized.json",
"replay_profile": "inject-stale-acceptance",
"expected_violation": "stale-result-accepted",
"command_count": 1,
"sha256": "d4eb0ed9fc6819f98ba9b3361faf854e7a04e6b1bae510280659baaa20e508d9"
},
{
"trace_file": "failure-source-overwritten-minimized.json",
"replay_profile": "inject-source-overwrite",
"expected_violation": "source-overwritten",
"command_count": 1,
"sha256": "f0af352cb2c2587ee46dcbfe7adac9e880de124f62c65d06a5763ca087fde950"
},
{
"trace_file": "failure-rollback-history-minimized.json",
"replay_profile": "inject-history-mutation",
"expected_violation": "rollback-history-mutated",
"command_count": 2,
"sha256": "01d976d572d0b0be3f063085f45ec4bd6bc2536eb0502a54e5658fcf53c1664b"
}
]
}
Loading
Loading