add RDM testing
This commit is contained in:
parent
3745f44a5f
commit
946a2dd9f4
|
@ -11,6 +11,7 @@ if (GTest_FOUND)
|
|||
target_link_libraries(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
GTest::gtest
|
||||
LCP::RDM
|
||||
LCP::UUID
|
||||
LCP::sACN
|
||||
)
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
test_rdm.cpp
|
||||
|
||||
Copyright (c) 2023 Kevin Matz (kevin.matz@gmail.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <responder.h>
|
||||
|
||||
class RDMdataTest
|
||||
: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
RDMdataTest()
|
||||
{
|
||||
responder.deviceModelID = 0x4242;
|
||||
responder.deviceProductCategory = RDM::PRODUCT_CATEGORY_TEST;
|
||||
sender_token = responder.setSender([this](const std::vector<uint8_t> &r){rdm_data = r;});
|
||||
}
|
||||
RDM::Responder responder = RDM::Responder(RDM::UID(0x12345678, 0x1234));
|
||||
std::vector<uint8_t> rdm_data;
|
||||
std::shared_ptr<void> sender_token;
|
||||
};
|
||||
|
||||
|
||||
TEST_F(RDMdataTest, device_info) {
|
||||
rdm_data.clear();
|
||||
rdm_data.push_back(RDM::SC_RDM); // START code
|
||||
rdm_data.push_back(RDM::SC_SUB_MESSAGE); // sub-START code
|
||||
rdm_data.push_back(24); // message length
|
||||
RDM::Message::writeType<uint16_t>(rdm_data, responder.uid.manufacturer); // dest manufacturer
|
||||
RDM::Message::writeType<uint32_t>(rdm_data, responder.uid.device); // dest device
|
||||
RDM::Message::writeType<uint16_t>(rdm_data, 0x5678); // source manufacturer
|
||||
RDM::Message::writeType<uint32_t>(rdm_data, 0x87654321); // source device
|
||||
rdm_data.push_back(42); // transaction number
|
||||
rdm_data.push_back(1); // port ID
|
||||
rdm_data.push_back(0); // message count
|
||||
RDM::Message::writeType<uint16_t>(rdm_data, 0); // sub device
|
||||
rdm_data.push_back(RDM::GET_COMMAND); // command class
|
||||
RDM::Message::writeType<uint16_t>(rdm_data, RDM::DEVICE_INFO.pid); // parameter ID
|
||||
rdm_data.push_back(0); // Parameter Data Length
|
||||
RDM::Message::writeType<uint16_t>(rdm_data, RDM::Message::checksum(rdm_data)); // checksum
|
||||
|
||||
EXPECT_EQ(rdm_data.size(), 26) << "mallformed DEVICE_INFO GET_COMMAND";
|
||||
responder.receive(rdm_data);
|
||||
EXPECT_EQ(rdm_data.size(), 26+0x13) << "mallformed DEVICE_INFO GET_RESPONSE";
|
||||
|
||||
RDM::Message reply;
|
||||
reply.read(rdm_data);
|
||||
EXPECT_EQ(reply.failure_mode, 0) << "Reply Message failed";
|
||||
EXPECT_EQ(reply.source.manufacturer, responder.uid.manufacturer) << "Responder manufacturer mismatch";
|
||||
EXPECT_EQ(reply.source.device, responder.uid.device) << "Responder device mismatch";
|
||||
EXPECT_EQ(reply.tn, 42) << "Failed to track command conversation";
|
||||
EXPECT_EQ(reply.responseType, RDM::RESPONSE_TYPE_ACK) << "Command not acknowledged.";
|
||||
EXPECT_EQ(reply.messageCount, 0) << "Unexpected queued messages";
|
||||
EXPECT_EQ(reply.mdb.cc, RDM::GET_COMMAND_RESPONSE) << "Unexpected command class";
|
||||
EXPECT_EQ(reply.mdb.pid, RDM::DEVICE_INFO.pid) << "Unexpected PID";
|
||||
EXPECT_EQ(reply.mdb.pdl(), 0x13) << "PDL length mismatch";
|
||||
|
||||
auto proto_version = RDM::Message::readType<uint16_t>(reply.mdb.pd, 0);
|
||||
EXPECT_EQ(proto_version, RDM::RDM_PROTOCOL_VERSION) << "Unknown RDM version.";
|
||||
|
||||
auto device_model = RDM::Message::readType<uint16_t>(reply.mdb.pd, 2);
|
||||
EXPECT_EQ(device_model, 0x4242) << "Unexpected Device Model";
|
||||
|
||||
auto product_category = RDM::Message::readType<uint16_t>(reply.mdb.pd, 4);
|
||||
EXPECT_EQ(product_category, RDM::PRODUCT_CATEGORY_TEST) << "Unexpected Product Category";
|
||||
}
|
Loading…
Reference in New Issue