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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://www.qtsoftware.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtTest/QtTest>
#include <qtextdocument.h>
#include <qtextdocumentfragment.h>
#include <qtextlist.h>
#include <qabstracttextdocumentlayout.h>
#include <qtextcursor.h>
#include "../qtextdocument/common.h"
//TESTED_CLASS=
//TESTED_FILES=
class tst_QTextList : public QObject
{
Q_OBJECT
public:
tst_QTextList();
public slots:
void init();
void cleanup();
private slots:
void item();
void autoNumbering();
void autoNumberingRTL();
void formatChange();
void cursorNavigation();
void partialRemoval();
void formatReferenceChange();
void ensureItemOrder();
void add();
void defaultIndent();
void blockUpdate();
private:
QTextDocument *doc;
QTextCursor cursor;
QTestDocumentLayout *layout;
};
tst_QTextList::tst_QTextList()
{}
void tst_QTextList::init()
{
doc = new QTextDocument();
layout = new QTestDocumentLayout(doc);
doc->setDocumentLayout(layout);
cursor = QTextCursor(doc);
}
void tst_QTextList::cleanup()
{
cursor = QTextCursor();
delete doc;
doc = 0;
}
void tst_QTextList::item()
{
// this is basically a test for the key() + 1 in QTextList::item.
QTextList *list = cursor.createList(QTextListFormat());
QVERIFY(list->item(0).blockFormat().objectIndex() != -1);
}
void tst_QTextList::autoNumbering()
{
QTextListFormat fmt;
fmt.setStyle(QTextListFormat::ListLowerAlpha);
QTextList *list = cursor.createList(fmt);
QVERIFY(list);
for (int i = 0; i < 27; ++i)
cursor.insertBlock();
QVERIFY(list->count() == 28);
QVERIFY(cursor.currentList());
QVERIFY(cursor.currentList()->itemNumber(cursor.block()) == 27);
QVERIFY(cursor.currentList()->itemText(cursor.block()) == "ab.");
}
void tst_QTextList::autoNumberingRTL()
{
QTextBlockFormat bfmt;
bfmt.setLayoutDirection(Qt::RightToLeft);
cursor.setBlockFormat(bfmt);
QTextListFormat fmt;
fmt.setStyle(QTextListFormat::ListUpperAlpha);
QTextList *list = cursor.createList(fmt);
QVERIFY(list);
cursor.insertBlock();
QVERIFY(list->count() == 2);
QVERIFY(cursor.currentList()->itemText(cursor.block()) == ".B");
}
void tst_QTextList::formatChange()
{
// testing the formatChanged slot in QTextListManager
/* <initial block>
* 1.
* 2.
*/
QTextList *list = cursor.insertList(QTextListFormat::ListDecimal);
QTextList *firstList = list;
cursor.insertBlock();
QVERIFY(list && list->count() == 2);
QTextBlockFormat bfmt = cursor.blockFormat();
// QVERIFY(bfmt.object() == list);
bfmt.setObjectIndex(-1);
cursor.setBlockFormat(bfmt);
QVERIFY(firstList->count() == 1);
}
void tst_QTextList::cursorNavigation()
{
// testing some cursor list methods
/* <initial block>
* 1.
* 2.
*/
cursor.insertList(QTextListFormat::ListDecimal);
cursor.insertBlock();
cursor.movePosition(QTextCursor::Start);
cursor.movePosition(QTextCursor::NextBlock);
cursor.movePosition(QTextCursor::NextBlock);
QVERIFY(cursor.currentList());
cursor.movePosition(QTextCursor::PreviousBlock);
QVERIFY(cursor.currentList());
QVERIFY(cursor.currentList()->itemNumber(cursor.block()) == 0);
}
void tst_QTextList::partialRemoval()
{
/* this is essentially a test for PieceTable::removeBlock to not miss any
blocks with the blockChanged signal emission that actually get removed.
It creates two lists, like this:
1. Hello World
a. Foobar
and then removes from within the 'Hello World' into the 'Foobar' .
There used to be no emission for the removal of the second (a.) block,
causing list inconsistencies.
*/
QTextList *firstList = cursor.insertList(QTextListFormat::ListDecimal);
QTextCursor selStart = cursor;
selStart.movePosition(QTextCursor::PreviousCharacter);
cursor.insertText("Hello World");
// position it well into the 'hello world' text.
selStart.movePosition(QTextCursor::NextCharacter);
selStart.movePosition(QTextCursor::NextCharacter);
selStart.clearSelection();
QPointer<QTextList> secondList = cursor.insertList(QTextListFormat::ListCircle);
cursor.insertText("Foobar");
// position it into the 'foo bar' text.
cursor.movePosition(QTextCursor::PreviousCharacter);
QTextCursor selEnd = cursor;
// this creates a selection that includes parts of both text-fragments and also the list item of the second list.
QTextCursor selection = selStart;
selection.setPosition(selEnd.position(), QTextCursor::KeepAnchor);
selection.deleteChar(); // deletes the second list
QVERIFY(!secondList);
QVERIFY(!firstList->isEmpty());
doc->undo();
}
void tst_QTextList::formatReferenceChange()
{
QTextList *list = cursor.insertList(QTextListFormat::ListDecimal);
cursor.insertText("Some Content...");
cursor.insertBlock(QTextBlockFormat());
cursor.setPosition(list->item(0).position());
int listItemStartPos = cursor.position();
cursor.movePosition(QTextCursor::NextBlock);
int listItemLen = cursor.position() - listItemStartPos;
layout->expect(listItemStartPos, listItemLen, listItemLen);
QTextListFormat fmt = list->format();
fmt.setStyle(QTextListFormat::ListCircle);
list->setFormat(fmt);
QVERIFY(layout->called);
QVERIFY(!layout->error);
}
void tst_QTextList::ensureItemOrder()
{
/*
* Insert a new list item before the first one and verify the blocks
* are sorted after that.
*/
QTextList *list = cursor.insertList(QTextListFormat::ListDecimal);
QTextBlockFormat fmt = cursor.blockFormat();
cursor.movePosition(QTextCursor::Start);
cursor.insertBlock(fmt);
QCOMPARE(list->item(0).position(), 1);
QCOMPARE(list->item(1).position(), 2);
}
void tst_QTextList::add()
{
QTextList *list = cursor.insertList(QTextListFormat::ListDecimal);
cursor.insertBlock(QTextBlockFormat());
QCOMPARE(list->count(), 1);
cursor.insertBlock(QTextBlockFormat());
list->add(cursor.block());
QCOMPARE(list->count(), 2);
}
// Task #72036
void tst_QTextList::defaultIndent()
{
QTextListFormat fmt;
QCOMPARE(fmt.indent(), 1);
}
void tst_QTextList::blockUpdate()
{
// three items
QTextList *list = cursor.insertList(QTextListFormat::ListDecimal);
cursor.insertBlock();
cursor.insertBlock();
// remove second, needs also update on the third
// since the numbering might have changed
const int len = cursor.position() + cursor.block().length() - 1;
layout->expect(1, len, len);
list->remove(list->item(1));
QVERIFY(!layout->error);
}
QTEST_MAIN(tst_QTextList)
#include "tst_qtextlist.moc"
|