author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 12 Mar 2010 15:46:37 +0200 | |
branch | RCL_3 |
changeset 5 | d3bac044e0f0 |
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 <qstringmatcher.h> |
|
45 |
||
46 |
class tst_QStringMatcher : public QObject |
|
47 |
{ |
|
48 |
Q_OBJECT |
|
49 |
||
50 |
private slots: |
|
51 |
void qstringmatcher_data(); |
|
52 |
void qstringmatcher(); |
|
53 |
void caseSensitivity(); |
|
54 |
void indexIn_data(); |
|
55 |
void indexIn(); |
|
56 |
void setCaseSensitivity_data(); |
|
57 |
void setCaseSensitivity(); |
|
58 |
void assignOperator(); |
|
59 |
}; |
|
60 |
||
61 |
// Subclass that exposes the protected functions. |
|
62 |
class SubQStringMatcher : public QStringMatcher |
|
63 |
{ |
|
64 |
public: |
|
65 |
}; |
|
66 |
||
67 |
void tst_QStringMatcher::qstringmatcher_data() |
|
68 |
{ |
|
69 |
} |
|
70 |
||
71 |
void tst_QStringMatcher::qstringmatcher() |
|
72 |
{ |
|
73 |
SubQStringMatcher matcher; |
|
74 |
QCOMPARE(matcher.caseSensitivity(), Qt::CaseSensitive); |
|
75 |
QCOMPARE(matcher.indexIn("foo", 1), 1); |
|
76 |
QCOMPARE(matcher.pattern(), QString()); |
|
77 |
} |
|
78 |
||
79 |
// public Qt::CaseSensitivity caseSensitivity() const |
|
80 |
void tst_QStringMatcher::caseSensitivity() |
|
81 |
{ |
|
82 |
SubQStringMatcher matcher; |
|
83 |
||
84 |
matcher.setCaseSensitivity(Qt::CaseSensitive); |
|
85 |
QCOMPARE(matcher.caseSensitivity(), Qt::CaseSensitive); |
|
86 |
matcher.setCaseSensitivity(Qt::CaseInsensitive); |
|
87 |
QCOMPARE(matcher.caseSensitivity(), Qt::CaseInsensitive); |
|
88 |
} |
|
89 |
||
90 |
void tst_QStringMatcher::indexIn_data() |
|
91 |
{ |
|
92 |
QTest::addColumn<QString>("needle"); |
|
93 |
QTest::addColumn<QString>("haystack"); |
|
94 |
QTest::addColumn<int>("from"); |
|
95 |
QTest::addColumn<int>("indexIn"); |
|
96 |
QTest::newRow("empty") << QString() << QString("foo") << 0 << 0; |
|
97 |
QTest::newRow("empty") << QString() << QString("foo") << 10 << -1; |
|
98 |
QTest::newRow("empty") << QString() << QString("foo") << -10 << 0; |
|
99 |
||
100 |
QTest::newRow("simple") << QString("a") << QString("foo") << 0 << -1; |
|
101 |
QTest::newRow("simple") << QString("a") << QString("bar") << 0 << 1; |
|
102 |
QTest::newRow("harder") << QString("foo") << QString("slkdf sldkjf slakjf lskd ffools ldjf") << 0 << 26; |
|
103 |
QTest::newRow("harder") << QString("foo") << QString("slkdf sldkjf slakjf lskd ffools ldjf") << 20 << 26; |
|
104 |
QTest::newRow("harder") << QString("foo") << QString("slkdf sldkjf slakjf lskd ffools ldjf") << 26 << 26; |
|
105 |
QTest::newRow("harder") << QString("foo") << QString("slkdf sldkjf slakjf lskd ffools ldjf") << 27 << -1; |
|
106 |
} |
|
107 |
||
108 |
void tst_QStringMatcher::indexIn() |
|
109 |
{ |
|
110 |
QFETCH(QString, needle); |
|
111 |
QFETCH(QString, haystack); |
|
112 |
QFETCH(int, from); |
|
113 |
QFETCH(int, indexIn); |
|
114 |
||
115 |
SubQStringMatcher matcher; |
|
116 |
matcher.setPattern(needle); |
|
117 |
||
118 |
QCOMPARE(matcher.indexIn(haystack, from), indexIn); |
|
119 |
} |
|
120 |
||
121 |
void tst_QStringMatcher::setCaseSensitivity_data() |
|
122 |
{ |
|
123 |
QTest::addColumn<QString>("needle"); |
|
124 |
QTest::addColumn<QString>("haystack"); |
|
125 |
QTest::addColumn<int>("from"); |
|
126 |
QTest::addColumn<int>("indexIn"); |
|
127 |
QTest::addColumn<int>("cs"); |
|
128 |
||
129 |
QTest::newRow("overshot") << QString("foo") << QString("baFooz foo bar") << 14 << -1 << (int) Qt::CaseSensitive; |
|
130 |
QTest::newRow("sensitive") << QString("foo") << QString("baFooz foo bar") << 1 << 7 << (int) Qt::CaseSensitive; |
|
131 |
QTest::newRow("insensitive") << QString("foo") << QString("baFooz foo bar") << 1 << 2 << (int) Qt::CaseInsensitive; |
|
132 |
} |
|
133 |
||
134 |
void tst_QStringMatcher::setCaseSensitivity() |
|
135 |
{ |
|
136 |
QFETCH(QString, needle); |
|
137 |
QFETCH(QString, haystack); |
|
138 |
QFETCH(int, from); |
|
139 |
QFETCH(int, indexIn); |
|
140 |
QFETCH(int, cs); |
|
141 |
||
142 |
SubQStringMatcher matcher; |
|
143 |
matcher.setPattern(needle); |
|
144 |
matcher.setCaseSensitivity(static_cast<Qt::CaseSensitivity> (cs)); |
|
145 |
||
146 |
QCOMPARE(matcher.indexIn(haystack, from), indexIn); |
|
147 |
} |
|
148 |
||
149 |
void tst_QStringMatcher::assignOperator() |
|
150 |
{ |
|
151 |
QString needle("d"); |
|
152 |
QString hayStack("abcdef"); |
|
153 |
QStringMatcher m1(needle); |
|
154 |
QCOMPARE(m1.indexIn(hayStack), 3); |
|
155 |
||
156 |
QStringMatcher m2 = m1; |
|
157 |
QCOMPARE(m2.pattern(), needle); |
|
158 |
QCOMPARE(m2.indexIn(hayStack), 3); |
|
159 |
} |
|
160 |
||
161 |
QTEST_MAIN(tst_QStringMatcher) |
|
162 |
#include "tst_qstringmatcher.moc" |
|
163 |