qnxplugin.cpp 26.5 KB
Newer Older
Tobias Nätterlund's avatar
Tobias Nätterlund committed
1 2
/**************************************************************************
**
3
** Copyright (C) 2012 - 2014 BlackBerry Limited. All rights reserved.
Tobias Nätterlund's avatar
Tobias Nätterlund committed
4
**
5
** Contact: BlackBerry (qt@blackberry.com)
Tobias Nätterlund's avatar
Tobias Nätterlund committed
6 7
** Contact: KDAB (info@kdab.com)
**
hjk's avatar
hjk committed
8
** This file is part of Qt Creator.
Tobias Nätterlund's avatar
Tobias Nätterlund committed
9
**
hjk's avatar
hjk committed
10 11 12 13 14 15 16
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
Tobias Nätterlund's avatar
Tobias Nätterlund committed
17
**
hjk's avatar
hjk committed
18 19 20 21 22 23 24 25 26 27
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
Tobias Nätterlund's avatar
Tobias Nätterlund committed
28 29
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
30
****************************************************************************/
Tobias Nätterlund's avatar
Tobias Nätterlund committed
31 32 33 34 35 36 37 38 39 40 41

#include "qnxplugin.h"

#include "blackberrydeviceconfigurationfactory.h"
#include "qnxconstants.h"
#include "blackberryqtversionfactory.h"
#include "blackberrydeployconfigurationfactory.h"
#include "blackberrycreatepackagestepfactory.h"
#include "blackberrydeploystepfactory.h"
#include "blackberryrunconfigurationfactory.h"
#include "blackberryruncontrolfactory.h"
42
#include "qnxattachdebugsupport.h"
Tobias Nätterlund's avatar
Tobias Nätterlund committed
43 44 45 46 47 48
#include "qnxdeviceconfigurationfactory.h"
#include "qnxruncontrolfactory.h"
#include "qnxdeploystepfactory.h"
#include "qnxdeployconfigurationfactory.h"
#include "qnxrunconfigurationfactory.h"
#include "qnxqtversionfactory.h"
49
#include "blackberryndksettingspage.h"
50 51
#include "bardescriptoreditorfactory.h"
#include "bardescriptormagicmatcher.h"
52
#include "blackberrykeyspage.h"
53
#include "blackberrycheckdevicestatusstepfactory.h"
54
#include "blackberrydeviceconnectionmanager.h"
55
#include "blackberryconfigurationmanager.h"
56
#include "blackberryconfiguration.h"
57
#include "cascadesimport/cascadesimportwizard.h"
58
#include "qnxtoolchain.h"
59
#include "qnxattachdebugsupport.h"
60

61 62 63
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/coreconstants.h>
64 65
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
66
#include <projectexplorer/kitinformation.h>
67
#include <projectexplorer/projectexplorer.h>
68
#include <projectexplorer/projectexplorerconstants.h>
69
#include <projectexplorer/taskhub.h>
70
#include <projectexplorer/kitmanager.h>
Tobias Nätterlund's avatar
Tobias Nätterlund committed
71

72
#include <QAction>
Tobias Nätterlund's avatar
Tobias Nätterlund committed
73 74 75 76 77
#include <QtPlugin>

using namespace Qnx::Internal;

QNXPlugin::QNXPlugin()
78 79
    : m_debugSeparator(0)
    , m_attachToQnxApplication(0)
Tobias Nätterlund's avatar
Tobias Nätterlund committed
80 81 82 83 84
{
}

QNXPlugin::~QNXPlugin()
{
85
    delete BlackBerryDeviceConnectionManager::instance();
Tobias Nätterlund's avatar
Tobias Nätterlund committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
}

