0
|
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 |
#include <qregexp.h>
|
|
45 |
|
|
46 |
|
|
47 |
#include <qvalidator.h>
|
|
48 |
|
|
49 |
//TESTED_CLASS=
|
|
50 |
//TESTED_FILES=corelib/tools/qregexp.h corelib/tools/qregexp.cpp
|
|
51 |
|
|
52 |
class tst_QRegExpValidator : public QObject
|
|
53 |
{
|
|
54 |
Q_OBJECT
|
|
55 |
|
|
56 |
public:
|
|
57 |
tst_QRegExpValidator();
|
|
58 |
virtual ~tst_QRegExpValidator();
|
|
59 |
|
|
60 |
|
|
61 |
// I can think of no other way to do this for the moment
|
|
62 |
enum State { Invalid=0, Intermediate=1, Acceptable=2 };
|
|
63 |
public slots:
|
|
64 |
void init();
|
|
65 |
void cleanup();
|
|
66 |
private slots:
|
|
67 |
void validate_data();
|
|
68 |
void validate();
|
|
69 |
};
|
|
70 |
|
|
71 |
tst_QRegExpValidator::tst_QRegExpValidator()
|
|
72 |
{
|
|
73 |
}
|
|
74 |
|
|
75 |
tst_QRegExpValidator::~tst_QRegExpValidator()
|
|
76 |
{
|
|
77 |
|
|
78 |
}
|
|
79 |
|
|
80 |
void tst_QRegExpValidator::init()
|
|
81 |
{
|
|
82 |
}
|
|
83 |
|
|
84 |
void tst_QRegExpValidator::cleanup()
|
|
85 |
{
|
|
86 |
}
|
|
87 |
|
|
88 |
void tst_QRegExpValidator::validate_data()
|
|
89 |
{
|
|
90 |
|
|
91 |
QTest::addColumn<QString>("rx");
|
|
92 |
QTest::addColumn<QString>("value");
|
|
93 |
QTest::addColumn<int>("state");
|
|
94 |
|
|
95 |
QTest::newRow( "data0" ) << QString("[1-9]\\d{0,3}") << QString("0") << 0;
|
|
96 |
QTest::newRow( "data1" ) << QString("[1-9]\\d{0,3}") << QString("12345") << 0;
|
|
97 |
QTest::newRow( "data2" ) << QString("[1-9]\\d{0,3}") << QString("1") << 2;
|
|
98 |
|
|
99 |
QTest::newRow( "data3" ) << QString("\\S+") << QString("myfile.txt") << 2;
|
|
100 |
QTest::newRow( "data4" ) << QString("\\S+") << QString("my file.txt") << 0;
|
|
101 |
|
|
102 |
QTest::newRow( "data5" ) << QString("[A-C]\\d{5}[W-Z]") << QString("a12345Z") << 0;
|
|
103 |
QTest::newRow( "data6" ) << QString("[A-C]\\d{5}[W-Z]") << QString("A12345Z") << 2;
|
|
104 |
QTest::newRow( "data7" ) << QString("[A-C]\\d{5}[W-Z]") << QString("B12") << 1;
|
|
105 |
|
|
106 |
QTest::newRow( "data8" ) << QString("read\\S?me(\\.(txt|asc|1st))?") << QString("readme") << 2;
|
|
107 |
QTest::newRow( "data9" ) << QString("read\\S?me(\\.(txt|asc|1st))?") << QString("read me.txt") << 0;
|
|
108 |
QTest::newRow( "data10" ) << QString("read\\S?me(\\.(txt|asc|1st))?") << QString("readm") << 1;
|
|
109 |
}
|
|
110 |
|
|
111 |
void tst_QRegExpValidator::validate()
|
|
112 |
{
|
|
113 |
QFETCH( QString, rx );
|
|
114 |
QFETCH( QString, value );
|
|
115 |
QFETCH( int, state );
|
|
116 |
|
|
117 |
QRegExpValidator rv( 0 );
|
|
118 |
rv.setRegExp( QRegExp( rx ) );
|
|
119 |
int dummy;
|
|
120 |
QCOMPARE( (int)rv.validate( value, dummy ), state );
|
|
121 |
}
|
|
122 |
|
|
123 |
QTEST_MAIN(tst_QRegExpValidator)
|
|
124 |
#include "tst_qregexpvalidator.moc"
|