Warning, file /frameworks/kcontacts/autotests/birthdaytest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of kcontacts. 0003 SPDX-FileCopyrightText: 2016-2019 Laurent Montel <montel@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "birthdaytest.h" 0009 #include "addressee.h" 0010 #include "vcard_p.h" 0011 #include <QTest> 0012 #include <vcardtool_p.h> 0013 0014 BirthDayTest::BirthDayTest(QObject *parent) 0015 : QObject(parent) 0016 { 0017 } 0018 0019 BirthDayTest::~BirthDayTest() 0020 { 0021 } 0022 0023 void BirthDayTest::shouldParseBirthDay() 0024 { 0025 QByteArray vcarddata( 0026 "BEGIN:VCARD\r\n" 0027 "VERSION:4.0\r\n" 0028 "BDAY:19760505T120505\r\n" 0029 "EMAIL:foo@kde.org\r\n" 0030 "EMAIL:bla@kde.org\r\n" 0031 "N:;;;;\r\n" 0032 "UID:testuid\r\n" 0033 "END:VCARD\r\n\r\n"); 0034 0035 KContacts::VCardTool vcard; 0036 const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); 0037 QCOMPARE(lst.count(), 1); 0038 QDateTime dt(QDate(1976, 5, 5), QTime(12, 5, 5)); 0039 QCOMPARE(lst.at(0).birthday(), dt); 0040 QCOMPARE(lst.at(0).birthdayHasTime(), true); 0041 } 0042 0043 void BirthDayTest::shouldParseBirthDayWithoutTime() 0044 { 0045 QByteArray vcarddata( 0046 "BEGIN:VCARD\r\n" 0047 "VERSION:4.0\r\n" 0048 "BDAY:19760505\r\n" 0049 "EMAIL:foo@kde.org\r\n" 0050 "EMAIL:bla@kde.org\r\n" 0051 "N:;;;;\r\n" 0052 "UID:testuid\r\n" 0053 "END:VCARD\r\n\r\n"); 0054 0055 KContacts::VCardTool vcard; 0056 const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); 0057 QCOMPARE(lst.count(), 1); 0058 QDateTime dt(QDate(1976, 5, 5).startOfDay()); 0059 0060 QCOMPARE(lst.at(0).birthday(), dt); 0061 QCOMPARE(lst.at(0).birthdayHasTime(), false); 0062 } 0063 0064 void BirthDayTest::shouldParseBirthDayWithoutTimeAndYear() 0065 { 0066 QByteArray vcarddata( 0067 "BEGIN:VCARD\r\n" 0068 "VERSION:4.0\r\n" 0069 "BDAY:--0505\r\n" 0070 "EMAIL:foo@kde.org\r\n" 0071 "EMAIL:bla@kde.org\r\n" 0072 "N:;;;;\r\n" 0073 "UID:testuid\r\n" 0074 "END:VCARD\r\n\r\n"); 0075 0076 KContacts::VCardTool vcard; 0077 const KContacts::AddresseeList lst = vcard.parseVCards(vcarddata); 0078 QCOMPARE(lst.count(), 1); 0079 QDateTime dt(QDate(-1, 5, 5).startOfDay()); 0080 QCOMPARE(lst.at(0).birthday(), dt); 0081 QCOMPARE(lst.at(0).birthdayHasTime(), false); 0082 } 0083 0084 void BirthDayTest::shouldExportVcard4() 0085 { 0086 KContacts::AddresseeList lst; 0087 KContacts::Addressee addr; 0088 addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); 0089 addr.setUid(QStringLiteral("testuid")); 0090 const QDateTime dt(QDate(1976, 5, 5), QTime(12, 5, 5)); 0091 addr.setBirthday(dt); 0092 lst << addr; 0093 KContacts::VCardTool vcard; 0094 const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); 0095 QByteArray expected( 0096 "BEGIN:VCARD\r\n" 0097 "VERSION:4.0\r\n" 0098 "BDAY:19760505T120505\r\n" 0099 "EMAIL:foo@kde.org\r\n" 0100 "EMAIL:bla@kde.org\r\n" 0101 "N:;;;;\r\n" 0102 "UID:testuid\r\n" 0103 "END:VCARD\r\n\r\n"); 0104 0105 QCOMPARE(ba, expected); 0106 } 0107 0108 void BirthDayTest::shouldExportVcard4WithoutTime() 0109 { 0110 KContacts::AddresseeList lst; 0111 KContacts::Addressee addr; 0112 addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); 0113 addr.setUid(QStringLiteral("testuid")); 0114 const QDate d(1976, 5, 5); 0115 addr.setBirthday(d); 0116 lst << addr; 0117 KContacts::VCardTool vcard; 0118 const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); 0119 QByteArray expected( 0120 "BEGIN:VCARD\r\n" 0121 "VERSION:4.0\r\n" 0122 "BDAY:19760505\r\n" 0123 "EMAIL:foo@kde.org\r\n" 0124 "EMAIL:bla@kde.org\r\n" 0125 "N:;;;;\r\n" 0126 "UID:testuid\r\n" 0127 "END:VCARD\r\n\r\n"); 0128 0129 QCOMPARE(ba, expected); 0130 } 0131 0132 void BirthDayTest::shouldExportVcard4WithoutTimeAndWithoutYear() 0133 { 0134 KContacts::AddresseeList lst; 0135 KContacts::Addressee addr; 0136 addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); 0137 addr.setUid(QStringLiteral("testuid")); 0138 const QDate d(-1, 5, 5); 0139 addr.setBirthday(d); 0140 lst << addr; 0141 KContacts::VCardTool vcard; 0142 const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v4_0); 0143 QByteArray expected( 0144 "BEGIN:VCARD\r\n" 0145 "VERSION:4.0\r\n" 0146 "BDAY:--0505\r\n" 0147 "EMAIL:foo@kde.org\r\n" 0148 "EMAIL:bla@kde.org\r\n" 0149 "N:;;;;\r\n" 0150 "UID:testuid\r\n" 0151 "END:VCARD\r\n\r\n"); 0152 0153 QCOMPARE(ba, expected); 0154 } 0155 0156 void BirthDayTest::shouldExportVcard3() 0157 { 0158 KContacts::AddresseeList lst; 0159 KContacts::Addressee addr; 0160 addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); 0161 addr.setUid(QStringLiteral("testuid")); 0162 const QDateTime dt(QDate(1976, 5, 5), QTime(12, 5, 5)); 0163 addr.setBirthday(dt); 0164 lst << addr; 0165 KContacts::VCardTool vcard; 0166 const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); 0167 QByteArray expected( 0168 "BEGIN:VCARD\r\n" 0169 "VERSION:3.0\r\n" 0170 "BDAY:1976-05-05T12:05:05\r\n" 0171 "EMAIL:foo@kde.org\r\n" 0172 "EMAIL:bla@kde.org\r\n" 0173 "N:;;;;\r\n" 0174 "UID:testuid\r\n" 0175 "END:VCARD\r\n\r\n"); 0176 0177 QCOMPARE(ba, expected); 0178 } 0179 0180 void BirthDayTest::shouldExportVcard3WithoutTimeAndWithoutYear() 0181 { 0182 KContacts::AddresseeList lst; 0183 KContacts::Addressee addr; 0184 addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); 0185 addr.setUid(QStringLiteral("testuid")); 0186 const QDate d(-1, 5, 5); 0187 addr.setBirthday(d); 0188 lst << addr; 0189 KContacts::VCardTool vcard; 0190 const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); 0191 QByteArray expected( 0192 "BEGIN:VCARD\r\n" 0193 "VERSION:3.0\r\n" 0194 "BDAY:--05-05\r\n" 0195 "EMAIL:foo@kde.org\r\n" 0196 "EMAIL:bla@kde.org\r\n" 0197 "N:;;;;\r\n" 0198 "UID:testuid\r\n" 0199 "END:VCARD\r\n\r\n"); 0200 0201 QCOMPARE(ba, expected); 0202 } 0203 0204 void BirthDayTest::shouldExportVcard3WithoutTime() 0205 { 0206 KContacts::AddresseeList lst; 0207 KContacts::Addressee addr; 0208 addr.setEmails(QStringList() << QStringLiteral("foo@kde.org") << QStringLiteral("bla@kde.org")); 0209 addr.setUid(QStringLiteral("testuid")); 0210 const QDate d(1976, 5, 5); 0211 addr.setBirthday(d); 0212 lst << addr; 0213 KContacts::VCardTool vcard; 0214 const QByteArray ba = vcard.exportVCards(lst, KContacts::VCard::v3_0); 0215 QByteArray expected( 0216 "BEGIN:VCARD\r\n" 0217 "VERSION:3.0\r\n" 0218 "BDAY:1976-05-05\r\n" 0219 "EMAIL:foo@kde.org\r\n" 0220 "EMAIL:bla@kde.org\r\n" 0221 "N:;;;;\r\n" 0222 "UID:testuid\r\n" 0223 "END:VCARD\r\n\r\n"); 0224 0225 QCOMPARE(ba, expected); 0226 } 0227 0228 QTEST_MAIN(BirthDayTest)