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 |
|
|
45 |
#include <qbytearraymatcher.h>
|
|
46 |
|
|
47 |
class tst_QByteArrayMatcher : public QObject
|
|
48 |
{
|
|
49 |
Q_OBJECT
|
|
50 |
|
|
51 |
private slots:
|
|
52 |
void interface();
|
|
53 |
void task251958();
|
|
54 |
};
|
|
55 |
|
|
56 |
static QByteArrayMatcher matcher1;
|
|
57 |
|
|
58 |
void tst_QByteArrayMatcher::interface()
|
|
59 |
{
|
|
60 |
const char needle[] = "abc123";
|
|
61 |
QByteArray haystack(500, 'a');
|
|
62 |
haystack.insert(6, "123");
|
|
63 |
haystack.insert(31, "abc");
|
|
64 |
haystack.insert(42, "abc123");
|
|
65 |
haystack.insert(84, "abc123");
|
|
66 |
|
|
67 |
matcher1 = QByteArrayMatcher(QByteArray(needle));
|
|
68 |
QByteArrayMatcher matcher2;
|
|
69 |
matcher2.setPattern(QByteArray(needle));
|
|
70 |
|
|
71 |
QByteArrayMatcher matcher3 = QByteArrayMatcher(QByteArray(needle));
|
|
72 |
QByteArrayMatcher matcher4(needle, sizeof(needle - 1));
|
|
73 |
QByteArrayMatcher matcher5(matcher2);
|
|
74 |
QByteArrayMatcher matcher6;
|
|
75 |
matcher6 = matcher3;
|
|
76 |
|
|
77 |
QCOMPARE(matcher1.indexIn(haystack), 42);
|
|
78 |
QCOMPARE(matcher2.indexIn(haystack), 42);
|
|
79 |
QCOMPARE(matcher3.indexIn(haystack), 42);
|
|
80 |
QCOMPARE(matcher4.indexIn(haystack), 42);
|
|
81 |
QCOMPARE(matcher5.indexIn(haystack), 42);
|
|
82 |
QCOMPARE(matcher6.indexIn(haystack), 42);
|
|
83 |
|
|
84 |
QCOMPARE(matcher1.indexIn(haystack.constData(), haystack.length()), 42);
|
|
85 |
|
|
86 |
QCOMPARE(matcher1.indexIn(haystack, 43), 84);
|
|
87 |
QCOMPARE(matcher1.indexIn(haystack.constData(), haystack.length(), 43), 84);
|
|
88 |
QCOMPARE(matcher1.indexIn(haystack, 85), -1);
|
|
89 |
QCOMPARE(matcher1.indexIn(haystack.constData(), haystack.length(), 85), -1);
|
|
90 |
|
|
91 |
QByteArrayMatcher matcher7(QByteArray("123"));
|
|
92 |
QCOMPARE(matcher7.indexIn(haystack), 6);
|
|
93 |
|
|
94 |
matcher7 = QByteArrayMatcher(QByteArray("abc"));
|
|
95 |
QCOMPARE(matcher7.indexIn(haystack), 31);
|
|
96 |
|
|
97 |
matcher7.setPattern(matcher4.pattern());
|
|
98 |
QCOMPARE(matcher7.indexIn(haystack), 42);
|
|
99 |
}
|
|
100 |
|
|
101 |
|
|
102 |
static QByteArrayMatcher matcher;
|
|
103 |
|
|
104 |
void tst_QByteArrayMatcher::task251958()
|
|
105 |
{
|
|
106 |
const char p_data[] = { 0x0, 0x0, 0x1 };
|
|
107 |
QByteArray pattern(p_data, sizeof(p_data));
|
|
108 |
|
|
109 |
QByteArray haystack(8, '\0');
|
|
110 |
haystack[7] = 0x1;
|
|
111 |
|
|
112 |
matcher = QByteArrayMatcher(pattern);
|
|
113 |
QCOMPARE(matcher.indexIn(haystack, 0), 5);
|
|
114 |
QCOMPARE(matcher.indexIn(haystack, 1), 5);
|
|
115 |
QCOMPARE(matcher.indexIn(haystack, 2), 5);
|
|
116 |
|
|
117 |
matcher.setPattern(pattern);
|
|
118 |
QCOMPARE(matcher.indexIn(haystack, 0), 5);
|
|
119 |
QCOMPARE(matcher.indexIn(haystack, 1), 5);
|
|
120 |
QCOMPARE(matcher.indexIn(haystack, 2), 5);
|
|
121 |
}
|
|
122 |
|
|
123 |
QTEST_APPLESS_MAIN(tst_QByteArrayMatcher)
|
|
124 |
#include "tst_qbytearraymatcher.moc"
|