1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#include <qtest.h>
#include <QtDeclarative/qmlengine.h>
#include <QtDeclarative/qmlcomponent.h>
#include <QtDeclarative/qfxloader.h>
class tst_qfxloader : public QObject
{
Q_OBJECT
public:
tst_qfxloader();
private slots:
void url();
void component();
void sizeLoaderToItem();
void sizeItemToLoader();
void noResize();
private:
QmlEngine engine;
};
/*
inline QUrl TEST_FILE(const QString &filename)
{
QFileInfo fileInfo(__FILE__);
return QUrl::fromLocalFile(fileInfo.absoluteDir().filePath(filename));
}
inline QUrl TEST_FILE(const char *filename)
{
return TEST_FILE(QLatin1String(filename));
}
*/
tst_qfxloader::tst_qfxloader()
{
}
void tst_qfxloader::url()
{
QmlComponent component(&engine, QByteArray("import Qt 4.6\nLoader { source: \"Rect120x60.qml\" }"), QUrl("file://" SRCDIR "/"));
QFxLoader *loader = qobject_cast<QFxLoader*>(component.create());
QVERIFY(loader != 0);
QVERIFY(loader->item());
QCOMPARE(loader->progress(), 1.0);
QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
}
void tst_qfxloader::component()
{
QmlComponent component(&engine, QUrl("file://" SRCDIR "/SetSourceComponent.qml"));
QFxItem *item = qobject_cast<QFxItem*>(component.create());
QVERIFY(item);
QFxLoader *loader = qobject_cast<QFxLoader*>(item->QGraphicsObject::children().at(1));
QVERIFY(loader);
QVERIFY(loader->item());
QCOMPARE(loader->progress(), 1.0);
QCOMPARE(static_cast<QGraphicsItem*>(loader)->children().count(), 1);
}
void tst_qfxloader::sizeLoaderToItem()
{
QmlComponent component(&engine, QUrl("file://" SRCDIR "/SizeToItem.qml"));
QFxLoader *loader = qobject_cast<QFxLoader*>(component.create());
QVERIFY(loader != 0);
QCOMPARE(loader->width(), 120.0);
QCOMPARE(loader->height(), 60.0);
}
void tst_qfxloader::sizeItemToLoader()
{
QmlComponent component(&engine, QUrl("file://" SRCDIR "/SizeToLoader.qml"));
QFxLoader *loader = qobject_cast<QFxLoader*>(component.create());
QVERIFY(loader != 0);
QCOMPARE(loader->width(), 200.0);
QCOMPARE(loader->height(), 80.0);
QFxItem *rect = loader->item();
QVERIFY(rect);
QCOMPARE(rect->width(), 200.0);
QCOMPARE(rect->height(), 80.0);
}
void tst_qfxloader::noResize()
{
QmlComponent component(&engine, QUrl("file://" SRCDIR "/NoResize.qml"));
QFxLoader *loader = qobject_cast<QFxLoader*>(component.create());
QVERIFY(loader != 0);
QCOMPARE(loader->width(), 200.0);
QCOMPARE(loader->height(), 80.0);
QFxItem *rect = loader->item();
QVERIFY(rect);
QCOMPARE(rect->width(), 120.0);
QCOMPARE(rect->height(), 60.0);
}
QTEST_MAIN(tst_qfxloader)
#include "tst_qfxloader.moc"
|