File indexing completed on 2024-11-10 04:40:21
0001 /* 0002 SPDX-FileCopyrightText: 2011 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "storage/parttypehelper.h" 0008 #include "aktest.h" 0009 0010 #include <QObject> 0011 #include <QTest> 0012 0013 #define QL1S(x) QStringLiteral(x) 0014 0015 using namespace Akonadi::Server; 0016 0017 class PartTypeHelperTest : public QObject 0018 { 0019 Q_OBJECT 0020 private Q_SLOTS: 0021 void testParseFqName_data() 0022 { 0023 QTest::addColumn<QString>("fqName"); 0024 QTest::addColumn<QString>("ns"); 0025 QTest::addColumn<QString>("name"); 0026 QTest::addColumn<bool>("shouldThrow"); 0027 0028 QTest::newRow("empty") << QString() << QString() << QString() << true; 0029 QTest::newRow("valid") << "PLD:RFC822" 0030 << "PLD" 0031 << "RFC822" << false; 0032 QTest::newRow("no separator") << "ABC" << QString() << QString() << true; 0033 QTest::newRow("no ns") << ":RFC822" << QString() << QString() << true; 0034 QTest::newRow("no name") << "PLD:" << QString() << QString() << true; 0035 QTest::newRow("too many separators") << "A:B:C" << QString() << QString() << true; 0036 } 0037 0038 void testParseFqName() 0039 { 0040 QFETCH(QString, fqName); 0041 QFETCH(QString, ns); 0042 QFETCH(QString, name); 0043 QFETCH(bool, shouldThrow); 0044 0045 std::pair<QString, QString> p; 0046 bool didThrow = false; 0047 try { 0048 p = PartTypeHelper::parseFqName(fqName); 0049 } catch (const PartTypeException &e) { 0050 didThrow = true; 0051 } 0052 0053 QCOMPARE(didThrow, shouldThrow); 0054 QCOMPARE(p.first, ns); 0055 QCOMPARE(p.second, name); 0056 } 0057 0058 void testConditionFromName() 0059 { 0060 Query::Condition c = PartTypeHelper::conditionFromFqName(QL1S("PLD:RFC822")); 0061 QVERIFY(!c.isEmpty()); 0062 QCOMPARE(c.subConditions().size(), 2); 0063 } 0064 0065 void testConditionFromNames() 0066 { 0067 Query::Condition c = PartTypeHelper::conditionFromFqNames(QStringList() << QL1S("PLD:RFC822") << QL1S("PLD:HEAD") << QL1S("PLD:ENVELOPE")); 0068 QVERIFY(!c.isEmpty()); 0069 QCOMPARE(c.subConditions().size(), 3); 0070 const auto subCs = c.subConditions(); 0071 for (const Query::Condition &subC : subCs) { 0072 QCOMPARE(subC.subConditions().size(), 2); 0073 } 0074 } 0075 }; 0076 0077 AKTEST_MAIN(PartTypeHelperTest) 0078 0079 #include "parttypehelpertest.moc"