|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 |
|
43 #include <QtTest/QtTest> |
|
44 |
|
45 #include <qcoreapplication.h> |
|
46 #include <qdebug.h> |
|
47 #include <qabstracttextdocumentlayout.h> |
|
48 #include <qimage.h> |
|
49 #include <qtextobject.h> |
|
50 |
|
51 //TESTED_CLASS= |
|
52 //TESTED_FILES= |
|
53 |
|
54 class tst_QAbstractTextDocumentLayout : public QObject |
|
55 { |
|
56 Q_OBJECT |
|
57 |
|
58 public: |
|
59 tst_QAbstractTextDocumentLayout(); |
|
60 virtual ~tst_QAbstractTextDocumentLayout(); |
|
61 |
|
62 private slots: |
|
63 void getSetCheck(); |
|
64 void maximumBlockCount(); |
|
65 }; |
|
66 |
|
67 tst_QAbstractTextDocumentLayout::tst_QAbstractTextDocumentLayout() |
|
68 { |
|
69 } |
|
70 |
|
71 tst_QAbstractTextDocumentLayout::~tst_QAbstractTextDocumentLayout() |
|
72 { |
|
73 } |
|
74 |
|
75 class MyAbstractTextDocumentLayout : public QAbstractTextDocumentLayout |
|
76 { |
|
77 Q_OBJECT |
|
78 public: |
|
79 MyAbstractTextDocumentLayout(QTextDocument *doc) |
|
80 : QAbstractTextDocumentLayout(doc) |
|
81 , gotFullLayout(false) |
|
82 , blockCount(0) |
|
83 , changeEvents(0) |
|
84 { |
|
85 } |
|
86 |
|
87 void draw(QPainter *, const PaintContext &) {} |
|
88 int hitTest(const QPointF &, Qt::HitTestAccuracy) const { return 0; } |
|
89 int pageCount() const { return 0; } |
|
90 QSizeF documentSize() const { return QSizeF(); } |
|
91 QRectF frameBoundingRect(QTextFrame *) const { return QRectF(); } |
|
92 QRectF blockBoundingRect(const QTextBlock &) const { return QRectF(); } |
|
93 void documentChanged(int from, int oldLength, int length) { |
|
94 ++changeEvents; |
|
95 |
|
96 QTextBlock last = document()->lastBlock(); |
|
97 int lastPos = last.position() + last.length() - 1; |
|
98 if (from == 0 && length == lastPos) |
|
99 gotFullLayout = true; |
|
100 } |
|
101 |
|
102 bool gotFullLayout; |
|
103 int blockCount; |
|
104 int changeEvents; |
|
105 |
|
106 public slots: |
|
107 void blockCountChanged(int bc) { blockCount = bc; } |
|
108 }; |
|
109 |
|
110 // Testing get/set functions |
|
111 void tst_QAbstractTextDocumentLayout::getSetCheck() |
|
112 { |
|
113 QTextDocument doc; |
|
114 MyAbstractTextDocumentLayout obj1(&doc); |
|
115 // QPaintDevice * QAbstractTextDocumentLayout::paintDevice() |
|
116 // void QAbstractTextDocumentLayout::setPaintDevice(QPaintDevice *) |
|
117 QImage *var1 = new QImage(QSize(10,10), QImage::Format_ARGB32_Premultiplied); |
|
118 obj1.setPaintDevice(var1); |
|
119 QCOMPARE(static_cast<QPaintDevice *>(var1), obj1.paintDevice()); |
|
120 obj1.setPaintDevice((QPaintDevice *)0); |
|
121 QCOMPARE(static_cast<QPaintDevice *>(0), obj1.paintDevice()); |
|
122 delete var1; |
|
123 } |
|
124 |
|
125 void tst_QAbstractTextDocumentLayout::maximumBlockCount() |
|
126 { |
|
127 QTextDocument doc; |
|
128 doc.setMaximumBlockCount(10); |
|
129 |
|
130 MyAbstractTextDocumentLayout layout(&doc); |
|
131 doc.setDocumentLayout(&layout); |
|
132 QObject::connect(&doc, SIGNAL(blockCountChanged(int)), &layout, SLOT(blockCountChanged(int))); |
|
133 |
|
134 QTextCursor cursor(&doc); |
|
135 for (int i = 0; i < 10; ++i) { |
|
136 cursor.insertBlock(); |
|
137 cursor.insertText("bla"); |
|
138 } |
|
139 |
|
140 QCOMPARE(layout.blockCount, 10); |
|
141 |
|
142 layout.gotFullLayout = false; |
|
143 layout.changeEvents = 0; |
|
144 cursor.insertBlock(); |
|
145 QCOMPARE(layout.changeEvents, 2); |
|
146 cursor.insertText("foo"); |
|
147 QCOMPARE(layout.changeEvents, 3); |
|
148 cursor.insertBlock(); |
|
149 QCOMPARE(layout.changeEvents, 5); |
|
150 cursor.insertText("foo"); |
|
151 QCOMPARE(layout.changeEvents, 6); |
|
152 |
|
153 QVERIFY(!layout.gotFullLayout); |
|
154 |
|
155 QCOMPARE(layout.blockCount, 10); |
|
156 } |
|
157 |
|
158 QTEST_MAIN(tst_QAbstractTextDocumentLayout) |
|
159 #include "tst_qabstracttextdocumentlayout.moc" |