Changeset View
Changeset View
Standalone View
Standalone View
autotests/usermetadatawritertest.cpp
Show All 19 Lines | |||||
20 | #include "usermetadatawritertest.h" | 20 | #include "usermetadatawritertest.h" | ||
21 | #include "indexerextractortestsconfig.h" | 21 | #include "indexerextractortestsconfig.h" | ||
22 | #include "usermetadata.h" | 22 | #include "usermetadata.h" | ||
23 | 23 | | |||
24 | #include <QTest> | 24 | #include <QTest> | ||
25 | #include <QFile> | 25 | #include <QFile> | ||
26 | 26 | | |||
27 | #define TEST_FILENAME "writertest.txt" | 27 | #define TEST_FILENAME "writertest.txt" | ||
28 | #define TEST_SYMLINK "dangling_symlink" | ||||
28 | 29 | | |||
29 | using namespace KFileMetaData; | 30 | using namespace KFileMetaData; | ||
30 | 31 | | |||
31 | QString UserMetaDataWriterTest::testFilePath(const QString& fileName) const | 32 | QString UserMetaDataWriterTest::testFilePath(const QString& fileName) const | ||
32 | { | 33 | { | ||
33 | return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; | 34 | return QLatin1String(INDEXER_TESTS_SAMPLE_FILES_PATH) + QLatin1Char('/') + fileName; | ||
34 | } | 35 | } | ||
35 | 36 | | |||
36 | void UserMetaDataWriterTest::initTestCase() | 37 | void UserMetaDataWriterTest::initTestCase() | ||
37 | { | 38 | { | ||
38 | QFile testFile(testFilePath("plain_text_file.txt")); | 39 | QFile testFile(testFilePath("plain_text_file.txt")); | ||
39 | QFile writerTestFile(testFilePath(TEST_FILENAME)); | 40 | QFile writerTestFile(testFilePath(TEST_FILENAME)); | ||
40 | QFile::copy(testFilePath("plain_text_file.txt"), testFilePath(TEST_FILENAME)); | 41 | QFile::copy(testFilePath("plain_text_file.txt"), testFilePath(TEST_FILENAME)); | ||
42 | | ||||
43 | QFile::link(testFilePath("invalid_target"), testFilePath(TEST_SYMLINK)); | ||||
41 | } | 44 | } | ||
bruns: You can just use the static overload and provide an invalid target name.
https://doc.qt.io/qt… | |||||
You are right. I tried that with an empty string and it didn't work, but it does with a non-existent filename. iasensio: You are right. I tried that with an empty string and it didn't work, but it does with a non… | |||||
42 | 45 | | |||
43 | void UserMetaDataWriterTest::test() | 46 | void UserMetaDataWriterTest::test() | ||
44 | { | 47 | { | ||
45 | 48 | | |||
46 | KFileMetaData::UserMetaData md(testFilePath(TEST_FILENAME)); | 49 | KFileMetaData::UserMetaData md(testFilePath(TEST_FILENAME)); | ||
47 | QVERIFY(md.isSupported()); | 50 | QVERIFY(md.isSupported()); | ||
48 | 51 | | |||
49 | // Tags | 52 | // Tags | ||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
114 | // Check for side effects of calling sequence | 117 | // Check for side effects of calling sequence | ||
115 | QVERIFY(!md.hasAttribute(QStringLiteral("test.check_contains"))); | 118 | QVERIFY(!md.hasAttribute(QStringLiteral("test.check_contains"))); | ||
116 | md.setAttribute(QStringLiteral("test.check_contains"), QStringLiteral("dummy")); | 119 | md.setAttribute(QStringLiteral("test.check_contains"), QStringLiteral("dummy")); | ||
117 | QVERIFY(md.hasAttribute(QStringLiteral("test.check_contains"))); | 120 | QVERIFY(md.hasAttribute(QStringLiteral("test.check_contains"))); | ||
118 | md.setAttribute(QStringLiteral("test.check_contains"), QString()); | 121 | md.setAttribute(QStringLiteral("test.check_contains"), QString()); | ||
119 | QVERIFY(!md.hasAttribute(QStringLiteral("test.check_contains"))); | 122 | QVERIFY(!md.hasAttribute(QStringLiteral("test.check_contains"))); | ||
120 | } | 123 | } | ||
121 | 124 | | |||
125 | | ||||
126 | void UserMetaDataWriterTest::testDanglingSymlink() | ||||
127 | { | ||||
128 | KFileMetaData::UserMetaData md(testFilePath(TEST_SYMLINK)); | ||||
129 | QVERIFY(md.queryAttributes(UserMetaData::Attribute::All) == UserMetaData::Attribute::None); | ||||
130 | } | ||||
131 | | ||||
122 | void UserMetaDataWriterTest::cleanupTestCase() | 132 | void UserMetaDataWriterTest::cleanupTestCase() | ||
123 | { | 133 | { | ||
124 | QFile::remove(testFilePath(TEST_FILENAME)); | 134 | QFile::remove(testFilePath(TEST_FILENAME)); | ||
135 | QFile::remove(testFilePath(TEST_SYMLINK)); | ||||
125 | } | 136 | } | ||
126 | 137 | | |||
127 | QTEST_GUILESS_MAIN(UserMetaDataWriterTest) | 138 | QTEST_GUILESS_MAIN(UserMetaDataWriterTest) |
You can just use the static overload and provide an invalid target name.
https://doc.qt.io/qt-5/qfile.html#link-1