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

kaddressbook

  • sources
  • kde-4.14
  • kdepim
  • kaddressbook
  • printing
  • grantlee
  • autotests
grantleeprinttest.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 #include "grantleeprinttest.h"
19 #include "../grantleeprint.h"
20 #include <qtest_kde.h>
21 #include <KABC/Addressee>
22 
23 GrantleePrintTest::GrantleePrintTest(QObject *parent)
24  : QObject(parent)
25 {
26 
27 }
28 
29 GrantleePrintTest::~GrantleePrintTest()
30 {
31 
32 }
33 
34 void GrantleePrintTest::shouldHaveDefaultValue()
35 {
36  KABPrinting::GrantleePrint *grantleePrint = new KABPrinting::GrantleePrint;
37  QVERIFY(grantleePrint);
38  grantleePrint->deleteLater();
39  grantleePrint = 0;
40 }
41 
42 void GrantleePrintTest::shouldReturnEmptyStringWhenNotContentAndNoContacts()
43 {
44  KABPrinting::GrantleePrint *grantleePrint = new KABPrinting::GrantleePrint;
45  KABC::Addressee::List lst;
46  QVERIFY(grantleePrint->contactsToHtml(lst).isEmpty());
47  grantleePrint->deleteLater();
48  grantleePrint = 0;
49 }
50 
51 void GrantleePrintTest::shouldReturnEmptyStringWhenAddContentWithoutContacts()
52 {
53  KABPrinting::GrantleePrint *grantleePrint = new KABPrinting::GrantleePrint;
54  grantleePrint->setContent(QLatin1String("foo"));
55  KABC::Addressee::List lst;
56 
57  QVERIFY(grantleePrint->contactsToHtml(lst).isEmpty());
58  grantleePrint->deleteLater();
59  grantleePrint = 0;
60 }
61 
62 void GrantleePrintTest::shouldReturnStringWhenAddContentAndContacts()
63 {
64  KABPrinting::GrantleePrint *grantleePrint = new KABPrinting::GrantleePrint;
65  grantleePrint->setContent(QLatin1String("foo"));
66  KABC::Addressee::List lst;
67  KABC::Addressee address;
68  address.setName(QLatin1String("foo1"));
69  address.insertEmail(QLatin1String("foo@kde.org"), true);
70  lst << address;
71 
72  QCOMPARE(grantleePrint->contactsToHtml(lst), QLatin1String("foo"));
73  grantleePrint->deleteLater();
74  grantleePrint = 0;
75 }
76 
77 void GrantleePrintTest::shouldReturnEmails()
78 {
79  KABPrinting::GrantleePrint *grantleePrint = new KABPrinting::GrantleePrint;
80  KABC::Addressee::List lst;
81  KABC::Addressee address;
82  address.setName(QLatin1String("foo1"));
83  address.insertEmail(QLatin1String("foo@kde.org"), true);
84  lst << address;
85  grantleePrint->setContent(QLatin1String("{% if contacts %}{% for contact in contacts %}{% if contact.name %}{{ contact.name }}{% endif %}{% endfor %}{% endif %}"));
86 
87  QCOMPARE(grantleePrint->contactsToHtml(lst), QLatin1String("foo1"));
88  grantleePrint->deleteLater();
89  grantleePrint = 0;
90 }
91 
92 void GrantleePrintTest::shouldDisplayContactInfo_data()
93 {
94  QTest::addColumn<QString>("variable");
95  QTest::addColumn<QString>("result");
96  QTest::newRow("name") << QString(QLatin1String("name")) << QString(QLatin1String("foo1"));
97  QTest::newRow("organization") << QString(QLatin1String("organization")) << QString(QLatin1String("kde"));
98  QTest::newRow("languages") << QString(QLatin1String("languages")) << QString(QLatin1String("fr"));
99  QTest::newRow("note") << QString(QLatin1String("note")) << QString(QLatin1String("foo-note"));
100  QTest::newRow("title") << QString(QLatin1String("title")) << QString(QLatin1String("foo-title"));
101  QTest::newRow("nickName") << QString(QLatin1String("nickName")) << QString(QLatin1String("foo-nickname"));
102  QTest::newRow("familyName") << QString(QLatin1String("familyName")) << QString(QLatin1String("foo-familyname"));
103  QTest::newRow("role") << QString(QLatin1String("role")) << QString(QLatin1String("foo-role"));
104  QTest::newRow("suffix") << QString(QLatin1String("suffix")) << QString(QLatin1String("foo-suffix"));
105  QTest::newRow("prefix") << QString(QLatin1String("prefix")) << QString(QLatin1String("foo-prefix"));
106  QTest::newRow("department") << QString(QLatin1String("department")) << QString(QLatin1String("foo-department"));
107  QTest::newRow("office") << QString(QLatin1String("office")) << QString(QLatin1String("foo-office"));
108  QTest::newRow("profesion") << QString(QLatin1String("profession")) << QString(QLatin1String("foo-profession"));
109  QTest::newRow("manager") << QString(QLatin1String("manager")) << QString(QLatin1String("foo-managersname"));
110  QTest::newRow("assistant") << QString(QLatin1String("assistant")) << QString(QLatin1String("foo-assistantsname"));
111  QTest::newRow("spouse") << QString(QLatin1String("spouse")) << QString(QLatin1String("foo-spousesname"));
112  QTest::newRow("givenname") << QString(QLatin1String("givenName")) << QString(QLatin1String("foo-givenname"));
113  QTest::newRow("additionalname") << QString(QLatin1String("additionalName")) << QString(QLatin1String("foo-additionalname"));
114 #if 0
115  QString realName() const;
116  QString formattedName() const;
117  QStringList emails() const;
118  QString webPage() const;
119  QString preferredEmail() const;
120  QString birthday() const;
121  QVariant addresses() const;
122  QVariant phones() const;
123  QString addressBookName() const;
124  QVariant instantManging() const;
125  QVariant geo() const;
126  QString photo() const;
127  QString logo() const;
128  QVariant crypto() const;
129 #endif
130 }
131 
132 void GrantleePrintTest::shouldDisplayContactInfo()
133 {
134  QFETCH( QString, variable );
135  QFETCH( QString, result );
136 
137  KABPrinting::GrantleePrint *grantleePrint = new KABPrinting::GrantleePrint;
138  KABC::Addressee::List lst;
139  KABC::Addressee address;
140  address.setGivenName(QLatin1String("foo-givenname"));
141  address.setAdditionalName(QLatin1String("foo-additionalname"));
142  address.setName(QLatin1String("foo1"));
143  address.insertEmail(QLatin1String("foo@kde.org"), true);
144  address.setOrganization(QLatin1String("kde"));
145  address.insertLang(KABC::Lang(QLatin1String("fr")));
146  address.setNote(QLatin1String("foo-note"));
147  address.setTitle(QLatin1String("foo-title"));
148  address.setNickName(QLatin1String("foo-nickname"));
149  address.setFamilyName(QLatin1String("foo-familyname"));
150  address.setRole(QLatin1String("foo-role"));
151  address.setSuffix(QLatin1String("foo-suffix"));
152  address.setPrefix(QLatin1String("foo-prefix"));
153  address.setDepartment(QLatin1String("foo-department"));
154  address.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Office" ), QString(QLatin1String("foo-office")));
155  address.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Profession" ) , QString(QLatin1String("foo-profession")));
156  address.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-Office" ) , QString(QLatin1String("foo-office")));
157  address.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-ManagersName" ) , QString(QLatin1String("foo-managersname")));
158  address.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-AssistantsName" ) , QString(QLatin1String("foo-assistantsname")));
159  address.insertCustom( QLatin1String( "KADDRESSBOOK" ), QLatin1String( "X-SpousesName" ) , QString(QLatin1String("foo-spousesname")));
160 
161  lst << address;
162  grantleePrint->setContent(QString::fromLatin1("{% if contacts %}{% for contact in contacts %}{% if contact.%1 %}{{ contact.%1 }}{% endif %}{% endfor %}{% endif %}").arg(variable));
163 
164  QCOMPARE(grantleePrint->contactsToHtml(lst), result);
165  grantleePrint->deleteLater();
166  grantleePrint = 0;
167 }
168 
169 QTEST_KDEMAIN(GrantleePrintTest, NoGUI)
GrantleePrintTest::~GrantleePrintTest
~GrantleePrintTest()
Definition: grantleeprinttest.cpp:29
QObject
QString::isEmpty
bool isEmpty() const
QObject::deleteLater
void deleteLater()
QString
QStringList
QObject::setName
void setName(const char *name)
QTest::newRow
QTestData & newRow(const char *dataTag)
QLatin1String
GrantleePrintTest::GrantleePrintTest
GrantleePrintTest(QObject *parent=0)
Definition: grantleeprinttest.cpp:23
GrantleePrintTest
Definition: grantleeprinttest.h:23
KABPrinting::GrantleePrint::contactsToHtml
QString contactsToHtml(const KABC::Addressee::List &contacts)
Definition: grantleeprint.cpp:64
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KABPrinting::GrantleePrint::setContent
void setContent(const QString &content)
Definition: grantleeprint.cpp:56
grantleeprinttest.h
KABPrinting::GrantleePrint
Definition: grantleeprint.h:31
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:34 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kaddressbook

Skip menu "kaddressbook"
  • 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