File indexing completed on 2024-05-12 05:15:04

0001 /*
0002     Copyright (c) 2017 Sandro Knauß <sknauss@kde.org>
0003 
0004     This program is free software; you can redistribute it and/or modify
0005     it under the terms of the GNU General Public License as published by
0006     the Free Software Foundation; either version 2 of the License, or
0007     (at your option) any later version.
0008 
0009     This program is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0012     GNU General Public License for more details.
0013 
0014     You should have received a copy of the GNU General Public License
0015     along with this program; if not, write to the Free Software
0016     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0017 */
0018 
0019 #include "davcollectiontest.h"
0020 
0021 #include <KDAV2/DavCollection>
0022 #include <KDAV2/DavUrl>
0023 
0024 // #include <QColor>
0025 #include <QDebug>
0026 #include <QDataStream>
0027 #include <QTest>
0028 
0029 void DavCollectionTest::createEmpty()
0030 {
0031     KDAV2::DavCollection davCollection;
0032 
0033     QCOMPARE(davCollection.url().protocol(), KDAV2::CalDav);
0034     QCOMPARE(davCollection.CTag(), QString());
0035     QCOMPARE(davCollection.displayName(), QString());
0036     // QCOMPARE(davCollection.color(), QColor());
0037     QCOMPARE(davCollection.contentTypes(), KDAV2::DavCollection::ContentTypes());
0038     QCOMPARE(davCollection.privileges(), KDAV2::Privileges());
0039 }
0040 
0041 void DavCollectionTest::storeTest()
0042 {
0043     QUrl url(QStringLiteral("test://me:pw@test"));
0044     KDAV2::DavUrl davUrl(url, KDAV2::CardDav);
0045     KDAV2::DavCollection davCollection(davUrl, QStringLiteral("myname"), KDAV2::DavCollection::Events | KDAV2::DavCollection::Todos);
0046 
0047     QCOMPARE(davCollection.url().protocol(), KDAV2::CardDav);
0048     QCOMPARE(davCollection.url().url(), url);
0049     QCOMPARE(davCollection.CTag(), QString());
0050     QCOMPARE(davCollection.displayName(), QStringLiteral("myname"));
0051     // QCOMPARE(davCollection.color(), QColor());
0052     QCOMPARE(davCollection.contentTypes(), KDAV2::DavCollection::Events | KDAV2::DavCollection::Todos);
0053     QCOMPARE(davCollection.privileges(), KDAV2::All);
0054 }
0055 
0056 void DavCollectionTest::setTest()
0057 {
0058     QUrl url(QStringLiteral("test://me:pw@test"));
0059     KDAV2::DavUrl davUrl(url, KDAV2::CardDav);
0060     KDAV2::DavCollection davCollection;
0061 
0062     davCollection.setUrl(davUrl);
0063     davCollection.setCTag(QStringLiteral("ctag"));
0064     davCollection.setDisplayName(QStringLiteral("myname"));
0065     // davCollection.setColor(QColor(1,2,3));
0066     davCollection.setContentTypes(KDAV2::DavCollection::Events | KDAV2::DavCollection::Todos);
0067     davCollection.setPrivileges(KDAV2::Read | KDAV2::Write);
0068 
0069     QCOMPARE(davCollection.url().protocol(), KDAV2::CardDav);
0070     QCOMPARE(davCollection.url().url(), url);
0071     QCOMPARE(davCollection.CTag(), QStringLiteral("ctag"));
0072     QCOMPARE(davCollection.displayName(), QStringLiteral("myname"));
0073     // QCOMPARE(davCollection.color(), QColor(1,2,3));
0074     QCOMPARE(davCollection.contentTypes(), KDAV2::DavCollection::Events | KDAV2::DavCollection::Todos);
0075     QCOMPARE(davCollection.privileges(), KDAV2::Read | KDAV2::Write);
0076 }
0077 
0078 void DavCollectionTest::copyTest()
0079 {
0080     KDAV2::DavCollection davCollection;
0081 
0082     QUrl url(QStringLiteral("test://me:pw@test"));
0083     KDAV2::DavUrl davUrl(url, KDAV2::CardDav);
0084 
0085     davCollection.setUrl(davUrl);
0086     davCollection.setCTag(QStringLiteral("ctag"));
0087     davCollection.setDisplayName(QStringLiteral("myname"));
0088     // davCollection.setColor(QColor(1,2,3));
0089     davCollection.setContentTypes(KDAV2::DavCollection::Events | KDAV2::DavCollection::Todos);
0090     davCollection.setPrivileges(KDAV2::Read | KDAV2::Write);
0091 
0092     KDAV2::DavCollection copy1(davCollection);
0093     QCOMPARE(copy1.url().protocol(), davCollection.url().protocol());
0094     QCOMPARE(copy1.url().url(), davCollection.url().url());
0095     QCOMPARE(copy1.CTag(), davCollection.CTag());
0096     QCOMPARE(copy1.displayName(), davCollection.displayName());
0097     QCOMPARE(copy1.color(), davCollection.color());
0098     QCOMPARE(copy1.contentTypes(), davCollection.contentTypes());
0099     QCOMPARE(copy1.privileges(), davCollection.privileges());
0100 
0101     KDAV2::DavCollection copy2;
0102     copy2 = davCollection;
0103 
0104     QCOMPARE(copy2.url().protocol(), davCollection.url().protocol());
0105     QCOMPARE(copy2.url().url(), davCollection.url().url());
0106     QCOMPARE(copy2.CTag(), davCollection.CTag());
0107     QCOMPARE(copy2.displayName(), davCollection.displayName());
0108     QCOMPARE(copy2.color(), davCollection.color());
0109     QCOMPARE(copy2.contentTypes(), davCollection.contentTypes());
0110     QCOMPARE(copy2.privileges(), davCollection.privileges());
0111 }
0112 
0113 QTEST_GUILESS_MAIN(DavCollectionTest)