1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42
43 #include <QtTest/QtTest>
44 #include <qapplication.h>
45 #include <qdebug.h>
46 #include <q3stylesheet.h>
47
48 //TESTED_CLASS=
49 //TESTED_FILES=
50
51 class tst_Q3StyleSheet : public QObject
52 {
53 Q_OBJECT
54
55 public:
56 tst_Q3StyleSheet();
57 virtual ~tst_Q3StyleSheet();
58
59 private slots:
60 void getSetCheck();
61 };
62
tst_Q3StyleSheet()63 tst_Q3StyleSheet::tst_Q3StyleSheet()
64 {
65 }
66
~tst_Q3StyleSheet()67 tst_Q3StyleSheet::~tst_Q3StyleSheet()
68 {
69 }
70
71 // Testing get/set functions
getSetCheck()72 void tst_Q3StyleSheet::getSetCheck()
73 {
74 Q3StyleSheet ss;
75 Q3StyleSheetItem *obj1 = new Q3StyleSheetItem(&ss, "Stylesheet Item");
76 // DisplayMode Q3StyleSheetItem::displayMode()
77 // void Q3StyleSheetItem::setDisplayMode(DisplayMode)
78 obj1->setDisplayMode(Q3StyleSheetItem::DisplayMode(Q3StyleSheetItem::DisplayInline));
79 QCOMPARE(obj1->displayMode(), Q3StyleSheetItem::DisplayMode(Q3StyleSheetItem::DisplayInline));
80 obj1->setDisplayMode(Q3StyleSheetItem::DisplayMode(Q3StyleSheetItem::DisplayListItem));
81 QCOMPARE(obj1->displayMode(), Q3StyleSheetItem::DisplayMode(Q3StyleSheetItem::DisplayListItem));
82 obj1->setDisplayMode(Q3StyleSheetItem::DisplayMode(Q3StyleSheetItem::DisplayNone));
83 QCOMPARE(obj1->displayMode(), Q3StyleSheetItem::DisplayMode(Q3StyleSheetItem::DisplayNone));
84 obj1->setDisplayMode(Q3StyleSheetItem::DisplayMode(Q3StyleSheetItem::DisplayBlock));
85 QCOMPARE(obj1->displayMode(), Q3StyleSheetItem::DisplayMode(Q3StyleSheetItem::DisplayBlock));
86
87 // int Q3StyleSheetItem::alignment()
88 // void Q3StyleSheetItem::setAlignment(int)
89 obj1->setAlignment(0);
90 QCOMPARE(obj1->alignment(), 0);
91 obj1->setAlignment(INT_MIN);
92 QCOMPARE(obj1->alignment(), INT_MIN);
93 obj1->setAlignment(INT_MAX);
94 QCOMPARE(obj1->alignment(), INT_MAX);
95
96 // VerticalAlignment Q3StyleSheetItem::verticalAlignment()
97 // void Q3StyleSheetItem::setVerticalAlignment(VerticalAlignment)
98 obj1->setVerticalAlignment(Q3StyleSheetItem::VerticalAlignment(Q3StyleSheetItem::VAlignBaseline));
99 QCOMPARE(obj1->verticalAlignment(), Q3StyleSheetItem::VerticalAlignment(Q3StyleSheetItem::VAlignBaseline));
100 obj1->setVerticalAlignment(Q3StyleSheetItem::VerticalAlignment(Q3StyleSheetItem::VAlignSub));
101 QCOMPARE(obj1->verticalAlignment(), Q3StyleSheetItem::VerticalAlignment(Q3StyleSheetItem::VAlignSub));
102 obj1->setVerticalAlignment(Q3StyleSheetItem::VerticalAlignment(Q3StyleSheetItem::VAlignSuper));
103 QCOMPARE(obj1->verticalAlignment(), Q3StyleSheetItem::VerticalAlignment(Q3StyleSheetItem::VAlignSuper));
104
105 // int Q3StyleSheetItem::fontWeight()
106 // void Q3StyleSheetItem::setFontWeight(int)
107 obj1->setFontWeight(0);
108 QCOMPARE(obj1->fontWeight(), 0);
109 obj1->setFontWeight(INT_MIN);
110 // Should return 0, but we cannot change this behavior in a Qt3Support class.
111 QCOMPARE(obj1->fontWeight(), INT_MIN); // Range<0, 99>
112 obj1->setFontWeight(INT_MAX);
113 // Should return 99, but we cannot change this behavior in a Qt3Support class.
114 QCOMPARE(obj1->fontWeight(), INT_MAX); // Range<0, 99>
115
116 // int Q3StyleSheetItem::logicalFontSize()
117 // void Q3StyleSheetItem::setLogicalFontSize(int)
118 obj1->setLogicalFontSize(0);
119 // Should return 1, but we cannot change this behavior in a Qt3Support class.
120 QCOMPARE(obj1->logicalFontSize(), 0); // Range<1, 7>
121 obj1->setLogicalFontSize(INT_MIN);
122 // Should return 1, but we cannot change this behavior in a Qt3Support class.
123 QCOMPARE(obj1->logicalFontSize(), INT_MIN); // Range<1, 7>
124 obj1->setLogicalFontSize(INT_MAX);
125 // Should return 7, but we cannot change this behavior in a Qt3Support class.
126 QCOMPARE(obj1->logicalFontSize(), INT_MAX); // Range<1, 7>
127
128 // int Q3StyleSheetItem::logicalFontSizeStep()
129 // void Q3StyleSheetItem::setLogicalFontSizeStep(int)
130 obj1->setLogicalFontSizeStep(0);
131 QCOMPARE(obj1->logicalFontSizeStep(), 0);
132 obj1->setLogicalFontSizeStep(INT_MIN);
133 QCOMPARE(obj1->logicalFontSizeStep(), INT_MIN);
134 obj1->setLogicalFontSizeStep(INT_MAX);
135 QCOMPARE(obj1->logicalFontSizeStep(), INT_MAX);
136
137 // int Q3StyleSheetItem::fontSize()
138 // void Q3StyleSheetItem::setFontSize(int)
139 obj1->setFontSize(0);
140 QCOMPARE(obj1->fontSize(), 0);
141 obj1->setFontSize(INT_MIN);
142 // Should return -1, but we cannot change this behavior in a Qt3Support class.
143 QCOMPARE(obj1->fontSize(), INT_MIN); // Expect an undefined return value for non-valid point size, as per docs
144 obj1->setFontSize(INT_MAX);
145 QCOMPARE(obj1->fontSize(), INT_MAX);
146
147 // int Q3StyleSheetItem::numberOfColumns()
148 // void Q3StyleSheetItem::setNumberOfColumns(int)
149 int currentNumCols = obj1->numberOfColumns();
150 obj1->setNumberOfColumns(0);
151 QCOMPARE(obj1->numberOfColumns(), currentNumCols); // Can't set 0 column count
152 obj1->setNumberOfColumns(INT_MIN);
153 QCOMPARE(obj1->numberOfColumns(), currentNumCols); // Can't set negative column count
154 obj1->setNumberOfColumns(INT_MAX);
155 QCOMPARE(obj1->numberOfColumns(), INT_MAX);
156
157 // WhiteSpaceMode Q3StyleSheetItem::whiteSpaceMode()
158 // void Q3StyleSheetItem::setWhiteSpaceMode(WhiteSpaceMode)
159 obj1->setWhiteSpaceMode(Q3StyleSheetItem::WhiteSpaceMode(Q3StyleSheetItem::WhiteSpaceNormal));
160 QCOMPARE(obj1->whiteSpaceMode(), Q3StyleSheetItem::WhiteSpaceMode(Q3StyleSheetItem::WhiteSpaceNormal));
161 obj1->setWhiteSpaceMode(Q3StyleSheetItem::WhiteSpaceMode(Q3StyleSheetItem::WhiteSpacePre));
162 QCOMPARE(obj1->whiteSpaceMode(), Q3StyleSheetItem::WhiteSpaceMode(Q3StyleSheetItem::WhiteSpacePre));
163 obj1->setWhiteSpaceMode(Q3StyleSheetItem::WhiteSpaceMode(Q3StyleSheetItem::WhiteSpaceNoWrap));
164 QCOMPARE(obj1->whiteSpaceMode(), Q3StyleSheetItem::WhiteSpaceMode(Q3StyleSheetItem::WhiteSpaceNoWrap));
165
166 // int Q3StyleSheetItem::lineSpacing()
167 // void Q3StyleSheetItem::setLineSpacing(int)
168 obj1->setLineSpacing(0);
169 QCOMPARE(obj1->lineSpacing(), 0);
170 obj1->setLineSpacing(INT_MIN);
171 // Should return -1, but we cannot change this behavior in a Qt3Support class.
172 QCOMPARE(obj1->lineSpacing(), INT_MIN); // Should not be able to set negative line spacing(?)
173 obj1->setLineSpacing(INT_MAX);
174 QCOMPARE(obj1->lineSpacing(), INT_MAX);
175 }
176
177 QTEST_MAIN(tst_Q3StyleSheet)
178 #include "tst_q3stylesheet.moc"
179