Skip to content
Snippets Groups Projects
Commit 7ad113b4 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Device support: Add test for device manager.


Change-Id: Ie2ed6a3c93cd5d47e23ed68fb850ebed728cb667
Reviewed-by: default avatarChristian Kandeler <christian.kandeler@nokia.com>
parent b5a0ac30
No related branches found
No related tags found
No related merge requests found
......@@ -82,9 +82,9 @@ DeviceManager *DeviceManagerPrivate::clonedInstance = 0;
using namespace Internal;
DeviceManager *DeviceManager::instance()
DeviceManager *DeviceManager::instance(const QString &magicTestToken)
{
static DeviceManager deviceManager(true);
static DeviceManager deviceManager(magicTestToken != QLatin1String("magicTestToken"));
return &deviceManager;
}
......
......@@ -56,7 +56,7 @@ class PROJECTEXPLORER_EXPORT DeviceManager : public QObject
public:
~DeviceManager();
static DeviceManager *instance();
static DeviceManager *instance(const QString &magicTestToken = QString());
int deviceCount() const;
IDevice::ConstPtr deviceAt(int index) const;
......
include(../devices.pri)
TARGET=devicemanagertest
SOURCES= \
main.cpp \
devicemanagertest.cpp
HEADERS += \
devicemanagertest.h
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "devicemanagertest.h"
#include <projectexplorer/devicesupport/devicemanager.h>
#include <remotelinux/linuxdeviceconfiguration.h>
#include <utils/qtcassert.h>
#include <QCoreApplication>
#include <cstdlib>
#include <iostream>
using namespace ProjectExplorer;
using namespace RemoteLinux;
#define DEV_MGR_CHECK(cond) QTC_ASSERT(cond, exit(1))
DeviceManagerTest::DeviceManagerTest(QObject *parent) : QObject(parent)
{
}
void DeviceManagerTest::run()
{
DeviceManager * const devMgr = DeviceManager::instance("magicTestToken");
DEV_MGR_CHECK(m_slotsCalled.isEmpty());
connect(devMgr, SIGNAL(deviceAdded(Core::Id)), SLOT(handleDeviceAdded(Core::Id)));
connect(devMgr, SIGNAL(deviceRemoved(Core::Id)), SLOT(handleDeviceRemoved(Core::Id)));
connect(devMgr, SIGNAL(deviceUpdated(Core::Id)), SLOT(handleDeviceUpdated(Core::Id)));
connect(devMgr, SIGNAL(updated()), SLOT(handleUpdated()));
connect(devMgr, SIGNAL(deviceListChanged()), SLOT(handleDeviceListChanged()));
std::cout << "Initial add." << std::endl;
m_currentId = m_currentUpdateId = Core::Id("id1");
LinuxDeviceConfiguration::Ptr device = LinuxDeviceConfiguration::create("blubb", "mytype",
LinuxDeviceConfiguration::Hardware, IDevice::AutoDetected, m_currentId);
devMgr->addDevice(device);
DEV_MGR_CHECK(devMgr->deviceCount() == 1);
DEV_MGR_CHECK(devMgr->defaultDevice("mytype") == device);
DEV_MGR_CHECK(m_slotsCalled.count() == 2);
DEV_MGR_CHECK(m_slotsCalled.contains(SlotDeviceAdded));
DEV_MGR_CHECK(m_slotsCalled.contains(SlotUpdated));
std::cout << "Add with different id, but same name." << std::endl;
m_slotsCalled.clear();
m_currentId = Core::Id("id2");
m_currentUpdateId = Core::Id("doesnotexist");
device = LinuxDeviceConfiguration::create("blubb", "mytype",
LinuxDeviceConfiguration::Hardware, IDevice::AutoDetected, m_currentId);
devMgr->addDevice(device);
DEV_MGR_CHECK(devMgr->deviceCount() == 2);
DEV_MGR_CHECK(devMgr->defaultDevice("mytype")->id() == Core::Id("id1"));
DEV_MGR_CHECK(m_slotsCalled.count() == 2);
DEV_MGR_CHECK(m_slotsCalled.contains(SlotDeviceAdded));
DEV_MGR_CHECK(m_slotsCalled.contains(SlotUpdated));
DEV_MGR_CHECK(devMgr->deviceAt(1)->displayName() == "blubb (2)");
std::cout << "Add with same id." << std::endl;
m_slotsCalled.clear();
m_currentId = m_currentUpdateId = Core::Id("id1");
device = LinuxDeviceConfiguration::create("blubbblubb", "mytype",
LinuxDeviceConfiguration::Hardware, IDevice::AutoDetected, m_currentId);
devMgr->addDevice(device);
DEV_MGR_CHECK(devMgr->deviceCount() == 2);
DEV_MGR_CHECK(devMgr->defaultDevice("mytype")->id() == Core::Id("id1"));
DEV_MGR_CHECK(m_slotsCalled.count() == 2);
DEV_MGR_CHECK(m_slotsCalled.contains(SlotDeviceUpdated));
DEV_MGR_CHECK(m_slotsCalled.contains(SlotUpdated));
DEV_MGR_CHECK(devMgr->deviceAt(0)->displayName() == "blubbblubb");
std::cout << "Remove." << std::endl;
m_slotsCalled.clear();
m_currentId = Core::Id("id1");
m_currentUpdateId = Core::Id("id2");
devMgr->removeDevice(m_currentId);
DEV_MGR_CHECK(devMgr->deviceCount() == 1);
DEV_MGR_CHECK(devMgr->defaultDevice("mytype")->id() == Core::Id("id2"));
DEV_MGR_CHECK(m_slotsCalled.count() == 3);
DEV_MGR_CHECK(m_slotsCalled.contains(SlotDeviceRemoved));
DEV_MGR_CHECK(m_slotsCalled.contains(SlotDeviceUpdated));
DEV_MGR_CHECK(m_slotsCalled.contains(SlotUpdated));
std::cout << "All tests finished successfully." << std::endl;
qApp->quit();
}
void DeviceManagerTest::handleDeviceAdded(Core::Id id)
{
DEV_MGR_CHECK(id == m_currentId);
m_slotsCalled << SlotDeviceAdded;
}
void DeviceManagerTest::handleDeviceRemoved(Core::Id id)
{
DEV_MGR_CHECK(id == m_currentId);
m_slotsCalled << SlotDeviceRemoved;
}
void DeviceManagerTest::handleDeviceUpdated(Core::Id id)
{
DEV_MGR_CHECK(id == m_currentUpdateId);
m_slotsCalled << SlotDeviceUpdated;
}
void DeviceManagerTest::handleDeviceListChanged()
{
qWarning("deviceListChanged() unexpectedly called.");
qApp->exit(1);
}
void DeviceManagerTest::handleUpdated()
{
m_slotsCalled << SlotUpdated;
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef DEVICEMANAGERTEST_H
#define DEVICEMANAGERTEST_H
#include <coreplugin/id.h>
#include <QList>
#include <QObject>
class DeviceManagerTest : public QObject
{
Q_OBJECT
public:
explicit DeviceManagerTest(QObject *parent = 0);
public slots:
void run();
private slots:
void handleDeviceAdded(Core::Id id);
void handleDeviceRemoved(Core::Id id);
void handleDeviceUpdated(Core::Id id);
void handleDeviceListChanged();
void handleUpdated();
private:
enum Slot {
SlotDeviceAdded, SlotDeviceRemoved, SlotDeviceUpdated, SlotDeviceListChanged,
SlotUpdated
};
QList<Slot> m_slotsCalled;
Core::Id m_currentId;
Core::Id m_currentUpdateId;
};
#endif // DEVICEMANAGERTEST_H
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "devicemanagertest.h"
#include <QCoreApplication>
#include <QTimer>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
DeviceManagerTest devMgrTest;
QTimer::singleShot(0, &devMgrTest, SLOT(run()));
return app.exec();
}
QT = core
include (../../../qtcreator.pri)
include (../../../src/plugins/remotelinux/remotelinux.pri)
LIBS += -L$$IDE_PLUGIN_PATH/Nokia
macx:QMAKE_LFLAGS += -Wl,-rpath,\"$$IDE_BIN_PATH/..\"
INCLUDEPATH *= $$IDE_SOURCE_TREE/src/plugins
LIBS *= -L$$IDE_LIBRARY_PATH/Nokia
unix {
QMAKE_LFLAGS += -Wl,-rpath,\"$$IDE_PLUGIN_PATH/..\"
QMAKE_LFLAGS += -Wl,-rpath,\"$$IDE_PLUGIN_PATH/Nokia\"
}
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
DEPENDPATH+=.
INCLUDEPATH+=.
TEMPLATE = subdirs
SUBDIRS = devicemanager
......@@ -6,7 +6,8 @@ fakevim \
debugger \
preprocessor \
subdir_proparser \
utils
utils \
devices
unix {
# Uses popen
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment