author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
#include <qvalidator.h> |
|
45 |
||
46 |
class tst_QIntValidator : public QObject |
|
47 |
{ |
|
48 |
Q_OBJECT |
|
49 |
private slots: |
|
50 |
void validate_data(); |
|
51 |
void validate(); |
|
52 |
void validateArabic(); |
|
53 |
}; |
|
54 |
||
55 |
Q_DECLARE_METATYPE(QValidator::State); |
|
56 |
#define INV QValidator::Invalid |
|
57 |
#define INT QValidator::Intermediate |
|
58 |
#define ACC QValidator::Acceptable |
|
59 |
||
60 |
void tst_QIntValidator::validate_data() |
|
61 |
{ |
|
62 |
QTest::addColumn<int>("minimum"); |
|
63 |
QTest::addColumn<int>("maximum"); |
|
64 |
QTest::addColumn<QString>("value"); |
|
65 |
QTest::addColumn<QValidator::State>("state"); |
|
66 |
||
67 |
QTest::newRow("data0") << 0 << 100 << QString("50") << ACC; |
|
68 |
QTest::newRow("data1") << 0 << 100 << QString("500") << INV; |
|
69 |
QTest::newRow("data1a") << 0 << 100 << QString("5000") << INV; |
|
70 |
QTest::newRow("data1b") << -100 << 0 << QString("50") << INT; |
|
71 |
QTest::newRow("data1b") << -100 << 0 << QString("500") << INV; |
|
72 |
QTest::newRow("data1c") << -100 << 0 << QString("5000") << INV; |
|
73 |
QTest::newRow("data2") << 0 << 100 << QString("-35") << INV; |
|
74 |
QTest::newRow("data3") << 0 << 100 << QString("a") << INV; |
|
75 |
QTest::newRow("data4") << 0 << 100 << QString("-") << INV; |
|
76 |
QTest::newRow("data5") << 0 << 100 << QString("100") << ACC; |
|
77 |
QTest::newRow("data6") << -100 << 100 << QString("-") << INT; |
|
78 |
QTest::newRow("data7") << -100 << 100 << QString("-500") << INV; |
|
79 |
QTest::newRow("data8") << -100 << 100 << QString("-100") << ACC; |
|
80 |
QTest::newRow("data9") << -100 << -10 << QString("10") << INT; |
|
81 |
||
82 |
QTest::newRow("data10") << 100 << 999 << QString("") << INT; |
|
83 |
QTest::newRow("data11") << 100 << 999 << QString("5") << INT; |
|
84 |
QTest::newRow("data12") << 100 << 999 << QString("50") << INT; |
|
85 |
QTest::newRow("data13") << 100 << 999 << QString("99") << INT; |
|
86 |
QTest::newRow("data14") << 100 << 999 << QString("100") << ACC; |
|
87 |
QTest::newRow("data15") << 100 << 999 << QString("101") << ACC; |
|
88 |
QTest::newRow("data16") << 100 << 999 << QString("998") << ACC; |
|
89 |
QTest::newRow("data17") << 100 << 999 << QString("999") << ACC; |
|
90 |
QTest::newRow("data18") << 100 << 999 << QString("1000") << INV; |
|
91 |
QTest::newRow("data19") << 100 << 999 << QString("-10") << INV; |
|
92 |
||
93 |
QTest::newRow("data20") << -999 << -100 << QString("50") << INT; |
|
94 |
QTest::newRow("data21") << -999 << -100 << QString("-") << INT; |
|
95 |
QTest::newRow("data22") << -999 << -100 << QString("-1") << INT; |
|
96 |
QTest::newRow("data23") << -999 << -100 << QString("-10") << INT; |
|
97 |
QTest::newRow("data24") << -999 << -100 << QString("-100") << ACC; |
|
98 |
QTest::newRow("data25") << -999 << -100 << QString("-500") << ACC; |
|
99 |
QTest::newRow("data26") << -999 << -100 << QString("-998") << ACC; |
|
100 |
QTest::newRow("data27") << -999 << -100 << QString("-999") << ACC; |
|
101 |
QTest::newRow("data28") << -999 << -100 << QString("-1000") << INV; |
|
102 |
QTest::newRow("data29") << -999 << -100 << QString("-2000") << INV; |
|
103 |
||
104 |
QTest::newRow("1.1") << 0 << 10 << QString("") << INT; |
|
105 |
QTest::newRow("1.2") << 10 << 0 << QString("") << INT; |
|
106 |
||
107 |
QTest::newRow("2.1") << 0 << 10 << QString("-") << INV; |
|
108 |
QTest::newRow("2.2") << 0 << 10 << QString("-0") << INV; |
|
109 |
QTest::newRow("2.3") << -10 << -1 << QString("+") << INV; |
|
110 |
QTest::newRow("2.4") << -10 << 10 << QString("-") << INT; |
|
111 |
QTest::newRow("2.5") << -10 << 10 << QString("+") << INT; |
|
112 |
QTest::newRow("2.6") << -10 << 10 << QString("+0") << ACC; |
|
113 |
QTest::newRow("2.7") << -10 << 10 << QString("+1") << ACC; |
|
114 |
QTest::newRow("2.8") << -10 << 10 << QString("+-") << INV; |
|
115 |
QTest::newRow("2.9") << -10 << 10 << QString("-+") << INV; |
|
116 |
||
117 |
QTest::newRow("3.1") << 0 << 10 << QString("12345678901234567890") << INV; |
|
118 |
QTest::newRow("3.2") << 0 << 10 << QString("-12345678901234567890") << INV; |
|
119 |
QTest::newRow("3.3") << 0 << 10 << QString("000000000000000000000") << ACC; |
|
120 |
QTest::newRow("3.4") << 1 << 10 << QString("000000000000000000000") << INT; |
|
121 |
QTest::newRow("3.5") << 0 << 10 << QString("-000000000000000000000") << INV; |
|
122 |
QTest::newRow("3.6") << -10 << -1 << QString("-000000000000000000000") << INT; |
|
123 |
QTest::newRow("3.7") << -10 << -1 << QString("-0000000000000000000001") << ACC; |
|
124 |
||
125 |
QTest::newRow("4.1") << 0 << 10 << QString(" ") << INV; |
|
126 |
QTest::newRow("4.2") << 0 << 10 << QString(" 1") << INV; |
|
127 |
QTest::newRow("4.3") << 0 << 10 << QString("1 ") << INV; |
|
128 |
QTest::newRow("4.4") << 0 << 10 << QString("1.0") << INV; |
|
129 |
QTest::newRow("4.5") << 0 << 10 << QString("0.1") << INV; |
|
130 |
QTest::newRow("4.6") << 0 << 10 << QString(".1") << INV; |
|
131 |
QTest::newRow("4.7") << 0 << 10 << QString("-1.0") << INV; |
|
132 |
||
133 |
QTest::newRow("5.1") << 6 << 8 << QString("5") << INT; |
|
134 |
QTest::newRow("5.2") << 6 << 8 << QString("7") << ACC; |
|
135 |
QTest::newRow("5.3") << 6 << 8 << QString("9") << INV; |
|
136 |
QTest::newRow("5.3a") << 6 << 8 << QString("19") << INV; |
|
137 |
QTest::newRow("5.4") << -8 << -6 << QString("-5") << INT; |
|
138 |
QTest::newRow("5.5") << -8 << -6 << QString("-7") << ACC; |
|
139 |
QTest::newRow("5.6") << -8 << -6 << QString("-9") << INV; |
|
140 |
QTest::newRow("5.6a") << -8 << -6 << QString("-19") << INV; |
|
141 |
QTest::newRow("5.7") << -8 << -6 << QString("5") << INT; |
|
142 |
QTest::newRow("5.8") << -8 << -6 << QString("7") << INT; |
|
143 |
QTest::newRow("5.9") << -8 << -6 << QString("9") << INV; |
|
144 |
QTest::newRow("5.10") << -6 << 8 << QString("-5") << ACC; |
|
145 |
QTest::newRow("5.11") << -6 << 8 << QString("5") << ACC; |
|
146 |
QTest::newRow("5.12") << -6 << 8 << QString("-7") << INV; |
|
147 |
QTest::newRow("5.13") << -6 << 8 << QString("7") << ACC; |
|
148 |
QTest::newRow("5.14") << -6 << 8 << QString("-9") << INV; |
|
149 |
QTest::newRow("5.15") << -6 << 8 << QString("9") << INV; |
|
150 |
||
151 |
QTest::newRow("6.1") << 100 << 102 << QString("11") << INT; |
|
152 |
QTest::newRow("6.2") << 100 << 102 << QString("-11") << INV; |
|
153 |
||
154 |
QTest::newRow("7.1") << 0 << 10 << QString("100") << INV; |
|
155 |
QTest::newRow("7.2") << 0 << -10 << QString("100") << INV; |
|
156 |
QTest::newRow("7.3") << 0 << -10 << QString("-100") << INV; |
|
157 |
QTest::newRow("7.4") << -100 << 10 << QString("100") << INT; |
|
158 |
||
159 |
QTest::newRow("8.1") << -100 << -10 << QString("+") << INV; |
|
160 |
QTest::newRow("8.2") << -100 << -10 << QString("+50") << INV; |
|
161 |
QTest::newRow("8.3") << -100 << -10 << QString("50") << INT; |
|
162 |
QTest::newRow("8.4") << 10 << 100 << QString("-") << INV; |
|
163 |
QTest::newRow("8.5") << 10 << 100 << QString("-50") << INV; |
|
164 |
QTest::newRow("8.6") << 10 << 100 << QString("5") << INT; |
|
165 |
QTest::newRow("8.7") << -1 << 100 << QString("-") << INT; |
|
166 |
QTest::newRow("8.8") << -1 << 100 << QString("-50") << INV; |
|
167 |
QTest::newRow("8.9") << -1 << 100 << QString("5") << ACC; |
|
168 |
QTest::newRow("8.10") << -1 << 100 << QString("+") << INT; |
|
169 |
QTest::newRow("8.11") << -1 << 100 << QString("+50") << ACC; |
|
170 |
} |
|
171 |
||
172 |
void tst_QIntValidator::validateArabic() |
|
173 |
{ |
|
174 |
QString arabicNum; |
|
175 |
arabicNum += QChar(1633); // "18" in arabic |
|
176 |
arabicNum += QChar(1640); |
|
177 |
||
178 |
QIntValidator validator(-20, 20, 0); |
|
179 |
validator.setLocale(QLocale(QLocale::Arabic, QLocale::SaudiArabia)); |
|
180 |
int i; |
|
181 |
QCOMPARE(validator.validate(arabicNum, i), QValidator::Acceptable); |
|
182 |
||
183 |
} |
|
184 |
||
185 |
void tst_QIntValidator::validate() |
|
186 |
{ |
|
187 |
QFETCH(int, minimum); |
|
188 |
QFETCH(int, maximum); |
|
189 |
QFETCH(QString, value); |
|
190 |
QFETCH(QValidator::State, state); |
|
191 |
||
192 |
QIntValidator iv(minimum, maximum, 0); |
|
193 |
int dummy; |
|
194 |
QCOMPARE((int)iv.validate(value, dummy), (int)state); |
|
195 |
} |
|
196 |
||
197 |
QTEST_MAIN(tst_QIntValidator) |
|
198 |
#include "tst_qintvalidator.moc" |