Commit 3c5e28c8 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add autotests

parent 7fd28c37
......@@ -9,6 +9,7 @@ add_definitions( -DQT_NO_CAST_TO_ASCII )
if(BUILD_TESTING)
add_subdirectory( imagescaling/autotests )
add_subdirectory( imagescaling/tests )
add_subdirectory( composer-ng/autotests )
endif()
......
macro(add_composerng_autocorrect_unittest _source)
ecm_add_test(${_source}
NAME_PREFIX "messagecomposer-composerng-"
LINK_LIBRARIES Qt5::Test KF5::MessageComposer
)
endmacro()
add_composerng_autocorrect_unittest(richtextcomposerngtest.cpp)
/*
Copyright (C) 2016 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 as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "richtextcomposerngtest.h"
#include "../richtextcomposerng.h"
#include <PimCommon/AutoCorrection>
#include <QTest>
RichTextComposerNgTest::RichTextComposerNgTest(QObject *parent)
: QObject(parent)
{
}
RichTextComposerNgTest::~RichTextComposerNgTest()
{
}
void RichTextComposerNgTest::shouldHaveDefaultValue()
{
MessageComposer::RichTextComposerNg richtextComposerNg;
QVERIFY(richtextComposerNg.composerSignature());
QVERIFY(!richtextComposerNg.autocorrection());
}
void RichTextComposerNgTest::shouldForceAutoCorrection()
{
MessageComposer::RichTextComposerNg richtextComposerNg;
richtextComposerNg.setPlainText(QStringLiteral("boo bla bli. foo faa"));
PimCommon::AutoCorrection autocorrection;
autocorrection.setEnabledAutoCorrection(true);
autocorrection.setUppercaseFirstCharOfSentence(true);
richtextComposerNg.setAutocorrection(&autocorrection);
richtextComposerNg.forceAutoCorrection(false);
//FIXME first char !
QCOMPARE(richtextComposerNg.toPlainText(), QStringLiteral("boo bla bli. Foo faa"));
//TODO
}
QTEST_MAIN(RichTextComposerNgTest)
/*
Copyright (C) 2016 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 as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef RICHTEXTCOMPOSERNGTEST_H
#define RICHTEXTCOMPOSERNGTEST_H
#include <QObject>
class RichTextComposerNgTest : public QObject
{
Q_OBJECT
public:
explicit RichTextComposerNgTest(QObject *parent = Q_NULLPTR);
~RichTextComposerNgTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldForceAutoCorrection();
};
#endif // RICHTEXTCOMPOSERNGTEST_H
......@@ -360,7 +360,6 @@ void RichTextComposerNg::insertSignature(const KIdentityManagement::Signature &s
composerControler()->composerImages()->loadImage(image->image, image->name, image->name);
}
}
}
}
......@@ -371,22 +370,26 @@ QString RichTextComposerNg::toCleanHtml() const
void RichTextComposerNg::forceAutoCorrection(bool selectedText)
{
Q_UNUSED(selectedText);
if (d->autoCorrection && d->autoCorrection->isEnabledAutoCorrection()) {
if (!document()->isEmpty()) {
const bool richText = (textMode() == RichTextComposer::Rich);
const int initialPosition = textCursor().position();
QTextCursor cur = textCursor();
cur.beginEditBlock();
cur.movePosition(QTextCursor::Start);
if (selectedText && cur.hasSelection()) {
//TODO
cur.movePosition(QTextCursor::Start);
} else {
cur.movePosition(QTextCursor::Start);
}
while(!cur.atEnd()) {
if(isLineQuoted(cur.block().text())) {
cur.movePosition(QTextCursor::NextBlock);
} else {
cur.movePosition(QTextCursor::NextWord);
}
int cursortPosition = cur.position();
d->autoCorrection->autocorrect(richText, *document(), cursortPosition);
int cursorPosition = cur.position();
d->autoCorrection->autocorrect(richText, *document(), cursorPosition);
}
cur.endEditBlock();
if (cur.position() != initialPosition) {
......
......@@ -51,8 +51,8 @@ public:
void insertSignature(const KIdentityManagement::Signature &signature, KIdentityManagement::Signature::Placement placement, KIdentityManagement::Signature::AddedText addedText);
QString toCleanHtml() const;
private:
void forceAutoCorrection(bool selectedText = false) Q_DECL_OVERRIDE;
private:
bool processAutoCorrection(QKeyEvent *event) Q_DECL_OVERRIDE;
RichTextComposerNgPrivate *const d;
};
......
Supports Markdown
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