File indexing completed on 2024-04-21 03:53:28

0001 /*
0002     This file is part of the KContacts framework.
0003     SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include "timezonetest.h"
0009 #include "kcontacts/timezone.h"
0010 #include "vcardtool_p.h"
0011 #include <QTest>
0012 
0013 QTEST_MAIN(TimeZoneTest)
0014 
0015 void TimeZoneTest::emptyTest()
0016 {
0017     KContacts::TimeZone timezone;
0018 
0019     QVERIFY(timezone.isValid() == false);
0020 }
0021 
0022 void TimeZoneTest::storeTest()
0023 {
0024     KContacts::TimeZone timezone;
0025 
0026     timezone.setOffset(2);
0027 
0028     QVERIFY(timezone.offset() == 2);
0029 }
0030 
0031 void TimeZoneTest::equalsTest()
0032 {
0033     KContacts::TimeZone timezone1;
0034     KContacts::TimeZone timezone2;
0035 
0036     timezone1.setOffset(2);
0037     timezone2.setOffset(2);
0038 
0039     QVERIFY(timezone1 == timezone2);
0040 }
0041 
0042 void TimeZoneTest::differsTest()
0043 {
0044     KContacts::TimeZone timezone1(2);
0045     KContacts::TimeZone timezone2(3);
0046 
0047     QVERIFY(timezone1 != timezone2);
0048     QVERIFY(timezone1 != KContacts::TimeZone());
0049 }
0050 
0051 void TimeZoneTest::assignmentTest()
0052 {
0053     KContacts::TimeZone timezone1;
0054     KContacts::TimeZone timezone2;
0055 
0056     timezone1.setOffset(2);
0057     timezone1 = timezone2;
0058 
0059     QVERIFY(timezone1 == timezone2);
0060 }
0061 
0062 void TimeZoneTest::serializeTest()
0063 {
0064     KContacts::TimeZone timezone1;
0065     KContacts::TimeZone timezone2;
0066 
0067     timezone1.setOffset(2);
0068 
0069     QByteArray data;
0070     QDataStream s(&data, QIODevice::WriteOnly);
0071     s << timezone1;
0072 
0073     QDataStream t(&data, QIODevice::ReadOnly);
0074     t >> timezone2;
0075 
0076     QVERIFY(timezone1 == timezone2);
0077 }
0078 
0079 void TimeZoneTest::shouldGenerateVCard3()
0080 {
0081     KContacts::Addressee::List lst;
0082     KContacts::Addressee addr;
0083     addr.setEmails(QStringList() << QStringLiteral("foo@kde.org"));
0084     addr.setUid(QStringLiteral("testuid"));
0085     KContacts::TimeZone timezone;
0086 
0087     timezone.setOffset(2);
0088     addr.setTimeZone(timezone);
0089 
0090     lst << addr;
0091     KContacts::VCardTool vcard;
0092     const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0);
0093     QByteArray expected;
0094     expected = QByteArray(
0095         "BEGIN:VCARD\r\n"
0096         "VERSION:3.0\r\n"
0097         "EMAIL:foo@kde.org\r\n"
0098         "N:;;;;\r\n"
0099         "TZ:+00:02\r\n"
0100         "UID:testuid\r\n"
0101         "END:VCARD\r\n\r\n");
0102     QCOMPARE(ba, expected);
0103 }
0104 
0105 void TimeZoneTest::shouldGenerateVCard4()
0106 {
0107     // TODO fixme.
0108     KContacts::Addressee::List lst;
0109     KContacts::Addressee addr;
0110     addr.setEmails(QStringList() << QStringLiteral("foo@kde.org"));
0111     addr.setUid(QStringLiteral("testuid"));
0112     KContacts::TimeZone timezone;
0113 
0114     timezone.setOffset(2);
0115     addr.setTimeZone(timezone);
0116 
0117     lst << addr;
0118     KContacts::VCardTool vcard;
0119     const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0);
0120     const QByteArray expected(
0121         "BEGIN:VCARD\r\n"
0122         "VERSION:4.0\r\n"
0123         "EMAIL:foo@kde.org\r\n"
0124         "N:;;;;\r\n"
0125         "TZ:+00:02\r\n"
0126         "UID:testuid\r\n"
0127         "END:VCARD\r\n\r\n");
0128     QCOMPARE(ba, expected);
0129 }
0130 
0131 #include "moc_timezonetest.cpp"