• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • pim API Reference
  • KDE Home
  • Contact Us
 

kmailtransport

  • kde-4.x
  • pim
  • kmailtransport
  • src
  • kmailtransportakonadi
  • autotests
attributetest.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2009 Constantin Berzan <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 
20 #include "attributetest.h"
21 
22 #include <attributefactory.h>
23 #include <qtest_akonadi.h>
24 #include <addressattribute.h>
25 
26 #include <kmailtransportakonadi/dispatchmodeattribute.h>
27 #include <kmailtransportakonadi/errorattribute.h>
28 #include <kmailtransportakonadi/sentactionattribute.h>
29 #include <kmailtransportakonadi/sentbehaviourattribute.h>
30 #include <kmailtransportakonadi/transportattribute.h>
31 
32 using namespace Akonadi;
33 using namespace MailTransport;
34 
35 void AttributeTest::initTestCase()
36 {
37 }
38 
39 void AttributeTest::testRegistrar()
40 {
41  // The attributes should have been registered without any effort on our part.
42  {
43  Attribute *a = AttributeFactory::createAttribute("AddressAttribute");
44  QVERIFY(dynamic_cast<AddressAttribute *>(a));
45  delete a;
46  }
47 
48  {
49  Attribute *a = AttributeFactory::createAttribute("DispatchModeAttribute");
50  QVERIFY(dynamic_cast<DispatchModeAttribute *>(a));
51  delete a;
52  }
53 
54  {
55  Attribute *a = AttributeFactory::createAttribute("ErrorAttribute");
56  QVERIFY(dynamic_cast<ErrorAttribute *>(a));
57  delete a;
58  }
59 
60  {
61  Attribute *a = AttributeFactory::createAttribute("SentActionAttribute");
62  QVERIFY(dynamic_cast<SentActionAttribute *>(a));
63  delete a;
64  }
65 
66  {
67  Attribute *a = AttributeFactory::createAttribute("SentBehaviourAttribute");
68  QVERIFY(dynamic_cast<SentBehaviourAttribute *>(a));
69  delete a;
70  }
71 
72  {
73  Attribute *a = AttributeFactory::createAttribute("TransportAttribute");
74  QVERIFY(dynamic_cast<TransportAttribute *>(a));
75  delete a;
76  }
77 }
78 
79 void AttributeTest::testSerialization()
80 {
81  {
82  QString from(QStringLiteral("[email protected]"));
83  QStringList to(QStringLiteral("[email protected]"));
84  to << QStringLiteral("[email protected]");
85  QStringList cc(QStringLiteral("[email protected]"));
86  cc << QStringLiteral("[email protected]");
87  QStringList bcc(QStringLiteral("[email protected]"));
88  bcc << QStringLiteral("[email protected]");
89  AddressAttribute *a = new AddressAttribute(from, to, cc, bcc);
90  QByteArray data = a->serialized();
91  delete a;
92  a = new AddressAttribute;
93  a->deserialize(data);
94  QCOMPARE(from, a->from());
95  QCOMPARE(to, a->to());
96  QCOMPARE(cc, a->cc());
97  QCOMPARE(bcc, a->bcc());
98  delete a;
99  }
100 
101  {
102  DispatchModeAttribute::DispatchMode mode = DispatchModeAttribute::Automatic;
103  QDateTime date = QDateTime::currentDateTime();
104  // The serializer does not keep track of milliseconds, so forget them.
105  qDebug() << "ms" << date.toString(QStringLiteral("z"));
106  int ms = date.toString(QStringLiteral("z")).toInt();
107  date = date.addMSecs(-ms);
108  DispatchModeAttribute *a = new DispatchModeAttribute(mode);
109  a->setSendAfter(date);
110  QByteArray data = a->serialized();
111  delete a;
112  a = new DispatchModeAttribute;
113  a->deserialize(data);
114  QCOMPARE(mode, a->dispatchMode());
115  QCOMPARE(date, a->sendAfter());
116  delete a;
117  }
118 
119  {
120  QString msg(QStringLiteral("The #[email protected]$ing thing failed!"));
121  ErrorAttribute *a = new ErrorAttribute(msg);
122  QByteArray data = a->serialized();
123  delete a;
124  a = new ErrorAttribute;
125  a->deserialize(data);
126  QCOMPARE(msg, a->message());
127  delete a;
128  }
129 
130  {
131  SentActionAttribute *a = new SentActionAttribute();
132  const qlonglong id = 123456789012345ll;
133 
134  a->addAction(SentActionAttribute::Action::MarkAsReplied, QVariant(id));
135  a->addAction(SentActionAttribute::Action::MarkAsForwarded, QVariant(id));
136 
137  QByteArray data = a->serialized();
138  delete a;
139  a = new SentActionAttribute;
140  a->deserialize(data);
141 
142  const SentActionAttribute::Action::List actions = a->actions();
143  QCOMPARE(actions.count(), 2);
144 
145  QCOMPARE(SentActionAttribute::Action::MarkAsReplied, actions[0].type());
146  QCOMPARE(id, actions[0].value().toLongLong());
147 
148  QCOMPARE(SentActionAttribute::Action::MarkAsForwarded, actions[1].type());
149  QCOMPARE(id, actions[1].value().toLongLong());
150  delete a;
151  }
152 
153  {
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);
159  QByteArray data = a->serialized();
160  delete a;
161  a = new SentBehaviourAttribute;
162  a->deserialize(data);
163  QCOMPARE(beh, a->sentBehaviour());
164  QCOMPARE(id, a->moveToCollection().id());
165  QCOMPARE(sendSilently, a->sendSilently());
166  delete a;
167  }
168 
169  //MoveToCollection + silently
170  {
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);
176  QByteArray data = a->serialized();
177  delete a;
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);
187  delete a;
188  delete copy;
189  }
190 
191  //Delete + silently
192  {
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);
198  QByteArray data = a->serialized();
199  delete a;
200  a = new SentBehaviourAttribute;
201  a->deserialize(data);
202  QCOMPARE(beh, a->sentBehaviour());
203  //When delete we move to -1
204  QCOMPARE(a->moveToCollection().id(), -1);
205  QCOMPARE(sendSilently, a->sendSilently());
206  SentBehaviourAttribute *copy = a->clone();
207  QCOMPARE(copy->sentBehaviour(), beh);
208  //When delete we move to -1
209  QCOMPARE(copy->moveToCollection().id(), -1);
210  QCOMPARE(copy->sendSilently(), sendSilently);
211  delete a;
212  delete copy;
213  }
214 
215  //MoveToDefaultSentCollection + silently
216  {
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);
222  QByteArray data = a->serialized();
223  delete a;
224  a = new SentBehaviourAttribute;
225  a->deserialize(data);
226  QCOMPARE(beh, a->sentBehaviour());
227  //When movetodefaultsendCollection we move to -1
228  QCOMPARE(a->moveToCollection().id(), -1);
229  QCOMPARE(sendSilently, a->sendSilently());
230  SentBehaviourAttribute *copy = a->clone();
231  QCOMPARE(copy->sentBehaviour(), beh);
232  //When movetodefaultsendCollection we move to -1
233  QCOMPARE(copy->moveToCollection().id(), -1);
234  QCOMPARE(copy->sendSilently(), sendSilently);
235  delete a;
236  delete copy;
237  }
238 
239  {
240  int id = 3219;
241  TransportAttribute *a = new TransportAttribute(id);
242  QByteArray data = a->serialized();
243  delete a;
244  a = new TransportAttribute;
245  a->deserialize(data);
246  QCOMPARE(id, a->transportId());
247  delete a;
248  }
249 }
250 
251 QTEST_AKONADIMAIN(AttributeTest)
QDateTime::toString
QString toString(Qt::DateFormat format) const
dispatchmodeattribute.h
QByteArray
AttributeTest
This is a test of the various attributes.
Definition: attributetest.h:28
sentactionattribute.h
QString::toInt
int toInt(bool *ok, int base) const
QString
QStringList
sentbehaviourattribute.h
QDateTime::currentDateTime
QDateTime currentDateTime()
transportattribute.h
errorattribute.h
QDateTime
QVariant
QDateTime::addMSecs
QDateTime addMSecs(qint64 msecs) const
attributetest.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Wed Dec 11 2019 06:51:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kmailtransport

Skip menu "kmailtransport"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

pim API Reference

Skip menu "pim API Reference"
  • akonadi-calendar-tools
  •   konsolekalendar
  • akregator
  •   src
  • kalarmcal
  •   src
  •     lib
  • kdepim-runtime
  •   agents
  •   src
  • kleopatra
  •   src
  • kmailtransport
  • knotes
  • kontact
  • kontactinterface
  • kpimtextedit
  • ksmtp
  • ktnef
  • libkgapi
  • libkleo
  •   src
  •     src
  •     src

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal