MCPcopy Create free account
hub / github.com/KDE/okular / testDocdataMigration

Method testDocdataMigration

autotests/documenttest.cpp:73–129  ·  view source on GitHub ↗

Test that, if there's a XML file in docdata referring to a document, we detect that it must be migrated, that it doesn't get wiped out if you close the document without migrating and that it does get wiped out after migrating

Source from the content-addressed store, hash-verified

71// detect that it must be migrated, that it doesn't get wiped out if you close
72// the document without migrating and that it does get wiped out after migrating
73void DocumentTest::testDocdataMigration()
74{
75 Okular::SettingsCore::instance(QStringLiteral("documenttest"));
76
77 const QUrl testFileUrl = QUrl::fromLocalFile(QStringLiteral(KDESRCDIR "data/file1.pdf"));
78 const QString testFilePath = testFileUrl.toLocalFile();
79 const qint64 testFileSize = QFileInfo(testFilePath).size();
80
81 // Copy XML file to the docdata/ directory
82 const QString docDataPath = Okular::DocumentPrivate::docDataFileName(testFileUrl, testFileSize);
83 QFile::remove(docDataPath);
84 QVERIFY(QFile::copy(QStringLiteral(KDESRCDIR "data/file1-docdata.xml"), docDataPath));
85
86 // Open our document
87 Okular::Document *m_document = new Okular::Document(nullptr);
88 QMimeDatabase db;
89 const QMimeType mime = db.mimeTypeForFile(testFilePath);
90 QCOMPARE(m_document->openDocument(testFilePath, testFileUrl, mime), Okular::Document::OpenSuccess);
91
92 // Check that the annotation from file1-docdata.xml was loaded
93 QCOMPARE(m_document->page(0)->annotations().size(), 1);
94 QCOMPARE(m_document->page(0)->annotations().constFirst()->uniqueName(), QStringLiteral("testannot"));
95
96 // Check that we detect that it must be migrated
97 QVERIFY(m_document->isDocdataMigrationNeeded());
98 m_document->closeDocument();
99
100 // Reopen the document and check that the annotation is still present
101 // (because we have not migrated)
102 QCOMPARE(m_document->openDocument(testFilePath, testFileUrl, mime), Okular::Document::OpenSuccess);
103 QCOMPARE(m_document->page(0)->annotations().size(), 1);
104 QCOMPARE(m_document->page(0)->annotations().constFirst()->uniqueName(), QStringLiteral("testannot"));
105 QVERIFY(m_document->isDocdataMigrationNeeded());
106
107 // Do the migration
108 QTemporaryFile migratedSaveFile(QStringLiteral("%1/okrXXXXXX.pdf").arg(QDir::tempPath()));
109 QVERIFY(migratedSaveFile.open());
110 migratedSaveFile.close();
111 QVERIFY(m_document->saveChanges(migratedSaveFile.fileName()));
112 m_document->docdataMigrationDone();
113 QVERIFY(!m_document->isDocdataMigrationNeeded());
114 m_document->closeDocument();
115
116 // Now the docdata file should have no annotations, let's check
117 QCOMPARE(m_document->openDocument(testFilePath, testFileUrl, mime), Okular::Document::OpenSuccess);
118 QCOMPARE(m_document->page(0)->annotations().size(), 0);
119 QVERIFY(!m_document->isDocdataMigrationNeeded());
120 m_document->closeDocument();
121
122 // And the new file should have 1 annotation, let's check
123 QCOMPARE(m_document->openDocument(migratedSaveFile.fileName(), QUrl::fromLocalFile(migratedSaveFile.fileName()), mime), Okular::Document::OpenSuccess);
124 QCOMPARE(m_document->page(0)->annotations().size(), 1);
125 QVERIFY(!m_document->isDocdataMigrationNeeded());
126 m_document->closeDocument();
127
128 delete m_document;
129}
130

Callers

nothing calls this directly

Calls 12

annotationsMethod · 0.80
uniqueNameMethod · 0.80
saveChangesMethod · 0.80
docdataMigrationDoneMethod · 0.80
sizeMethod · 0.45
openDocumentMethod · 0.45
pageMethod · 0.45
closeDocumentMethod · 0.45
openMethod · 0.45
closeMethod · 0.45
fileNameMethod · 0.45

Tested by

no test coverage detected