bool QNXPlugin::initialize(const QStringList &arguments, QString *errorString)
{
    Q_UNUSED(arguments)
    Q_UNUSED(errorString)

    // Handles BlackBerry
    addAutoReleasedObject(new BlackBerryQtVersionFactory);
    addAutoReleasedObject(new BlackBerryDeployConfigurationFactory);
    addAutoReleasedObject(new BlackBerryDeviceConfigurationFactory);
    addAutoReleasedObject(new BlackBerryCreatePackageStepFactory);
    addAutoReleasedObject(new BlackBerryDeployStepFactory);
    addAutoReleasedObject(new BlackBerryRunConfigurationFactory);
    addAutoReleasedObject(new BlackBerryRunControlFactory);
101
    addAutoReleasedObject(new BlackBerryNDKSettingsPage);
102
    addAutoReleasedObject(new BlackBerryKeysPage);
103
    addAutoReleasedObject(new BlackBerryCheckDeviceStatusStepFactory);
104
    addAutoReleasedObject(new CascadesImportWizard);
105
    BlackBerryDeviceConnectionManager::instance()->initialize();
Tobias Nätterlund's avatar
Tobias Nätterlund committed
106 107 108 109 110 111 112 113 114

    // Handles QNX
    addAutoReleasedObject(new QnxQtVersionFactory);
    addAutoReleasedObject(new QnxDeviceConfigurationFactory);
    addAutoReleasedObject(new QnxRunControlFactory);
    addAutoReleasedObject(new QnxDeployStepFactory);
    addAutoReleasedObject(new QnxDeployConfigurationFactory);
    addAutoReleasedObject(new QnxRunConfigurationFactory);

115 116 117
    // Handle Qcc Compiler
    addAutoReleasedObject(new QnxToolChainFactory);

118
    // bar-descriptor.xml editor
119
    Core::MimeGlobPattern barDescriptorGlobPattern(QLatin1String("*.xml"), Core::MimeGlobPattern::MinWeight + 1);
120 121
    Core::MimeType barDescriptorMimeType;
    barDescriptorMimeType.setType(QLatin1String(Constants::QNX_BAR_DESCRIPTOR_MIME_TYPE));
Friedemann Kleint's avatar
Friedemann Kleint committed
122
    barDescriptorMimeType.setComment(tr("Bar descriptor file (BlackBerry)"));
123 124 125 126
    barDescriptorMimeType.setGlobPatterns(QList<Core::MimeGlobPattern>() << barDescriptorGlobPattern);
    barDescriptorMimeType.addMagicMatcher(QSharedPointer<Core::IMagicMatcher>(new BarDescriptorMagicMatcher));
    barDescriptorMimeType.setSubClassesOf(QStringList() << QLatin1String("application/xml"));

hjk's avatar
hjk committed
127
    if (!Core::MimeDatabase::addMimeType(barDescriptorMimeType)) {
128
        *errorString = tr("Could not add mime-type for bar-descriptor.xml editor.");
129 130 131 132
        return false;
    }
    addAutoReleasedObject(new BarDescriptorEditorFactory);

133 134
    connect(ProjectExplorer::KitManager::instance(), SIGNAL(kitsLoaded()), &BlackBerryConfigurationManager::instance(), SLOT(loadSettings()));

Tobias Nätterlund's avatar
Tobias Nätterlund committed
135 136 137 138 139
    return true;
}

void QNXPlugin::extensionsInitialized()
{
140 141
    ProjectExplorer::TaskHub::addCategory(Constants::QNX_TASK_CATEGORY_BARDESCRIPTOR,
                                          tr("Bar Descriptor"));
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158

    // Debug support
    QnxAttachDebugSupport *debugSupport = new QnxAttachDebugSupport(this);

    m_attachToQnxApplication = new QAction(this);
    m_attachToQnxApplication->setText(tr("Attach to Remote QNX Application..."));
    connect(m_attachToQnxApplication, SIGNAL(triggered()), debugSupport, SLOT(showProcessesDialog()));

    const Core::Context globalcontext(Core::Constants::C_GLOBAL);
    Core::ActionContainer *mstart = Core::ActionManager::actionContainer(ProjectExplorer::Constants::M_DEBUG_STARTDEBUGGING);
    mstart->appendGroup(Constants::QNX_DEBUGGING_GROUP);
    mstart->addSeparator(globalcontext, Constants::QNX_DEBUGGING_GROUP, &m_debugSeparator);

    Core::Command *cmd = Core::ActionManager::registerAction(m_attachToQnxApplication, "Debugger.AttachToQnxApplication", globalcontext);
    mstart->addAction(cmd, Constants::QNX_DEBUGGING_GROUP);

    connect(ProjectExplorer::KitManager::instance(), SIGNAL(kitsChanged()), this, SLOT(updateDebuggerActions()));
Tobias Nätterlund's avatar
Tobias Nätterlund committed
159 160 161 162 163 164 165
}

