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 "davurltest.h"
0020 
0021 #include <KDAV2/DavUrl>
0022 
0023 #include <QDataStream>
0024 #include <QTest>
0025 
0026 void DavUrlTest::createEmpty()
0027 {
0028     KDAV2::DavUrl davUrl;
0029 
0030     QCOMPARE(davUrl.protocol(), KDAV2::CalDav);
0031     QCOMPARE(davUrl.url(), QUrl());
0032 }
0033 
0034 void DavUrlTest::storeTest()
0035 {
0036     QUrl url(QStringLiteral("test://me:pw@test"));
0037     KDAV2::DavUrl davUrl(url, KDAV2::CardDav);
0038 
0039     QCOMPARE(davUrl.protocol(), KDAV2::CardDav);
0040     QCOMPARE(davUrl.url(), url);
0041     QCOMPARE(davUrl.toDisplayString(), QStringLiteral("test://test"));
0042 }
0043 
0044 void DavUrlTest::setTest()
0045 {
0046     QUrl url(QStringLiteral("test://me:pw@test"));
0047     KDAV2::DavUrl davUrl;
0048 
0049     davUrl.setProtocol(KDAV2::CardDav);
0050     davUrl.setUrl(url);
0051 
0052     QCOMPARE(davUrl.protocol(), KDAV2::CardDav);
0053     QCOMPARE(davUrl.url(), url);
0054     QCOMPARE(davUrl.toDisplayString(), QStringLiteral("test://test"));
0055 }
0056 
0057 void DavUrlTest::serializeTest()
0058 {
0059     KDAV2::DavUrl davUrl1, davUrl2;
0060 
0061     QUrl url(QStringLiteral("test://me:pw@test"));
0062     davUrl1.setProtocol(KDAV2::CardDav);
0063     davUrl1.setUrl(url);
0064 
0065     QByteArray data;
0066     QDataStream s(&data, QIODevice::WriteOnly);
0067     s << davUrl1;
0068 
0069     QDataStream t(&data, QIODevice::ReadOnly);
0070     t >> davUrl2;
0071 
0072     QCOMPARE(davUrl2.protocol(), davUrl1.protocol());
0073     QCOMPARE(davUrl2.url(), davUrl1.url());
0074 }
0075 
0076 QTEST_MAIN(DavUrlTest)