2011-04-27 12:13:26 +00:00
/****************************************************************************
* *
* * Copyright ( C ) 2011 Nokia Corporation and / or its subsidiary ( - ies ) .
* * All rights reserved .
* * Contact : Nokia Corporation ( qt - info @ nokia . com )
* *
* * This file is part of the test suite of the Qt Toolkit .
* *
* * $ QT_BEGIN_LICENSE : LGPL $
* * GNU Lesser General Public License Usage
2011-07-07 12:52:03 +00:00
* * This file may be used under the terms of the GNU Lesser General Public
* * License version 2.1 as published by the Free Software Foundation and
* * appearing in the file LICENSE . LGPL included in the packaging of this
* * file . Please review the following information to ensure the GNU Lesser
* * General Public License version 2.1 requirements will be met :
* * http : //www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
2011-04-27 12:13:26 +00:00
* *
* * In addition , as a special exception , Nokia gives you certain additional
2011-07-07 12:52:03 +00:00
* * rights . These rights are described in the Nokia Qt LGPL Exception
2011-04-27 12:13:26 +00:00
* * version 1.1 , included in the file LGPL_EXCEPTION . txt in this package .
* *
2011-07-07 12:52:03 +00:00
* * GNU General Public License Usage
* * Alternatively , this file may be used under the terms of the GNU General
* * Public License version 3.0 as published by the Free Software Foundation
* * and appearing in the file LICENSE . GPL included in the packaging of this
* * file . Please review the following information to ensure the GNU General
* * Public License version 3.0 requirements will be met :
* * http : //www.gnu.org/copyleft/gpl.html.
* *
* * Other Usage
* * Alternatively , this file may be used in accordance with the terms and
* * conditions contained in a signed written agreement between you and Nokia .
2011-04-27 12:13:26 +00:00
* *
* *
* *
* *
* *
* * $ QT_END_LICENSE $
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <qtest.h>
# include <QSignalSpy>
2011-08-17 07:46:54 +00:00
2011-04-27 12:13:26 +00:00
# include <QtDeclarative/qdeclarativeengine.h>
# include <QtDeclarative/qdeclarativecomponent.h>
2011-10-07 06:20:39 +00:00
# include <QtDeclarative/qdeclarativeincubator.h>
2011-10-14 08:51:42 +00:00
# include <private/qquickloader_p.h>
2011-04-27 12:13:26 +00:00
# include "testhttpserver.h"
2011-10-12 03:46:02 +00:00
# include "../shared/util.h"
2011-04-27 12:13:26 +00:00
# define SERVER_PORT 14450
inline QUrl TEST_FILE ( const QString & filename )
{
2011-10-12 03:46:02 +00:00
return QUrl : : fromLocalFile ( TESTDATA ( filename ) ) ;
2011-04-27 12:13:26 +00:00
}
2011-10-07 06:20:39 +00:00
class PeriodicIncubationController : public QObject ,
public QDeclarativeIncubationController
{
public :
PeriodicIncubationController ( ) {
startTimer ( 16 ) ;
}
protected :
virtual void timerEvent ( QTimerEvent * ) {
incubateFor ( 15 ) ;
}
} ;
2011-10-14 08:51:42 +00:00
class tst_QQuickLoader : public QObject
2011-04-27 12:13:26 +00:00
{
Q_OBJECT
public :
2011-10-14 08:51:42 +00:00
tst_QQuickLoader ( ) ;
2011-04-27 12:13:26 +00:00
private slots :
void sourceOrComponent ( ) ;
void sourceOrComponent_data ( ) ;
void clear ( ) ;
void urlToComponent ( ) ;
void componentToUrl ( ) ;
void anchoredLoader ( ) ;
void sizeLoaderToItem ( ) ;
void sizeItemToLoader ( ) ;
void noResize ( ) ;
void networkRequestUrl ( ) ;
void failNetworkRequest ( ) ;
// void networkComponent();
2011-08-17 07:46:54 +00:00
void active ( ) ;
void initialPropertyValues_data ( ) ;
void initialPropertyValues ( ) ;
void initialPropertyValuesBinding ( ) ;
void initialPropertyValuesError_data ( ) ;
void initialPropertyValuesError ( ) ;
2011-04-27 12:13:26 +00:00
void deleteComponentCrash ( ) ;
void nonItem ( ) ;
void vmeErrors ( ) ;
void creationContext ( ) ;
void QTBUG_16928 ( ) ;
void implicitSize ( ) ;
void QTBUG_17114 ( ) ;
2011-10-07 06:20:39 +00:00
void asynchronous_data ( ) ;
void asynchronous ( ) ;
void asynchronous_clear ( ) ;
2011-04-27 12:13:26 +00:00
2011-11-14 03:00:31 +00:00
void parented ( ) ;
2011-04-27 12:13:26 +00:00
private :
QDeclarativeEngine engine ;
} ;
2011-10-14 08:51:42 +00:00
tst_QQuickLoader : : tst_QQuickLoader ( )
2011-04-27 12:13:26 +00:00
{
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : sourceOrComponent ( )
2011-04-27 12:13:26 +00:00
{
2011-07-29 04:41:16 +00:00
QFETCH ( QString , sourceOrComponent ) ;
2011-04-27 12:13:26 +00:00
QFETCH ( QString , sourceDefinition ) ;
QFETCH ( QUrl , sourceUrl ) ;
QFETCH ( QString , errorString ) ;
bool error = ! errorString . isEmpty ( ) ;
if ( error )
QTest : : ignoreMessage ( QtWarningMsg , errorString . toUtf8 ( ) . constData ( ) ) ;
QDeclarativeComponent component ( & engine ) ;
component . setData ( QByteArray (
" import QtQuick 2.0 \n "
" Loader { \n "
" property int onItemChangedCount: 0 \n "
" property int onSourceChangedCount: 0 \n "
2011-07-29 04:41:16 +00:00
" property int onSourceComponentChangedCount: 0 \n "
2011-04-27 12:13:26 +00:00
" property int onStatusChangedCount: 0 \n "
" property int onProgressChangedCount: 0 \n "
" property int onLoadedCount: 0 \n " )
+ sourceDefinition . toUtf8 ( )
+ QByteArray (
" onItemChanged: onItemChangedCount += 1 \n "
" onSourceChanged: onSourceChangedCount += 1 \n "
2011-07-29 04:41:16 +00:00
" onSourceComponentChanged: onSourceComponentChangedCount += 1 \n "
2011-04-27 12:13:26 +00:00
" onStatusChanged: onStatusChangedCount += 1 \n "
" onProgressChanged: onProgressChangedCount += 1 \n "
" onLoaded: onLoadedCount += 1 \n "
" } " )
, TEST_FILE ( " " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ! = 0 ) ;
QCOMPARE ( loader - > item ( ) = = 0 , error ) ;
QCOMPARE ( loader - > source ( ) , sourceUrl ) ;
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , error ? QQuickLoader : : Error : QQuickLoader : : Ready ) ;
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , error ? 0 : 1 ) ;
2011-04-27 12:13:26 +00:00
if ( ! error ) {
2011-10-06 04:37:09 +00:00
bool sourceComponentIsChildOfLoader = false ;
for ( int ii = 0 ; ii < loader - > children ( ) . size ( ) ; + + ii ) {
QDeclarativeComponent * c = qobject_cast < QDeclarativeComponent * > ( loader - > children ( ) . at ( ii ) ) ;
if ( c & & c = = loader - > sourceComponent ( ) ) {
sourceComponentIsChildOfLoader = true ;
}
}
QVERIFY ( sourceComponentIsChildOfLoader ) ;
2011-04-27 12:13:26 +00:00
}
2011-07-29 04:41:16 +00:00
if ( sourceOrComponent = = " component " ) {
QCOMPARE ( loader - > property ( " onSourceComponentChangedCount " ) . toInt ( ) , 1 ) ;
QCOMPARE ( loader - > property ( " onSourceChangedCount " ) . toInt ( ) , 0 ) ;
} else {
QCOMPARE ( loader - > property ( " onSourceComponentChangedCount " ) . toInt ( ) , 0 ) ;
QCOMPARE ( loader - > property ( " onSourceChangedCount " ) . toInt ( ) , 1 ) ;
}
2011-04-27 12:13:26 +00:00
QCOMPARE ( loader - > property ( " onStatusChangedCount " ) . toInt ( ) , 1 ) ;
QCOMPARE ( loader - > property ( " onProgressChangedCount " ) . toInt ( ) , 1 ) ;
QCOMPARE ( loader - > property ( " onItemChangedCount " ) . toInt ( ) , error ? 0 : 1 ) ;
QCOMPARE ( loader - > property ( " onLoadedCount " ) . toInt ( ) , error ? 0 : 1 ) ;
delete loader ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : sourceOrComponent_data ( )
2011-04-27 12:13:26 +00:00
{
2011-07-29 04:41:16 +00:00
QTest : : addColumn < QString > ( " sourceOrComponent " ) ;
2011-04-27 12:13:26 +00:00
QTest : : addColumn < QString > ( " sourceDefinition " ) ;
QTest : : addColumn < QUrl > ( " sourceUrl " ) ;
QTest : : addColumn < QString > ( " errorString " ) ;
2011-10-12 03:46:02 +00:00
QTest : : newRow ( " source " ) < < " source " < < " source: 'Rect120x60.qml' \n " < < QUrl : : fromLocalFile ( TESTDATA ( " Rect120x60.qml " ) ) < < " " ;
2011-07-29 04:41:16 +00:00
QTest : : newRow ( " sourceComponent " ) < < " component " < < " Component { id: comp; Rectangle { width: 100; height: 50 } } \n sourceComponent: comp \n " < < QUrl ( ) < < " " ;
2011-10-12 03:46:02 +00:00
QTest : : newRow ( " invalid source " ) < < " source " < < " source: 'IDontExist.qml' \n " < < QUrl : : fromLocalFile ( TESTDATA ( " IDontExist.qml " ) )
< < QString ( QUrl : : fromLocalFile ( TESTDATA ( " IDontExist.qml " ) ) . toString ( ) + " : File not found " ) ;
2011-04-27 12:13:26 +00:00
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : clear ( )
2011-04-27 12:13:26 +00:00
{
{
QDeclarativeComponent component ( & engine ) ;
component . setData ( QByteArray (
" import QtQuick 2.0 \n "
" Loader { id: loader \n "
" source: 'Rect120x60.qml' \n "
" Timer { interval: 200; running: true; onTriggered: loader.source = '' } \n "
" } " )
, TEST_FILE ( " " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ! = 0 ) ;
QVERIFY ( loader - > item ( ) ) ;
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 1 ) ;
2011-04-27 12:13:26 +00:00
QTRY_VERIFY ( loader - > item ( ) = = 0 ) ;
QCOMPARE ( loader - > progress ( ) , 0.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Null ) ;
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 0 ) ;
2011-04-27 12:13:26 +00:00
delete loader ;
}
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " /SetSourceComponent.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * item = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( item ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( item - > QQuickItem : : childItems ( ) . at ( 0 ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ) ;
QVERIFY ( loader - > item ( ) ) ;
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 1 ) ;
2011-04-27 12:13:26 +00:00
loader - > setSourceComponent ( 0 ) ;
QVERIFY ( loader - > item ( ) = = 0 ) ;
QCOMPARE ( loader - > progress ( ) , 0.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Null ) ;
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 0 ) ;
2011-04-27 12:13:26 +00:00
delete item ;
}
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " /SetSourceComponent.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * item = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( item ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( item - > QQuickItem : : childItems ( ) . at ( 0 ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ) ;
QVERIFY ( loader - > item ( ) ) ;
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 1 ) ;
2011-04-27 12:13:26 +00:00
QMetaObject : : invokeMethod ( item , " clear " ) ;
QVERIFY ( loader - > item ( ) = = 0 ) ;
QCOMPARE ( loader - > progress ( ) , 0.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Null ) ;
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 0 ) ;
2011-04-27 12:13:26 +00:00
delete item ;
}
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : urlToComponent ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine ) ;
component . setData ( QByteArray ( " import QtQuick 2.0 \n "
" Loader { \n "
" id: loader \n "
" Component { id: myComp; Rectangle { width: 10; height: 10 } } \n "
" source: \" Rect120x60.qml \" \n "
" Timer { interval: 100; running: true; onTriggered: loader.sourceComponent = myComp } \n "
" } " )
, TEST_FILE ( " " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QTest : : qWait ( 200 ) ;
QTRY_VERIFY ( loader ! = 0 ) ;
QVERIFY ( loader - > item ( ) ) ;
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 1 ) ;
2011-04-27 12:13:26 +00:00
QCOMPARE ( loader - > width ( ) , 10.0 ) ;
QCOMPARE ( loader - > height ( ) , 10.0 ) ;
delete loader ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : componentToUrl ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " /SetSourceComponent.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * item = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( item ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( item - > QQuickItem : : childItems ( ) . at ( 0 ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ) ;
QVERIFY ( loader - > item ( ) ) ;
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 1 ) ;
2011-04-27 12:13:26 +00:00
loader - > setSource ( TEST_FILE ( " /Rect120x60.qml " ) ) ;
QVERIFY ( loader - > item ( ) ) ;
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 1 ) ;
2011-04-27 12:13:26 +00:00
QCOMPARE ( loader - > width ( ) , 120.0 ) ;
QCOMPARE ( loader - > height ( ) , 60.0 ) ;
delete item ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : anchoredLoader ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " /AnchoredLoader.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * rootItem = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( rootItem ! = 0 ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * loader = rootItem - > findChild < QQuickItem * > ( " loader " ) ;
QQuickItem * sourceElement = rootItem - > findChild < QQuickItem * > ( " sourceElement " ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ! = 0 ) ;
QVERIFY ( sourceElement ! = 0 ) ;
QCOMPARE ( rootItem - > width ( ) , 300.0 ) ;
QCOMPARE ( rootItem - > height ( ) , 200.0 ) ;
QCOMPARE ( loader - > width ( ) , 300.0 ) ;
QCOMPARE ( loader - > height ( ) , 200.0 ) ;
QCOMPARE ( sourceElement - > width ( ) , 300.0 ) ;
QCOMPARE ( sourceElement - > height ( ) , 200.0 ) ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : sizeLoaderToItem ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " /SizeToItem.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ! = 0 ) ;
QCOMPARE ( loader - > width ( ) , 120.0 ) ;
QCOMPARE ( loader - > height ( ) , 60.0 ) ;
// Check resize
2011-10-14 08:51:42 +00:00
QQuickItem * rect = qobject_cast < QQuickItem * > ( loader - > item ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( rect ) ;
rect - > setWidth ( 150 ) ;
rect - > setHeight ( 45 ) ;
QCOMPARE ( loader - > width ( ) , 150.0 ) ;
QCOMPARE ( loader - > height ( ) , 45.0 ) ;
// Check explicit width
loader - > setWidth ( 200.0 ) ;
QCOMPARE ( loader - > width ( ) , 200.0 ) ;
QCOMPARE ( rect - > width ( ) , 200.0 ) ;
rect - > setWidth ( 100.0 ) ; // when rect changes ...
QCOMPARE ( rect - > width ( ) , 100.0 ) ; // ... it changes
QCOMPARE ( loader - > width ( ) , 200.0 ) ; // ... but loader stays the same
// Check explicit height
loader - > setHeight ( 200.0 ) ;
QCOMPARE ( loader - > height ( ) , 200.0 ) ;
QCOMPARE ( rect - > height ( ) , 200.0 ) ;
rect - > setHeight ( 100.0 ) ; // when rect changes ...
QCOMPARE ( rect - > height ( ) , 100.0 ) ; // ... it changes
QCOMPARE ( loader - > height ( ) , 200.0 ) ; // ... but loader stays the same
// Switch mode
loader - > setWidth ( 180 ) ;
loader - > setHeight ( 30 ) ;
QCOMPARE ( rect - > width ( ) , 180.0 ) ;
QCOMPARE ( rect - > height ( ) , 30.0 ) ;
delete loader ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : sizeItemToLoader ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " /SizeToLoader.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ! = 0 ) ;
QCOMPARE ( loader - > width ( ) , 200.0 ) ;
QCOMPARE ( loader - > height ( ) , 80.0 ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * rect = qobject_cast < QQuickItem * > ( loader - > item ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( rect ) ;
QCOMPARE ( rect - > width ( ) , 200.0 ) ;
QCOMPARE ( rect - > height ( ) , 80.0 ) ;
// Check resize
loader - > setWidth ( 180 ) ;
loader - > setHeight ( 30 ) ;
QCOMPARE ( rect - > width ( ) , 180.0 ) ;
QCOMPARE ( rect - > height ( ) , 30.0 ) ;
// Switch mode
loader - > resetWidth ( ) ; // reset explicit size
loader - > resetHeight ( ) ;
rect - > setWidth ( 160 ) ;
rect - > setHeight ( 45 ) ;
QCOMPARE ( loader - > width ( ) , 160.0 ) ;
QCOMPARE ( loader - > height ( ) , 45.0 ) ;
delete loader ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : noResize ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " /NoResize.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * item = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( item ! = 0 ) ;
QCOMPARE ( item - > width ( ) , 200.0 ) ;
QCOMPARE ( item - > height ( ) , 80.0 ) ;
delete item ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : networkRequestUrl ( )
2011-04-27 12:13:26 +00:00
{
TestHTTPServer server ( SERVER_PORT ) ;
QVERIFY ( server . isValid ( ) ) ;
2011-10-12 03:46:02 +00:00
server . serveDirectory ( TESTDATA ( " " ) ) ;
2011-04-27 12:13:26 +00:00
QDeclarativeComponent component ( & engine ) ;
2011-10-12 03:46:02 +00:00
component . setData ( QByteArray ( " import QtQuick 2.0 \n Loader { property int signalCount : 0; source: \" http://127.0.0.1:14450/Rect120x60.qml \" ; onLoaded: signalCount += 1 } " ) , QUrl : : fromLocalFile ( TESTDATA ( " ../dummy.qml " ) ) ) ;
2011-04-27 12:13:26 +00:00
if ( component . isError ( ) )
qDebug ( ) < < component . errors ( ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ! = 0 ) ;
2011-10-14 08:51:42 +00:00
QTRY_VERIFY ( loader - > status ( ) = = QQuickLoader : : Ready ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader - > item ( ) ) ;
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
QCOMPARE ( loader - > property ( " signalCount " ) . toInt ( ) , 1 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 1 ) ;
2011-04-27 12:13:26 +00:00
delete loader ;
}
/* XXX Component waits until all dependencies are loaded. Is this actually possible?
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : networkComponent ( )
2011-04-27 12:13:26 +00:00
{
TestHTTPServer server ( SERVER_PORT ) ;
QVERIFY ( server . isValid ( ) ) ;
server . serveDirectory ( " slowdata " , TestHTTPServer : : Delay ) ;
QDeclarativeComponent component ( & engine ) ;
component . setData ( QByteArray (
" import QtQuick 2.0 \n "
" import \" http://127.0.0.1:14450/ \" as NW \n "
" Item { \n "
" Component { id: comp; NW.SlowRect {} } \n "
" Loader { sourceComponent: comp } } " )
, TEST_FILE ( " " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * item = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( item ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( item - > QQuickItem : : children ( ) . at ( 1 ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ) ;
2011-10-14 08:51:42 +00:00
QTRY_VERIFY ( loader - > status ( ) = = QQuickLoader : : Ready ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader - > item ( ) ) ;
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Ready ) ;
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > children ( ) . count ( ) , 1 ) ;
2011-04-27 12:13:26 +00:00
delete loader ;
}
*/
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : failNetworkRequest ( )
2011-04-27 12:13:26 +00:00
{
TestHTTPServer server ( SERVER_PORT ) ;
QVERIFY ( server . isValid ( ) ) ;
2011-10-12 03:46:02 +00:00
server . serveDirectory ( TESTDATA ( " " ) ) ;
2011-04-27 12:13:26 +00:00
QTest : : ignoreMessage ( QtWarningMsg , " http://127.0.0.1:14450/IDontExist.qml: File not found " ) ;
QDeclarativeComponent component ( & engine ) ;
component . setData ( QByteArray ( " import QtQuick 2.0 \n Loader { property int did_load: 123; source: \" http://127.0.0.1:14450/IDontExist.qml \" ; onLoaded: did_load=456 } " ) , QUrl : : fromLocalFile ( " http://127.0.0.1:14450/dummy.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ! = 0 ) ;
2011-10-14 08:51:42 +00:00
QTRY_VERIFY ( loader - > status ( ) = = QQuickLoader : : Error ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader - > item ( ) = = 0 ) ;
QCOMPARE ( loader - > progress ( ) , 0.0 ) ;
QCOMPARE ( loader - > property ( " did_load " ) . toInt ( ) , 123 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 0 ) ;
2011-04-27 12:13:26 +00:00
delete loader ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : active ( )
2011-08-17 07:46:54 +00:00
{
// check that the item isn't instantiated until active is set to true
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " active.1.qml " ) ) ;
QObject * object = component . create ( ) ;
QVERIFY ( object ! = 0 ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = object - > findChild < QQuickLoader * > ( " loader " ) ;
2011-08-17 07:46:54 +00:00
QVERIFY ( loader - > active ( ) = = false ) ; // set manually to false
QVERIFY ( loader - > item ( ) = = 0 ) ;
QMetaObject : : invokeMethod ( object , " doSetSourceComponent " ) ;
QVERIFY ( loader - > item ( ) = = 0 ) ;
QMetaObject : : invokeMethod ( object , " doSetSource " ) ;
QVERIFY ( loader - > item ( ) = = 0 ) ;
QMetaObject : : invokeMethod ( object , " doSetActive " ) ;
QVERIFY ( loader - > item ( ) ! = 0 ) ;
delete object ;
}
// check that the status is Null if active is set to false
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " active.2.qml " ) ) ;
QObject * object = component . create ( ) ;
QVERIFY ( object ! = 0 ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = object - > findChild < QQuickLoader * > ( " loader " ) ;
2011-08-17 07:46:54 +00:00
QVERIFY ( loader - > active ( ) = = true ) ; // active is true by default
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Ready ) ;
2011-08-17 07:46:54 +00:00
int currStatusChangedCount = loader - > property ( " statusChangedCount " ) . toInt ( ) ;
QMetaObject : : invokeMethod ( object , " doSetInactive " ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Null ) ;
2011-08-17 07:46:54 +00:00
QCOMPARE ( loader - > property ( " statusChangedCount " ) . toInt ( ) , ( currStatusChangedCount + 1 ) ) ;
delete object ;
}
// check that the source is not cleared if active is set to false
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " active.3.qml " ) ) ;
QObject * object = component . create ( ) ;
QVERIFY ( object ! = 0 ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = object - > findChild < QQuickLoader * > ( " loader " ) ;
2011-08-17 07:46:54 +00:00
QVERIFY ( loader - > active ( ) = = true ) ; // active is true by default
QVERIFY ( ! loader - > source ( ) . isEmpty ( ) ) ;
int currSourceChangedCount = loader - > property ( " sourceChangedCount " ) . toInt ( ) ;
QMetaObject : : invokeMethod ( object , " doSetInactive " ) ;
QVERIFY ( ! loader - > source ( ) . isEmpty ( ) ) ;
QCOMPARE ( loader - > property ( " sourceChangedCount " ) . toInt ( ) , currSourceChangedCount ) ;
delete object ;
}
// check that the sourceComponent is not cleared if active is set to false
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " active.4.qml " ) ) ;
QObject * object = component . create ( ) ;
QVERIFY ( object ! = 0 ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = object - > findChild < QQuickLoader * > ( " loader " ) ;
2011-08-17 07:46:54 +00:00
QVERIFY ( loader - > active ( ) = = true ) ; // active is true by default
QVERIFY ( loader - > sourceComponent ( ) ! = 0 ) ;
int currSourceComponentChangedCount = loader - > property ( " sourceComponentChangedCount " ) . toInt ( ) ;
QMetaObject : : invokeMethod ( object , " doSetInactive " ) ;
QVERIFY ( loader - > sourceComponent ( ) ! = 0 ) ;
QCOMPARE ( loader - > property ( " sourceComponentChangedCount " ) . toInt ( ) , currSourceComponentChangedCount ) ;
delete object ;
}
// check that the item is released if active is set to false
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " active.5.qml " ) ) ;
QObject * object = component . create ( ) ;
QVERIFY ( object ! = 0 ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = object - > findChild < QQuickLoader * > ( " loader " ) ;
2011-08-17 07:46:54 +00:00
QVERIFY ( loader - > active ( ) = = true ) ; // active is true by default
QVERIFY ( loader - > item ( ) ! = 0 ) ;
int currItemChangedCount = loader - > property ( " itemChangedCount " ) . toInt ( ) ;
QMetaObject : : invokeMethod ( object , " doSetInactive " ) ;
QVERIFY ( loader - > item ( ) = = 0 ) ;
QCOMPARE ( loader - > property ( " itemChangedCount " ) . toInt ( ) , ( currItemChangedCount + 1 ) ) ;
delete object ;
}
// check that the activeChanged signal is emitted correctly
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " active.6.qml " ) ) ;
QObject * object = component . create ( ) ;
QVERIFY ( object ! = 0 ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = object - > findChild < QQuickLoader * > ( " loader " ) ;
2011-08-17 07:46:54 +00:00
QVERIFY ( loader - > active ( ) = = true ) ; // active is true by default
loader - > setActive ( true ) ; // no effect
QCOMPARE ( loader - > property ( " activeChangedCount " ) . toInt ( ) , 0 ) ;
loader - > setActive ( false ) ; // change signal should be emitted
QCOMPARE ( loader - > property ( " activeChangedCount " ) . toInt ( ) , 1 ) ;
loader - > setActive ( false ) ; // no effect
QCOMPARE ( loader - > property ( " activeChangedCount " ) . toInt ( ) , 1 ) ;
loader - > setActive ( true ) ; // change signal should be emitted
QCOMPARE ( loader - > property ( " activeChangedCount " ) . toInt ( ) , 2 ) ;
loader - > setActive ( false ) ; // change signal should be emitted
QCOMPARE ( loader - > property ( " activeChangedCount " ) . toInt ( ) , 3 ) ;
QMetaObject : : invokeMethod ( object , " doSetActive " ) ;
QCOMPARE ( loader - > property ( " activeChangedCount " ) . toInt ( ) , 4 ) ;
QMetaObject : : invokeMethod ( object , " doSetActive " ) ;
QCOMPARE ( loader - > property ( " activeChangedCount " ) . toInt ( ) , 4 ) ;
QMetaObject : : invokeMethod ( object , " doSetInactive " ) ;
QCOMPARE ( loader - > property ( " activeChangedCount " ) . toInt ( ) , 5 ) ;
loader - > setActive ( true ) ; // change signal should be emitted
QCOMPARE ( loader - > property ( " activeChangedCount " ) . toInt ( ) , 6 ) ;
delete object ;
}
2011-10-06 04:37:09 +00:00
// check that the component isn't loaded until active is set to true
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " active.7.qml " ) ) ;
QObject * object = component . create ( ) ;
QVERIFY ( object ! = 0 ) ;
QCOMPARE ( object - > property ( " success " ) . toBool ( ) , true ) ;
delete object ;
}
// check that the component is loaded if active is not set (true by default)
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " active.8.qml " ) ) ;
QObject * object = component . create ( ) ;
QVERIFY ( object ! = 0 ) ;
QCOMPARE ( object - > property ( " success " ) . toBool ( ) , true ) ;
delete object ;
}
2011-08-17 07:46:54 +00:00
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : initialPropertyValues_data ( )
2011-08-17 07:46:54 +00:00
{
QTest : : addColumn < QUrl > ( " qmlFile " ) ;
QTest : : addColumn < QStringList > ( " expectedWarnings " ) ;
QTest : : addColumn < QStringList > ( " propertyNames " ) ;
QTest : : addColumn < QVariantList > ( " propertyValues " ) ;
QTest : : newRow ( " source url with value set in onLoaded, initially active = true " ) < < TEST_FILE ( " initialPropertyValues.1.qml " )
< < QStringList ( )
< < ( QStringList ( ) < < " initialValue " < < " behaviorCount " )
< < ( QVariantList ( ) < < 1 < < 1 ) ;
QTest : : newRow ( " set source with initial property values specified, active = true " ) < < TEST_FILE ( " initialPropertyValues.2.qml " )
< < QStringList ( )
< < ( QStringList ( ) < < " initialValue " < < " behaviorCount " )
< < ( QVariantList ( ) < < 2 < < 0 ) ;
QTest : : newRow ( " set source with initial property values specified, active = false " ) < < TEST_FILE ( " initialPropertyValues.3.qml " )
< < ( QStringList ( ) < < QString ( QLatin1String ( " file:// " ) + TEST_FILE ( " initialPropertyValues.3.qml " ) . toLocalFile ( ) + QLatin1String ( " :16: TypeError: Cannot read property 'canary' of null " ) ) )
< < ( QStringList ( ) )
< < ( QVariantList ( ) ) ;
QTest : : newRow ( " set source with initial property values specified, active = false, with active set true later " ) < < TEST_FILE ( " initialPropertyValues.4.qml " )
< < QStringList ( )
< < ( QStringList ( ) < < " initialValue " < < " behaviorCount " )
< < ( QVariantList ( ) < < 4 < < 0 ) ;
QTest : : newRow ( " set source without initial property values specified, active = true " ) < < TEST_FILE ( " initialPropertyValues.5.qml " )
< < QStringList ( )
< < ( QStringList ( ) < < " initialValue " < < " behaviorCount " )
< < ( QVariantList ( ) < < 0 < < 0 ) ;
QTest : : newRow ( " set source with initial property values specified with binding, active = true " ) < < TEST_FILE ( " initialPropertyValues.6.qml " )
< < QStringList ( )
< < ( QStringList ( ) < < " initialValue " < < " behaviorCount " )
< < ( QVariantList ( ) < < 6 < < 0 ) ;
QTest : : newRow ( " ensure initial property value semantics mimic createObject " ) < < TEST_FILE ( " initialPropertyValues.7.qml " )
< < QStringList ( )
< < ( QStringList ( ) < < " loaderValue " < < " createObjectValue " )
< < ( QVariantList ( ) < < 1 < < 1 ) ;
2011-10-06 06:29:52 +00:00
QTest : : newRow ( " ensure initial property values aren't disposed prior to component completion " ) < < TEST_FILE ( " initialPropertyValues.8.qml " )
< < QStringList ( )
< < ( QStringList ( ) < < " initialValue " )
< < ( QVariantList ( ) < < 6 ) ;
2011-08-17 07:46:54 +00:00
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : initialPropertyValues ( )
2011-08-17 07:46:54 +00:00
{
QFETCH ( QUrl , qmlFile ) ;
QFETCH ( QStringList , expectedWarnings ) ;
QFETCH ( QStringList , propertyNames ) ;
QFETCH ( QVariantList , propertyValues ) ;
2011-10-06 06:29:52 +00:00
TestHTTPServer server ( SERVER_PORT ) ;
QVERIFY ( server . isValid ( ) ) ;
2011-10-12 03:46:02 +00:00
server . serveDirectory ( TESTDATA ( " " ) ) ;
2011-10-06 06:29:52 +00:00
2011-08-17 07:46:54 +00:00
foreach ( const QString & warning , expectedWarnings )
QTest : : ignoreMessage ( QtWarningMsg , warning . toAscii ( ) . constData ( ) ) ;
QDeclarativeComponent component ( & engine , qmlFile ) ;
QObject * object = component . create ( ) ;
QVERIFY ( object ! = 0 ) ;
2011-10-06 06:29:52 +00:00
qApp - > processEvents ( ) ;
QTest : : qWait ( 50 ) ;
2011-08-17 07:46:54 +00:00
for ( int i = 0 ; i < propertyNames . size ( ) ; + + i )
QCOMPARE ( object - > property ( propertyNames . at ( i ) . toAscii ( ) . constData ( ) ) , propertyValues . at ( i ) ) ;
delete object ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : initialPropertyValuesBinding ( )
2011-08-17 07:46:54 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " initialPropertyValues.binding.qml " ) ) ;
QObject * object = component . create ( ) ;
QVERIFY ( object ! = 0 ) ;
QVERIFY ( object - > setProperty ( " bindable " , QVariant ( 8 ) ) ) ;
QCOMPARE ( object - > property ( " canaryValue " ) . toInt ( ) , 8 ) ;
delete object ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : initialPropertyValuesError_data ( )
2011-08-17 07:46:54 +00:00
{
QTest : : addColumn < QUrl > ( " qmlFile " ) ;
QTest : : addColumn < QStringList > ( " expectedWarnings " ) ;
QTest : : newRow ( " invalid initial property values object " ) < < TEST_FILE ( " initialPropertyValues.error.1.qml " )
< < ( QStringList ( ) < < QString ( TEST_FILE ( " initialPropertyValues.error.1.qml " ) . toString ( ) + " :6:5: QML Loader: setSource: value is not an object " ) ) ;
QTest : : newRow ( " nonexistent source url " ) < < TEST_FILE ( " initialPropertyValues.error.2.qml " )
< < ( QStringList ( ) < < QString ( TEST_FILE ( " NonexistentSourceComponent.qml " ) . toString ( ) + " : File not found " ) ) ;
QTest : : newRow ( " invalid source url " ) < < TEST_FILE ( " initialPropertyValues.error.3.qml " )
< < ( QStringList ( ) < < QString ( TEST_FILE ( " InvalidSourceComponent.qml " ) . toString ( ) + " :5:1: Syntax error " ) ) ;
QTest : : newRow ( " invalid initial property values object with invalid property access " ) < < TEST_FILE ( " initialPropertyValues.error.4.qml " )
< < ( QStringList ( ) < < QString ( TEST_FILE ( " initialPropertyValues.error.4.qml " ) . toString ( ) + " :7:5: QML Loader: setSource: value is not an object " )
< < QString ( TEST_FILE ( " initialPropertyValues.error.4.qml " ) . toString ( ) + " :5: TypeError: Cannot read property 'canary' of null " ) ) ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : initialPropertyValuesError ( )
2011-08-17 07:46:54 +00:00
{
QFETCH ( QUrl , qmlFile ) ;
QFETCH ( QStringList , expectedWarnings ) ;
foreach ( const QString & warning , expectedWarnings )
QTest : : ignoreMessage ( QtWarningMsg , warning . toUtf8 ( ) . constData ( ) ) ;
QDeclarativeComponent component ( & engine , qmlFile ) ;
QObject * object = component . create ( ) ;
QVERIFY ( object ! = 0 ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = object - > findChild < QQuickLoader * > ( " loader " ) ;
2011-08-17 07:46:54 +00:00
QVERIFY ( loader ! = 0 ) ;
QVERIFY ( loader - > item ( ) = = 0 ) ;
delete object ;
}
2011-04-27 12:13:26 +00:00
// QTBUG-9241
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : deleteComponentCrash ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " crash.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * item = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( item ) ;
item - > metaObject ( ) - > invokeMethod ( item , " setLoaderSource " ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( item - > QQuickItem : : childItems ( ) . at ( 0 ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ) ;
QVERIFY ( loader - > item ( ) ) ;
QCOMPARE ( loader - > item ( ) - > objectName ( ) , QLatin1String ( " blue " ) ) ;
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Ready ) ;
2011-10-07 06:20:39 +00:00
qApp - > processEvents ( QEventLoop : : DeferredDeletion ) ;
2011-10-14 08:51:42 +00:00
QTRY_COMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 1 ) ;
2011-10-12 03:46:02 +00:00
QVERIFY ( loader - > source ( ) = = QUrl : : fromLocalFile ( TESTDATA ( " BlueRect.qml " ) ) ) ;
2011-04-27 12:13:26 +00:00
delete item ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : nonItem ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " nonItem.qml " ) ) ;
2011-10-12 03:46:02 +00:00
QString err = QUrl : : fromLocalFile ( TESTDATA ( " nonItem.qml " ) ) . toString ( ) + " :3:1: QML Loader: Loader does not support loading non-visual elements. " ;
2011-04-27 12:13:26 +00:00
QTest : : ignoreMessage ( QtWarningMsg , err . toLatin1 ( ) . constData ( ) ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ) ;
QVERIFY ( loader - > item ( ) = = 0 ) ;
delete loader ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : vmeErrors ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " vmeErrors.qml " ) ) ;
2011-10-12 03:46:02 +00:00
QString err = QUrl : : fromLocalFile ( TESTDATA ( " VmeError.qml " ) ) . toString ( ) + " :6: Cannot assign object type QObject with no default method " ;
2011-04-27 12:13:26 +00:00
QTest : : ignoreMessage ( QtWarningMsg , err . toLatin1 ( ) . constData ( ) ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = qobject_cast < QQuickLoader * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( loader ) ;
QVERIFY ( loader - > item ( ) = = 0 ) ;
delete loader ;
}
// QTBUG-13481
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : creationContext ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " creationContext.qml " ) ) ;
QObject * o = component . create ( ) ;
QVERIFY ( o ! = 0 ) ;
QCOMPARE ( o - > property ( " test " ) . toBool ( ) , true ) ;
delete o ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : QTBUG_16928 ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " QTBUG_16928.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * item = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( item ) ;
QCOMPARE ( item - > width ( ) , 250. ) ;
QCOMPARE ( item - > height ( ) , 250. ) ;
delete item ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : implicitSize ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " implicitSize.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * item = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( item ) ;
QCOMPARE ( item - > width ( ) , 150. ) ;
QCOMPARE ( item - > height ( ) , 150. ) ;
QCOMPARE ( item - > property ( " implHeight " ) . toReal ( ) , 100. ) ;
QCOMPARE ( item - > property ( " implWidth " ) . toReal ( ) , 100. ) ;
delete item ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : QTBUG_17114 ( )
2011-04-27 12:13:26 +00:00
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " QTBUG_17114.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * item = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
2011-04-27 12:13:26 +00:00
QVERIFY ( item ) ;
QCOMPARE ( item - > property ( " loaderWidth " ) . toReal ( ) , 32. ) ;
QCOMPARE ( item - > property ( " loaderHeight " ) . toReal ( ) , 32. ) ;
delete item ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : asynchronous_data ( )
2011-10-07 06:20:39 +00:00
{
QTest : : addColumn < QUrl > ( " qmlFile " ) ;
QTest : : addColumn < QStringList > ( " expectedWarnings " ) ;
QTest : : newRow ( " Valid component " ) < < TEST_FILE ( " BigComponent.qml " )
< < QStringList ( ) ;
QTest : : newRow ( " Non-existant component " ) < < TEST_FILE ( " IDoNotExist.qml " )
< < ( QStringList ( ) < < QString ( TEST_FILE ( " IDoNotExist.qml " ) . toString ( ) + " : File not found " ) ) ;
QTest : : newRow ( " Invalid component " ) < < TEST_FILE ( " InvalidSourceComponent.qml " )
< < ( QStringList ( ) < < QString ( TEST_FILE ( " InvalidSourceComponent.qml " ) . toString ( ) + " :5:1: Syntax error " ) ) ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : asynchronous ( )
2011-10-07 06:20:39 +00:00
{
QFETCH ( QUrl , qmlFile ) ;
QFETCH ( QStringList , expectedWarnings ) ;
if ( ! engine . incubationController ( ) )
engine . setIncubationController ( new PeriodicIncubationController ) ;
QDeclarativeComponent component ( & engine , TEST_FILE ( " asynchronous.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * root = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
2011-10-07 06:20:39 +00:00
QVERIFY ( root ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = root - > findChild < QQuickLoader * > ( " loader " ) ;
2011-10-07 06:20:39 +00:00
QVERIFY ( loader ) ;
foreach ( const QString & warning , expectedWarnings )
QTest : : ignoreMessage ( QtWarningMsg , warning . toUtf8 ( ) . constData ( ) ) ;
QVERIFY ( ! loader - > item ( ) ) ;
root - > setProperty ( " comp " , qmlFile . toString ( ) ) ;
QMetaObject : : invokeMethod ( root , " loadComponent " ) ;
QVERIFY ( ! loader - > item ( ) ) ;
if ( expectedWarnings . isEmpty ( ) ) {
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Loading ) ;
2011-10-07 06:20:39 +00:00
QCOMPARE ( engine . incubationController ( ) - > incubatingObjectCount ( ) , 1 ) ;
QTRY_VERIFY ( loader - > item ( ) ) ;
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Ready ) ;
2011-10-07 06:20:39 +00:00
} else {
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
2011-10-14 08:51:42 +00:00
QTRY_COMPARE ( loader - > status ( ) , QQuickLoader : : Error ) ;
2011-10-07 06:20:39 +00:00
}
delete root ;
}
2011-10-14 08:51:42 +00:00
void tst_QQuickLoader : : asynchronous_clear ( )
2011-10-07 06:20:39 +00:00
{
if ( ! engine . incubationController ( ) )
engine . setIncubationController ( new PeriodicIncubationController ) ;
QDeclarativeComponent component ( & engine , TEST_FILE ( " asynchronous.qml " ) ) ;
2011-10-14 08:51:42 +00:00
QQuickItem * root = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
2011-10-07 06:20:39 +00:00
QVERIFY ( root ) ;
2011-10-14 08:51:42 +00:00
QQuickLoader * loader = root - > findChild < QQuickLoader * > ( " loader " ) ;
2011-10-07 06:20:39 +00:00
QVERIFY ( loader ) ;
QVERIFY ( ! loader - > item ( ) ) ;
root - > setProperty ( " comp " , " BigComponent.qml " ) ;
QMetaObject : : invokeMethod ( root , " loadComponent " ) ;
QVERIFY ( ! loader - > item ( ) ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Loading ) ;
2011-10-07 06:20:39 +00:00
QCOMPARE ( engine . incubationController ( ) - > incubatingObjectCount ( ) , 1 ) ;
// clear before component created
root - > setProperty ( " comp " , " " ) ;
QMetaObject : : invokeMethod ( root , " loadComponent " ) ;
QVERIFY ( ! loader - > item ( ) ) ;
QCOMPARE ( engine . incubationController ( ) - > incubatingObjectCount ( ) , 0 ) ;
QCOMPARE ( loader - > progress ( ) , 0.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Null ) ;
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 0 ) ;
2011-10-07 06:20:39 +00:00
// check loading component
root - > setProperty ( " comp " , " Rect120x60.qml " ) ;
QMetaObject : : invokeMethod ( root , " loadComponent " ) ;
QVERIFY ( ! loader - > item ( ) ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Loading ) ;
2011-10-07 06:20:39 +00:00
QCOMPARE ( engine . incubationController ( ) - > incubatingObjectCount ( ) , 1 ) ;
QTRY_VERIFY ( loader - > item ( ) ) ;
QCOMPARE ( loader - > progress ( ) , 1.0 ) ;
2011-10-14 08:51:42 +00:00
QCOMPARE ( loader - > status ( ) , QQuickLoader : : Ready ) ;
QCOMPARE ( static_cast < QQuickItem * > ( loader ) - > childItems ( ) . count ( ) , 1 ) ;
2011-10-07 06:20:39 +00:00
}
2011-11-14 03:00:31 +00:00
void tst_QQuickLoader : : parented ( )
{
QDeclarativeComponent component ( & engine , TEST_FILE ( " parented.qml " ) ) ;
QQuickItem * root = qobject_cast < QQuickItem * > ( component . create ( ) ) ;
QVERIFY ( root ) ;
QQuickItem * item = root - > findChild < QQuickItem * > ( " comp " ) ;
QVERIFY ( item ) ;
QVERIFY ( item - > parentItem ( ) = = root ) ;
QCOMPARE ( item - > width ( ) , 300. ) ;
QCOMPARE ( item - > height ( ) , 300. ) ;
delete root ;
}
2011-10-07 06:20:39 +00:00
2011-10-14 08:51:42 +00:00
QTEST_MAIN ( tst_QQuickLoader )
2011-04-27 12:13:26 +00:00
2011-10-14 08:51:42 +00:00
# include "tst_qquickloader.moc"