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 761c265e authored by Laurent Montel's avatar Laurent Montel 😁

improve unittest

parent fa4ce7f6
......@@ -4,5 +4,5 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/
set( knotes_knotesgrantleeprint_source knotesgrantleeprinttest.cpp )
kde4_add_unit_test( knotesgrantleeprinttest ${knotes_knotesgrantleeprint_source})
target_link_libraries( knotesgrantleeprinttest ${QT_QTTEST_LIBRARY} ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${KDEPIMLIBS_AKONADI_LIBS} knotesprivate)
target_link_libraries( knotesgrantleeprinttest ${QT_QTTEST_LIBRARY} ${KDE4_KDECORE_LIBS} ${QT_QTGUI_LIBRARY} ${KDEPIMLIBS_AKONADI_LIBS} knotesprivate akonadi_next ${KDEPIMLIBS_KMIME_LIBS})
......@@ -19,6 +19,10 @@
#include "knotesgrantleeprinttest.h"
#include "../knotegrantleeprint.h"
#include <qtest_kde.h>
#include <KMime/Message>
#include <Akonadi/Item>
#include <knotes/print/knoteprintobject.h>
#include "akonadi_next/note.h"
KNotesGrantleePrintTest::KNotesGrantleePrintTest(QObject *parent)
: QObject(parent)
......@@ -39,4 +43,64 @@ void KNotesGrantleePrintTest::shouldDefaultValue()
grantleePrint = 0;
}
void KNotesGrantleePrintTest::shouldReturnEmptyStringWhenNotContentAndNoNotes()
{
KNoteGrantleePrint *grantleePrint = new KNoteGrantleePrint;
QList<KNotePrintObject *> lst;
const QString result = grantleePrint->notesToHtml(lst);
QVERIFY(result.isEmpty());
grantleePrint->deleteLater();
grantleePrint = 0;
}
void KNotesGrantleePrintTest::shouldReturnEmptyStringWhenAddContentWithoutNotes()
{
KNoteGrantleePrint *grantleePrint = new KNoteGrantleePrint;
grantleePrint->setContent(QLatin1String("foo"));
QList<KNotePrintObject *> lst;
const QString result = grantleePrint->notesToHtml(lst);
QVERIFY(result.isEmpty());
grantleePrint->deleteLater();
grantleePrint = 0;
}
void KNotesGrantleePrintTest::shouldDisplayNoteInfo_data()
{
QTest::addColumn<QString>("variable");
QTest::addColumn<QString>("result");
QTest::newRow("name") << QString(QLatin1String("name")) << QString(QLatin1String("Test Note"));
QTest::newRow("description") << QString(QLatin1String("description")) << QString(QLatin1String("notes test"));
}
void KNotesGrantleePrintTest::shouldDisplayNoteInfo()
{
QFETCH( QString, variable );
QFETCH( QString, result );
Akonadi::Item note(42);
KNoteGrantleePrint *grantleePrint = new KNoteGrantleePrint;
grantleePrint->setContent(QString::fromLatin1("{% if notes %}{% for note in notes %}{{ note.%1 }}{% endfor %}{% endif %}").arg(variable));
KMime::Message::Ptr msg(new KMime::Message);
note.setMimeType( Akonotes::Note::mimeType() );
QString subject = QLatin1String("Test Note");
msg->subject(true)->fromUnicodeString(subject, "us-ascii");
msg->contentType( true )->setMimeType( "text/plain" );
msg->contentType()->setCharset("utf-8");
msg->contentTransferEncoding(true)->setEncoding(KMime::Headers::CEquPr);
msg->date( true )->setDateTime( KDateTime::currentLocalDateTime() );
msg->mainBodyPart()->fromUnicodeString( QLatin1String("notes test") );
note.setPayload( msg );
msg->assemble();
QList<KNotePrintObject *> lst;
KNotePrintObject *obj = new KNotePrintObject(note);
lst << obj;
const QString html = grantleePrint->notesToHtml(lst);
QCOMPARE(html, result);
grantleePrint->deleteLater();
grantleePrint = 0;
}
QTEST_KDEMAIN(KNotesGrantleePrintTest, NoGUI)
......@@ -29,6 +29,11 @@ public:
private Q_SLOTS:
void shouldDefaultValue();
void shouldReturnEmptyStringWhenNotContentAndNoNotes();
void shouldReturnEmptyStringWhenAddContentWithoutNotes();
void shouldDisplayNoteInfo_data();
void shouldDisplayNoteInfo();
};
#endif // KNOTESGRANTLEEPRINTTEST_H
......@@ -63,6 +63,8 @@ void KNoteGrantleePrint::setContent(const QString &content)
QString KNoteGrantleePrint::notesToHtml(const QList<KNotePrintObject *> lst)
{
if (lst.isEmpty())
return QString();
QVariantList notes;
Q_FOREACH(KNotePrintObject *n, lst)
notes << QVariant::fromValue(static_cast<QObject*>(n));
......
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