summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-08-26 21:37:15 (GMT)
committerMontel Laurent <montel@kde.org>2016-08-26 21:37:15 (GMT)
commit3c5e28c88cfceffb3cafb94258d3898310dec3c2 (patch)
tree5aa484cad9ab0aa3cfd73b7445ed0587aec0ab8a
parent7fd28c37ddd4905c74323ef59427de6178d40c58 (diff)
Add autotests
-rw-r--r--messagecomposer/src/CMakeLists.txt1
-rw-r--r--messagecomposer/src/composer-ng/autotests/CMakeLists.txt8
-rw-r--r--messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp61
-rw-r--r--messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h37
-rw-r--r--messagecomposer/src/composer-ng/richtextcomposerng.cpp13
-rw-r--r--messagecomposer/src/composer-ng/richtextcomposerng.h2
6 files changed, 116 insertions, 6 deletions
diff --git a/messagecomposer/src/CMakeLists.txt b/messagecomposer/src/CMakeLists.txt
index 4923e5e..328204d 100644
--- a/messagecomposer/src/CMakeLists.txt
+++ b/messagecomposer/src/CMakeLists.txt
@@ -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()
diff --git a/messagecomposer/src/composer-ng/autotests/CMakeLists.txt b/messagecomposer/src/composer-ng/autotests/CMakeLists.txt
new file mode 100644
index 0000000..4d15fe1
--- /dev/null
+++ b/messagecomposer/src/composer-ng/autotests/CMakeLists.txt
@@ -0,0 +1,8 @@
+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)
diff --git a/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
new file mode 100644
index 0000000..5a6a156
--- /dev/null
+++ b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.cpp
@@ -0,0 +1,61 @@
+/*
+ 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)
diff --git a/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h
new file mode 100644
index 0000000..0ea7d37
--- /dev/null
+++ b/messagecomposer/src/composer-ng/autotests/richtextcomposerngtest.h
@@ -0,0 +1,37 @@
+/*
+ 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
diff --git a/messagecomposer/src/composer-ng/richtextcomposerng.cpp b/messagecomposer/src/composer-ng/richtextcomposerng.cpp
index 6a79a41..bc7a217 100644
--- a/messagecomposer/src/composer-ng/richtextcomposerng.cpp
+++ b/messagecomposer/src/composer-ng/richtextcomposerng.cpp
@@ -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) {
diff --git a/messagecomposer/src/composer-ng/richtextcomposerng.h b/messagecomposer/src/composer-ng/richtextcomposerng.h
index f76fa75..23309cc 100644
--- a/messagecomposer/src/composer-ng/richtextcomposerng.h
+++ b/messagecomposer/src/composer-ng/richtextcomposerng.h
@@ -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;
};