Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 0214c0a6 authored by Laurent Montel's avatar Laurent Montel 😁

Add testcase for grantlee printing support

parent 1f8330fd
......@@ -140,6 +140,8 @@ target_link_libraries(kaddressbookprivate
add_subdirectory(merge/tests)
add_subdirectory(sendmail/tests)
add_subdirectory(sendvcards/autotests)
add_subdirectory(printing/grantlee/autotests)
if(QGPGME_FOUND)
target_link_libraries(kaddressbookprivate ${QGPGME_LIBRARIES})
endif()
......
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_SOURCE_DIR}/../../../ )
# Convenience macro to add unit tests.
macro( kaddressbook_printing_grantlee _source )
set( _test ${_source} )
get_filename_component( _name ${_source} NAME_WE )
kde4_add_unit_test( ${_name} TESTNAME kaddressbookprintinggrantlee-${_name} ${_test} )
target_link_libraries( ${_name} kaddressbookprivate ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDEPIMLIBS_AKONADI_LIBS} ${KDEPIMLIBS_KABC_LIBS} )
endmacro()
kaddressbook_printing_grantlee(grantleeprinttest.cpp)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "grantleeprinttest.h"
#include "../grantleeprint.h"
#include <qtest_kde.h>
#include <KABC/Addressee>
GrantleePrintTest::GrantleePrintTest(QObject *parent)
: QObject(parent)
{
}
GrantleePrintTest::~GrantleePrintTest()
{
}
void GrantleePrintTest::shouldHaveDefaultValue()
{
KABPrinting::GrantleePrint *grantleePrint = new KABPrinting::GrantleePrint;
QVERIFY(grantleePrint);
grantleePrint->deleteLater();
grantleePrint = 0;
}
void GrantleePrintTest::shouldReturnEmptyStringWhenNotContentAndNoContacts()
{
KABPrinting::GrantleePrint *grantleePrint = new KABPrinting::GrantleePrint;
KABC::Addressee::List lst;
QVERIFY(grantleePrint->contactsToHtml(lst).isEmpty());
grantleePrint->deleteLater();
grantleePrint = 0;
}
void GrantleePrintTest::shouldReturnEmptyStringWhenAddContentWithoutContacts()
{
KABPrinting::GrantleePrint *grantleePrint = new KABPrinting::GrantleePrint;
grantleePrint->setContent(QLatin1String("foo"));
KABC::Addressee::List lst;
QVERIFY(grantleePrint->contactsToHtml(lst).isEmpty());
grantleePrint->deleteLater();
grantleePrint = 0;
}
void GrantleePrintTest::shouldReturnStringWhenAddContentAndContacts()
{
KABPrinting::GrantleePrint *grantleePrint = new KABPrinting::GrantleePrint;
grantleePrint->setContent(QLatin1String("foo"));
KABC::Addressee::List lst;
KABC::Addressee address;
address.setName(QLatin1String("foo1"));
address.insertEmail(QLatin1String("foo@kde.org"), true);
lst << address;
QCOMPARE(grantleePrint->contactsToHtml(lst), QLatin1String("foo"));
grantleePrint->deleteLater();
grantleePrint = 0;
}
void GrantleePrintTest::shouldReturnEmails()
{
KABPrinting::GrantleePrint *grantleePrint = new KABPrinting::GrantleePrint;
KABC::Addressee::List lst;
KABC::Addressee address;
address.setName(QLatin1String("foo1"));
address.insertEmail(QLatin1String("foo@kde.org"), true);
lst << address;
grantleePrint->setContent(QLatin1String("{% if contacts %}{% for contact in contacts %}{% if contact.name %}{{ contact.name }}{% endif %}{% endfor %}{% endif %}"));
QCOMPARE(grantleePrint->contactsToHtml(lst), QLatin1String("foo1"));
grantleePrint->deleteLater();
grantleePrint = 0;
}
void GrantleePrintTest::shouldDisplayContactInfo_data()
{
QTest::addColumn<QString>("variable");
QTest::addColumn<QString>("result");
QTest::newRow("name") << QString(QLatin1String("name")) << QString(QLatin1String("foo1"));
QTest::newRow("organization") << QString(QLatin1String("organization")) << QString(QLatin1String("kde"));
QTest::newRow("languages") << QString(QLatin1String("languages")) << QString(QLatin1String("fr"));
QTest::newRow("note") << QString(QLatin1String("note")) << QString(QLatin1String("foo-note"));
QTest::newRow("title") << QString(QLatin1String("title")) << QString(QLatin1String("foo-title"));
QTest::newRow("nickName") << QString(QLatin1String("nickName")) << QString(QLatin1String("foo-nickname"));
QTest::newRow("familyName") << QString(QLatin1String("familyName")) << QString(QLatin1String("foo-familyname"));
#if 0
QString realName() const;
QString formattedName() const;
QString prefix() const;
QString givenName() const;
QString additionalName() const;
QString suffix() const;
QStringList emails() const;
QString webPage() const;
QString preferredEmail() const;
QString role() const;
QString birthday() const;
QString department() const;
QVariant addresses() const;
QVariant phones() const;
QString addressBookName() const;
QVariant instantManging() const;
QVariant geo() const;
QString photo() const;
QString logo() const;
QVariant crypto() const;
QString anniversary() const;
QString profession() const;
QString office() const;
QString manager() const;
QString assistant() const;
QString spouse() const;
#endif
}
void GrantleePrintTest::shouldDisplayContactInfo()
{
QFETCH( QString, variable );
QFETCH( QString, result );
KABPrinting::GrantleePrint *grantleePrint = new KABPrinting::GrantleePrint;
KABC::Addressee::List lst;
KABC::Addressee address;
address.setName(QLatin1String("foo1"));
address.insertEmail(QLatin1String("foo@kde.org"), true);
address.setOrganization(QLatin1String("kde"));
address.insertLang(KABC::Lang(QLatin1String("fr")));
address.setNote(QLatin1String("foo-note"));
address.setTitle(QLatin1String("foo-title"));
address.setNickName(QLatin1String("foo-nickname"));
address.setFamilyName(QLatin1String("foo-familyname"));
lst << address;
grantleePrint->setContent(QString::fromLatin1("{% if contacts %}{% for contact in contacts %}{% if contact.%1 %}{{ contact.%1 }}{% endif %}{% endfor %}{% endif %}").arg(variable));
QCOMPARE(grantleePrint->contactsToHtml(lst), result);
grantleePrint->deleteLater();
grantleePrint = 0;
}
QTEST_KDEMAIN(GrantleePrintTest, NoGUI)
/*
Copyright (c) 2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program 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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef GRANTLEEPRINTTEST_H
#define GRANTLEEPRINTTEST_H
#include <QObject>
class GrantleePrintTest : public QObject
{
Q_OBJECT
public:
explicit GrantleePrintTest(QObject *parent = 0);
~GrantleePrintTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldReturnEmptyStringWhenNotContentAndNoContacts();
void shouldReturnEmptyStringWhenAddContentWithoutContacts();
void shouldReturnStringWhenAddContentAndContacts();
void shouldReturnEmails();
void shouldDisplayContactInfo_data();
void shouldDisplayContactInfo();
};
#endif // GRANTLEEPRINTTEST_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment