1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the test suite of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29
30#include <QtTest/QtTest>
31
32#include <qcoreapplication.h>
33#include <qdebug.h>
34#include <qtextobject.h>
35#include <qtextdocument.h>
36#ifndef QT_NO_WIDGETS
37#include <qtextedit.h>
38#endif
39#include <qtextcursor.h>
40
41class tst_QTextObject : public QObject
42{
43Q_OBJECT
44
45public:
46 tst_QTextObject();
47 virtual ~tst_QTextObject();
48
49private slots:
50#ifndef QT_NO_WIDGETS
51 void getSetCheck();
52#endif
53 void testStandAloneTextObject();
54};
55
56tst_QTextObject::tst_QTextObject()
57{
58}
59
60tst_QTextObject::~tst_QTextObject()
61{
62}
63
64#ifndef QT_NO_WIDGETS
65// Testing get/set functions
66void tst_QTextObject::getSetCheck()
67{
68 QTextEdit edit;
69 QTextFrame obj1(edit.document());
70 // QTextFrameLayoutData * QTextFrame::layoutData()
71 // void QTextFrame::setLayoutData(QTextFrameLayoutData *)
72 QTextFrameLayoutData *var1 = new QTextFrameLayoutData;
73 obj1.setLayoutData(var1);
74 QCOMPARE(var1, obj1.layoutData());
75 obj1.setLayoutData((QTextFrameLayoutData *)0);
76 QCOMPARE((QTextFrameLayoutData *)0, obj1.layoutData());
77 // delete var1; // No delete, since QTextFrame takes ownership
78
79 QTextBlock obj2 = edit.textCursor().block();
80 // QTextBlockUserData * QTextBlock::userData()
81 // void QTextBlock::setUserData(QTextBlockUserData *)
82 QTextBlockUserData *var2 = new QTextBlockUserData;
83 obj2.setUserData(var2);
84 QCOMPARE(var2, obj2.userData());
85 obj2.setUserData((QTextBlockUserData *)0);
86 QCOMPARE((QTextBlockUserData *)0, obj2.userData());
87
88 // int QTextBlock::userState()
89 // void QTextBlock::setUserState(int)
90 obj2.setUserState(0);
91 QCOMPARE(0, obj2.userState());
92 obj2.setUserState(INT_MIN);
93 QCOMPARE(INT_MIN, obj2.userState());
94 obj2.setUserState(INT_MAX);
95 QCOMPARE(INT_MAX, obj2.userState());
96}
97#endif
98
99class TestTextObject : public QTextObject
100{
101public:
102 TestTextObject(QTextDocument *document) : QTextObject(document) {}
103};
104
105void tst_QTextObject::testStandAloneTextObject()
106{
107 QTextDocument document;
108 TestTextObject textObject(&document);
109
110 QCOMPARE(textObject.document(), &document);
111 // don't crash
112 textObject.format();
113 textObject.formatIndex();
114 QCOMPARE(textObject.objectIndex(), -1);
115}
116
117QTEST_MAIN(tst_QTextObject)
118#include "tst_qtextobject.moc"
119

source code of qtbase/tests/auto/gui/text/qtextobject/tst_qtextobject.cpp