|
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 #include <QStringList> |
|
42 #include <QFile> |
|
43 #include <qtest.h> |
|
44 |
|
45 class tst_QString: public QObject |
|
46 { |
|
47 Q_OBJECT |
|
48 private slots: |
|
49 void equals() const; |
|
50 void equals_data() const; |
|
51 void fromUtf8() const; |
|
52 }; |
|
53 |
|
54 void tst_QString::equals() const |
|
55 { |
|
56 QFETCH(QString, a); |
|
57 QFETCH(QString, b); |
|
58 |
|
59 QBENCHMARK { |
|
60 a == b; |
|
61 } |
|
62 } |
|
63 |
|
64 void tst_QString::equals_data() const |
|
65 { |
|
66 static const struct { |
|
67 ushort data[80]; |
|
68 int dummy; // just to ensure 4-byte alignment |
|
69 } data = { |
|
70 { |
|
71 64, 64, 64, 64, 64, 64, 64, 64, |
|
72 64, 64, 64, 64, 64, 64, 64, 64, // 16 |
|
73 64, 64, 64, 64, 64, 64, 64, 64, |
|
74 64, 64, 64, 64, 64, 64, 64, 64, // 32 |
|
75 64, 64, 64, 64, 64, 64, 64, 64, |
|
76 64, 64, 64, 64, 64, 64, 64, 64, // 48 |
|
77 64, 64, 64, 64, 64, 64, 64, 64, |
|
78 64, 64, 64, 64, 64, 64, 64, 64, // 64 |
|
79 64, 64, 64, 64, 96, 96, 96, 96, |
|
80 64, 64, 96, 96, 96, 96, 96, 96 // 80 |
|
81 }, 0 |
|
82 }; |
|
83 const QChar *ptr = reinterpret_cast<const QChar *>(data.data); |
|
84 |
|
85 QTest::addColumn<QString>("a"); |
|
86 QTest::addColumn<QString>("b"); |
|
87 QString base = QString::fromRawData(ptr, 64); |
|
88 |
|
89 QTest::newRow("different-length") << base << QString::fromRawData(ptr, 4); |
|
90 QTest::newRow("same-string") << base << base; |
|
91 QTest::newRow("same-data") << base << QString::fromRawData(ptr, 64); |
|
92 |
|
93 // try to avoid crossing a cache line (that is, at ptr[64]) |
|
94 QTest::newRow("aligned-aligned-4n") |
|
95 << QString::fromRawData(ptr, 60) << QString::fromRawData(ptr + 2, 60); |
|
96 QTest::newRow("aligned-unaligned-4n") |
|
97 << QString::fromRawData(ptr, 60) << QString::fromRawData(ptr + 1, 60); |
|
98 QTest::newRow("unaligned-unaligned-4n") |
|
99 << QString::fromRawData(ptr + 1, 60) << QString::fromRawData(ptr + 3, 60); |
|
100 |
|
101 QTest::newRow("aligned-aligned-4n+1") |
|
102 << QString::fromRawData(ptr, 61) << QString::fromRawData(ptr + 2, 61); |
|
103 QTest::newRow("aligned-unaligned-4n+1") |
|
104 << QString::fromRawData(ptr, 61) << QString::fromRawData(ptr + 1, 61); |
|
105 QTest::newRow("unaligned-unaligned-4n+1") |
|
106 << QString::fromRawData(ptr + 1, 61) << QString::fromRawData(ptr + 3, 61); |
|
107 |
|
108 QTest::newRow("aligned-aligned-4n-1") |
|
109 << QString::fromRawData(ptr, 59) << QString::fromRawData(ptr + 2, 59); |
|
110 QTest::newRow("aligned-unaligned-4n-1") |
|
111 << QString::fromRawData(ptr, 59) << QString::fromRawData(ptr + 1, 59); |
|
112 QTest::newRow("unaligned-unaligned-4n-1") |
|
113 << QString::fromRawData(ptr + 1, 59) << QString::fromRawData(ptr + 3, 59); |
|
114 |
|
115 QTest::newRow("aligned-aligned-2n") |
|
116 << QString::fromRawData(ptr, 58) << QString::fromRawData(ptr + 2, 58); |
|
117 QTest::newRow("aligned-unaligned-2n") |
|
118 << QString::fromRawData(ptr, 58) << QString::fromRawData(ptr + 1, 58); |
|
119 QTest::newRow("unaligned-unaligned-2n") |
|
120 << QString::fromRawData(ptr + 1, 58) << QString::fromRawData(ptr + 3, 58); |
|
121 } |
|
122 |
|
123 void tst_QString::fromUtf8() const |
|
124 { |
|
125 QFile file(SRCDIR "utf-8.txt"); |
|
126 if (!file.open(QFile::ReadOnly)) { |
|
127 qFatal("Cannot open input file"); |
|
128 return; |
|
129 } |
|
130 QByteArray data = file.readAll(); |
|
131 const char *d = data.constData(); |
|
132 int size = data.size(); |
|
133 |
|
134 QBENCHMARK { |
|
135 QString::fromUtf8(d, size); |
|
136 } |
|
137 } |
|
138 |
|
139 QTEST_MAIN(tst_QString) |
|
140 |
|
141 #include "main.moc" |