more tests
This commit is contained in:
89
tests/core/TestDevice.cpp
Normal file
89
tests/core/TestDevice.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
#include <QtTest>
|
||||
#include <LocalSendCore/Device.h>
|
||||
|
||||
class TestDevice : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testDefaultConstructor();
|
||||
void testParameterizedConstructor();
|
||||
void testDisplayNameWithAlias();
|
||||
void testDisplayNameWithoutAlias();
|
||||
void testIsHttps();
|
||||
void testEqualityByFingerprint();
|
||||
void testInequality();
|
||||
};
|
||||
|
||||
void TestDevice::testDefaultConstructor()
|
||||
{
|
||||
LocalSend::Device device;
|
||||
QVERIFY(device.ip.isEmpty());
|
||||
QCOMPARE(device.port, quint16(53317));
|
||||
QCOMPARE(device.protocol, LocalSend::ProtocolType::Http);
|
||||
QVERIFY(device.alias.isEmpty());
|
||||
QVERIFY(device.fingerprint.isEmpty());
|
||||
QCOMPARE(device.deviceType, LocalSend::DeviceType::Desktop);
|
||||
QVERIFY(!device.download);
|
||||
QCOMPARE(device.discoveryMethod, LocalSend::DiscoveryMethod::Multicast);
|
||||
QVERIFY(!device.lastSeen.isValid());
|
||||
}
|
||||
|
||||
void TestDevice::testParameterizedConstructor()
|
||||
{
|
||||
LocalSend::Device device(QStringLiteral("192.168.1.100"), 8080);
|
||||
QCOMPARE(device.ip, QStringLiteral("192.168.1.100"));
|
||||
QCOMPARE(device.port, quint16(8080));
|
||||
}
|
||||
|
||||
void TestDevice::testDisplayNameWithAlias()
|
||||
{
|
||||
LocalSend::Device device;
|
||||
device.alias = QStringLiteral("My Laptop");
|
||||
QCOMPARE(device.displayName(), QStringLiteral("My Laptop"));
|
||||
}
|
||||
|
||||
void TestDevice::testDisplayNameWithoutAlias()
|
||||
{
|
||||
LocalSend::Device device;
|
||||
device.ip = QStringLiteral("192.168.1.50");
|
||||
QCOMPARE(device.displayName(), QStringLiteral("192.168.1.50"));
|
||||
}
|
||||
|
||||
void TestDevice::testIsHttps()
|
||||
{
|
||||
LocalSend::Device httpDevice;
|
||||
httpDevice.protocol = LocalSend::ProtocolType::Http;
|
||||
QVERIFY(!httpDevice.isHttps());
|
||||
|
||||
LocalSend::Device httpsDevice;
|
||||
httpsDevice.protocol = LocalSend::ProtocolType::Https;
|
||||
QVERIFY(httpsDevice.isHttps());
|
||||
}
|
||||
|
||||
void TestDevice::testEqualityByFingerprint()
|
||||
{
|
||||
LocalSend::Device a;
|
||||
a.fingerprint = QStringLiteral("fp123");
|
||||
a.ip = QStringLiteral("10.0.0.1");
|
||||
|
||||
LocalSend::Device b;
|
||||
b.fingerprint = QStringLiteral("fp123");
|
||||
b.ip = QStringLiteral("10.0.0.2");
|
||||
|
||||
QVERIFY(a == b);
|
||||
}
|
||||
|
||||
void TestDevice::testInequality()
|
||||
{
|
||||
LocalSend::Device a;
|
||||
a.fingerprint = QStringLiteral("fp1");
|
||||
|
||||
LocalSend::Device b;
|
||||
b.fingerprint = QStringLiteral("fp2");
|
||||
|
||||
QVERIFY(a != b);
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestDevice)
|
||||
#include "TestDevice.moc"
|
||||
Reference in New Issue
Block a user