qtmobility/tests/auto/qvaluespacepublisher/tst_qvaluespacepublisher.cpp
changeset 4 90517678cc4f
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
1:2b40d63a9c3d 4:90517678cc4f
    53 
    53 
    54 #ifdef Q_OS_WIN
    54 #ifdef Q_OS_WIN
    55 #define _WIN32_WINNT 0x0500
    55 #define _WIN32_WINNT 0x0500
    56 #include <windows.h>
    56 #include <windows.h>
    57 #endif
    57 #endif
       
    58 
       
    59 #include <QProcess>
    58 
    60 
    59 #define QTRY_COMPARE(a,e)                       \
    61 #define QTRY_COMPARE(a,e)                       \
    60     for (int _i = 0; _i < 5000; _i += 100) {    \
    62     for (int _i = 0; _i < 5000; _i += 100) {    \
    61         if ((a) == (e)) break;                  \
    63         if ((a) == (e)) break;                  \
    62         QTest::qWait(100);                      \
    64         QTest::qWait(100);                      \
   130 #ifdef Q_OS_UNIX
   132 #ifdef Q_OS_UNIX
   131     QFile::remove("/tmp/qt-0/valuespace_shmlayer");
   133     QFile::remove("/tmp/qt-0/valuespace_shmlayer");
   132 #endif
   134 #endif
   133 
   135 
   134     QValueSpace::initValueSpaceServer();
   136     QValueSpace::initValueSpaceServer();
       
   137 
       
   138     if (QValueSpace::availableLayers().contains(QVALUESPACE_GCONF_LAYER)) {
       
   139         QCOMPARE(QProcess::execute("gconftool-2 -u /value"), 0);
       
   140         QCOMPARE(QProcess::execute("gconftool-2 -u /testConstructor/value"), 0);
       
   141         QCOMPARE(QProcess::execute("gconftool-2 -u /testConstructor/subpath/value"), 0);
       
   142     }
       
   143 
   135 }
   144 }
   136 
   145 
   137 void tst_QValueSpacePublisher::cleanupTestCase()
   146 void tst_QValueSpacePublisher::cleanupTestCase()
   138 {
   147 {
   139 }
   148 }
   472     QTest::addColumn<unsigned int>("count");
   481     QTest::addColumn<unsigned int>("count");
   473     QTest::addColumn<bool>("sequential");
   482     QTest::addColumn<bool>("sequential");
   474 
   483 
   475     QList<QAbstractValueSpaceLayer *> layers = QValueSpaceManager::instance()->getLayers();
   484     QList<QAbstractValueSpaceLayer *> layers = QValueSpaceManager::instance()->getLayers();
   476 
   485 
       
   486     int foundLayers = 0;
   477     for (int i = 0; i < layers.count(); ++i) {
   487     for (int i = 0; i < layers.count(); ++i) {
   478         QAbstractValueSpaceLayer *layer = layers.at(i);
   488         QAbstractValueSpaceLayer *layer = layers.at(i);
   479 
   489 
   480         if (layer->id() == QVALUESPACE_NONVOLATILEREGISTRY_LAYER)
   490         if (layer->id() == QVALUESPACE_NONVOLATILEREGISTRY_LAYER)
       
   491             continue;
       
   492 
       
   493         //GConfLayer can't provide thread-safety because it eventually depends on
       
   494         //DBus which isn't fully thread-safe
       
   495         if (layer->id() == QVALUESPACE_GCONF_LAYER)
   481             continue;
   496             continue;
   482 
   497 
   483 #ifdef Q_OS_WINCE
   498 #ifdef Q_OS_WINCE
   484         // Limit number of items on Windows CE to prevent out of disk space errors.
   499         // Limit number of items on Windows CE to prevent out of disk space errors.
   485         if (layer->id() == QVALUESPACE_VOLATILEREGISTRY_LAYER) {
   500         if (layer->id() == QVALUESPACE_VOLATILEREGISTRY_LAYER) {
   569             QTest::newRow("2 threads, 5000 items")
   584             QTest::newRow("2 threads, 5000 items")
   570                 << layer->id() << uint(2) << uint(5000) << false;
   585                 << layer->id() << uint(2) << uint(5000) << false;
   571             QTest::newRow("100 threads, 100 items")
   586             QTest::newRow("100 threads, 100 items")
   572                 << layer->id() << uint(100) << uint(100) << false;
   587                 << layer->id() << uint(100) << uint(100) << false;
   573         }
   588         }
   574     }
   589         foundLayers++;
       
   590     }
       
   591 
       
   592     if (foundLayers == 0)
       
   593         QSKIP("No layers providing thread-safety found", SkipAll);
   575 }
   594 }
   576 
   595 
   577 void tst_QValueSpacePublisher::threads()
   596 void tst_QValueSpacePublisher::threads()
   578 {
   597 {
   579     QFETCH(QUuid, uuid);
   598     QFETCH(QUuid, uuid);
   580     QFETCH(unsigned int, threads);
   599     QFETCH(unsigned int, threads);
   581     QFETCH(unsigned int, count);
   600     QFETCH(unsigned int, count);
   582     QFETCH(bool, sequential);
   601     QFETCH(bool, sequential);
   583 
   602 
       
   603     if (QValueSpace::availableLayers().contains(QVALUESPACE_GCONF_LAYER)) {
       
   604         QCOMPARE(QProcess::execute("gconftool-2 --recursive-unset /threads"), 0);
       
   605     }
   584     QStringList expectedPaths;
   606     QStringList expectedPaths;
   585     for (unsigned int i = 0; i < threads; ++i)
   607     for (unsigned int i = 0; i < threads; ++i)
   586         expectedPaths.append(QString("thread%1").arg(i));
   608         expectedPaths.append(QString("thread%1").arg(i));
   587 
   609 
   588     QHash<QString, QString> expectedValues;
   610     QHash<QString, QString> expectedValues;