MCPcopy Create free account
hub / github.com/TeXworks/texworks / rootFile_data

Method rootFile_data

unit-tests/Document_test.cpp:956–1023  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

954}
955
956void TestDocument::rootFile_data()
957{
958 QTest::addColumn<QSharedPointer<Tw::Document::TeXDocument>>("doc");
959 QTest::addColumn<QString>("rootPath");
960
961 auto createDoc = [](const QString & content) {
962 return QSharedPointer<Tw::Document::TeXDocument>(new Tw::Document::TeXDocument(content));
963 };
964
965 auto loadDoc = [](const QString & filename) {
966 QFile fin(filename);
967 if (!fin.open(QFile::ReadOnly)) {
968 return QSharedPointer<Tw::Document::TeXDocument>();
969 }
970 QSharedPointer<Tw::Document::TeXDocument> retVal(new Tw::Document::TeXDocument(QString::fromUtf8(fin.readAll())));
971 fin.close();
972 retVal->setFileInfo(QFileInfo(fin));
973 retVal->setStoredInFilesystem();
974 return retVal;
975 };
976
977 auto saveDoc = [](const QString & filename, const QString & content) {
978 QFile fout(filename);
979 if (!fout.open(QFile::WriteOnly)) {
980 return false;
981 }
982 fout.write(content.toUtf8());
983 fout.close();
984 return true;
985 };
986
987 const QString syncFilename = QFileInfo("sync.tex").absoluteFilePath();
988 const QString doesNotExistFilename = QFileInfo("does-not-exist").absoluteFilePath();
989#if QT_VERSION < QT_VERSION_CHECK(5, 9, 0)
990 const QString symlinkFilename = QDir(m_tempDir.path()).absoluteFilePath(QStringLiteral("symlink.tex"));
991 const QString brokenSymlinkFilename = QDir(m_tempDir.path()).absoluteFilePath(QStringLiteral("broken-symlink.tex"));
992 const QString validSymlinkRootFilename = QDir(m_tempDir.path()).absoluteFilePath(QStringLiteral("a.tex"));
993 const QString invalidSymlinkRootFilename = QDir(m_tempDir.path()).absoluteFilePath(QStringLiteral("b.tex"));
994#else
995 const QString symlinkFilename = m_tempDir.filePath(QStringLiteral("symlink.tex"));
996 const QString brokenSymlinkFilename = m_tempDir.filePath(QStringLiteral("broken-symlink.tex"));
997 const QString validSymlinkRootFilename = m_tempDir.filePath(QStringLiteral("a.tex"));
998 const QString invalidSymlinkRootFilename = m_tempDir.filePath(QStringLiteral("b.tex"));
999#endif
1000
1001 QTest::newRow("ram-self") << createDoc(QString()) << QString();
1002 QTest::newRow("ram-modline-valid") << createDoc(QStringLiteral("%!TeX root=sync.tex\n")) << syncFilename;
1003 QTest::newRow("ram-modline-invalid") << createDoc(QStringLiteral("%!TeX root=does-not-exist\n")) << doesNotExistFilename;
1004
1005 QTest::newRow("disk-self") << loadDoc("sync.tex") << syncFilename;
1006
1007 if (m_tempDir.isValid()) {
1008 qDebug() << "Creating temp files in" << m_tempDir.path();
1009
1010 // Set up dummy data
1011 QFile::link(syncFilename, symlinkFilename);
1012 QFile::link(QStringLiteral("does-not-exist"), brokenSymlinkFilename);
1013 saveDoc(validSymlinkRootFilename, QStringLiteral("%!TeX root=symlink.tex\n"));

Callers

nothing calls this directly

Calls 5

setFileInfoMethod · 0.80
setStoredInFilesystemMethod · 0.80
openMethod · 0.45
absoluteFilePathMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected