|
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 <qtextobject.h> |
|
48 #include <qtextdocument.h> |
|
49 #include <qtextedit.h> |
|
50 #include <qtextcursor.h> |
|
51 |
|
52 //TESTED_CLASS= |
|
53 //TESTED_FILES= |
|
54 |
|
55 class tst_QTextObject : public QObject |
|
56 { |
|
57 Q_OBJECT |
|
58 |
|
59 public: |
|
60 tst_QTextObject(); |
|
61 virtual ~tst_QTextObject(); |
|
62 |
|
63 private slots: |
|
64 void getSetCheck(); |
|
65 void testStandAloneTextObject(); |
|
66 }; |
|
67 |
|
68 tst_QTextObject::tst_QTextObject() |
|
69 { |
|
70 } |
|
71 |
|
72 tst_QTextObject::~tst_QTextObject() |
|
73 { |
|
74 } |
|
75 |
|
76 // Testing get/set functions |
|
77 void tst_QTextObject::getSetCheck() |
|
78 { |
|
79 QTextEdit edit; |
|
80 QTextFrame obj1(edit.document()); |
|
81 // QTextFrameLayoutData * QTextFrame::layoutData() |
|
82 // void QTextFrame::setLayoutData(QTextFrameLayoutData *) |
|
83 QTextFrameLayoutData *var1 = new QTextFrameLayoutData; |
|
84 obj1.setLayoutData(var1); |
|
85 QCOMPARE(var1, obj1.layoutData()); |
|
86 obj1.setLayoutData((QTextFrameLayoutData *)0); |
|
87 QCOMPARE((QTextFrameLayoutData *)0, obj1.layoutData()); |
|
88 // delete var1; // No delete, since QTextFrame takes ownership |
|
89 |
|
90 QTextBlock obj2 = edit.textCursor().block(); |
|
91 // QTextBlockUserData * QTextBlock::userData() |
|
92 // void QTextBlock::setUserData(QTextBlockUserData *) |
|
93 QTextBlockUserData *var2 = new QTextBlockUserData; |
|
94 obj2.setUserData(var2); |
|
95 QCOMPARE(var2, obj2.userData()); |
|
96 obj2.setUserData((QTextBlockUserData *)0); |
|
97 QCOMPARE((QTextBlockUserData *)0, obj2.userData()); |
|
98 |
|
99 // int QTextBlock::userState() |
|
100 // void QTextBlock::setUserState(int) |
|
101 obj2.setUserState(0); |
|
102 QCOMPARE(0, obj2.userState()); |
|
103 obj2.setUserState(INT_MIN); |
|
104 QCOMPARE(INT_MIN, obj2.userState()); |
|
105 obj2.setUserState(INT_MAX); |
|
106 QCOMPARE(INT_MAX, obj2.userState()); |
|
107 } |
|
108 |
|
109 class TestTextObject : public QTextObject |
|
110 { |
|
111 public: |
|
112 TestTextObject(QTextDocument *document) : QTextObject(document) {} |
|
113 }; |
|
114 |
|
115 void tst_QTextObject::testStandAloneTextObject() |
|
116 { |
|
117 QTextDocument document; |
|
118 TestTextObject textObject(&document); |
|
119 |
|
120 QCOMPARE(textObject.document(), &document); |
|
121 // don't crash |
|
122 textObject.format(); |
|
123 textObject.formatIndex(); |
|
124 QCOMPARE(textObject.objectIndex(), -1); |
|
125 } |
|
126 |
|
127 QTEST_MAIN(tst_QTextObject) |
|
128 #include "tst_qtextobject.moc" |