22 #include <attributefactory.h>
23 #include <qtest_akonadi.h>
24 #include <addressattribute.h>
32 using namespace Akonadi;
33 using namespace MailTransport;
35 void AttributeTest::initTestCase()
39 void AttributeTest::testRegistrar()
43 Attribute *a = AttributeFactory::createAttribute(
"AddressAttribute");
44 QVERIFY(dynamic_cast<AddressAttribute *>(a));
49 Attribute *a = AttributeFactory::createAttribute(
"DispatchModeAttribute");
50 QVERIFY(dynamic_cast<DispatchModeAttribute *>(a));
55 Attribute *a = AttributeFactory::createAttribute(
"ErrorAttribute");
56 QVERIFY(dynamic_cast<ErrorAttribute *>(a));
61 Attribute *a = AttributeFactory::createAttribute(
"SentActionAttribute");
62 QVERIFY(dynamic_cast<SentActionAttribute *>(a));
67 Attribute *a = AttributeFactory::createAttribute(
"SentBehaviourAttribute");
68 QVERIFY(dynamic_cast<SentBehaviourAttribute *>(a));
73 Attribute *a = AttributeFactory::createAttribute(
"TransportAttribute");
74 QVERIFY(dynamic_cast<TransportAttribute *>(a));
79 void AttributeTest::testSerialization()
89 AddressAttribute *a =
new AddressAttribute(from, to, cc, bcc);
92 a =
new AddressAttribute;
94 QCOMPARE(from, a->from());
95 QCOMPARE(to, a->to());
96 QCOMPARE(cc, a->cc());
97 QCOMPARE(bcc, a->bcc());
102 DispatchModeAttribute::DispatchMode mode = DispatchModeAttribute::Automatic;
105 qDebug() <<
"ms" << date.
toString(QStringLiteral(
"z"));
108 DispatchModeAttribute *a =
new DispatchModeAttribute(mode);
109 a->setSendAfter(date);
112 a =
new DispatchModeAttribute;
113 a->deserialize(data);
114 QCOMPARE(mode, a->dispatchMode());
115 QCOMPARE(date, a->sendAfter());
121 ErrorAttribute *a =
new ErrorAttribute(msg);
124 a =
new ErrorAttribute;
125 a->deserialize(data);
126 QCOMPARE(msg, a->message());
131 SentActionAttribute *a =
new SentActionAttribute();
132 const qlonglong
id = 123456789012345ll;
134 a->addAction(SentActionAttribute::Action::MarkAsReplied,
QVariant(
id));
135 a->addAction(SentActionAttribute::Action::MarkAsForwarded,
QVariant(
id));
139 a =
new SentActionAttribute;
140 a->deserialize(data);
142 const SentActionAttribute::Action::List actions = a->actions();
143 QCOMPARE(actions.count(), 2);
145 QCOMPARE(SentActionAttribute::Action::MarkAsReplied, actions[0].type());
146 QCOMPARE(
id, actions[0].value().toLongLong());
148 QCOMPARE(SentActionAttribute::Action::MarkAsForwarded, actions[1].type());
149 QCOMPARE(
id, actions[1].value().toLongLong());
154 SentBehaviourAttribute::SentBehaviour beh = SentBehaviourAttribute::MoveToCollection;
155 Collection::Id
id = 123456789012345ll;
156 SentBehaviourAttribute *a =
new SentBehaviourAttribute(beh, Collection(
id));
157 bool sendSilently =
true;
158 a->setSendSilently(sendSilently);
161 a =
new SentBehaviourAttribute;
162 a->deserialize(data);
163 QCOMPARE(beh, a->sentBehaviour());
164 QCOMPARE(
id, a->moveToCollection().id());
165 QCOMPARE(sendSilently, a->sendSilently());
171 SentBehaviourAttribute::SentBehaviour beh = SentBehaviourAttribute::MoveToCollection;
172 Collection::Id
id = 123456789012345ll;
173 SentBehaviourAttribute *a =
new SentBehaviourAttribute(beh, Collection(
id));
174 bool sendSilently =
true;
175 a->setSendSilently(sendSilently);
178 a =
new SentBehaviourAttribute;
179 a->deserialize(data);
180 QCOMPARE(beh, a->sentBehaviour());
181 QCOMPARE(
id, a->moveToCollection().id());
182 QCOMPARE(sendSilently, a->sendSilently());
183 SentBehaviourAttribute *copy = a->clone();
184 QCOMPARE(copy->sentBehaviour(), beh);
185 QCOMPARE(copy->moveToCollection().id(), id);
186 QCOMPARE(copy->sendSilently(), sendSilently);
193 SentBehaviourAttribute::SentBehaviour beh = SentBehaviourAttribute::Delete;
194 Collection::Id
id = 123456789012345ll;
195 SentBehaviourAttribute *a =
new SentBehaviourAttribute(beh, Collection(
id));
196 bool sendSilently =
true;
197 a->setSendSilently(sendSilently);
200 a =
new SentBehaviourAttribute;
201 a->deserialize(data);
202 QCOMPARE(beh, a->sentBehaviour());
204 QCOMPARE(a->moveToCollection().id(), -1);
205 QCOMPARE(sendSilently, a->sendSilently());
206 SentBehaviourAttribute *copy = a->clone();
207 QCOMPARE(copy->sentBehaviour(), beh);
209 QCOMPARE(copy->moveToCollection().id(), -1);
210 QCOMPARE(copy->sendSilently(), sendSilently);
217 SentBehaviourAttribute::SentBehaviour beh = SentBehaviourAttribute::MoveToDefaultSentCollection;
218 Collection::Id
id = 123456789012345ll;
219 SentBehaviourAttribute *a =
new SentBehaviourAttribute(beh, Collection(
id));
220 bool sendSilently =
true;
221 a->setSendSilently(sendSilently);
224 a =
new SentBehaviourAttribute;
225 a->deserialize(data);
226 QCOMPARE(beh, a->sentBehaviour());
228 QCOMPARE(a->moveToCollection().id(), -1);
229 QCOMPARE(sendSilently, a->sendSilently());
230 SentBehaviourAttribute *copy = a->clone();
231 QCOMPARE(copy->sentBehaviour(), beh);
233 QCOMPARE(copy->moveToCollection().id(), -1);
234 QCOMPARE(copy->sendSilently(), sendSilently);
241 TransportAttribute *a =
new TransportAttribute(
id);
244 a =
new TransportAttribute;
245 a->deserialize(data);
246 QCOMPARE(
id, a->transportId());
QString toString(Qt::DateFormat format) const
This is a test of the various attributes.
int toInt(bool *ok, int base) const
QDateTime currentDateTime()
QDateTime addMSecs(qint64 msecs) const