init commit
This commit is contained in:
122
tests/core/TestDtoTypes.cpp
Normal file
122
tests/core/TestDtoTypes.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
#include <QtTest>
|
||||
#include <LocalSendCore/DtoTypes.h>
|
||||
#include <LocalSendCore/Constants.h>
|
||||
|
||||
class TestDtoTypes : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testMulticastDtoSerialization();
|
||||
void testInfoDtoSerialization();
|
||||
void testRegisterDtoSerialization();
|
||||
void testFileDtoSerialization();
|
||||
void testPrepareUploadRequestDto();
|
||||
};
|
||||
|
||||
void TestDtoTypes::testMulticastDtoSerialization()
|
||||
{
|
||||
LocalSend::MulticastDto dto;
|
||||
dto.alias = QStringLiteral("Test Device");
|
||||
dto.version = LocalSend::PROTOCOL_VERSION;
|
||||
dto.deviceModel = QStringLiteral("Test Model");
|
||||
dto.deviceType = LocalSend::DeviceType::Desktop;
|
||||
dto.fingerprint = QStringLiteral("abc123");
|
||||
dto.port = 53317;
|
||||
dto.protocol = LocalSend::ProtocolType::Http;
|
||||
dto.download = false;
|
||||
dto.announcement = true;
|
||||
dto.announce = true;
|
||||
|
||||
QJsonObject json = dto.toJson();
|
||||
LocalSend::MulticastDto parsed = LocalSend::MulticastDto::fromJson(json);
|
||||
|
||||
QCOMPARE(parsed.alias, dto.alias);
|
||||
QCOMPARE(parsed.version, dto.version);
|
||||
QCOMPARE(parsed.deviceModel, dto.deviceModel);
|
||||
QCOMPARE(parsed.deviceType, dto.deviceType);
|
||||
QCOMPARE(parsed.fingerprint, dto.fingerprint);
|
||||
QCOMPARE(parsed.port, dto.port);
|
||||
QCOMPARE(parsed.protocol, dto.protocol);
|
||||
QCOMPARE(parsed.download, dto.download);
|
||||
QCOMPARE(parsed.announcement, dto.announcement);
|
||||
QCOMPARE(parsed.announce, dto.announce);
|
||||
}
|
||||
|
||||
void TestDtoTypes::testInfoDtoSerialization()
|
||||
{
|
||||
LocalSend::InfoDto dto;
|
||||
dto.alias = QStringLiteral("My Device");
|
||||
dto.version = QStringLiteral("2.1");
|
||||
dto.deviceModel = QStringLiteral("Desktop");
|
||||
dto.deviceType = LocalSend::DeviceType::Desktop;
|
||||
dto.fingerprint = QStringLiteral("def456");
|
||||
dto.download = true;
|
||||
|
||||
QJsonObject json = dto.toJson();
|
||||
LocalSend::InfoDto parsed = LocalSend::InfoDto::fromJson(json);
|
||||
|
||||
QCOMPARE(parsed.alias, dto.alias);
|
||||
QCOMPARE(parsed.version, dto.version);
|
||||
QCOMPARE(parsed.fingerprint, dto.fingerprint);
|
||||
}
|
||||
|
||||
void TestDtoTypes::testRegisterDtoSerialization()
|
||||
{
|
||||
LocalSend::RegisterDto dto;
|
||||
dto.alias = QStringLiteral("Sender");
|
||||
dto.port = 53318;
|
||||
dto.protocol = LocalSend::ProtocolType::Https;
|
||||
|
||||
QJsonObject json = dto.toJson();
|
||||
LocalSend::RegisterDto parsed = LocalSend::RegisterDto::fromJson(json);
|
||||
|
||||
QCOMPARE(parsed.port, dto.port);
|
||||
QCOMPARE(parsed.protocol, dto.protocol);
|
||||
}
|
||||
|
||||
void TestDtoTypes::testFileDtoSerialization()
|
||||
{
|
||||
LocalSend::FileDto dto;
|
||||
dto.id = QStringLiteral("file1");
|
||||
dto.fileName = QStringLiteral("test.txt");
|
||||
dto.size = 1024;
|
||||
dto.fileType = QStringLiteral("text/plain");
|
||||
dto.hash = QStringLiteral("sha256hash");
|
||||
|
||||
QJsonObject json = dto.toJson();
|
||||
LocalSend::FileDto parsed = LocalSend::FileDto::fromJson(json);
|
||||
|
||||
QCOMPARE(parsed.id, dto.id);
|
||||
QCOMPARE(parsed.fileName, dto.fileName);
|
||||
QCOMPARE(parsed.size, dto.size);
|
||||
QCOMPARE(parsed.fileType, dto.fileType);
|
||||
}
|
||||
|
||||
void TestDtoTypes::testPrepareUploadRequestDto()
|
||||
{
|
||||
LocalSend::PrepareUploadRequestDto dto;
|
||||
dto.info.alias = QStringLiteral("Sender");
|
||||
|
||||
LocalSend::FileDto file1;
|
||||
file1.id = QStringLiteral("f1");
|
||||
file1.fileName = QStringLiteral("file1.txt");
|
||||
file1.size = 100;
|
||||
dto.files.insert(QStringLiteral("f1"), file1);
|
||||
|
||||
LocalSend::FileDto file2;
|
||||
file2.id = QStringLiteral("f2");
|
||||
file2.fileName = QStringLiteral("file2.txt");
|
||||
file2.size = 200;
|
||||
dto.files.insert(QStringLiteral("f2"), file2);
|
||||
|
||||
QJsonObject json = dto.toJson();
|
||||
LocalSend::PrepareUploadRequestDto parsed = LocalSend::PrepareUploadRequestDto::fromJson(json);
|
||||
|
||||
QCOMPARE(parsed.files.size(), 2);
|
||||
QCOMPARE(parsed.files[QStringLiteral("f1")].fileName, QStringLiteral("file1.txt"));
|
||||
QCOMPARE(parsed.files[QStringLiteral("f2")].size, 200);
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestDtoTypes)
|
||||
#include "TestDtoTypes.moc"
|
||||
19
tests/core/TestMulticastDiscovery.cpp
Normal file
19
tests/core/TestMulticastDiscovery.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <QtTest>
|
||||
#include <LocalSendCore/MulticastDiscovery.h>
|
||||
|
||||
class TestMulticastDiscovery : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testDefaults();
|
||||
};
|
||||
|
||||
void TestMulticastDiscovery::testDefaults()
|
||||
{
|
||||
LocalSend::MulticastDiscovery discovery;
|
||||
QVERIFY(!discovery.parent());
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestMulticastDiscovery)
|
||||
#include "TestMulticastDiscovery.moc"
|
||||
Reference in New Issue
Block a user