0
|
1 |
/****************************************************************************
|
|
2 |
**
|
18
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
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 |
#define LITERAL "some literal"
|
|
43 |
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
44 |
// "some literal", but replacing all vocals by their umlauted UTF-8 string :)
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
45 |
#define UTF8_LITERAL "s\xc3\xb6m\xc3\xab l\xc3\xaft\xc3\xabr\xc3\xa4l"
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
46 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
47 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
48 |
//fix for gcc4.0: if the operator+ does not exist without QT_USE_FAST_OPERATOR_PLUS
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
49 |
#ifndef QT_USE_FAST_CONCATENATION
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
50 |
#define Q %
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
51 |
#else
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
52 |
#define Q P
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
53 |
#endif
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
54 |
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
55 |
void runScenario()
|
0
|
56 |
{
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
57 |
// set codec for C strings to 0, enforcing Latin1
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
58 |
QTextCodec::setCodecForCStrings(0);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
59 |
QVERIFY(!QTextCodec::codecForCStrings());
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
60 |
|
0
|
61 |
QLatin1Literal l1literal(LITERAL);
|
|
62 |
QLatin1String l1string(LITERAL);
|
|
63 |
QString string(l1string);
|
|
64 |
QStringRef stringref(&string, 2, 10);
|
|
65 |
QLatin1Char achar('c');
|
|
66 |
QString r2(QLatin1String(LITERAL LITERAL));
|
|
67 |
QString r;
|
|
68 |
QByteArray ba(LITERAL);
|
|
69 |
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
70 |
r = l1literal Q l1literal;
|
0
|
71 |
QCOMPARE(r, r2);
|
|
72 |
r = string P string;
|
|
73 |
QCOMPARE(r, r2);
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
74 |
r = stringref Q stringref;
|
0
|
75 |
QCOMPARE(r, QString(stringref.toString() + stringref.toString()));
|
30
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
76 |
r = string Q l1literal;
|
0
|
77 |
QCOMPARE(r, r2);
|
|
78 |
r = string P l1string;
|
|
79 |
QCOMPARE(r, r2);
|
|
80 |
r = string + achar;
|
|
81 |
QCOMPARE(r, QString(string P achar));
|
|
82 |
r = achar + string;
|
|
83 |
QCOMPARE(r, QString(achar P string));
|
|
84 |
#ifndef QT_NO_CAST_FROM_ASCII
|
|
85 |
r = string P LITERAL;
|
|
86 |
QCOMPARE(r, r2);
|
|
87 |
r = LITERAL P string;
|
|
88 |
QCOMPARE(r, r2);
|
|
89 |
r = ba P string;
|
|
90 |
QCOMPARE(r, r2);
|
|
91 |
r = string P ba;
|
|
92 |
QCOMPARE(r, r2);
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
93 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
94 |
// now test with codec for C strings set
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
95 |
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
96 |
QVERIFY(QTextCodec::codecForCStrings());
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
97 |
QCOMPARE(QTextCodec::codecForCStrings()->name(), QByteArray("UTF-8"));
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
98 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
99 |
string = QString::fromUtf8(UTF8_LITERAL);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
100 |
r2 = QString::fromUtf8(UTF8_LITERAL UTF8_LITERAL);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
101 |
ba = UTF8_LITERAL;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
102 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
103 |
r = string P UTF8_LITERAL;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
104 |
QCOMPARE(r.size(), r2.size());
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
105 |
QCOMPARE(r, r2);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
106 |
r = UTF8_LITERAL P string;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
107 |
QCOMPARE(r, r2);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
108 |
r = ba P string;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
109 |
QCOMPARE(r, r2);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
110 |
r = string P ba;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
111 |
QCOMPARE(r, r2);
|
0
|
112 |
#endif
|
|
113 |
}
|