// Copyright (C) 2017 Witekio. // Copyright (C) 2018 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include #include #include #include #include class tst_QCoapResource : public QObject { Q_OBJECT private Q_SLOTS: void parseCoreLink_data(); void parseCoreLink(); }; void tst_QCoapResource::parseCoreLink_data() { QTest::addColumn("resourceNumber"); QTest::addColumn("senderAddress"); QTest::addColumn>("pathList"); QTest::addColumn>("titleList"); QTest::addColumn>("resourceTypeList"); QTest::addColumn>("contentFormatList"); QTest::addColumn>("interfaceList"); QTest::addColumn>("maximumSizeList"); QTest::addColumn>("observableList"); QTest::addColumn("coreLinkList"); QList pathList; pathList << "/obs" << "/separate" << "/seg1" << "/seg1/seg2" << "/large-separate" << "/.well-known/core" << "/multi-format" << "/path" << "/path/sub1" << "/link1" << "/validate" << "/test" << "/query" << "/large-post" << "/obs-non" << "/shutdown"; QList titleList; titleList << "Observable resource which changes every 5 seconds" << "Resource which cannot be served immediately and which cannot be acknowledged in a piggy-backed way" << "Long path resource" << "Long path resource" << "Large resource" << "" << "Resource that exists in different content formats (text/plain utf8 and application/xml)" << "Hierarchical link description entry" << "Hierarchical link description sub-resource" << "Link test resource" << "Resource which varies" << "Default test resource" << "Resource accepting query parameters" << "Handle PostOperation with two-way blockwise transfer" << "Observable resource which changes every 5 seconds" << ""; QList resourceTypeList; resourceTypeList << "observe" << "" << "" << "" << "block" << "" << "" << "" << "" << "Type1 Type2" << "" << "" << "" << "block" << "observe" << ""; QList contentFormatList; contentFormatList << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 40 << 0 << 0 << 0 << 0 << 0 << 0 << 0 << 0; QList interfaceList; interfaceList << "" << "" << "" << "" << "" << "" << "" << "" << "" << "If1" << "" << "" << "" << "" << "" << ""; QList maximumSizeList; maximumSizeList << -1 << -1 << -1 << -1 << 1280 << -1 << -1 << -1 << -1 << -1 << -1 << -1 << -1 << -1 << -1 << -1; QList observableList; observableList << true << false << false << false << false << false << false << false << false << false << false << false << false << false << true << false; QByteArray coreLinks; // Resources are separated by a comma coreLinks.append(";obs;rt=\"observe\";title=\"Observable resource which changes every" " 5 seconds\",;title=\"Resource which cannot be served immediately" " and which cannot be acknowledged in a piggy-backed way\",;title=\"" "Long path resource\",;title=\"Long path resource\"," ";rt=\"block\";sz=1280;title=\"Large resource\"," ",;ct=\"0 41\";title=\"Resource that exists" " in different content formats (text/plain utf8 and application/xml)\"," ";ct=40;title=\"Hierarchical link description entry\",;" "title=\"Hierarchical link description sub-resource\",;if=\"If1\";" "rt=\"Type1 Type2\";title=\"Link test resource\",;title=\"Resource" " which varies\",;title=\"Default test resource\",;" "title=\"Resource accepting query parameters\",;rt=\"block\";" "title=\"Handle PostOperation with two-way blockwise transfer\",;" "obs;rt=\"observe\";title=\"Observable resource which changes every 5 " "seconds\","); QTest::newRow("parse") << 16 << QString("10.20.30.40") << pathList << titleList << resourceTypeList << contentFormatList << interfaceList << maximumSizeList << observableList << coreLinks; } void tst_QCoapResource::parseCoreLink() { #ifdef QT_BUILD_INTERNAL QFETCH(int, resourceNumber); QFETCH(QString, senderAddress); QFETCH(QList, pathList); QFETCH(QList, titleList); QFETCH(QList, resourceTypeList); QFETCH(QList, contentFormatList); QFETCH(QList, interfaceList); QFETCH(QList, maximumSizeList); QFETCH(QList, observableList); QFETCH(QByteArray, coreLinkList); const auto resourceList = QCoapResourceDiscoveryReplyPrivate::resourcesFromCoreLinkList( QHostAddress(senderAddress), coreLinkList); QCOMPARE(resourceList.size(), resourceNumber); int resourceIndex = 0; for (const auto &resource : resourceList) { QCOMPARE(resource.host(), QHostAddress(senderAddress)); QCOMPARE(resource.path(), pathList[resourceIndex]); QCOMPARE(resource.title(), titleList[resourceIndex]); QCOMPARE(resource.resourceType(), resourceTypeList[resourceIndex]); QCOMPARE(resource.contentFormat(), contentFormatList[resourceIndex]); QCOMPARE(resource.interface(), interfaceList[resourceIndex]); QCOMPARE(resource.maximumSize(), maximumSizeList[resourceIndex]); QCOMPARE(resource.observable(), observableList[resourceIndex]); ++resourceIndex; } #else QSKIP("Not an internal build, skipping this test"); #endif } QTEST_APPLESS_MAIN(tst_QCoapResource) #include "tst_qcoapresource.moc"