ExtensionSystem::IPlugin::ShutdownFlag QNXPlugin::aboutToShutdown()
{
    return SynchronousShutdown;
}

166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
void QNXPlugin::updateDebuggerActions()
{
    bool hasValidQnxKit = false;
    ProjectExplorer::DeviceTypeMatcher qnxTypeMatcher(Constants::QNX_QNX_OS_TYPE);
    const QList<ProjectExplorer::Kit *> qnxKits = ProjectExplorer::KitManager::matchingKits(qnxTypeMatcher);

    foreach (ProjectExplorer::Kit *qnxKit, qnxKits) {
        if (qnxKit->isValid() && !ProjectExplorer::DeviceKitInformation::device(qnxKit).isNull()) {
            hasValidQnxKit = true;
            break;
        }
    }

    m_attachToQnxApplication->setVisible(hasValidQnxKit);
    m_debugSeparator->setVisible(hasValidQnxKit);
}

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
#ifdef WITH_TESTS
#include <QTest>

#include "bardescriptordocument.h"

void QNXPlugin::testBarDescriptorDocumentSetValue_data()
{
    QTest::addColumn<BarDescriptorDocument::Tag>("tag");
    QTest::addColumn<QVariant>("value");
    QTest::addColumn<QString>("baseXml");
    QTest::addColumn<QString>("xml");
    QTest::addColumn<bool>("compareResultValue");

    QTest::newRow("new-id") << BarDescriptorDocument::id
                            << QVariant(QString::fromLatin1("my-application-id"))
                            << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                   "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>\n")
                            << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                   "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                   "    <id>my-application-id</id>\n"
                                                   "</qnx>\n")
                            << true;

    QTest::newRow("changed-id") << BarDescriptorDocument::id
                                << QVariant(QString::fromLatin1("my-application-id"))
                                << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                       "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                       "    <id>some-application-id</id>\n"
                                                       "</qnx>\n")
                                << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                       "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                       "    <id>my-application-id</id>\n"
                                                       "</qnx>\n")
                                << true;


    QTest::newRow("removed-id") << BarDescriptorDocument::id
                                << QVariant(QString::fromLatin1(""))
                                << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                       "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                       "    <id>some-application-id</id>\n"
                                                       "</qnx>\n")
                                << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                       "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>\n")
                                << true;

    QStringList splashScreens;
    splashScreens << QLatin1String("image1.png")
                  << QLatin1String("image2.png");
    QTest::newRow("new-splashScreens") << BarDescriptorDocument::splashScreens
                                       << QVariant(splashScreens)
                                       << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                              "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>\n")
                                       << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                              "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                              "    <splashScreens>\n"
                                                              "        <image>image1.png</image>\n"
                                                              "        <image>image2.png</image>\n"
                                                              "    </splashScreens>\n"
                                                              "</qnx>\n")
                                       << true;

    QTest::newRow("changed-splashScreens") << BarDescriptorDocument::splashScreens
                                           << QVariant(splashScreens)
                                           << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                                  "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                                  "    <splashScreens>\n"
                                                                  "        <image>image3.png</image>\n"
                                                                  "        <image>image4.png</image>\n"
                                                                  "    </splashScreens>\n"
                                                                  "</qnx>\n")
                                           << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                                  "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                                  "    <splashScreens>\n"
                                                                  "        <image>image1.png</image>\n"
                                                                  "        <image>image2.png</image>\n"
                                                                  "    </splashScreens>\n"
                                                                  "</qnx>\n")
                                           << true;

    QTest::newRow("removed-splashScreens") << BarDescriptorDocument::splashScreens
                                           << QVariant(QStringList())
                                           << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                                  "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                                  "    <splashScreens>\n"
                                                                  "        <image>image1.png</image>\n"
                                                                  "        <image>image2.png</image>\n"
                                                                  "    </splashScreens>\n"
                                                                  "</qnx>\n")
                                           << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                                  "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>\n")
                                           << true;

    BarDescriptorAsset asset1;
    asset1.source = QLatin1String("/path/to/file");
    asset1.destination = QLatin1String("file");
    asset1.entry = false;

    BarDescriptorAsset asset2;
    asset2.source = QLatin1String("/path/to/file2");
    asset2.destination = QLatin1String("file2");
    asset2.entry = false; // Cannot test "true", as "type" and "entry" attributes show up in seemingly arbitrary order

    BarDescriptorAssetList assetList1;
    assetList1 << asset1 << asset2;

    QVariant assets;
    assets.setValue(assetList1);

    QTest::newRow("new-assets") << BarDescriptorDocument::asset
                                << assets
                                << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                       "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>\n")
                                << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                       "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                       "    <asset path=\"/path/to/file\">file</asset>\n"
                                                       "    <asset path=\"/path/to/file2\">file2</asset>\n"
                                                       "</qnx>\n")
                                << false;

    asset2.destination = QLatin1String("file3");
    BarDescriptorAssetList assetList2;
    assetList2 << asset1 << asset2;
    assets.setValue(assetList2);

    QTest::newRow("changed-assets") << BarDescriptorDocument::asset
                                    << assets
                                    << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                           "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                           "    <asset path=\"/path/to/file\">file</asset>\n"
                                                           "    <asset path=\"/path/to/file2\">file2</asset>\n"
                                                           "</qnx>\n")
                                    << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                           "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                           "    <asset path=\"/path/to/file\">file</asset>\n"
                                                           "    <asset path=\"/path/to/file2\">file3</asset>\n"
                                                           "</qnx>\n")
                                    << false;

    QTest::newRow("maintain-position") << BarDescriptorDocument::id
                                       << QVariant(QString::fromLatin1("my-application-id"))
                                       << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                              "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                              "    <asset path=\"/path/to/file\">file</asset>\n"
                                                              "    <asset path=\"/path/to/file2\">file2</asset>\n"
                                                              "    <id>some-application-id</id>\n"
                                                              "    <splashScreens>\n"
                                                              "        <image>image1.png</image>\n"
                                                              "        <image>image2.png</image>\n"
                                                              "    </splashScreens>\n"
                                                              "</qnx>\n")
                                       << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                              "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                              "    <asset path=\"/path/to/file\">file</asset>\n"
                                                              "    <asset path=\"/path/to/file2\">file2</asset>\n"
                                                              "    <id>my-application-id</id>\n"
                                                              "    <splashScreens>\n"
                                                              "        <image>image1.png</image>\n"
                                                              "        <image>image2.png</image>\n"
                                                              "    </splashScreens>\n"
                                                              "</qnx>\n")
                                       << true;

    QTest::newRow("removed-icon") << BarDescriptorDocument::icon
                                  << QVariant(QString())
                                  << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                         "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\">\n"
                                                         "    <icon>\n"
                                                         "        <image>icon1.png</image>\n"
                                                         "    </icon>\n"
                                                         "</qnx>\n")
                                  << QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n"
                                                         "<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>\n")
                                  << true;
}

