~ubuntu-branches/ubuntu/vivid/qtdeclarative-opensource-src-gles/vivid

« back to all changes in this revision

Viewing changes to tests/auto/qml/qqmlenginecleanup/tst_qqmlenginecleanup.cpp

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2015-03-11 16:51:45 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20150311165145-7653iqap3mau92gy
Tags: 5.4.1-0ubuntu1
Sync package with qtdeclarative-opensource-src - 5.4.1-1ubuntu3

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
 
47
47
private slots:
48
48
    void test_qmlClearTypeRegistrations();
 
49
    void test_valueTypeProviderModule(); // QTBUG-43004
49
50
};
50
51
 
51
52
void tst_qqmlenginecleanup::test_qmlClearTypeRegistrations()
85
86
    delete component;
86
87
}
87
88
 
 
89
static void cleanState(QQmlEngine **e)
 
90
{
 
91
    delete *e;
 
92
    qmlClearTypeRegistrations();
 
93
    *e = new QQmlEngine;
 
94
    QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
 
95
    QCoreApplication::processEvents();
 
96
}
 
97
 
 
98
void tst_qqmlenginecleanup::test_valueTypeProviderModule()
 
99
{
 
100
    // this test ensures that a module which installs a value type
 
101
    // provider can be reinitialized after multiple calls to
 
102
    // qmlClearTypeRegistrations() without causing cycles in the
 
103
    // value type provider list.
 
104
    QQmlEngine *e = 0;
 
105
    QUrl testFile1 = testFileUrl("testFile1.qml");
 
106
    QUrl testFile2 = testFileUrl("testFile2.qml");
 
107
    bool noCycles = false;
 
108
    for (int i = 0; i < 20; ++i) {
 
109
        cleanState(&e);
 
110
        QQmlComponent c(e, this);
 
111
        c.loadUrl(i % 2 == 0 ? testFile1 : testFile2); // this will hang if cycles exist.
 
112
    }
 
113
    delete e;
 
114
    e = 0;
 
115
    noCycles = true;
 
116
    QVERIFY(noCycles);
 
117
 
 
118
    // this test ensures that no crashes occur due to using
 
119
    // a dangling QQmlType pointer in the type compiler
 
120
    // which results from qmlClearTypeRegistrations()
 
121
    QUrl testFile3 = testFileUrl("testFile3.qml");
 
122
    bool noDangling = false;
 
123
    for (int i = 0; i < 20; ++i) {
 
124
        cleanState(&e);
 
125
        QQmlComponent c(e, this);
 
126
        c.loadUrl(i % 2 == 0 ? testFile1 : testFile3); // this will crash if dangling ptr exists.
 
127
    }
 
128
    delete e;
 
129
    noDangling = true;
 
130
    QVERIFY(noDangling);
 
131
}
 
132
 
88
133
QTEST_MAIN(tst_qqmlenginecleanup)
89
134
 
90
135
#include "tst_qqmlenginecleanup.moc"