AusweisApp2/test/qt/remote_device/test_RemoteDeviceListImpl.cpp

78 lines
1.9 KiB
C++
Raw Permalink Normal View History

2017-12-20 14:54:05 +01:00
/*!
2019-05-22 10:08:38 +02:00
* \copyright Copyright (c) 2017-2019 Governikus GmbH & Co. KG, Germany
2017-12-20 14:54:05 +01:00
*/
#include "RemoteDeviceList.h"
#include "messages/Discovery.h"
2019-09-30 17:22:19 +02:00
#include <QtTest>
2017-12-20 14:54:05 +01:00
using namespace governikus;
class test_RemoteDeviceListImpl
: public QObject
{
Q_OBJECT
private Q_SLOTS:
void testAddAndRemove()
{
RemoteDeviceListImpl deviceList(10, 1);
QSignalSpy spyVanished(&deviceList, &RemoteDeviceListImpl::fireDeviceVanished);
2019-01-03 15:06:22 +01:00
const Discovery offerMsg1 = Discovery("Dev1", QStringLiteral("0123456789ABCDEF"), 1234, {IfdVersion::Version::v0});
const Discovery offerMsg2 = Discovery("Dev1", QStringLiteral("0123456789ABCDFF"), 1234, {IfdVersion::Version::v0});
const QHostAddress addr1 = QHostAddress(QString("5.6.7.8"));
const QHostAddress addr2 = QHostAddress(QString("5.6.7.9"));
2017-12-20 14:54:05 +01:00
{
const RemoteDeviceDescriptor descr(offerMsg1, addr1);
QSignalSpy spy(&deviceList, &RemoteDeviceListImpl::fireDeviceAppeared);
deviceList.update(descr);
QCOMPARE(spy.count(), 1);
}
{
2019-01-03 15:06:22 +01:00
const RemoteDeviceDescriptor descr(offerMsg1, addr1);
2017-12-20 14:54:05 +01:00
QSignalSpy spy(&deviceList, &RemoteDeviceListImpl::fireDeviceAppeared);
deviceList.update(descr);
QCOMPARE(spy.count(), 0);
}
{
const RemoteDeviceDescriptor descr(offerMsg1, addr2);
2019-01-03 15:06:22 +01:00
QSignalSpy spy(&deviceList, &RemoteDeviceListImpl::fireDeviceAppeared);
deviceList.update(descr);
QCOMPARE(spy.count(), 0);
}
{
const RemoteDeviceDescriptor descr(offerMsg2, addr2);
2017-12-20 14:54:05 +01:00
QSignalSpy spy(&deviceList, &RemoteDeviceListImpl::fireDeviceAppeared);
deviceList.update(descr);
QCOMPARE(spy.count(), 1);
}
2019-01-03 15:06:22 +01:00
{
const RemoteDeviceDescriptor descr(offerMsg2, addr1);
QSignalSpy spy(&deviceList, &RemoteDeviceListImpl::fireDeviceAppeared);
deviceList.update(descr);
QCOMPARE(spy.count(), 0);
}
QTRY_COMPARE(spyVanished.count(), 2);
2017-12-20 14:54:05 +01:00
}
};
QTEST_GUILESS_MAIN(test_RemoteDeviceListImpl)
#include "test_RemoteDeviceListImpl.moc"