void QNXPlugin::testBarDescriptorDocumentSetValue()
{
    QFETCH(BarDescriptorDocument::Tag, tag);
    QFETCH(QVariant, value);
    QFETCH(QString, baseXml);
    QFETCH(QString, xml);
    QFETCH(bool, compareResultValue);

    BarDescriptorDocument doc;
    doc.loadContent(baseXml, false);
    QCOMPARE(doc.xmlSource(), baseXml);

    doc.setValue(tag, value);
    QCOMPARE(doc.xmlSource(), xml);
    QCOMPARE(doc.isModified(), true);
    if (compareResultValue)
        QCOMPARE(doc.value(tag), value);
}

378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438
void QNXPlugin::testBarDescriptorDocumentSetBannerComment_data()
{
    QTest::addColumn<QString>("comment");
    QTest::addColumn<QString>("baseXml");
    QTest::addColumn<QString>("xml");

    QString procInstr = QString::fromLatin1("<?xml version='1.0' encoding='UTF-8' standalone='no'?>");
    QString comment = QString::fromLatin1("This file is autogenerated, any change will be ...");
    QString xmlComment = QString::fromLatin1("<!--%1-->").arg(comment);
    QString oldXmlComment = QString::fromLatin1("<!-- Some old banner comment -->");
    QString docRoot = QString::fromLatin1("<qnx xmlns=\"http://www.qnx.com/schemas/application/1.0\"/>");
    QChar lf = QChar::fromLatin1('\n');

    QTest::newRow("new-comment")
        << comment
        << QString(procInstr + lf + docRoot + lf)
        << QString(procInstr + lf + xmlComment + lf + docRoot + lf);

    QTest::newRow("new-comment-noproc")
        << comment
        << QString(docRoot + lf)
        << QString(xmlComment + lf + docRoot + lf);

    QTest::newRow("replace-comment")
        << comment
        << QString(procInstr + lf + oldXmlComment + lf + docRoot + lf)
        << QString(procInstr + lf + xmlComment + lf + docRoot + lf);

    QTest::newRow("replace-comment-noproc")
        << comment
        << QString(oldXmlComment + lf + docRoot + lf)
        << QString(xmlComment + lf + docRoot + lf);

    QTest::newRow("remove-comment")
        << QString()
        << QString(procInstr + lf + oldXmlComment + lf + docRoot + lf)
        << QString(procInstr + lf + docRoot + lf);

    QTest::newRow("remove-comment-noproc")
        << QString()
        << QString(oldXmlComment + lf + docRoot + lf)
        << QString(docRoot + lf);

}

