X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/8d155558e980197b4dc2180660ea9bc61a23f3d3..246fdb3ebbde298ddb20f0323ba717c5cf9ba925:/src/tests/viewpropertiestest.cpp diff --git a/src/tests/viewpropertiestest.cpp b/src/tests/viewpropertiestest.cpp index e4d434383..9252f17ba 100644 --- a/src/tests/viewpropertiestest.cpp +++ b/src/tests/viewpropertiestest.cpp @@ -29,6 +29,7 @@ private Q_SLOTS: void testParamMigrationToFileAttrKeepDirectory(); void testExtendedAttributeFull(); void testUseAsDefaultViewSettings(); + void testUseAsCustomDefaultViewSettings(); private: bool m_globalViewProps; @@ -284,12 +285,6 @@ void ViewPropertiesTest::testExtendedAttributeFull() void ViewPropertiesTest::testUseAsDefaultViewSettings() { - // Create new test directory for this test to make sure the settings are defaults - auto testDir = new TestDir(QDir::homePath() + "/.viewPropertiesTest-"); - auto cleanupTestDir = qScopeGuard([testDir] { - delete testDir; - }); - // Create a global viewproperties folder QUrl globalPropertiesPath = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).append("/view_properties/").append(QStringLiteral("global"))); @@ -300,9 +295,9 @@ void ViewPropertiesTest::testUseAsDefaultViewSettings() ViewProperties globalProps(globalPropertiesPath); // Check that theres no .directory file and metadata is supported - QString dotDirectoryFile = testDir->url().toLocalFile() + "/.directory"; + QString dotDirectoryFile = m_testDir->url().toLocalFile() + "/.directory"; QVERIFY(!QFile::exists(dotDirectoryFile)); - KFileMetaData::UserMetaData testDirMetadata(testDir->url().toLocalFile()); + KFileMetaData::UserMetaData testDirMetadata(m_testDir->url().toLocalFile()); KFileMetaData::UserMetaData globalDirMetadata(globalPropertiesPath.toLocalFile()); if (!testDirMetadata.isSupported()) { QSKIP("need extended attribute/filesystem metadata to be usefull"); @@ -323,7 +318,7 @@ void ViewPropertiesTest::testUseAsDefaultViewSettings() auto defaultData = globalDirProperties.data(); // Load testdir data - QScopedPointer testDirProperties(new ViewProperties(testDir->url())); + QScopedPointer testDirProperties(new ViewProperties(m_testDir->url())); auto testData = testDirProperties.data(); // Make sure globalDirProperties are not empty, so they will be used @@ -339,6 +334,63 @@ void ViewPropertiesTest::testUseAsDefaultViewSettings() QCOMPARE(testData->viewMode(), defaultData->viewMode()); } +void ViewPropertiesTest::testUseAsCustomDefaultViewSettings() +{ + // Create a global viewproperties folder + QUrl globalPropertiesPath = + QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).append("/view_properties/").append(QStringLiteral("global"))); + QVERIFY(QDir().mkpath(globalPropertiesPath.toLocalFile())); + auto cleanupGlobalDir = qScopeGuard([globalPropertiesPath] { + QDir().rmdir(globalPropertiesPath.toLocalFile()); + }); + ViewProperties globalProps(globalPropertiesPath); + + // Check that theres no .directory file and metadata is supported + QString dotDirectoryFile = m_testDir->url().toLocalFile() + "/.directory"; + QVERIFY(!QFile::exists(dotDirectoryFile)); + KFileMetaData::UserMetaData testDirMetadata(m_testDir->url().toLocalFile()); + KFileMetaData::UserMetaData globalDirMetadata(globalPropertiesPath.toLocalFile()); + if (!testDirMetadata.isSupported()) { + QSKIP("need extended attribute/filesystem metadata to be usefull"); + } + + // Equivalent of useAsDefault in ViewPropertiesDialog + // This sets the DetailsView as default viewMode + GeneralSettings::setGlobalViewProps(true); + globalProps.setViewMode(DolphinView::Mode::DetailsView); + globalProps.setDirProperties(globalProps); + globalProps.save(); + GeneralSettings::setGlobalViewProps(false); + + // Make sure globalDirProperties are not empty, so they will be used + auto globalDirPropString = globalDirMetadata.attribute(QStringLiteral("kde.fm.viewproperties#1")); + QVERIFY(!globalDirPropString.isEmpty()); + + // Load default data + QScopedPointer globalDirProperties(new ViewProperties(globalPropertiesPath)); + auto defaultData = globalDirProperties.data(); + QCOMPARE(defaultData->viewMode(), DolphinView::Mode::DetailsView); + + // Load testdir data, set to icon, i.e default hardcoded, not current user default + QScopedPointer testDirProperties(new ViewProperties(m_testDir->url())); + testDirProperties->setViewMode(DolphinView::Mode::IconsView); + testDirProperties->save(); + + // testDirProperties is not default + auto testDirPropString = testDirMetadata.attribute(QStringLiteral("kde.fm.viewproperties#1")); + QVERIFY(!testDirPropString.isEmpty()); + QCOMPARE(testDirProperties.data()->viewMode(), DolphinView::Mode::IconsView); + + // testDirProperties is now default + testDirProperties->setViewMode(DolphinView::Mode::DetailsView); + testDirProperties->save(); + + // no more metedata => the defaults settings are in effect for the folder + testDirPropString = testDirMetadata.attribute(QStringLiteral("kde.fm.viewproperties#1")); + QVERIFY(testDirPropString.isEmpty()); + QCOMPARE(testDirProperties.data()->viewMode(), DolphinView::Mode::DetailsView); +} + QTEST_GUILESS_MAIN(ViewPropertiesTest) #include "viewpropertiestest.moc"