blob: 665651db031a3a4f55eb03448ed58443d576f751 (
plain)
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
|
#include <qtest.h>
#include <QtDeclarative/qfxview.h>
#include <QtDeclarative/qmlcontext.h>
#include <QtDeclarative/qmlengine.h>
#include <QtDeclarative/qfxrect.h>
#include <QtDeclarative/qfxtext.h>
#include <QDir>
class tst_namespaces : public QObject
{
Q_OBJECT
public:
tst_namespaces();
private slots:
void simple();
void simple_data();
};
tst_namespaces::tst_namespaces()
{
}
void tst_namespaces::simple_data()
{
QTest::addColumn<QString>("qml");
QTest::addColumn<bool>("valid");
QTest::addColumn<QString>("texts");
QTest::addColumn<QString>("rects");
QTest::newRow("Control") <<
"<Rect objectName=\"a\">"
"<Rect objectName=\"b\"/>"
"</Rect>"
<< true << "" << "ab";
QTest::newRow("Control2") <<
"<Rect objectName=\"a\">"
"<Text objectName=\"b\"/>"
"</Rect>"
<< true << "b" << "a";
QTest::newRow("Replace builtin") <<
"<Rect objectName=\"a\" xmlns:rs=\"http://nokia.com/qml/Red\">"
"<rs:Rect objectName=\"b\"/>"
"</Rect>"
<< true << "b" << "a";
}
void tst_namespaces::simple()
{
QFETCH(QString, qml);
QFETCH(bool, valid);
QFETCH(QString, texts);
QFETCH(QString, rects);
QFxView canvas(0);
canvas.rootContext()->engine()->addNameSpacePath("http://nokia.com/qml", SRCDIR "/data");
canvas.setXml(qml);
canvas.execute();
qApp->processEvents();
QFxItem *testObject = qobject_cast<QFxItem*>(canvas.root());
QCOMPARE((testObject != 0),valid);
if (valid && testObject != 0) {
QString textids;
QList<QFxText*> textobjects = testObject->findChildren<QFxText*>();
if (qobject_cast<QFxText*>(testObject))
textids += testObject->objectName();
foreach (QFxText *obj, textobjects) {
textids += obj->objectName();
}
if (textids != texts)
testObject->dump();
QCOMPARE(textids,texts);
QString rectids;
QList<QFxRect*> rectobjects = testObject->findChildren<QFxRect*>();
if (qobject_cast<QFxRect*>(testObject))
rectids += testObject->objectName();
foreach (QFxRect *obj, rectobjects)
rectids += obj->objectName();
if (rectids != rects)
testObject->dump();
QCOMPARE(rectids,rects);
}
}
QTEST_MAIN(tst_namespaces)
#include "tst_namespaces.moc"
|