diff options
author | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-03-09 13:45:44 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@theqtcompany.com> | 2015-07-20 15:57:07 +0000 |
commit | ee0fd8700724848e73c228d973bf72e246077d07 (patch) | |
tree | 9ebf56c9e242be2823b1d6d3bcaa668eb40ea72c /tests/auto/corelib/kernel | |
parent | 49fee77ccc68424758823dd2579e731e4ef4073f (diff) | |
download | qtbase-ee0fd8700724848e73c228d973bf72e246077d07.tar.gz |
Selectively update library paths when creating QCoreApplication
We force a recreation of the library paths with added information on
construction of QCoreApplication. This way we can find plugins in
the application directory which only becomes known when
QCoreApplication is created. When the user changes the library path
we create a new list of the manually modified library paths and
recalculate it from the delta of original vs. modified paths when
QCoreApplication is created.
The upsides of this approach vs. keeping an explicit delta are:
* We don't need to introduce a separate data structure to hold
the added/removed status for delta items or the information that
the whole list got replaced.
* The lists never get larger than the the real library paths. An
explicit delta would have to record all modifications.
* I don't think the delta replay algorithm we would have to do
anyway could be made much more compact than the one this change
introduces.
Of course, if the user actually changes anything, the list is
duplicated. Considering that this is a rarely used function and
that we would have to save some extra information anyway, I think
we can live with this.
Task-number: QTBUG-38598
Change-Id: I3bfbbd1be62dd5804dcc7ac808b053428a4e3149
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r-- | tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp | 27 | ||||
-rw-r--r-- | tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index 696a1c4722..060ef99d65 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -903,6 +903,33 @@ void tst_QCoreApplication::threadedEventDelivery() QCOMPARE(receiver.recordedEvents.contains(QEvent::User + 1), eventsReceived); } +void tst_QCoreApplication::addRemoveLibPaths() +{ + QStringList paths = QCoreApplication::libraryPaths(); + if (paths.isEmpty()) + QSKIP("Cannot add/remove library paths if there are none."); + + QString currentDir = QDir().absolutePath(); + QCoreApplication::addLibraryPath(currentDir); + QVERIFY(QCoreApplication::libraryPaths().contains(currentDir)); + + QCoreApplication::removeLibraryPath(paths[0]); + QVERIFY(!QCoreApplication::libraryPaths().contains(paths[0])); + + int argc = 1; + char *argv[] = { const_cast<char*>(QTest::currentAppName()) }; + TestApplication app(argc, argv); + + // Check that modifications stay alive across the creation of an application. + QVERIFY(QCoreApplication::libraryPaths().contains(currentDir)); + QVERIFY(!QCoreApplication::libraryPaths().contains(paths[0])); + + QStringList replace; + replace << currentDir << paths[0]; + QCoreApplication::setLibraryPaths(replace); + QVERIFY(QCoreApplication::libraryPaths() == replace); +} + static void createQObjectOnDestruction() { // Make sure that we can create a QObject after the last QObject has been diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h index 8efe374a2b..d9296b3846 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.h @@ -63,6 +63,7 @@ private slots: void applicationEventFilters_auxThread(); void threadedEventDelivery_data(); void threadedEventDelivery(); + void addRemoveLibPaths(); }; #endif // TST_QCOREAPPLICATION_H |