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

knotes

  • sources
  • kde-4.14
  • kdepim
  • knotes
  • print
  • autotests
knotesgrantleeprinttest.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2015 Montel Laurent <montel@kde.org>
3 
4  This program is free software; you can redistribute it and/or modify it
5  under the terms of the GNU General Public License, version 2, as
6  published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful, but
9  WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 
19 #include "knotesgrantleeprinttest.h"
20 #include "../knotegrantleeprint.h"
21 #include <qtest_kde.h>
22 #include <KMime/Message>
23 #include <Akonadi/Item>
24 #include <knotes/print/knoteprintobject.h>
25 #include <Akonadi/Notes/NoteUtils>
26 
27 KNotesGrantleePrintTest::KNotesGrantleePrintTest(QObject *parent)
28  : QObject(parent)
29 {
30 
31 }
32 
33 KNotesGrantleePrintTest::~KNotesGrantleePrintTest()
34 {
35 
36 }
37 
38 void KNotesGrantleePrintTest::shouldDefaultValue()
39 {
40  KNoteGrantleePrint *grantleePrint = new KNoteGrantleePrint;
41  QVERIFY(grantleePrint);
42  grantleePrint->deleteLater();
43  grantleePrint = 0;
44 }
45 
46 void KNotesGrantleePrintTest::shouldReturnEmptyStringWhenNotContentAndNoNotes()
47 {
48  KNoteGrantleePrint *grantleePrint = new KNoteGrantleePrint;
49  QList<KNotePrintObject *> lst;
50  const QString result = grantleePrint->notesToHtml(lst);
51  QVERIFY(result.isEmpty());
52  grantleePrint->deleteLater();
53  grantleePrint = 0;
54 }
55 
56 void KNotesGrantleePrintTest::shouldReturnEmptyStringWhenAddContentWithoutNotes()
57 {
58  KNoteGrantleePrint *grantleePrint = new KNoteGrantleePrint;
59  grantleePrint->setContent(QLatin1String("foo"));
60  QList<KNotePrintObject *> lst;
61  const QString result = grantleePrint->notesToHtml(lst);
62  QVERIFY(result.isEmpty());
63  grantleePrint->deleteLater();
64  grantleePrint = 0;
65 }
66 
67 void KNotesGrantleePrintTest::shouldDisplayNoteInfo_data()
68 {
69  QTest::addColumn<QString>("variable");
70  QTest::addColumn<QString>("result");
71  QTest::newRow("name") << QString(QLatin1String("name")) << QString(QLatin1String("Test Note"));
72  QTest::newRow("description") << QString(QLatin1String("description")) << QString(QLatin1String("notes test"));
73 }
74 
75 void KNotesGrantleePrintTest::shouldDisplayNoteInfo()
76 {
77  QFETCH( QString, variable );
78  QFETCH( QString, result );
79  Akonadi::Item note(42);
80 
81  KNoteGrantleePrint *grantleePrint = new KNoteGrantleePrint;
82  grantleePrint->setContent(QString::fromLatin1("{% if notes %}{% for note in notes %}{{ note.%1 }}{% endfor %}{% endif %}").arg(variable));
83 
84  KMime::Message::Ptr msg(new KMime::Message);
85  note.setMimeType( Akonadi::NoteUtils::noteMimeType() );
86  QString subject = QLatin1String("Test Note");
87  msg->subject(true)->fromUnicodeString(subject, "us-ascii");
88  msg->contentType( true )->setMimeType( "text/plain" );
89  msg->contentType()->setCharset("utf-8");
90  msg->contentTransferEncoding(true)->setEncoding(KMime::Headers::CEquPr);
91  msg->date( true )->setDateTime( KDateTime::currentLocalDateTime() );
92  msg->mainBodyPart()->fromUnicodeString( QLatin1String("notes test") );
93  note.setPayload( msg );
94  msg->assemble();
95 
96  QList<KNotePrintObject *> lst;
97  KNotePrintObject *obj = new KNotePrintObject(note);
98  lst << obj;
99  const QString html = grantleePrint->notesToHtml(lst);
100  QCOMPARE(html, result);
101  grantleePrint->deleteLater();
102  grantleePrint = 0;
103 }
104 
105 
106 QTEST_KDEMAIN(KNotesGrantleePrintTest, NoGUI)
KNotePrintObject
Definition: knoteprintobject.h:27
KNoteGrantleePrint::setContent
void setContent(const QString &content)
Definition: knotegrantleeprint.cpp:56
KNoteGrantleePrint
Definition: knotegrantleeprint.h:28
knotesgrantleeprinttest.h
KNotesGrantleePrintTest::~KNotesGrantleePrintTest
~KNotesGrantleePrintTest()
Definition: knotesgrantleeprinttest.cpp:33
knoteprintobject.h
QObject
QString::isEmpty
bool isEmpty() const
KNotesGrantleePrintTest
Definition: knotesgrantleeprinttest.h:23
QObject::deleteLater
void deleteLater()
QString
QList
KNotesGrantleePrintTest::KNotesGrantleePrintTest
KNotesGrantleePrintTest(QObject *parent=0)
Definition: knotesgrantleeprinttest.cpp:27
QTest::newRow
QTestData & newRow(const char *dataTag)
QLatin1String
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KNoteGrantleePrint::notesToHtml
QString notesToHtml(const QList< KNotePrintObject * > lst)
Definition: knotegrantleeprint.cpp:64
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:28 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

knotes

Skip menu "knotes"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

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