summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLincoln Ramsay <lincoln.ramsay@nokia.com>2012-03-16 16:14:01 +1000
committerQt by Nokia <qt-info@nokia.com>2012-03-19 05:42:09 +0100
commit3a2b8fcaa52af48f89ecb95a942aad8ecbfde83a (patch)
tree9a89b0e1ed6b7ac94c16cd0f60422ef0d3fdb304
parent53dc7cbe6e6a67132acfafb5230fe0fc897014cc (diff)
Use an environment variable to suppress loading of plugins.
This removes the last use of the sensors_unit_test_hook function so it can be removed. Change-Id: I9f0b27fc69bfe74a151826714e3a1c0e207a7e0c Reviewed-by: Wolfgang Beck <wolfgang.beck@nokia.com>
-rw-r--r--src/sensors/qsensormanager.cpp38
-rw-r--r--tests/auto/qsensor/tst_qsensor.cpp13
-rw-r--r--tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp4
3 files changed, 9 insertions, 46 deletions
diff --git a/src/sensors/qsensormanager.cpp b/src/sensors/qsensormanager.cpp
index 67e5b442..72273806 100644
--- a/src/sensors/qsensormanager.cpp
+++ b/src/sensors/qsensormanager.cpp
@@ -70,9 +70,15 @@ public:
, loader(new QFactoryLoader("com.nokia.Qt.QSensorPluginInterface/1.0", QLatin1String("/sensors")))
, defaultIdentifierForTypeLoaded(false)
, sensorsChanged(false)
+ , loadExternalPlugins(true)
{
+ QByteArray env = qgetenv("QT_SENSORS_LOAD_PLUGINS");
+ if (env == "0") {
+ loadExternalPlugins = false;
+ }
}
+ bool loadExternalPlugins;
PluginLoadingState pluginLoadingState;
QFactoryLoader *loader;
void loadPlugins();
@@ -129,36 +135,6 @@ public Q_SLOTS:
Q_GLOBAL_STATIC(QSensorManagerPrivate, sensorManagerPrivate)
-// The unit test needs to change the behaviour of the library. It does this
-// through an exported but undocumented function.
-static void initPlugin(QObject *plugin);
-static bool load_external_plugins = true;
-Q_SENSORS_EXPORT void sensors_unit_test_hook(int index)
-{
- QSensorManagerPrivate *d = sensorManagerPrivate();
-
- switch (index) {
- case 0:
- Q_ASSERT(d->pluginLoadingState == QSensorManagerPrivate::NotLoaded);
- load_external_plugins = false;
- break;
- case 1:
- {
- Q_ASSERT(load_external_plugins == false);
- Q_ASSERT(d->pluginLoadingState == QSensorManagerPrivate::Loaded);
- SENSORLOG() << "initializing plugins";
- QList<QJsonObject> meta = d->loader->metaData();
- for (int i = 0; i < meta.count(); i++) {
- QObject *plugin = d->loader->instance(i);
- initPlugin(plugin);
- }
- break;
- }
- default:
- break;
- }
-}
-
static void initPlugin(QObject *o)
{
if (!o) return;
@@ -191,7 +167,7 @@ void QSensorManagerPrivate::loadPlugins()
initPlugin(plugin);
}
- if (load_external_plugins) {
+ if (d->loadExternalPlugins) {
SENSORLOG() << "initializing plugins";
QList<QJsonObject> meta = d->loader->metaData();
for (int i = 0; i < meta.count(); i++) {
diff --git a/tests/auto/qsensor/tst_qsensor.cpp b/tests/auto/qsensor/tst_qsensor.cpp
index 5a697ee3..92cb281a 100644
--- a/tests/auto/qsensor/tst_qsensor.cpp
+++ b/tests/auto/qsensor/tst_qsensor.cpp
@@ -117,7 +117,7 @@ class tst_QSensor : public QObject
public:
tst_QSensor()
{
- sensors_unit_test_hook(0); // change some flags the library uses
+ qputenv("QT_SENSORS_LOAD_PLUGINS", "0"); // Do not load plugins
}
private slots:
@@ -924,17 +924,6 @@ private slots:
sensor2.start();
QVERIFY(sensor2.isActive());
}
-
- // This test must be LAST or it will interfere with the other tests
- void testLoadingPlugins()
- {
- // Go ahead and load the actual plugins (as a test that plugin loading works)
- sensors_unit_test_hook(1);
-
- // Hmm... There's no real way to tell if this worked or not.
- // If it doesn't work the unit test will probably crash.
- // That's what it did on Symbian before plugin loading was fixed.
- }
};
QT_END_NAMESPACE
diff --git a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
index fd54ea15..30e600a8 100644
--- a/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
+++ b/tests/auto/sensors2qmlapi/tst_sensors2qmlapi.cpp
@@ -59,8 +59,6 @@ QDeclProximitySensor* TestSensorPlugin::stProxi = 0;
QT_BEGIN_NAMESPACE
-Q_SENSORS_EXPORT void sensors_unit_test_hook(int index);
-
class tst_Sensors2QMLAPI : public QObject
{
Q_OBJECT
@@ -86,7 +84,7 @@ protected:
void tst_Sensors2QMLAPI::initTestCase()
{
- sensors_unit_test_hook(0); // change some flags the library uses
+ qputenv("QT_SENSORS_LOAD_PLUGINS", "0"); // Do not load plugins
_plugin.registerSensors();
_tilt = 0;
}