|
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 // Horrible hack, but this get this out of the way for now |
|
44 // Carlos Duclos, 2007-12-11 |
|
45 #if !defined(Q_WS_MAC) |
|
46 |
|
47 #include <QtTest/QtTest> |
|
48 #include <private/qtextengine_p.h> |
|
49 |
|
50 #include "bidireorderstring.h" |
|
51 |
|
52 |
|
53 //TESTED_CLASS= |
|
54 //TESTED_FILES=gui/widgets/qcombobox.h gui/widgets/qcombobox.cpp |
|
55 |
|
56 class tst_QComplexText : public QObject |
|
57 { |
|
58 Q_OBJECT |
|
59 |
|
60 public: |
|
61 tst_QComplexText(); |
|
62 virtual ~tst_QComplexText(); |
|
63 |
|
64 |
|
65 public slots: |
|
66 void init(); |
|
67 void cleanup(); |
|
68 private slots: |
|
69 void bidiReorderString_data(); |
|
70 void bidiReorderString(); |
|
71 }; |
|
72 |
|
73 tst_QComplexText::tst_QComplexText() |
|
74 { |
|
75 } |
|
76 |
|
77 tst_QComplexText::~tst_QComplexText() |
|
78 { |
|
79 |
|
80 } |
|
81 |
|
82 void tst_QComplexText::init() |
|
83 { |
|
84 // This will be executed immediately before each test is run. |
|
85 // TODO: Add initialization code here. |
|
86 } |
|
87 |
|
88 void tst_QComplexText::cleanup() |
|
89 { |
|
90 // This will be executed immediately after each test is run. |
|
91 // TODO: Add cleanup code here. |
|
92 } |
|
93 |
|
94 void tst_QComplexText::bidiReorderString_data() |
|
95 { |
|
96 QTest::addColumn<QString>("logical"); |
|
97 QTest::addColumn<QString>("VISUAL"); |
|
98 QTest::addColumn<int>("basicDir"); |
|
99 |
|
100 const LV *data = logical_visual; |
|
101 while ( data->name ) { |
|
102 //next we fill it with data |
|
103 QTest::newRow( data->name ) |
|
104 << QString::fromUtf8( data->logical ) |
|
105 << QString::fromUtf8( data->visual ) |
|
106 << (int) data->basicDir; |
|
107 data++; |
|
108 } |
|
109 } |
|
110 |
|
111 void tst_QComplexText::bidiReorderString() |
|
112 { |
|
113 QFETCH( QString, logical ); |
|
114 QFETCH( int, basicDir ); |
|
115 |
|
116 // replace \n with Unicode newline. The new algorithm ignores \n |
|
117 logical.replace(QChar('\n'), QChar(0x2028)); |
|
118 |
|
119 QTextEngine e(logical, QFont()); |
|
120 e.option.setTextDirection((QChar::Direction)basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft); |
|
121 e.itemize(); |
|
122 quint8 levels[256]; |
|
123 int visualOrder[256]; |
|
124 int nitems = e.layoutData->items.size(); |
|
125 int i; |
|
126 for (i = 0; i < nitems; ++i) { |
|
127 //qDebug("item %d bidiLevel=%d", i, e.items[i].analysis.bidiLevel); |
|
128 levels[i] = e.layoutData->items[i].analysis.bidiLevel; |
|
129 } |
|
130 e.bidiReorder(nitems, levels, visualOrder); |
|
131 |
|
132 QString visual; |
|
133 for (i = 0; i < nitems; ++i) { |
|
134 QScriptItem &si = e.layoutData->items[visualOrder[i]]; |
|
135 QString sub = logical.mid(si.position, e.length(visualOrder[i])); |
|
136 if (si.analysis.bidiLevel % 2) { |
|
137 // reverse sub |
|
138 QChar *a = (QChar *)sub.unicode(); |
|
139 QChar *b = a + sub.length() - 1; |
|
140 while (a < b) { |
|
141 QChar tmp = *a; |
|
142 *a = *b; |
|
143 *b = tmp; |
|
144 ++a; |
|
145 --b; |
|
146 } |
|
147 a = (QChar *)sub.unicode(); |
|
148 b = a + sub.length(); |
|
149 while (a<b) { |
|
150 *a = a->mirroredChar(); |
|
151 ++a; |
|
152 } |
|
153 } |
|
154 visual += sub; |
|
155 } |
|
156 // replace Unicode newline back with \n to compare. |
|
157 visual.replace(QChar(0x2028), QChar('\n')); |
|
158 |
|
159 QTEST(visual, "VISUAL"); |
|
160 } |
|
161 |
|
162 |
|
163 QTEST_MAIN(tst_QComplexText) |
|
164 #include "tst_qcomplextext.moc" |
|
165 |
|
166 #endif // Q_WS_MAC |
|
167 |