void QNXPlugin::testBarDescriptorDocumentSetBannerComment()
{
    QFETCH(QString, comment);
    QFETCH(QString, baseXml);
    QFETCH(QString, xml);

    BarDescriptorDocument doc;
    doc.loadContent(baseXml, false);
    QCOMPARE(doc.xmlSource(), baseXml);

    doc.setBannerComment(comment);
    QCOMPARE(doc.xmlSource(), xml);
    QCOMPARE(doc.isModified(), true);
    QCOMPARE(doc.bannerComment(), comment);
}

439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
void QNXPlugin::testConfigurationManager_data()
{
    const QLatin1String NDKEnvFileKey("NDKEnvFile");
    const QLatin1String NDKPathKey("NDKPath");
    const QLatin1String NDKDisplayNameKey("NDKDisplayName");
    const QLatin1String NDKTargetKey("NDKTarget");
    const QLatin1String NDKHostKey("NDKHost");
    const QLatin1String NDKVersionKey("NDKVersion");
    const QLatin1String NDKAutoDetectionSourceKey("NDKAutoDetectionSource");
    const QLatin1String NDKAutoDetectedKey("NDKAutoDetectedKey");

    QTest::addColumn<QVariantMap>("newerConfiguration");
    QTest::addColumn<QVariantMap>("olderConfiguration");

    QVariantMap newerConfiguration;
    newerConfiguration.insert(NDKEnvFileKey, QLatin1String("bbndk-env.sh"));
    newerConfiguration.insert(NDKPathKey, QLatin1String("NDKPath"));
    newerConfiguration.insert(NDKDisplayNameKey, QLatin1String("NDKDisplayName"));
    newerConfiguration.insert(NDKTargetKey, QLatin1String("NDKTarget"));
    newerConfiguration.insert(NDKHostKey, QLatin1String("NDKHost"));
    newerConfiguration.insert(NDKVersionKey, QLatin1String("10.1.0.1008"));
    newerConfiguration.insert(NDKAutoDetectionSourceKey, QLatin1String("NDKAutoDetectionSource"));
    newerConfiguration.insert(NDKAutoDetectedKey, QLatin1String("NDKAutoDetectedKey"));

    QVariantMap olderConfiguration;
    olderConfiguration.insert(NDKEnvFileKey, QLatin1String("bbndk-env2.sh"));
    olderConfiguration.insert(NDKPathKey, QLatin1String("NDKPath"));
    olderConfiguration.insert(NDKDisplayNameKey, QLatin1String("NDKDisplayName"));
    olderConfiguration.insert(NDKTargetKey, QLatin1String("NDKTarget"));
    olderConfiguration.insert(NDKHostKey, QLatin1String("NDKHost"));
    newerConfiguration.insert(NDKVersionKey, QLatin1String("10.2.0.1008"));
    olderConfiguration.insert(NDKAutoDetectionSourceKey, QLatin1String("NDKAutoDetectionSource"));
    olderConfiguration.insert(NDKAutoDetectedKey, QLatin1String("NDKAutoDetectedKey"));

    QTest::newRow("configurations") << newerConfiguration << olderConfiguration;;
}

