File indexing completed on 2024-11-10 04:40:21
0001 /* 0002 SPDX-FileCopyrightText: 2012 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "storage/parthelper.h" 0008 #include "aktest.h" 0009 #include "entities.h" 0010 0011 #include <QDir> 0012 #include <QObject> 0013 #include <QTest> 0014 0015 #define QL1S(x) QString::fromLatin1(x) 0016 0017 using namespace Akonadi::Server; 0018 0019 class PartHelperTest : public QObject 0020 { 0021 Q_OBJECT 0022 private Q_SLOTS: 0023 #if 0 0024 void testFileName() 0025 { 0026 akTestSetInstanceIdentifier(QString()); 0027 0028 Part p; 0029 p.setId(42); 0030 0031 QString fileName = PartHelper::fileNameForPart(&p); 0032 QVERIFY(fileName.endsWith(QL1S("42"))); 0033 } 0034 #endif 0035 0036 void testRemoveFile_data() 0037 { 0038 QTest::addColumn<QString>("instance"); 0039 QTest::newRow("main") << QString(); 0040 QTest::newRow("multi-instance") << QL1S("foo"); 0041 } 0042 0043 #if 0 0044 void testRemoveFile() 0045 { 0046 QFETCH(QString, instance); 0047 akTestSetInstanceIdentifier(instance); 0048 0049 Part p; 0050 p.setId(23); 0051 const QString validFileName = PartHelper::storagePath() + QDir::separator() + PartHelper::fileNameForPart(&p); 0052 PartHelper::removeFile(validFileName); // no throw 0053 } 0054 #endif 0055 0056 #if 0 0057 void testInvalidRemoveFile_data() 0058 { 0059 QTest::addColumn<QString>("fileName"); 0060 QTest::newRow("empty") << QString(); 0061 QTest::newRow("relative") << QL1S("foo"); 0062 QTest::newRow("absolute") << QL1S("/foo"); 0063 0064 akTestSetInstanceIdentifier(QL1S("foo")); 0065 Part p; 0066 p.setId(23); 0067 QTest::newRow("wrong instance") << PartHelper::fileNameForPart(&p); 0068 } 0069 #endif 0070 0071 #if 0 0072 void testInvalidRemoveFile() 0073 { 0074 QFETCH(QString, fileName); 0075 akTestSetInstanceIdentifier(QString()); 0076 try { 0077 PartHelper::removeFile(fileName); 0078 } catch (const PartHelperException &e) { 0079 return; // all good 0080 } 0081 QVERIFY(false); // didn't throw 0082 } 0083 #endif 0084 0085 #if 0 0086 void testStorageLocation() 0087 { 0088 akTestSetInstanceIdentifier(QString()); 0089 const QString mainLocation = PartHelper::storagePath(); 0090 QVERIFY(mainLocation.endsWith(QDir::separator())); 0091 QVERIFY(mainLocation.startsWith(QDir::separator())); 0092 0093 akTestSetInstanceIdentifier(QL1S("foo")); 0094 QVERIFY(PartHelper::storagePath().endsWith(QDir::separator())); 0095 QVERIFY(PartHelper::storagePath().startsWith(QDir::separator())); 0096 QVERIFY(mainLocation != PartHelper::storagePath()); 0097 } 0098 #endif 0099 0100 #if 0 0101 void testResolveAbsolutePath() 0102 { 0103 #ifndef Q_OS_WIN 0104 QVERIFY(PartHelper::resolveAbsolutePath("foo").startsWith(QLatin1Char('/'))); 0105 QCOMPARE(PartHelper::resolveAbsolutePath("/foo"), QString::fromLatin1("/foo")); 0106 QVERIFY(!PartHelper::resolveAbsolutePath("foo").contains(QL1S("//"))); // no double separator 0107 #endif 0108 } 0109 #endif 0110 }; 0111 0112 AKTEST_MAIN(PartHelperTest) 0113 0114 #include "parthelpertest.moc"