summaryrefslogtreecommitdiff
path: root/notes/tests/notestest.cpp
blob: fcf5a0faeb5011acaa9442801a3522013401e977 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
    Copyright (c) 2012 Christian Mollekopf <mollekopf@kolabsys.com>

    This library is free software; you can redistribute it and/or modify it
    under the terms of the GNU Library General Public License as published by
    the Free Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This library is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
    License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to the
    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
*/

#include "noteutils.h"

#include <QTest>
#include <QHash>
#include <QDebug>

#include <KDateTime>
#include <kmime/kmime_message.h>

using namespace Akonadi::NoteUtils;
class NotesTest : public QObject
{
  Q_OBJECT
  private slots:

    void testSerializeAndParse()
    {
      NoteMessageWrapper note;
      note.setTitle("title");
      note.setText("title");
      note.setUid("uid");
      note.setClassification(NoteMessageWrapper::Private);
      note.setFrom("from@kde.org");
      note.setCreationDate(KDateTime(QDate(2012,3,3), QTime(3,3,3), KDateTime::UTC));
      note.setLastModifiedDate(KDateTime(QDate(2012,3,3), QTime(4,4,4), KDateTime::UTC));
      Attachment a("testfile2", "mimetype/mime3");
      a.setLabel("label");
      note.attachments() << Attachment(QUrl("file://url/to/file"), "mimetype/mime") << Attachment("testfile", "mimetype/mime2") << a;
      note.custom().insert("key1", "value1");
      note.custom().insert("key2", "value2");
      note.custom().insert("key3", "value3");

      KMime::MessagePtr msg = note.message();
//       qWarning() << msg->encodedContent();

      NoteMessageWrapper result(msg);

      QCOMPARE(result.title(), note.title());
      QCOMPARE(result.text(), note.text());
      QCOMPARE(result.textFormat(), note.textFormat());
      QCOMPARE(result.uid(), note.uid());
      QCOMPARE(result.classification(), note.classification());
      QCOMPARE(result.from(), note.from());
      QCOMPARE(result.creationDate(), note.creationDate());
      QCOMPARE(result.lastModifiedDate(), note.lastModifiedDate());
      QCOMPARE(result.custom(), note.custom());
      QCOMPARE(result.attachments(), note.attachments());

//       qWarning() << result.message()->encodedContent();
    }

    void createIfEmpty()
    {
      NoteMessageWrapper note;
      NoteMessageWrapper result(note.message());
//       qDebug() << result.uid();
      QVERIFY(!result.uid().isEmpty());
      QVERIFY(result.creationDate().isValid());
      QVERIFY(result.lastModifiedDate().isValid());
    }

};

QTEST_MAIN( NotesTest )

#include "notestest.moc"