void QNXPlugin::testConfigurationManager()
{
    BlackBerryConfigurationManager &manager = BlackBerryConfigurationManager::instance();

    QCOMPARE(manager.configurations().count(), 0);
    QCOMPARE(manager.activeConfigurations().count(), 0);
    QCOMPARE(manager.defaultConfiguration(), static_cast<BlackBerryConfiguration*>(0));
    QVERIFY(manager.newestConfigurationEnabled());

    QFETCH(QVariantMap, newerConfiguration);
    QFETCH(QVariantMap, olderConfiguration);

    BlackBerryConfiguration::setFakeConfig(true);
    BlackBerryConfiguration *newerConfig = new BlackBerryConfiguration(newerConfiguration);
    BlackBerryConfiguration *oldConfig = new BlackBerryConfiguration(olderConfiguration);

    QVERIFY(manager.addConfiguration(oldConfig));
    QVERIFY(manager.newestConfigurationEnabled());
    QCOMPARE(manager.defaultConfiguration(), oldConfig);

    manager.setDefaultConfiguration(oldConfig);

    QCOMPARE(manager.defaultConfiguration(), oldConfig);
    QCOMPARE(manager.configurations().first(), oldConfig);
    QVERIFY(!manager.newestConfigurationEnabled());

    QVERIFY(manager.addConfiguration(newerConfig));
    QCOMPARE(manager.configurations().first(), newerConfig);
    QCOMPARE(manager.defaultConfiguration(), oldConfig);

    manager.setDefaultConfiguration(0);
    QVERIFY(manager.newestConfigurationEnabled());
    QCOMPARE(manager.defaultConfiguration(), newerConfig);

    manager.setDefaultConfiguration(oldConfig);
    manager.removeConfiguration(oldConfig);
    QCOMPARE(manager.defaultConfiguration(), newerConfig);
    QVERIFY(manager.newestConfigurationEnabled());

    manager.removeConfiguration(newerConfig);
    QCOMPARE(manager.defaultConfiguration(), static_cast<BlackBerryConfiguration*>(0));
    QVERIFY(manager.newestConfigurationEnabled());
}

520 521
#endif

Tobias Nätterlund's avatar
Tobias Nätterlund committed
522
Q_EXPORT_PLUGIN2(QNX, QNXPlugin)