|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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 #include "testgenerator.h" |
|
43 |
|
44 #include <QtCore/qdatastream.h> |
|
45 #include <QtCore/qdatetime.h> |
|
46 #include <QtCore/qdebug.h> |
|
47 #include <QtCore/qnumeric.h> |
|
48 #include <QtCore/qstringlist.h> |
|
49 #include <QtCore/qtextstream.h> |
|
50 #include <QtCore/qvariant.h> |
|
51 #include <QtScript/qscriptvalue.h> |
|
52 |
|
53 void TestGenerator::save(const QString& data) |
|
54 { |
|
55 QTextStream out(&m_ofile); |
|
56 out << data; |
|
57 } |
|
58 |
|
59 static QString escape(QString txt) |
|
60 { |
|
61 return txt.replace("\\","\\\\").replace("\"","\\\"").replace("\n","\\n"); |
|
62 } |
|
63 |
|
64 template<typename T> |
|
65 QString prepareToInsert(T value) {return QString::fromAscii("\"") + escape(value) + "\"";} |
|
66 template<> |
|
67 QString prepareToInsert<qsreal>(qsreal value) |
|
68 { |
|
69 if (qIsNaN(value)) |
|
70 return "qQNaN()"; |
|
71 if (qIsInf(value)) |
|
72 return "qInf()"; |
|
73 return QString::number(value, 'g', 16); |
|
74 } |
|
75 template<> |
|
76 QString prepareToInsert<qint32>(qint32 value) {return QString::number(value);} |
|
77 template<> |
|
78 QString prepareToInsert<quint32>(quint32 value) {return QString::number(value);} |
|
79 template<> |
|
80 QString prepareToInsert<quint16>(quint16 value) {return QString::number(value);} |
|
81 template<> |
|
82 QString prepareToInsert<bool>(bool value) {return value ? "true" : "false";} |
|
83 template<> |
|
84 QString prepareToInsert<QString>(QString value) {return QString::fromAscii("\"") + escape(value) + "\"";} |
|
85 |
|
86 template<typename T> |
|
87 QString typeName() {return QString();} |
|
88 template<> |
|
89 QString typeName<qsreal>() {return "qsreal";} |
|
90 template<> |
|
91 QString typeName<qint32>() {return "qint32";} |
|
92 template<> |
|
93 QString typeName<quint32>() {return "quint32";} |
|
94 template<> |
|
95 QString typeName<quint16>() {return "quint16";} |
|
96 template<> |
|
97 QString typeName<bool>() {return "bool";} |
|
98 template<> |
|
99 QString typeName<QString>() {return "QString";} |
|
100 |
|
101 static QString generateIsXXXDef(const QString& name, const QList<QString>& list) |
|
102 { |
|
103 static const QString templ("void tst_QScriptValue::%1_initData()\n"\ |
|
104 "{\n"\ |
|
105 " QTest::addColumn<bool>(\"expected\");\n"\ |
|
106 " initScriptValues();\n"\ |
|
107 "}\n"\ |
|
108 "\n"\ |
|
109 "void tst_QScriptValue::%1_makeData(const char* expr)\n"\ |
|
110 "{\n"\ |
|
111 " static QSet<QString> %1;\n"\ |
|
112 " if (%1.isEmpty()) {\n"\ |
|
113 " %1%2\n"\ |
|
114 " }\n"\ |
|
115 " newRow(expr) << %1.contains(expr);\n"\ |
|
116 "}\n"\ |
|
117 "\n"\ |
|
118 "void tst_QScriptValue::%1_test(const char*, const QScriptValue& value)\n"\ |
|
119 "{\n"\ |
|
120 " QFETCH(bool, expected);\n"\ |
|
121 " QCOMPARE(value.%1(), expected);\n"\ |
|
122 "}\n"\ |
|
123 "\n"\ |
|
124 "DEFINE_TEST_FUNCTION(%1)\n"\ |
|
125 "\n"); |
|
126 |
|
127 if (!list.size()) { |
|
128 qWarning() << name << ": nothing to add!" ; |
|
129 return QString(); |
|
130 } |
|
131 |
|
132 QString result = templ; |
|
133 QStringList set; |
|
134 foreach(QString t, list) { |
|
135 t = escape(t); |
|
136 t.append('\"'); |
|
137 t.prepend('\"'); |
|
138 set.append(QString(" << ")); |
|
139 set.append(t); |
|
140 set.append("\n "); |
|
141 } |
|
142 set.append(";"); |
|
143 return result.arg(name, set.join(QString())); |
|
144 } |
|
145 |
|
146 template<typename T> |
|
147 static QString generateToXXXDef(const QString& name, const QList<QPair<QString, T> >& list) |
|
148 { |
|
149 static const QString templ = "\n"\ |
|
150 "void tst_QScriptValue::%1_initData()\n"\ |
|
151 "{\n"\ |
|
152 " QTest::addColumn<%2>(\"expected\");\n"\ |
|
153 " initScriptValues();\n"\ |
|
154 "}\n"\ |
|
155 "\n"\ |
|
156 "void tst_QScriptValue::%1_makeData(const char* expr)\n"\ |
|
157 "{\n"\ |
|
158 " static QHash<QString, %2> %1;\n"\ |
|
159 " if (%1.isEmpty()) {\n"\ |
|
160 "%3"\ |
|
161 " }\n"\ |
|
162 " newRow(expr) << %1.value(expr);\n"\ |
|
163 "}\n"\ |
|
164 "\n"\ |
|
165 "void tst_QScriptValue::%1_test(const char*, const QScriptValue& value)\n"\ |
|
166 "{\n"\ |
|
167 " QFETCH(%2, expected);\n"\ |
|
168 " QCOMPARE(value.%1(), expected);\n"\ |
|
169 "}\n"\ |
|
170 "\n"\ |
|
171 "DEFINE_TEST_FUNCTION(%1)\n"; |
|
172 QString result = templ; |
|
173 |
|
174 typename QList<QPair<QString, T> >::const_iterator i = list.constBegin(); |
|
175 QStringList set; |
|
176 for(; i != list.constEnd(); ++i) { |
|
177 QPair<QString, T> t = *i; |
|
178 t.first = escape(t.first); |
|
179 set.append(QString(" ")); |
|
180 set.append(name); |
|
181 set.append(".insert(\""); |
|
182 set.append(t.first); |
|
183 set.append(QString::fromAscii("\", ")); |
|
184 set.append(prepareToInsert<T>(t.second)); |
|
185 set.append(QString::fromAscii(");\n")); |
|
186 } |
|
187 return result.arg(name, typeName<T>(), set.join(QString())); |
|
188 } |
|
189 |
|
190 |
|
191 template<> |
|
192 QString generateToXXXDef<qsreal>(const QString& name, const QList<QPair<QString, qsreal> >& list) |
|
193 { |
|
194 static const QString templ = "\n"\ |
|
195 "void tst_QScriptValue::%1_initData()\n"\ |
|
196 "{\n"\ |
|
197 " QTest::addColumn<%2>(\"expected\");\n"\ |
|
198 " initScriptValues();\n"\ |
|
199 "}\n"\ |
|
200 "\n"\ |
|
201 "void tst_QScriptValue::%1_makeData(const char* expr)\n"\ |
|
202 "{\n"\ |
|
203 " static QHash<QString, %2> %1;\n"\ |
|
204 " if (%1.isEmpty()) {\n"\ |
|
205 "%3"\ |
|
206 " }\n"\ |
|
207 " newRow(expr) << %1.value(expr);\n"\ |
|
208 "}\n"\ |
|
209 "\n"\ |
|
210 "void tst_QScriptValue::%1_test(const char*, const QScriptValue& value)\n"\ |
|
211 "{\n"\ |
|
212 " QFETCH(%2, expected);\n"\ |
|
213 "%666" |
|
214 " if (qIsInf(expected)) {\n"\ |
|
215 " QVERIFY(qIsInf(value.%1()));\n"\ |
|
216 " return;\n"\ |
|
217 " }\n"\ |
|
218 " QCOMPARE(value.%1(), expected);\n"\ |
|
219 "}\n"\ |
|
220 "\n"\ |
|
221 "DEFINE_TEST_FUNCTION(%1)\n"; |
|
222 QString result = templ; |
|
223 |
|
224 QList<QPair<QString, qsreal> >::const_iterator i = list.constBegin(); |
|
225 QStringList set; |
|
226 for(; i != list.constEnd(); ++i) { |
|
227 QPair<QString, qsreal> t = *i; |
|
228 t.first = escape(t.first); |
|
229 set.append(QString(" ")); |
|
230 set.append(name); |
|
231 set.append(".insert(\""); |
|
232 set.append(t.first); |
|
233 set.append(QString::fromAscii("\", ")); |
|
234 set.append(prepareToInsert<qsreal>(t.second)); |
|
235 set.append(QString::fromAscii(");\n")); |
|
236 } |
|
237 // toInteger shouldn't return NaN, so it would be nice to catch the case. |
|
238 QString hook; |
|
239 if (name == "toNumber") { |
|
240 hook = |
|
241 " if (qIsNaN(expected)) {\n"\ |
|
242 " QVERIFY(qIsNaN(value.toNumber()));\n"\ |
|
243 " return;\n"\ |
|
244 " }\n"; |
|
245 } |
|
246 return result.arg(name, typeName<qsreal>(), set.join(QString()), hook); |
|
247 } |
|
248 |
|
249 template<typename T> |
|
250 static QString generateCastDef(const QList<QPair<QString, T> >& list) |
|
251 { |
|
252 static const QString templ = "\n"\ |
|
253 "void tst_QScriptValue::qscriptvalue_cast%2_initData()\n"\ |
|
254 "{\n"\ |
|
255 " QTest::addColumn<%2>(\"expected\");\n"\ |
|
256 " initScriptValues();\n"\ |
|
257 "}\n"\ |
|
258 "\n"\ |
|
259 "void tst_QScriptValue::qscriptvalue_cast%2_makeData(const char* expr)\n"\ |
|
260 "{\n"\ |
|
261 " static QHash<QString, %2> value;\n"\ |
|
262 " if (value.isEmpty()) {\n"\ |
|
263 "%3"\ |
|
264 " }\n"\ |
|
265 " newRow(expr) << value.value(expr);\n"\ |
|
266 "}\n"\ |
|
267 "\n"\ |
|
268 "void tst_QScriptValue::qscriptvalue_cast%2_test(const char*, const QScriptValue& value)\n"\ |
|
269 "{\n"\ |
|
270 " QFETCH(%2, expected);\n"\ |
|
271 " QCOMPARE(qscriptvalue_cast<%2>(value), expected);\n"\ |
|
272 "}\n"\ |
|
273 "\n"\ |
|
274 "DEFINE_TEST_FUNCTION(qscriptvalue_cast%2)\n"; |
|
275 QString result = templ; |
|
276 |
|
277 typename QList<QPair<QString, T> >::const_iterator i = list.constBegin(); |
|
278 QStringList set; |
|
279 for(; i != list.constEnd(); ++i) { |
|
280 QPair<QString, T> t = *i; |
|
281 t.first = escape(t.first); |
|
282 set.append(QString(" ")); |
|
283 set.append("value.insert(\""); |
|
284 set.append(t.first); |
|
285 set.append(QString::fromAscii("\", ")); |
|
286 set.append(prepareToInsert<T>(t.second)); |
|
287 set.append(QString::fromAscii(");\n")); |
|
288 } |
|
289 return result.arg(typeName<T>(), set.join(QString())); |
|
290 } |
|
291 |
|
292 template<> |
|
293 QString generateCastDef<qsreal>(const QList<QPair<QString, qsreal> >& list) |
|
294 { |
|
295 static const QString templ = "\n"\ |
|
296 "void tst_QScriptValue::qscriptvalue_cast%2_initData()\n"\ |
|
297 "{\n"\ |
|
298 " QTest::addColumn<%2>(\"expected\");\n"\ |
|
299 " initScriptValues();\n"\ |
|
300 "}\n"\ |
|
301 "\n"\ |
|
302 "void tst_QScriptValue::qscriptvalue_cast%2_makeData(const char* expr)\n"\ |
|
303 "{\n"\ |
|
304 " static QHash<QString, %2> value;\n"\ |
|
305 " if (value.isEmpty()) {\n"\ |
|
306 "%3"\ |
|
307 " }\n"\ |
|
308 " newRow(expr) << value.value(expr);\n"\ |
|
309 "}\n"\ |
|
310 "\n"\ |
|
311 "void tst_QScriptValue::qscriptvalue_cast%2_test(const char*, const QScriptValue& value)\n"\ |
|
312 "{\n"\ |
|
313 " QFETCH(%2, expected);\n"\ |
|
314 " if (qIsNaN(expected)) {\n" |
|
315 " QVERIFY(qIsNaN(qscriptvalue_cast<%2>(value)));\n" |
|
316 " return;\n" |
|
317 " }\n"\ |
|
318 " if (qIsInf(expected)) {\n" |
|
319 " QVERIFY(qIsInf(qscriptvalue_cast<%2>(value)));\n" |
|
320 " return;\n" |
|
321 " }\n" |
|
322 " QCOMPARE(qscriptvalue_cast<%2>(value), expected);\n"\ |
|
323 "}\n"\ |
|
324 "\n"\ |
|
325 "DEFINE_TEST_FUNCTION(qscriptvalue_cast%2)\n"; |
|
326 QString result = templ; |
|
327 |
|
328 QList<QPair<QString, qsreal> >::const_iterator i = list.constBegin(); |
|
329 QStringList set; |
|
330 for(; i != list.constEnd(); ++i) { |
|
331 QPair<QString, qsreal> t = *i; |
|
332 t.first = escape(t.first); |
|
333 set.append(QString(" ")); |
|
334 set.append("value.insert(\""); |
|
335 set.append(t.first); |
|
336 set.append(QString::fromAscii("\", ")); |
|
337 set.append(prepareToInsert<qsreal>(t.second)); |
|
338 set.append(QString::fromAscii(");\n")); |
|
339 } |
|
340 return result.arg(typeName<qsreal>(), set.join(QString())); |
|
341 } |
|
342 |
|
343 static QString generateCompareDef(const QString& comparisionType, const QList<QString> tags) |
|
344 { |
|
345 static const QString templ = "\n"\ |
|
346 "void tst_QScriptValue::%1_initData()\n"\ |
|
347 "{\n"\ |
|
348 " QTest::addColumn<QScriptValue>(\"other\");\n"\ |
|
349 " QTest::addColumn<bool>(\"expected\");\n"\ |
|
350 " initScriptValues();\n"\ |
|
351 "}\n"\ |
|
352 "\n"\ |
|
353 "void tst_QScriptValue::%1_makeData(const char *expr)\n"\ |
|
354 "{\n"\ |
|
355 " static QSet<QString> equals;\n"\ |
|
356 " if (equals.isEmpty()) {\n"\ |
|
357 "%2\n"\ |
|
358 " }\n"\ |
|
359 " QHash<QString, QScriptValue>::const_iterator it;\n"\ |
|
360 " for (it = m_values.constBegin(); it != m_values.constEnd(); ++it) {\n"\ |
|
361 " QString tag = QString::fromLatin1(\"%20 <=> %21\").arg(expr).arg(it.key());\n"\ |
|
362 " newRow(tag.toLatin1()) << it.value() << equals.contains(tag);\n"\ |
|
363 " }\n"\ |
|
364 "}\n"\ |
|
365 "\n"\ |
|
366 "void tst_QScriptValue::%1_test(const char *, const QScriptValue& value)\n"\ |
|
367 "{\n"\ |
|
368 " QFETCH(QScriptValue, other);\n"\ |
|
369 " QFETCH(bool, expected);\n"\ |
|
370 " QCOMPARE(value.%1(other), expected);\n"\ |
|
371 "}\n"\ |
|
372 "\n"\ |
|
373 "DEFINE_TEST_FUNCTION(%1)\n"; |
|
374 Q_ASSERT(comparisionType == "strictlyEquals" |
|
375 || comparisionType == "equals" |
|
376 || comparisionType == "lessThan" |
|
377 || comparisionType == "instanceOf"); |
|
378 QString result = templ; |
|
379 |
|
380 QStringList set; |
|
381 foreach(const QString& tmp, tags) { |
|
382 set.append(" equals.insert(\"" + escape(tmp) + "\");"); |
|
383 } |
|
384 return result.arg(comparisionType, set.join("\n")); |
|
385 } |
|
386 |
|
387 static QString generateInitDef(const QVector<QString>& allDataTags) |
|
388 { |
|
389 static const QString templ = "/****************************************************************************\n" |
|
390 "**\n" |
|
391 "** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).\n" |
|
392 "** All rights reserved.\n" |
|
393 "** Contact: Nokia Corporation (qt-info@nokia.com)\n" |
|
394 "**\n" |
|
395 "** This file is part of the test suite of the Qt Toolkit.\n" |
|
396 "**\n" |
|
397 "** $QT_BEGIN_LICENSE:LGPL$\n" |
|
398 "** No Commercial Usage\n" |
|
399 "** This file contains pre-release code and may not be distributed.\n" |
|
400 "** You may use this file in accordance with the terms and conditions\n" |
|
401 "** contained in the Technology Preview License Agreement accompanying\n" |
|
402 "** this package.\n" |
|
403 "**\n" |
|
404 "** GNU Lesser General Public License Usage\n" |
|
405 "** Alternatively, this file may be used under the terms of the GNU Lesser\n" |
|
406 "** General Public License version 2.1 as published by the Free Software\n" |
|
407 "** Foundation and appearing in the file LICENSE.LGPL included in the\n" |
|
408 "** packaging of this file. Please review the following information to\n" |
|
409 "** ensure the GNU Lesser General Public License version 2.1 requirements\n" |
|
410 "** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.\n" |
|
411 "**\n" |
|
412 "** In addition, as a special exception, Nokia gives you certain additional\n" |
|
413 "** rights. These rights are described in the Nokia Qt LGPL Exception\n" |
|
414 "** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.\n" |
|
415 "**\n" |
|
416 "** If you have questions regarding the use of this file, please contact\n" |
|
417 "** Nokia at qt-info@nokia.com.\n" |
|
418 "**\n" |
|
419 "**\n" |
|
420 "**\n" |
|
421 "**\n" |
|
422 "**\n" |
|
423 "**\n" |
|
424 "**\n" |
|
425 "**\n" |
|
426 "** $QT_END_LICENSE$\n" |
|
427 "**\n" |
|
428 "****************************************************************************/\n" |
|
429 "\n"\ |
|
430 "#include \"tst_qscriptvalue.h\"\n\n"\ |
|
431 "#define DEFINE_TEST_VALUE(expr) m_values.insert(QString::fromLatin1(#expr), expr)\n"\ |
|
432 "\n"\ |
|
433 "void tst_QScriptValue::initScriptValues()\n"\ |
|
434 "{\n"\ |
|
435 " m_values.clear();\n"\ |
|
436 " if (engine) \n"\ |
|
437 " delete engine;\n"\ |
|
438 " engine = new QScriptEngine;\n"\ |
|
439 "%1\n}\n\n"; |
|
440 QString result = templ; |
|
441 QStringList set; |
|
442 foreach(const QString tag, allDataTags) { |
|
443 set.append(" DEFINE_TEST_VALUE(" + tag + ");"); |
|
444 } |
|
445 |
|
446 return result.arg(set.join("\n")); |
|
447 } |
|
448 |
|
449 static void squashTags(QString dataTag, const QVector<bool>& results, QList<QString>& tags, QVector<QString> dataTags) |
|
450 { |
|
451 for(int i = 0; i < results.count(); ++i) { |
|
452 if (results.at(i)) |
|
453 tags.append(dataTag + " <=> " + dataTags[i]); |
|
454 } |
|
455 } |
|
456 |
|
457 |
|
458 QString TestGenerator::generateTest() |
|
459 { |
|
460 // All data tags keept in one place. |
|
461 QVector<QString> dataTags; |
|
462 |
|
463 // Data tags for values that return true in isXXX call |
|
464 QList<QString> isValidList; |
|
465 QList<QString> isBoolList; |
|
466 QList<QString> isBooleanList; |
|
467 QList<QString> isNumberList; |
|
468 QList<QString> isFunctionList; |
|
469 QList<QString> isNullList; |
|
470 QList<QString> isStringList; |
|
471 QList<QString> isUndefinedList; |
|
472 QList<QString> isVariantList; |
|
473 QList<QString> isQObjectList; |
|
474 QList<QString> isQMetaObjectList; |
|
475 QList<QString> isObjectList; |
|
476 QList<QString> isDateList; |
|
477 QList<QString> isRegExpList; |
|
478 QList<QString> isArrayList; |
|
479 QList<QString> isErrorList; |
|
480 |
|
481 // List of pairs data tag and value returned from toXXX call |
|
482 QList<QPair<QString, QString> > toStringList; |
|
483 QList<QPair<QString, qsreal> > toNumberList; |
|
484 QList<QPair<QString, bool> > toBoolList; |
|
485 QList<QPair<QString, bool> > toBooleanList; |
|
486 QList<QPair<QString, qsreal> > toIntegerList; |
|
487 QList<QPair<QString, qint32> > toInt32List; |
|
488 QList<QPair<QString, quint32> > toUInt32List; |
|
489 QList<QPair<QString, quint16> > toUInt16List; |
|
490 |
|
491 // List of complex tags returning true |
|
492 QList<QString> equalsList; |
|
493 QList<QString> strictlyEqualsList; |
|
494 QList<QString> lessThanList; |
|
495 QList<QString> instanceOfList; |
|
496 |
|
497 QList<QPair<QString, QString> > castStringList; |
|
498 QList<QPair<QString, qsreal> > castSRealList; |
|
499 QList<QPair<QString, bool> > castBoolList; |
|
500 QList<QPair<QString, qint32> > castInt32List; |
|
501 QList<QPair<QString, quint32> > castUInt32List; |
|
502 QList<QPair<QString, quint16> > castUInt16List; |
|
503 |
|
504 // Load. |
|
505 m_tempFile.seek(0); |
|
506 QDataStream in(&m_tempFile); |
|
507 in >> dataTags; |
|
508 Q_ASSERT(in.status() == in.Ok); |
|
509 |
|
510 while(!in.atEnd()) |
|
511 { |
|
512 bool isValidRes; |
|
513 bool isBoolRes; |
|
514 bool isBooleanRes; |
|
515 bool isNumberRes; |
|
516 bool isFunctionRes; |
|
517 bool isNullRes; |
|
518 bool isStringRes; |
|
519 bool isUndefinedRes; |
|
520 bool isVariantRes; |
|
521 bool isQObjectRes; |
|
522 bool isQMetaObjectRes; |
|
523 bool isObjectRes; |
|
524 bool isDateRes; |
|
525 bool isRegExpRes; |
|
526 bool isArrayRes; |
|
527 bool isErrorRes; |
|
528 |
|
529 QString toStringRes; |
|
530 qsreal toNumberRes; |
|
531 bool toBoolRes; |
|
532 bool toBooleanRes; |
|
533 qsreal toIntegerRes; |
|
534 qint32 toInt32Res; |
|
535 quint32 toUInt32Res; |
|
536 quint16 toUInt16Res; |
|
537 //toVariantRes; |
|
538 //toDateTimeRes; |
|
539 |
|
540 QVector<bool> equalsRes; |
|
541 QVector<bool> strictlyEqualsRes; |
|
542 QVector<bool> lessThanRes; |
|
543 QVector<bool> instanceOfRes; |
|
544 |
|
545 QString castStringRes; |
|
546 qsreal castSRealRes; |
|
547 bool castBoolRes; |
|
548 qint32 castInt32Res; |
|
549 quint32 castUInt32Res; |
|
550 quint16 castUInt16Res; |
|
551 |
|
552 QString dataTag; |
|
553 in >> dataTag; |
|
554 in >> isValidRes; |
|
555 in >> isBoolRes; |
|
556 in >> isBooleanRes; |
|
557 in >> isNumberRes; |
|
558 in >> isFunctionRes; |
|
559 in >> isNullRes; |
|
560 in >> isStringRes; |
|
561 in >> isUndefinedRes; |
|
562 in >> isVariantRes; |
|
563 in >> isQObjectRes; |
|
564 in >> isQMetaObjectRes; |
|
565 in >> isObjectRes; |
|
566 in >> isDateRes; |
|
567 in >> isRegExpRes; |
|
568 in >> isArrayRes; |
|
569 in >> isErrorRes; |
|
570 |
|
571 if (isValidRes) isValidList.append(dataTag); |
|
572 if (isBoolRes) isBoolList.append(dataTag); |
|
573 if (isBooleanRes) isBooleanList.append(dataTag); |
|
574 if (isNumberRes) isNumberList.append(dataTag); |
|
575 if (isFunctionRes) isFunctionList.append(dataTag); |
|
576 if (isNullRes) isNullList.append(dataTag); |
|
577 if (isStringRes) isStringList.append(dataTag); |
|
578 if (isUndefinedRes) isUndefinedList.append(dataTag); |
|
579 if (isVariantRes) isVariantList.append(dataTag); |
|
580 if (isQObjectRes) isQObjectList.append(dataTag); |
|
581 if (isQMetaObjectRes) isQMetaObjectList.append(dataTag); |
|
582 if (isObjectRes) isObjectList.append(dataTag); |
|
583 if (isDateRes) isDateList.append(dataTag); |
|
584 if (isRegExpRes) isRegExpList.append(dataTag); |
|
585 if (isArrayRes) isArrayList.append(dataTag); |
|
586 if (isErrorRes) isErrorList.append(dataTag); |
|
587 |
|
588 in >> toStringRes; |
|
589 in >> toNumberRes; |
|
590 in >> toBoolRes; |
|
591 in >> toBooleanRes; |
|
592 in >> toIntegerRes; |
|
593 in >> toInt32Res; |
|
594 in >> toUInt32Res; |
|
595 in >> toUInt16Res; |
|
596 //in >> toVariantRes; |
|
597 //in >> toDateTimeRes; |
|
598 |
|
599 toStringList.append(QPair<QString, QString>(dataTag, toStringRes)); |
|
600 toNumberList.append(QPair<QString, qsreal>(dataTag, toNumberRes)); |
|
601 toBoolList.append(QPair<QString, bool>(dataTag, toBoolRes)); |
|
602 toBooleanList.append(QPair<QString, bool>(dataTag, toBooleanRes)); |
|
603 toIntegerList.append(QPair<QString, qsreal>(dataTag, toIntegerRes)); |
|
604 toInt32List.append(QPair<QString, qint32>(dataTag, toInt32Res)); |
|
605 toUInt32List.append(QPair<QString, quint32>(dataTag, toUInt32Res)); |
|
606 toUInt16List.append(QPair<QString, quint16>(dataTag, toUInt16Res)); |
|
607 |
|
608 in >> equalsRes; |
|
609 in >> strictlyEqualsRes; |
|
610 in >> lessThanRes; |
|
611 in >> instanceOfRes; |
|
612 |
|
613 squashTags(dataTag, equalsRes, equalsList, dataTags); |
|
614 squashTags(dataTag, strictlyEqualsRes, strictlyEqualsList, dataTags); |
|
615 squashTags(dataTag, lessThanRes, lessThanList, dataTags); |
|
616 squashTags(dataTag, instanceOfRes, instanceOfList, dataTags); |
|
617 |
|
618 in >> castStringRes; |
|
619 in >> castSRealRes; |
|
620 in >> castBoolRes; |
|
621 in >> castInt32Res; |
|
622 in >> castUInt32Res; |
|
623 in >> castUInt16Res; |
|
624 |
|
625 castStringList.append(QPair<QString, QString>(dataTag, castStringRes)); |
|
626 castSRealList.append(QPair<QString, qsreal>(dataTag, castSRealRes)); |
|
627 castBoolList.append(QPair<QString, bool>(dataTag, castBoolRes)); |
|
628 castInt32List.append(QPair<QString, qint32>(dataTag, castInt32Res)); |
|
629 castUInt32List.append(QPair<QString, quint32>(dataTag, castUInt32Res)); |
|
630 castUInt16List.append(QPair<QString, quint16>(dataTag, castUInt16Res)); |
|
631 |
|
632 Q_ASSERT(in.status() == in.Ok); |
|
633 } |
|
634 |
|
635 Q_ASSERT(in.atEnd()); |
|
636 |
|
637 // Generate. |
|
638 QStringList result; |
|
639 result.append(generateInitDef(dataTags)); |
|
640 result.append(generateIsXXXDef("isValid", isValidList)); |
|
641 result.append(generateIsXXXDef("isBool", isBoolList)); |
|
642 result.append(generateIsXXXDef("isBoolean", isBooleanList)); |
|
643 result.append(generateIsXXXDef("isNumber", isNumberList)); |
|
644 result.append(generateIsXXXDef("isFunction", isFunctionList)); |
|
645 result.append(generateIsXXXDef("isNull", isNullList)); |
|
646 result.append(generateIsXXXDef("isString", isStringList)); |
|
647 result.append(generateIsXXXDef("isUndefined", isUndefinedList)); |
|
648 result.append(generateIsXXXDef("isVariant", isVariantList)); |
|
649 result.append(generateIsXXXDef("isQObject", isQObjectList)); |
|
650 result.append(generateIsXXXDef("isQMetaObject", isQMetaObjectList)); |
|
651 result.append(generateIsXXXDef("isObject", isObjectList)); |
|
652 result.append(generateIsXXXDef("isDate", isDateList)); |
|
653 result.append(generateIsXXXDef("isRegExp", isRegExpList)); |
|
654 result.append(generateIsXXXDef("isArray", isArrayList)); |
|
655 result.append(generateIsXXXDef("isError", isErrorList)); |
|
656 |
|
657 result.append(generateToXXXDef<QString>("toString", toStringList)); |
|
658 result.append(generateToXXXDef<qsreal>("toNumber", toNumberList)); |
|
659 result.append(generateToXXXDef<bool>("toBool", toBoolList)); |
|
660 result.append(generateToXXXDef<bool>("toBoolean", toBooleanList)); |
|
661 result.append(generateToXXXDef<qsreal>("toInteger", toIntegerList)); |
|
662 result.append(generateToXXXDef<qint32>("toInt32", toInt32List)); |
|
663 result.append(generateToXXXDef<quint32>("toUInt32", toUInt32List)); |
|
664 result.append(generateToXXXDef<quint16>("toUInt16", toUInt16List)); |
|
665 |
|
666 result.append(generateCompareDef("equals", equalsList)); |
|
667 result.append(generateCompareDef("strictlyEquals", strictlyEqualsList)); |
|
668 result.append(generateCompareDef("lessThan", lessThanList)); |
|
669 result.append(generateCompareDef("instanceOf", instanceOfList)); |
|
670 |
|
671 result.append(generateCastDef(castStringList)); |
|
672 result.append(generateCastDef(castSRealList)); |
|
673 result.append(generateCastDef(castBoolList)); |
|
674 result.append(generateCastDef(castInt32List)); |
|
675 result.append(generateCastDef(castUInt32List)); |
|
676 result.append(generateCastDef(castUInt16List)); |
|
677 |
|
678 return result.join("\n"); |
|
679 } |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |