File: ktextedit_unittest.cpp

package info (click to toggle)
kf6-ktextwidgets 6.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 23,984 kB
  • sloc: cpp: 5,382; sh: 18; makefile: 7
file content (100 lines) | stat: -rw-r--r-- 3,305 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
    This file is part of the KDE libraries
    SPDX-FileCopyrightText: 2008 David Faure <faure@kde.org>
    SPDX-FileCopyrightText: 2008 Stephen Kelly <steveire@gmail.com>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#include <QClipboard>
#include <QTest>

#include <ktextedit.h>

class KTextEdit_UnitTest : public QObject
{
    Q_OBJECT

private Q_SLOTS:
    void testPaste();
    // These tests are probably invalid due to using invalid html.
    //     void testImportWithHorizontalTraversal();
    //     void testImportWithVerticalTraversal();
    //     void testBrInsideParagraphThroughTextEdit();
};

void KTextEdit_UnitTest::testPaste()
{
    const QString origText = QApplication::clipboard()->text();
    const QString pastedText = QStringLiteral("Test paste from ktextedit_unittest");
    QApplication::clipboard()->setText(pastedText);
    KTextEdit w;
    w.setPlainText(QStringLiteral("Hello world"));
    w.selectAll();
    QTest::keyClick(&w, Qt::Key_V, Qt::ControlModifier);
    QCOMPARE(w.toPlainText(), pastedText);
    QApplication::clipboard()->setText(origText);
}

// void KTextEdit_UnitTest::testImportWithVerticalTraversal()
// {
//     QTextEdit *te = new QTextEdit();
//
//     te->setHtml("<p>Foo</p><br /><br /><br /><p>Bar</p>");
//
//     QTextCursor cursor = te->textCursor();
//     cursor.movePosition(QTextCursor::Start);
//     QVERIFY(cursor.block().text() == QString( "Foo" ));
//     cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, 4);
//
//     // Cursor is at the beginning of the block.
//     QVERIFY(cursor.block().position() == cursor.position());
//     QVERIFY(cursor.block().text() == QString( "Bar" ));
// }
//
// void KTextEdit_UnitTest::testImportWithHorizontalTraversal()
// {
//     QTextEdit *te = new QTextEdit();
//
//     te->setHtml("<p>Foo</p><br /><p>Bar</p>");
//
//     // br elements should be represented just like empty paragraphs.
//
//     QTextCursor cursor = te->textCursor();
//     cursor.movePosition(QTextCursor::Start);
//     QVERIFY(cursor.block().text() == QString( "Foo" ));
//     cursor.movePosition(QTextCursor::EndOfBlock);
//     cursor.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor, 2);
//
//     // Cursor is at the beginning of the block.
//     QVERIFY(cursor.block().position() == cursor.position());
//     QVERIFY(cursor.block().text() == QString( "Bar" ));
// }
//
// void KTextEdit_UnitTest::testBrInsideParagraphThroughTextEdit()
// {
//     QSKIP("This is worked around during export");
//     QTextEdit *te = new QTextEdit();
//
//     te->setHtml("<p>Foo<br />Bar</p>");
//
//     // br elements inside paragraphs should be a single linebreak.
//
//     QTextCursor cursor = te->textCursor();
//     cursor.movePosition(QTextCursor::Start);
//
//     // This doesn't work, because Qt puts Foo and Bar in the same block, separated by a QChar::LineSeparator
//
//     QVERIFY(cursor.block().text() == QString( "Foo" ));
//     cursor.movePosition(QTextCursor::EndOfBlock);
//     cursor.movePosition(QTextCursor::Right);
//
//     // Cursor is at the beginning of the block.
//     QVERIFY(cursor.block().position() == cursor.position());
//     QVERIFY(cursor.block().text() == QString( "Bar" ));
//
// }

QTEST_MAIN(KTextEdit_UnitTest)

#include "ktextedit_unittest.moc"