diff options
author | Lucie Gerard <lucie.gerard@qt.io> | 2018-02-02 12:42:49 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2018-02-04 23:24:23 +0000 |
commit | b35742650330392615bdd503679864bd0f82d050 (patch) | |
tree | 0b201c42eb0638babc9c7f74951b10386357674d /tests/auto/qknxtunnelframefactory/tst_qknxtunnelframefactory.cpp | |
parent | c5efd03382700c10cf3af1bc75a390a02e845035 (diff) |
Add tunnel frame factory for A_Memory services and auto test
Change-Id: I5c3893214899fa39ad33ee597412ec8305852c39
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
Diffstat (limited to 'tests/auto/qknxtunnelframefactory/tst_qknxtunnelframefactory.cpp')
-rw-r--r-- | tests/auto/qknxtunnelframefactory/tst_qknxtunnelframefactory.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/auto/qknxtunnelframefactory/tst_qknxtunnelframefactory.cpp b/tests/auto/qknxtunnelframefactory/tst_qknxtunnelframefactory.cpp index b0b13c6..fd894c6 100644 --- a/tests/auto/qknxtunnelframefactory/tst_qknxtunnelframefactory.cpp +++ b/tests/auto/qknxtunnelframefactory/tst_qknxtunnelframefactory.cpp @@ -38,6 +38,9 @@ private Q_SLOTS: void testGroupValueRead(); void testGroupValueResponse(); void testGroupValueWrite(); + void testMemoryRead(); + void testMemoryResponse(); + void testMemoryWrite(); }; void tst_QKnxLinkLayerFrameFactory::testGroupValueRead() @@ -110,6 +113,92 @@ void tst_QKnxLinkLayerFrameFactory::testGroupValueWrite() QCOMPARE(frame.controlField().frameType(), QKnxControlField::FrameType::Standard); } +void tst_QKnxLinkLayerFrameFactory::testMemoryRead() +{ + QKnxAddress source { QKnxAddress::Type::Individual, 0 }; + QKnxAddress destination { QKnxAddress::Type::Individual, QString("1.2.3") }; + auto frame = QKnxLinkLayerFrameFactory::Memory::createReadRequest(source, destination, 52, 3); + QCOMPARE(frame.extendedControlField().destinationAddressType(), QKnxAddress::Type::Individual); + QCOMPARE(frame.extendedControlField().bytes(), quint8(96)); + QCOMPARE(frame.tpdu().bytes(), QVector<quint8>({ 0x42, 0x03, 0x00, 0x34 })); + QCOMPARE(frame.bytes(), QByteArray::fromHex("1100b460000012030342030034")); + QCOMPARE(frame.controlField().frameType(), QKnxControlField::FrameType::Standard); + + QKnxAddress destinationWrong = { QKnxAddress::Type::Group, QString("0.0.2") }; + frame = QKnxLinkLayerFrameFactory::Memory::createReadRequest(source, destinationWrong, 52, 3); + QCOMPARE(frame.bytes(), QKnxLinkLayerFrame().bytes()); + + source = { QKnxAddress::Type::Individual, QString("1.1.2") }; + frame = QKnxLinkLayerFrameFactory::Memory::createReadConfirmation(source, destination, 52, 3, 0, + QKnxControlField::Confirm::NoError); + QCOMPARE(frame.bytes(), QByteArray::fromHex("2e00b460110212030342030034")); + QCOMPARE(frame.controlField().frameType(), QKnxControlField::FrameType::Standard); + + frame = QKnxLinkLayerFrameFactory::Memory::createReadIndication(source, destination, 52, 3); + QCOMPARE(frame.bytes(), QByteArray::fromHex("2900b460110212030342030034")); + QCOMPARE(frame.controlField().frameType(), QKnxControlField::FrameType::Standard); +} + +void tst_QKnxLinkLayerFrameFactory::testMemoryResponse() +{ + QVector<quint8> data({ 0x01, 0x02, 0x03 }); + QKnxAddress source { QKnxAddress::Type::Individual, 0 }; + QKnxAddress destination { QKnxAddress::Type::Individual, QString("1.2.3") }; + auto frame = QKnxLinkLayerFrameFactory::Memory::createResponseRequest(source, destination, 52, 3, + data); + QCOMPARE(frame.extendedControlField().destinationAddressType(), QKnxAddress::Type::Individual); + QCOMPARE(frame.extendedControlField().bytes(), quint8(96)); + QCOMPARE(frame.tpdu().bytes(), QVector<quint8>({ 0x42, 0x43, 0x00, 0x34, 0x01, 0x02, 0x03 })); + QCOMPARE(frame.bytes(), QByteArray::fromHex("1100b460000012030642430034010203")); + QCOMPARE(frame.controlField().frameType(), QKnxControlField::FrameType::Standard); + + QKnxAddress destinationWrong = { QKnxAddress::Type::Group, QString("0.0.2") }; + frame = QKnxLinkLayerFrameFactory::Memory::createResponseRequest(source, destinationWrong, 52, 3, + data); + QCOMPARE(frame.bytes(), QKnxLinkLayerFrame().bytes()); + + source = { QKnxAddress::Type::Individual, QString("1.1.2") }; + frame = QKnxLinkLayerFrameFactory::Memory::createResponseConfirmation(source, destination, 52, 3, + data, 0, QKnxControlField::Confirm::NoError); + QCOMPARE(frame.bytes(), QByteArray::fromHex("2e00b460110212030642430034010203")); + QCOMPARE(frame.controlField().frameType(), QKnxControlField::FrameType::Standard); + + frame = QKnxLinkLayerFrameFactory::Memory::createResponseIndication(source, destination, 52, 3, + data); + QCOMPARE(frame.bytes(), QByteArray::fromHex("2900b460110212030642430034010203")); + QCOMPARE(frame.controlField().frameType(), QKnxControlField::FrameType::Standard); +} + +void tst_QKnxLinkLayerFrameFactory::testMemoryWrite() +{ + QVector<quint8> data({ 0x01, 0x02, 0x03 }); + QKnxAddress source { QKnxAddress::Type::Individual, 0 }; + QKnxAddress destination { QKnxAddress::Type::Individual, QString("1.2.3") }; + auto frame = QKnxLinkLayerFrameFactory::Memory::createWriteRequest(source, destination, 52, 3, + data); + QCOMPARE(frame.extendedControlField().destinationAddressType(), QKnxAddress::Type::Individual); + QCOMPARE(frame.extendedControlField().bytes(), quint8(96)); + QCOMPARE(frame.tpdu().bytes(), QVector<quint8>({ 0x42, 0x83, 0x00, 0x34, 0x01, 0x02, 0x03 })); + QCOMPARE(frame.bytes(), QByteArray::fromHex("1100b460000012030642830034010203")); + QCOMPARE(frame.controlField().frameType(), QKnxControlField::FrameType::Standard); + + QKnxAddress destinationWrong = { QKnxAddress::Type::Group, QString("0.0.2") }; + frame = QKnxLinkLayerFrameFactory::Memory::createWriteRequest(source, destinationWrong, 52, 3, + data); + QCOMPARE(frame.bytes(), QKnxLinkLayerFrame().bytes()); + + source = { QKnxAddress::Type::Individual, QString("1.1.2") }; + frame = QKnxLinkLayerFrameFactory::Memory::createWriteConfirmation(source, destination, 52, 3, + data, 0, QKnxControlField::Confirm::NoError); + QCOMPARE(frame.bytes(), QByteArray::fromHex("2e00b460110212030642830034010203")); + QCOMPARE(frame.controlField().frameType(), QKnxControlField::FrameType::Standard); + + frame = QKnxLinkLayerFrameFactory::Memory::createWriteIndication(source, destination, 52, 3, + data); + QCOMPARE(frame.bytes(), QByteArray::fromHex("2900b460110212030642830034010203")); + QCOMPARE(frame.controlField().frameType(), QKnxControlField::FrameType::Standard); +} + QTEST_APPLESS_MAIN(tst_QKnxLinkLayerFrameFactory) #include "tst_qknxtunnelframefactory.moc" |