File indexing completed on 2024-11-24 04:43:51

0001 /*
0002     SPDX-FileCopyrightText: 2017 Krzysztof Nowicki <krissn@op.pl>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include <QTest>
0008 #include <QTimeZone>
0009 #include <QXmlStreamReader>
0010 
0011 #include "ewsattachment.h"
0012 #include "fakehttppost.h"
0013 
0014 class UtEwsAttachment : public QObject
0015 {
0016     Q_OBJECT
0017 private Q_SLOTS:
0018     void read();
0019     void read_data();
0020     void write();
0021     void write_data();
0022 };
0023 
0024 Q_DECLARE_METATYPE(EwsAttachment::Type)
0025 
0026 static const QString xmlMsgNsUri = QStringLiteral("http://schemas.microsoft.com/exchange/services/2006/message");
0027 static const QString xmlTypeNsUri = QStringLiteral("http://schemas.microsoft.com/exchange/services/2006/types");
0028 
0029 static const QString xmlHead = QStringLiteral("<?xml version=\"1.0\"?>");
0030 static const QString xmlDocHead = xmlHead + QLatin1StringView("<Test xmlns=\"") + xmlTypeNsUri + QLatin1StringView("\">");
0031 static const QString xmlDocTail = QStringLiteral("</Test><Test2/>");
0032 static const QString xmlItemAttHead = xmlDocHead + QStringLiteral("<ItemAttachment>");
0033 static const QString xmlItemAttTail = QLatin1StringView("</ItemAttachment>") + xmlDocTail;
0034 static const QString xmlFileAttHead = xmlDocHead + QStringLiteral("<FileAttachment>");
0035 static const QString xmlFileAttTail = QLatin1StringView("</FileAttachment>") + xmlDocTail;
0036 
0037 void UtEwsAttachment::read()
0038 {
0039     QFETCH(QString, xml);
0040     QFETCH(bool, isValid);
0041 
0042     QXmlStreamReader reader(xml);
0043 
0044     reader.readNextStartElement();
0045     reader.readNextStartElement();
0046 
0047     EwsAttachment att(reader);
0048 
0049     QCOMPARE(att.isValid(), isValid);
0050 
0051     if (!isValid) {
0052         return;
0053     }
0054 
0055     QFETCH(EwsAttachment::Type, type);
0056 
0057     QCOMPARE(att.type(), type);
0058 
0059     QFETCH(bool, hasId);
0060     QFETCH(QString, id);
0061     QCOMPARE(att.hasId(), hasId);
0062     if (hasId) {
0063         QCOMPARE(att.id(), id);
0064     }
0065 
0066     QFETCH(bool, hasName);
0067     QFETCH(QString, name);
0068     QCOMPARE(att.hasName(), hasName);
0069     if (hasName) {
0070         QCOMPARE(att.name(), name);
0071     }
0072 
0073     QFETCH(bool, hasContentType);
0074     QFETCH(QString, contentType);
0075     QCOMPARE(att.hasContentType(), hasContentType);
0076     if (hasContentType) {
0077         QCOMPARE(att.contentType(), contentType);
0078     }
0079 
0080     QFETCH(bool, hasContentId);
0081     QFETCH(QString, contentId);
0082     QCOMPARE(att.hasContentId(), hasContentId);
0083     if (hasContentId) {
0084         QCOMPARE(att.contentId(), contentId);
0085     }
0086 
0087     QFETCH(bool, hasContentLocation);
0088     QFETCH(QString, contentLocation);
0089     QCOMPARE(att.hasContentLocation(), hasContentLocation);
0090     if (hasContentLocation) {
0091         QCOMPARE(att.contentLocation(), contentLocation);
0092     }
0093 
0094     QFETCH(bool, hasSize);
0095     QFETCH(long, size);
0096     QCOMPARE(att.hasSize(), hasSize);
0097     if (hasSize) {
0098         QCOMPARE(att.size(), size);
0099     }
0100 
0101     QFETCH(bool, hasLastModifiedTime);
0102     QFETCH(QDateTime, lastModifiedTime);
0103     QCOMPARE(att.hasLastModifiedTime(), hasLastModifiedTime);
0104     if (hasLastModifiedTime) {
0105         QCOMPARE(att.lastModifiedTime(), lastModifiedTime);
0106     }
0107 
0108     QFETCH(bool, hasIsInline);
0109     QFETCH(bool, isInline);
0110     QCOMPARE(att.hasIsInline(), hasIsInline);
0111     if (hasIsInline) {
0112         QCOMPARE(att.isInline(), isInline);
0113     }
0114 
0115     QFETCH(bool, hasIsContactPhoto);
0116     QFETCH(bool, isContactPhoto);
0117     QCOMPARE(att.hasIsContactPhoto(), hasIsContactPhoto);
0118     if (hasIsContactPhoto) {
0119         QCOMPARE(att.isContactPhoto(), isContactPhoto);
0120     }
0121 
0122     QFETCH(bool, hasContent);
0123     QFETCH(QByteArray, content);
0124     QCOMPARE(att.hasContent(), hasContent);
0125     if (hasContent) {
0126         QCOMPARE(att.content(), content);
0127     }
0128 
0129     QFETCH(bool, hasItem);
0130     QFETCH(EwsItem, item);
0131     QCOMPARE(att.hasItem(), hasItem);
0132     if (hasItem) {
0133         QCOMPARE(att.item(), item);
0134     }
0135     reader.skipCurrentElement();
0136 
0137     reader.readNextStartElement();
0138     QCOMPARE(reader.name().toString(), QStringLiteral("Test2"));
0139 }
0140 
0141 void UtEwsAttachment::read_data()
0142 {
0143     QTest::addColumn<QString>("xml");
0144     QTest::addColumn<bool>("isValid");
0145 
0146     QTest::addColumn<EwsAttachment::Type>("type");
0147 
0148     QTest::addColumn<bool>("hasId");
0149     QTest::addColumn<QString>("id");
0150 
0151     QTest::addColumn<bool>("hasName");
0152     QTest::addColumn<QString>("name");
0153 
0154     QTest::addColumn<bool>("hasContentType");
0155     QTest::addColumn<QString>("contentType");
0156 
0157     QTest::addColumn<bool>("hasContentId");
0158     QTest::addColumn<QString>("contentId");
0159 
0160     QTest::addColumn<bool>("hasContentLocation");
0161     QTest::addColumn<QString>("contentLocation");
0162 
0163     QTest::addColumn<bool>("hasSize");
0164     QTest::addColumn<long>("size");
0165 
0166     QTest::addColumn<bool>("hasLastModifiedTime");
0167     QTest::addColumn<QDateTime>("lastModifiedTime");
0168 
0169     QTest::addColumn<bool>("hasIsInline");
0170     QTest::addColumn<bool>("isInline");
0171 
0172     QTest::addColumn<bool>("hasIsContactPhoto");
0173     QTest::addColumn<bool>("isContactPhoto");
0174 
0175     QTest::addColumn<bool>("hasContent");
0176     QTest::addColumn<QByteArray>("content");
0177 
0178     QTest::addColumn<bool>("hasItem");
0179     QTest::addColumn<EwsItem>("item");
0180 
0181     QTest::newRow("invalid namespace") << xmlDocHead + QLatin1StringView("<FileAttachment xmlns=\"") + xmlMsgNsUri + QLatin1StringView("\" />") + xmlDocTail
0182                                        << false << EwsAttachment::UnknownAttachment << false << QString() << false << QString() << false << QString() << false
0183                                        << QString() << false << QString() << false << 0l << false << QDateTime() << false << false << false << false << false
0184                                        << QByteArray() << false << EwsItem();
0185 
0186     QTest::newRow("invalid type") << xmlDocHead + QStringLiteral("<TestAttachment />") + xmlDocTail << false << EwsAttachment::UnknownAttachment << false
0187                                   << QString() << false << QString() << false << QString() << false << QString() << false << QString() << false << 0l << false
0188                                   << QDateTime() << false << false << false << false << false << QByteArray() << false << EwsItem();
0189 
0190     QTest::newRow("empty file attachment") << xmlDocHead + QStringLiteral("<FileAttachment />") + xmlDocTail << true << EwsAttachment::FileAttachment << false
0191                                            << QString() << false << QString() << false << QString() << false << QString() << false << QString() << false << 0l
0192                                            << false << QDateTime() << false << false << false << false << false << QByteArray() << false << EwsItem();
0193 
0194     QTest::newRow("empty item attachment") << xmlDocHead + QStringLiteral("<ItemAttachment />") + xmlDocTail << true << EwsAttachment::ItemAttachment << false
0195                                            << QString() << false << QString() << false << QString() << false << QString() << false << QString() << false << 0l
0196                                            << false << QDateTime() << false << false << false << false << false << QByteArray() << false << EwsItem();
0197 
0198     QTest::newRow("empty reference attachment") << xmlDocHead + QStringLiteral("<ReferenceAttachment />") + xmlDocTail << true
0199                                                 << EwsAttachment::ReferenceAttachment << false << QString() << false << QString() << false << QString() << false
0200                                                 << QString() << false << QString() << false << 0l << false << QDateTime() << false << false << false << false
0201                                                 << false << QByteArray() << false << EwsItem();
0202 
0203     QTest::newRow("invalid attachment id - bad namespace")
0204         << xmlFileAttHead + QStringLiteral("<AttachmentId xmlns=\"") + xmlMsgNsUri + QStringLiteral("\" Id=\"JCPhyc4Kg73tIuurR3c0Pw==\" />") + xmlFileAttTail
0205         << false << EwsAttachment::UnknownAttachment << false << QString() << false << QString() << false << QString() << false << QString() << false
0206         << QString() << false << 0l << false << QDateTime() << false << false << false << false << false << QByteArray() << false << EwsItem();
0207 
0208     QTest::newRow("invalid attachment id - bad attribute")
0209         << xmlFileAttHead + QStringLiteral("<AttachmentId TestId=\"JCPhyc4Kg73tIuurR3c0Pw==\" />") + xmlFileAttTail << false << EwsAttachment::UnknownAttachment
0210         << false << QString() << false << QString() << false << QString() << false << QString() << false << QString() << false << 0l << false << QDateTime()
0211         << false << false << false << false << false << QByteArray() << false << EwsItem();
0212 
0213     QTest::newRow("valid attachment id") << xmlFileAttHead + QStringLiteral("<AttachmentId Id=\"JCPhyc4Kg73tIuurR3c0Pw==\" />") + xmlFileAttTail << true
0214                                          << EwsAttachment::FileAttachment << true << QStringLiteral("JCPhyc4Kg73tIuurR3c0Pw==") << false << QString() << false
0215                                          << QString() << false << QString() << false << QString() << false << 0l << false << QDateTime() << false << false
0216                                          << false << false << false << QByteArray() << false << EwsItem();
0217 
0218     QTest::newRow("invalid name") << xmlFileAttHead + QStringLiteral("<Name>Test <b>name</b></Name>") + xmlFileAttTail << false
0219                                   << EwsAttachment::UnknownAttachment << false << QString() << false << QString() << false << QString() << false << QString()
0220                                   << false << QString() << false << 0l << false << QDateTime() << false << false << false << false << false << QByteArray()
0221                                   << false << EwsItem();
0222 
0223     QTest::newRow("valid name") << xmlFileAttHead + QStringLiteral("<Name>Test name</Name>") + xmlFileAttTail << true << EwsAttachment::FileAttachment << false
0224                                 << QString() << true << QStringLiteral("Test name") << false << QString() << false << QString() << false << QString() << false
0225                                 << 0l << false << QDateTime() << false << false << false << false << false << QByteArray() << false << EwsItem();
0226 
0227     QTest::newRow("valid content type") << xmlFileAttHead + QStringLiteral("<ContentType>application/x-test</ContentType>") + xmlFileAttTail << true
0228                                         << EwsAttachment::FileAttachment << false << QString() << false << QString() << true
0229                                         << QStringLiteral("application/x-test") << false << QString() << false << QString() << false << 0l << false
0230                                         << QDateTime() << false << false << false << false << false << QByteArray() << false << EwsItem();
0231 
0232     QTest::newRow("valid content id") << xmlFileAttHead + QStringLiteral("<ContentId>FE938BD618330B9DA0C965A6077BB3FF20415531@1</ContentId>") + xmlFileAttTail
0233                                       << true << EwsAttachment::FileAttachment << false << QString() << false << QString() << false << QString() << true
0234                                       << QStringLiteral("FE938BD618330B9DA0C965A6077BB3FF20415531@1") << false << QString() << false << 0l << false
0235                                       << QDateTime() << false << false << false << false << false << QByteArray() << false << EwsItem();
0236 
0237     QTest::newRow("valid content location") << xmlFileAttHead + QStringLiteral("<ContentLocation>file:///foo/bar.txt</ContentLocation>") + xmlFileAttTail
0238                                             << true << EwsAttachment::FileAttachment << false << QString() << false << QString() << false << QString() << false
0239                                             << QString() << true << QStringLiteral("file:///foo/bar.txt") << false << 0l << false << QDateTime() << false
0240                                             << false << false << false << false << QByteArray() << false << EwsItem();
0241 
0242     QTest::newRow("invalid size - not a number") << xmlFileAttHead + QStringLiteral("<Size>foo</Size>") + xmlFileAttTail << false
0243                                                  << EwsAttachment::UnknownAttachment << false << QString() << false << QString() << false << QString() << false
0244                                                  << QString() << false << QString() << false << 0l << false << QDateTime() << false << false << false << false
0245                                                  << false << QByteArray() << false << EwsItem();
0246 
0247     QTest::newRow("valid size") << xmlFileAttHead + QStringLiteral("<Size>123</Size>") + xmlFileAttTail << true << EwsAttachment::FileAttachment << false
0248                                 << QString() << false << QString() << false << QString() << false << QString() << false << QString() << true << 123l << false
0249                                 << QDateTime() << false << false << false << false << false << QByteArray() << false << EwsItem();
0250 
0251     QTest::newRow("invalid last modified time - bad time")
0252         << xmlFileAttHead + QStringLiteral("<LastModifiedTime>2017-01-03T09:74:39</LastModifiedTime>") + xmlFileAttTail << false
0253         << EwsAttachment::UnknownAttachment << false << QString() << false << QString() << false << QString() << false << QString() << false << QString()
0254         << false << 0l << false << QDateTime() << false << false << false << false << false << QByteArray() << false << EwsItem();
0255 
0256     QTest::newRow("invalid last modified time - nested XML element")
0257         << xmlFileAttHead + QStringLiteral("<LastModifiedTime>2017-<b>01</b>-03T09:74:39</LastModifiedTime>") + xmlFileAttTail << false
0258         << EwsAttachment::UnknownAttachment << false << QString() << false << QString() << false << QString() << false << QString() << false << QString()
0259         << false << 0l << false << QDateTime() << false << false << false << false << false << QByteArray() << false << EwsItem();
0260 
0261     QTest::newRow("valid last modified time") << xmlFileAttHead + QStringLiteral("<LastModifiedTime>2017-01-03T08:24:39Z</LastModifiedTime>") + xmlFileAttTail
0262                                               << true << EwsAttachment::FileAttachment << false << QString() << false << QString() << false << QString()
0263                                               << false << QString() << false << QString() << false << 0l << true
0264                                               << QDateTime::fromSecsSinceEpoch(1483431879, QTimeZone::utc()) << false << false << false << false << false
0265                                               << QByteArray() << false << EwsItem();
0266 
0267     QTest::newRow("invalid is inline - bad value") << xmlFileAttHead + QStringLiteral("<IsInline>fake</IsInline>") + xmlFileAttTail << false
0268                                                    << EwsAttachment::UnknownAttachment << false << QString() << false << QString() << false << QString()
0269                                                    << false << QString() << false << QString() << false << 0l << false << QDateTime() << false << false << false
0270                                                    << false << false << QByteArray() << false << EwsItem();
0271 
0272     QTest::newRow("valid is inline") << xmlFileAttHead + QStringLiteral("<IsInline>true</IsInline>") + xmlFileAttTail << true << EwsAttachment::FileAttachment
0273                                      << false << QString() << false << QString() << false << QString() << false << QString() << false << QString() << false
0274                                      << 0l << false << QDateTime() << true << true << false << false << false << QByteArray() << false << EwsItem();
0275 
0276     QTest::newRow("invalid is contact photo - bad value")
0277         << xmlFileAttHead + QStringLiteral("<IsContactPhoto>fake</IsContactPhoto>") + xmlFileAttTail << false << EwsAttachment::UnknownAttachment << false
0278         << QString() << false << QString() << false << QString() << false << QString() << false << QString() << false << 0l << false << QDateTime() << false
0279         << false << false << false << false << QByteArray() << false << EwsItem();
0280 
0281     QTest::newRow("invalid is contact photo - inside ItemAttachment")
0282         << xmlItemAttHead + QStringLiteral("<IsContactPhoto>true</IsContactPhoto>") + xmlItemAttTail << false << EwsAttachment::UnknownAttachment << false
0283         << QString() << false << QString() << false << QString() << false << QString() << false << QString() << false << 0l << false << QDateTime() << false
0284         << false << false << false << false << QByteArray() << false << EwsItem();
0285 
0286     QTest::newRow("valid is contact photo") << xmlFileAttHead + QStringLiteral("<IsContactPhoto>true</IsContactPhoto>") + xmlFileAttTail << true
0287                                             << EwsAttachment::FileAttachment << false << QString() << false << QString() << false << QString() << false
0288                                             << QString() << false << QString() << false << 0l << false << QDateTime() << false << false << true << true << false
0289                                             << QByteArray() << false << EwsItem();
0290 
0291     QTest::newRow("invalid content - nested XML element")
0292         << xmlFileAttHead + QStringLiteral("<Content>djsaoij<b>sa</b></Content>") + xmlFileAttTail << false << EwsAttachment::UnknownAttachment << false
0293         << QString() << false << QString() << false << QString() << false << QString() << false << QString() << false << 0l << false << QDateTime() << false
0294         << false << false << false << false << QByteArray() << false << EwsItem();
0295 
0296     QTest::newRow("invalid content - inside ItemAttachment")
0297         << xmlItemAttHead + QStringLiteral("<Content>VGhpcyBpcyBhIHRlc3Q=</Content>") + xmlItemAttTail << false << EwsAttachment::UnknownAttachment << false
0298         << QString() << false << QString() << false << QString() << false << QString() << false << QString() << false << 0l << false << QDateTime() << false
0299         << false << false << false << false << QByteArray() << false << EwsItem();
0300 
0301     QTest::newRow("valid content") << xmlFileAttHead + QStringLiteral("<Content>VGhpcyBpcyBhIHRlc3Q=</Content>") + xmlFileAttTail << true
0302                                    << EwsAttachment::FileAttachment << false << QString() << false << QString() << false << QString() << false << QString()
0303                                    << false << QString() << false << 0l << false << QDateTime() << false << false << false << false << true
0304                                    << QByteArray("This is a test") << false << EwsItem();
0305 
0306     QTest::newRow("invalid item - bad data") << xmlItemAttHead + QStringLiteral("<Akonadi/Item><foo></foo></Item>") + xmlItemAttTail << false
0307                                              << EwsAttachment::UnknownAttachment << false << QString() << false << QString() << false << QString() << false
0308                                              << QString() << false << QString() << false << 0l << false << QDateTime() << false << false << false << false
0309                                              << false << QByteArray() << false << EwsItem();
0310 
0311     QTest::newRow("invalid item - inside FileAttachment")
0312         << xmlFileAttHead + QStringLiteral("<Akonadi/Item><ItemId Id=\"VGhpcyBpcyBhIHRlc3Q=\" ChangeKey=\"muKls0n8pUM=\" /></Item>") + xmlFileAttTail << false
0313         << EwsAttachment::UnknownAttachment << false << QString() << false << QString() << false << QString() << false << QString() << false << QString()
0314         << false << 0l << false << QDateTime() << false << false << false << false << false << QByteArray() << false << EwsItem();
0315 
0316     EwsItem item1;
0317     item1.setType(EwsItemTypeItem);
0318     item1.setField(EwsItemFieldItemId, QVariant::fromValue<EwsId>(EwsId(QStringLiteral("VGhpcyBpcyBhIHRlc3Q="), QStringLiteral("muKls0n8pUM="))));
0319     QTest::newRow("valid item") << xmlItemAttHead + QStringLiteral("<Akonadi/Item><ItemId Id=\"VGhpcyBpcyBhIHRlc3Q=\" ChangeKey=\"muKls0n8pUM=\" /></Item>")
0320             + xmlItemAttTail << true
0321                                 << EwsAttachment::ItemAttachment << false << QString() << false << QString() << false << QString() << false << QString()
0322                                 << false << QString() << false << 0l << false << QDateTime() << false << false << false << false << false << QByteArray()
0323                                 << true << item1;
0324 }
0325 
0326 void UtEwsAttachment::write()
0327 {
0328     QFETCH(EwsAttachment::Type, type);
0329     QFETCH(bool, isValid);
0330 
0331     EwsAttachment att;
0332     if (isValid) {
0333         att.setType(type);
0334 
0335         QFETCH(bool, hasId);
0336         QFETCH(QString, id);
0337         if (hasId) {
0338             att.setId(id);
0339         }
0340 
0341         QFETCH(bool, hasName);
0342         QFETCH(QString, name);
0343         if (hasName) {
0344             att.setName(name);
0345         }
0346 
0347         QFETCH(bool, hasContentType);
0348         QFETCH(QString, contentType);
0349         if (hasContentType) {
0350             att.setContentType(contentType);
0351         }
0352 
0353         QFETCH(bool, hasContentId);
0354         QFETCH(QString, contentId);
0355         if (hasContentId) {
0356             att.setContentId(contentId);
0357         }
0358 
0359         QFETCH(bool, hasContentLocation);
0360         QFETCH(QString, contentLocation);
0361         if (hasContentLocation) {
0362             att.setContentLocation(contentLocation);
0363         }
0364 
0365         QFETCH(bool, hasSize);
0366         QFETCH(long, size);
0367         if (hasSize) {
0368             att.setSize(size);
0369         }
0370 
0371         QFETCH(bool, hasLastModifiedTime);
0372         QFETCH(QDateTime, lastModifiedTime);
0373         if (hasLastModifiedTime) {
0374             att.setLastModifiedTime(lastModifiedTime);
0375         }
0376 
0377         QFETCH(bool, hasIsInline);
0378         QFETCH(bool, isInline);
0379         if (hasIsInline) {
0380             att.setIsInline(isInline);
0381         }
0382 
0383         QFETCH(bool, hasIsContactPhoto);
0384         QFETCH(bool, isContactPhoto);
0385         if (hasIsContactPhoto) {
0386             att.setIsContactPhoto(isContactPhoto);
0387         }
0388 
0389         QFETCH(bool, hasContent);
0390         QFETCH(QByteArray, content);
0391         if (hasContent) {
0392             att.setContent(content);
0393         }
0394 
0395         QFETCH(bool, hasItem);
0396         QFETCH(EwsItem, item);
0397         if (hasItem) {
0398             att.setItem(item);
0399         }
0400     }
0401 
0402     QFETCH(QString, xml);
0403 
0404     QString xmlData;
0405     QXmlStreamWriter writer(&xmlData);
0406 
0407     writer.setCodec("UTF-8");
0408 
0409     writer.writeStartDocument();
0410 
0411     writer.writeDefaultNamespace(xmlTypeNsUri);
0412 
0413     att.write(writer);
0414 
0415     writer.writeEndDocument();
0416 
0417     QCOMPARE(xmlData.trimmed(), xml);
0418 }
0419 
0420 void UtEwsAttachment::write_data()
0421 {
0422     QTest::addColumn<QString>("xml");
0423     QTest::addColumn<bool>("isValid");
0424 
0425     QTest::addColumn<EwsAttachment::Type>("type");
0426 
0427     QTest::addColumn<bool>("hasId");
0428     QTest::addColumn<QString>("id");
0429 
0430     QTest::addColumn<bool>("hasName");
0431     QTest::addColumn<QString>("name");
0432 
0433     QTest::addColumn<bool>("hasContentType");
0434     QTest::addColumn<QString>("contentType");
0435 
0436     QTest::addColumn<bool>("hasContentId");
0437     QTest::addColumn<QString>("contentId");
0438 
0439     QTest::addColumn<bool>("hasContentLocation");
0440     QTest::addColumn<QString>("contentLocation");
0441 
0442     QTest::addColumn<bool>("hasSize");
0443     QTest::addColumn<long>("size");
0444 
0445     QTest::addColumn<bool>("hasLastModifiedTime");
0446     QTest::addColumn<QDateTime>("lastModifiedTime");
0447 
0448     QTest::addColumn<bool>("hasIsInline");
0449     QTest::addColumn<bool>("isInline");
0450 
0451     QTest::addColumn<bool>("hasIsContactPhoto");
0452     QTest::addColumn<bool>("isContactPhoto");
0453 
0454     QTest::addColumn<bool>("hasContent");
0455     QTest::addColumn<QByteArray>("content");
0456 
0457     QTest::addColumn<bool>("hasItem");
0458     QTest::addColumn<EwsItem>("item");
0459 
0460     QTest::newRow("invalid") << xmlHead << false << EwsAttachment::UnknownAttachment << false << QString() << false << QString() << false << QString() << false
0461                              << QString() << false << QString() << false << 0l << false << QDateTime() << false << false << false << false << false
0462                              << QByteArray() << false << EwsItem();
0463 
0464     QTest::newRow("unknown type") << xmlHead << true << EwsAttachment::UnknownAttachment << false << QString() << false << QString() << false << QString()
0465                                   << false << QString() << false << QString() << false << 0l << false << QDateTime() << false << false << false << false
0466                                   << false << QByteArray() << false << EwsItem();
0467 
0468     QTest::newRow("empty file attachment") << xmlHead + QStringLiteral("<FileAttachment xmlns=\"") + xmlTypeNsUri + QStringLiteral("\"/>") << true
0469                                            << EwsAttachment::FileAttachment << false << QString() << false << QString() << false << QString() << false
0470                                            << QString() << false << QString() << false << 0l << false << QDateTime() << false << false << false << false
0471                                            << false << QByteArray() << false << EwsItem();
0472 
0473     QTest::newRow("empty item attachment") << xmlHead + QStringLiteral("<ItemAttachment xmlns=\"") + xmlTypeNsUri + QStringLiteral("\"/>") << true
0474                                            << EwsAttachment::ItemAttachment << false << QString() << false << QString() << false << QString() << false
0475                                            << QString() << false << QString() << false << 0l << false << QDateTime() << false << false << false << false
0476                                            << false << QByteArray() << false << EwsItem();
0477 
0478     QTest::newRow("empty reference attachment") << xmlHead + QStringLiteral("<ReferenceAttachment xmlns=\"") + xmlTypeNsUri + QStringLiteral("\"/>") << true
0479                                                 << EwsAttachment::ReferenceAttachment << false << QString() << false << QString() << false << QString() << false
0480                                                 << QString() << false << QString() << false << 0l << false << QDateTime() << false << false << false << false
0481                                                 << false << QByteArray() << false << EwsItem();
0482 
0483     QTest::newRow("non-empty reference attachment") << xmlHead + QStringLiteral("<ReferenceAttachment xmlns=\"") + xmlTypeNsUri + QStringLiteral("\"/>") << true
0484                                                     << EwsAttachment::ReferenceAttachment << true << QStringLiteral("5IaIqJVsJzamf2105wg4wQ==") << false
0485                                                     << QString() << false << QString() << false << QString() << false << QString() << false << 0l << false
0486                                                     << QDateTime() << false << false << false << false << false << QByteArray() << false << EwsItem();
0487 
0488     EwsItem item1;
0489     item1.setType(EwsItemTypeItem);
0490     item1.setField(EwsItemFieldItemId, QVariant::fromValue<EwsId>(EwsId(QStringLiteral("VGhpcyBpcyBhIHRlc3Q="), QStringLiteral("muKls0n8pUM="))));
0491 
0492     QDateTime testDt(QDateTime::fromSecsSinceEpoch(1483621243, QTimeZone::utc()));
0493 
0494     QTest::newRow("non-empty item attachment") << xmlHead + QStringLiteral("<ItemAttachment xmlns=\"") + xmlTypeNsUri
0495             + QStringLiteral(
0496                   "\">"
0497                   "<AttachmentId Id=\"5IaIqJVsJzamf2105wg4wQ==\"/>"
0498                   "<ContentType>application/x-test</ContentType>"
0499                   "<ContentLocation>file:///foo/bar</ContentLocation>"
0500                   "<LastModifiedTime>%1</LastModifiedTime>"
0501                   "<Akonadi/Item><ItemId Id=\"VGhpcyBpcyBhIHRlc3Q=\" ChangeKey=\"muKls0n8pUM=\"/></Item>"
0502                   "</ItemAttachment>")
0503                   .arg(testDt.toString(Qt::ISODate))
0504                                                << true << EwsAttachment::ItemAttachment << true << QStringLiteral("5IaIqJVsJzamf2105wg4wQ==") << false
0505                                                << QStringLiteral("Test attachment") << true << QStringLiteral("application/x-test") << false
0506                                                << QStringLiteral("FE938BD618330B9DA0C965A6077BB3FF20415531@1") << true << QStringLiteral("file:///foo/bar")
0507                                                << false << 123l << true << testDt << false << true << true << true << true << QByteArray("This is another test")
0508                                                << true << item1;
0509 
0510     QTest::newRow("non-empty file attachment") << xmlHead + QStringLiteral("<FileAttachment xmlns=\"") + xmlTypeNsUri
0511             + QStringLiteral("\">"
0512                              "<Name>Test attachment</Name>"
0513                              "<ContentId>FE938BD618330B9DA0C965A6077BB3FF20415531@1</ContentId>"
0514                              "<Size>123</Size>"
0515                              "<IsInline>true</IsInline>"
0516                              "<IsContactPhoto>true</IsContactPhoto>"
0517                              "<Content>VGhpcyBpcyBhbm90aGVyIHRlc3Q=</Content>"
0518                              "</FileAttachment>")
0519                                                << true << EwsAttachment::FileAttachment << false << QStringLiteral("5IaIqJVsJzamf2105wg4wQ==") << true
0520                                                << QStringLiteral("Test attachment") << false << QStringLiteral("application/x-test") << true
0521                                                << QStringLiteral("FE938BD618330B9DA0C965A6077BB3FF20415531@1") << false << QStringLiteral("file:///foo/bar")
0522                                                << true << 123l << false << testDt << true << true << true << true << true << QByteArray("This is another test")
0523                                                << true << item1;
0524 }
0525 
0526 QTEST_MAIN(UtEwsAttachment)
0527 
0528 #include "ewsattachment_ut.moc"