1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
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
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
43 #include <private/qdeclarativecompiler_p.h>
46 // In Symbian OS test data is located in applications private dir
50 class tst_qdeclarativeinstruction : public QObject
54 tst_qdeclarativeinstruction() {}
60 static QStringList messages;
61 static void msgHandler(QtMsgType, const char *msg)
63 messages << QLatin1String(msg);
66 void tst_qdeclarativeinstruction::dump()
68 QDeclarativeCompiledData *data = new QDeclarativeCompiledData(0);
70 QDeclarativeInstruction i;
72 i.type = QDeclarativeInstruction::Init;
73 i.init.bindingsSize = 0;
74 i.init.parserStatusSize = 3;
75 i.init.contextCache = -1;
76 i.init.compiledBinding = -1;
81 QDeclarativeCompiledData::TypeReference ref;
82 ref.className = "Test";
85 QDeclarativeInstruction i;
87 i.type = QDeclarativeInstruction::CreateObject;
90 i.create.bindingBits = -1;
96 data->primitives << "testId";
98 QDeclarativeInstruction i;
100 i.type = QDeclarativeInstruction::SetId;
101 i.setId.value = data->primitives.count() - 1;
107 QDeclarativeInstruction i;
109 i.type = QDeclarativeInstruction::SetDefault;
114 QDeclarativeInstruction i;
116 i.type = QDeclarativeInstruction::CreateComponent;
117 i.createComponent.count = 3;
118 i.createComponent.column = 4;
119 i.createComponent.endLine = 14;
120 i.createComponent.metaObject = 0;
126 QDeclarativeInstruction i;
128 i.type = QDeclarativeInstruction::StoreMetaObject;
129 i.storeMeta.data = 3;
130 i.storeMeta.aliasData = 6;
131 i.storeMeta.propertyCache = 7;
137 QDeclarativeInstruction i;
139 i.type = QDeclarativeInstruction::StoreFloat;
140 i.storeFloat.propertyIndex = 3;
141 i.storeFloat.value = 11.3;
146 QDeclarativeInstruction i;
148 i.type = QDeclarativeInstruction::StoreDouble;
149 i.storeDouble.propertyIndex = 4;
150 i.storeDouble.value = 14.8;
155 QDeclarativeInstruction i;
157 i.type = QDeclarativeInstruction::StoreInteger;
158 i.storeInteger.propertyIndex = 5;
159 i.storeInteger.value = 9;
164 QDeclarativeInstruction i;
166 i.type = QDeclarativeInstruction::StoreBool;
167 i.storeBool.propertyIndex = 6;
168 i.storeBool.value = true;
174 data->primitives << "Test String";
175 QDeclarativeInstruction i;
177 i.type = QDeclarativeInstruction::StoreString;
178 i.storeString.propertyIndex = 7;
179 i.storeString.value = data->primitives.count() - 1;
184 data->urls << QUrl("http://www.nokia.com");
185 QDeclarativeInstruction i;
187 i.type = QDeclarativeInstruction::StoreUrl;
188 i.storeUrl.propertyIndex = 8;
189 i.storeUrl.value = data->urls.count() - 1;
194 QDeclarativeInstruction i;
196 i.type = QDeclarativeInstruction::StoreColor;
197 i.storeColor.propertyIndex = 9;
198 i.storeColor.value = 0xFF00FF00;
203 QDeclarativeInstruction i;
205 i.type = QDeclarativeInstruction::StoreDate;
206 i.storeDate.propertyIndex = 10;
207 i.storeDate.value = 9;
212 QDeclarativeInstruction i;
214 i.type = QDeclarativeInstruction::StoreTime;
215 i.storeTime.propertyIndex = 11;
216 i.storeTime.valueIndex = 33;
221 QDeclarativeInstruction i;
223 i.type = QDeclarativeInstruction::StoreDateTime;
224 i.storeDateTime.propertyIndex = 12;
225 i.storeDateTime.valueIndex = 44;
230 QDeclarativeInstruction i;
232 i.type = QDeclarativeInstruction::StorePoint;
233 i.storeRealPair.propertyIndex = 13;
234 i.storeRealPair.valueIndex = 3;
239 QDeclarativeInstruction i;
241 i.type = QDeclarativeInstruction::StorePointF;
242 i.storeRealPair.propertyIndex = 14;
243 i.storeRealPair.valueIndex = 9;
248 QDeclarativeInstruction i;
250 i.type = QDeclarativeInstruction::StoreSize;
251 i.storeRealPair.propertyIndex = 15;
252 i.storeRealPair.valueIndex = 8;
257 QDeclarativeInstruction i;
259 i.type = QDeclarativeInstruction::StoreSizeF;
260 i.storeRealPair.propertyIndex = 16;
261 i.storeRealPair.valueIndex = 99;
266 QDeclarativeInstruction i;
268 i.type = QDeclarativeInstruction::StoreRect;
269 i.storeRect.propertyIndex = 17;
270 i.storeRect.valueIndex = 2;
275 QDeclarativeInstruction i;
277 i.type = QDeclarativeInstruction::StoreRectF;
278 i.storeRect.propertyIndex = 18;
279 i.storeRect.valueIndex = 19;
284 QDeclarativeInstruction i;
286 i.type = QDeclarativeInstruction::StoreVector3D;
287 i.storeVector3D.propertyIndex = 19;
288 i.storeVector3D.valueIndex = 9;
293 data->primitives << "color(1, 1, 1, 1)";
294 QDeclarativeInstruction i;
296 i.type = QDeclarativeInstruction::StoreVariant;
297 i.storeString.propertyIndex = 20;
298 i.storeString.value = data->primitives.count() - 1;
304 QDeclarativeInstruction i;
306 i.type = QDeclarativeInstruction::StoreObject;
307 i.storeObject.propertyIndex = 21;
312 QDeclarativeInstruction i;
314 i.type = QDeclarativeInstruction::StoreVariantObject;
315 i.storeObject.propertyIndex = 22;
320 QDeclarativeInstruction i;
322 i.type = QDeclarativeInstruction::StoreInterface;
323 i.storeObject.propertyIndex = 23;
328 data->primitives << "console.log(1921)";
330 QDeclarativeInstruction i;
332 i.type = QDeclarativeInstruction::StoreSignal;
333 i.storeSignal.signalIndex = 2;
334 i.storeSignal.value = data->primitives.count() - 1;
339 QDeclarativeInstruction i;
341 i.type = QDeclarativeInstruction::StoreScriptString;
342 i.storeScriptString.propertyIndex = 24;
343 i.storeScriptString.value = 3;
344 i.storeScriptString.scope = 1;
349 data->datas << "mySignal";
351 QDeclarativeInstruction i;
353 i.type = QDeclarativeInstruction::AssignSignalObject;
354 i.assignSignalObject.signal = 0;
359 QDeclarativeInstruction i;
361 i.type = QDeclarativeInstruction::AssignCustomType;
362 i.assignCustomType.propertyIndex = 25;
363 i.assignCustomType.valueIndex = 4;
368 QDeclarativeInstruction i;
370 i.type = QDeclarativeInstruction::StoreBinding;
371 i.assignBinding.property = 26;
372 i.assignBinding.value = 3;
373 i.assignBinding.context = 2;
374 i.assignBinding.owner = 0;
379 QDeclarativeInstruction i;
381 i.type = QDeclarativeInstruction::StoreCompiledBinding;
382 i.assignBinding.property = 27;
383 i.assignBinding.value = 2;
384 i.assignBinding.context = 4;
385 i.assignBinding.owner = 0;
390 QDeclarativeInstruction i;
392 i.type = QDeclarativeInstruction::StoreValueSource;
393 i.assignValueSource.property = 29;
394 i.assignValueSource.owner = 1;
395 i.assignValueSource.castValue = 4;
400 QDeclarativeInstruction i;
402 i.type = QDeclarativeInstruction::StoreValueInterceptor;
403 i.assignValueInterceptor.property = 30;
404 i.assignValueInterceptor.owner = 2;
405 i.assignValueInterceptor.castValue = -4;
410 QDeclarativeInstruction i;
412 i.type = QDeclarativeInstruction::BeginObject;
413 i.begin.castValue = 4;
418 QDeclarativeInstruction i;
420 i.type = QDeclarativeInstruction::StoreObjectQList;
425 QDeclarativeInstruction i;
427 i.type = QDeclarativeInstruction::AssignObjectList;
432 QDeclarativeInstruction i;
434 i.type = QDeclarativeInstruction::FetchAttached;
435 i.fetchAttached.id = 23;
440 QDeclarativeInstruction i;
442 i.type = QDeclarativeInstruction::FetchQList;
443 i.fetch.property = 32;
448 QDeclarativeInstruction i;
450 i.type = QDeclarativeInstruction::FetchObject;
451 i.fetch.property = 33;
456 QDeclarativeInstruction i;
458 i.type = QDeclarativeInstruction::FetchValueType;
459 i.fetchValue.property = 34;
460 i.fetchValue.type = 6;
461 i.fetchValue.bindingSkipList = 7;
466 QDeclarativeInstruction i;
468 i.type = QDeclarativeInstruction::PopFetchedObject;
473 QDeclarativeInstruction i;
475 i.type = QDeclarativeInstruction::PopQList;
480 QDeclarativeInstruction i;
482 i.type = QDeclarativeInstruction::PopValueType;
483 i.fetchValue.property = 35;
484 i.fetchValue.type = 8;
489 QDeclarativeInstruction i;
491 i.type = QDeclarativeInstruction::Defer;
492 i.defer.deferCount = 7;
497 QDeclarativeInstruction i;
499 i.type = QDeclarativeInstruction::Defer;
500 i.defer.deferCount = 7;
505 QDeclarativeInstruction i;
507 i.type = QDeclarativeInstruction::StoreImportedScript;
508 i.storeScript.value = 2;
513 QDeclarativeInstruction i;
515 i.type = (QDeclarativeInstruction::Type)(1234); // Non-existent
520 QDeclarativeInstruction i;
522 i.type = QDeclarativeInstruction::StoreVariantInteger;
523 i.storeInteger.value = 11;
524 i.storeInteger.propertyIndex = 32;
529 QDeclarativeInstruction i;
531 i.type = QDeclarativeInstruction::StoreVariantDouble;
532 i.storeDouble.value = 33.7;
533 i.storeDouble.propertyIndex = 19;
539 << "Index\tLine\tOperation\t\tData1\tData2\tData3\tComments"
540 << "-------------------------------------------------------------------------------"
541 << "0\t\t0\tINIT\t\t\t0\t3\t-1\t-1"
542 << "1\t\t1\tCREATE\t\t\t0\t-1\t\t\"Test\""
543 << "2\t\t2\tSETID\t\t\t0\t\t\t\"testId\""
544 << "3\t\t3\tSET_DEFAULT"
545 << "4\t\t4\tCREATE_COMPONENT\t3"
546 << "5\t\t5\tSTORE_META\t\t3"
547 << "6\t\t6\tSTORE_FLOAT\t\t3\t11.3"
548 << "7\t\t7\tSTORE_DOUBLE\t\t4\t14.8"
549 << "8\t\t8\tSTORE_INTEGER\t\t5\t9"
550 << "9\t\t9\tSTORE_BOOL\t\t6\ttrue"
551 << "10\t\t10\tSTORE_STRING\t\t7\t1\t\t\"Test String\""
552 << "11\t\t11\tSTORE_URL\t\t8\t0\t\tQUrl(\"http://www.nokia.com\") "
553 << "12\t\t12\tSTORE_COLOR\t\t9\t\t\t\"ff00ff00\""
554 << "13\t\t13\tSTORE_DATE\t\t10\t9"
555 << "14\t\t14\tSTORE_TIME\t\t11\t33"
556 << "15\t\t15\tSTORE_DATETIME\t\t12\t44"
557 << "16\t\t16\tSTORE_POINT\t\t13\t3"
558 << "17\t\t17\tSTORE_POINTF\t\t14\t9"
559 << "18\t\t18\tSTORE_SIZE\t\t15\t8"
560 << "19\t\t19\tSTORE_SIZEF\t\t16\t99"
561 << "20\t\t20\tSTORE_RECT\t\t17\t2"
562 << "21\t\t21\tSTORE_RECTF\t\t18\t19"
563 << "22\t\t22\tSTORE_VECTOR3D\t\t19\t9"
564 << "23\t\t23\tSTORE_VARIANT\t\t20\t2\t\t\"color(1, 1, 1, 1)\""
565 << "24\t\t24\tSTORE_OBJECT\t\t21"
566 << "25\t\t25\tSTORE_VARIANT_OBJECT\t22"
567 << "26\t\t26\tSTORE_INTERFACE\t\t23"
568 << "27\t\t27\tSTORE_SIGNAL\t\t2\t3\t\t\"console.log(1921)\""
569 << "28\t\t29\tSTORE_SCRIPT_STRING\t24\t3\t1"
570 << "29\t\t30\tASSIGN_SIGNAL_OBJECT\t0\t\t\t\"mySignal\""
571 << "30\t\t31\tASSIGN_CUSTOMTYPE\t25\t4"
572 << "31\t\t32\tSTORE_BINDING\t26\t3\t2"
573 << "32\t\t33\tSTORE_COMPILED_BINDING\t27\t2\t4"
574 << "33\t\t34\tSTORE_VALUE_SOURCE\t29\t4"
575 << "34\t\t35\tSTORE_VALUE_INTERCEPTOR\t30\t-4"
576 << "35\t\t36\tBEGIN\t\t\t4"
577 << "36\t\t38\tSTORE_OBJECT_QLIST"
578 << "37\t\t39\tASSIGN_OBJECT_LIST"
579 << "38\t\t40\tFETCH_ATTACHED\t\t23"
580 << "39\t\t42\tFETCH_QLIST\t\t32"
581 << "40\t\t43\tFETCH\t\t\t33"
582 << "41\t\t44\tFETCH_VALUE\t\t34\t6\t7"
584 << "43\t\t46\tPOP_QLIST"
585 << "44\t\t47\tPOP_VALUE\t\t35\t8"
586 << "45\t\t48\tDEFER\t\t\t7"
587 << "46\t\tNA\tDEFER\t\t\t7"
588 << "47\t\t48\tSTORE_IMPORTED_SCRIPT\t2"
589 << "48\t\t50\tXXX UNKNOWN INSTRUCTION\t1234"
590 << "49\t\t51\tSTORE_VARIANT_INTEGER\t\t32\t11"
591 << "50\t\t52\tSTORE_VARIANT_DOUBLE\t\t19\t33.7"
592 << "-------------------------------------------------------------------------------";
594 messages = QStringList();
595 QtMsgHandler old = qInstallMsgHandler(msgHandler);
596 data->dumpInstructions();
597 qInstallMsgHandler(old);
599 QCOMPARE(messages.count(), expect.count());
600 for (int ii = 0; ii < messages.count(); ++ii) {
601 QCOMPARE(messages.at(ii), expect.at(ii));
607 QTEST_MAIN(tst_qdeclarativeinstruction)
609 #include "tst_qdeclarativeinstruction.moc"