File indexing completed on 2024-11-10 04:40:09

0001 /*
0002     SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "collectionpathresolvertest.h"
0008 #include "collectionpathresolver.h"
0009 #include "control.h"
0010 
0011 #include "qtest_akonadi.h"
0012 
0013 using namespace Akonadi;
0014 
0015 QTEST_AKONADIMAIN(CollectionPathResolverTest)
0016 
0017 void CollectionPathResolverTest::initTestCase()
0018 {
0019     AkonadiTest::checkTestIsIsolated();
0020     Control::start();
0021 }
0022 
0023 void CollectionPathResolverTest::testPathResolver()
0024 {
0025     auto resolver = new CollectionPathResolver(QStringLiteral("/res1/foo/bar/bla"), this);
0026     AKVERIFYEXEC(resolver);
0027     int col = resolver->collection();
0028     QVERIFY(col > 0);
0029 
0030     resolver = new CollectionPathResolver(Collection(col), this);
0031     AKVERIFYEXEC(resolver);
0032     QCOMPARE(resolver->path(), QStringLiteral("res1/foo/bar/bla"));
0033 }
0034 
0035 void CollectionPathResolverTest::testRoot()
0036 {
0037     auto resolver = new CollectionPathResolver(CollectionPathResolver::pathDelimiter(), this);
0038     AKVERIFYEXEC(resolver);
0039     QCOMPARE(resolver->collection(), Collection::root().id());
0040 
0041     resolver = new CollectionPathResolver(Collection::root(), this);
0042     AKVERIFYEXEC(resolver);
0043     QVERIFY(resolver->path().isEmpty());
0044 }
0045 
0046 void CollectionPathResolverTest::testFailure()
0047 {
0048     auto resolver = new CollectionPathResolver(QStringLiteral("/I/do not/exist"), this);
0049     QVERIFY(!resolver->exec());
0050 
0051     resolver = new CollectionPathResolver(Collection(INT_MAX), this);
0052     QVERIFY(!resolver->exec());
0053 }
0054 
0055 #include "moc_collectionpathresolvertest.cpp"