/* * Check some of the error conditions */ void DmxterWidgetTest::testErrorConditions() { uint8_t RDM_REQUEST_LABEL = 0x80; UID source(0x4744, 0x12345678); UID destination(3, 4); RDMFrames frames; RDMRequest *request = NewRequest(source, destination, NULL, 0); unsigned int size = RDMCommandSerializer::RequiredSize(*request); uint8_t *expected_packet = new uint8_t[size + 1]; expected_packet[0] = 0xcc; OLA_ASSERT(RDMCommandSerializer::Pack(*request, expected_packet + 1, &size)); // to small to be valid uint8_t return_packet[] = {0x00}; m_endpoint->AddExpectedUsbProDataAndReturn( RDM_REQUEST_LABEL, expected_packet, size + 1, RDM_REQUEST_LABEL, return_packet, sizeof(return_packet)); m_widget->SendRDMRequest( request, ola::NewSingleCallback(this, &DmxterWidgetTest::ValidateStatus, ola::rdm::RDM_INVALID_RESPONSE, frames)); m_ss.Run(); m_endpoint->Verify(); // check mismatched version request = NewRequest(source, destination, NULL, 0); request->SetTransactionNumber(1); OLA_ASSERT(RDMCommandSerializer::Pack(*request, expected_packet + 1, &size)); // non-0 version uint8_t return_packet2[] = {0x01, 0x11, 0xcc}; m_endpoint->AddExpectedUsbProDataAndReturn( RDM_REQUEST_LABEL, expected_packet, size + 1, RDM_REQUEST_LABEL, return_packet2, sizeof(return_packet2)); m_widget->SendRDMRequest( request, ola::NewSingleCallback(this, &DmxterWidgetTest::ValidateStatus, ola::rdm::RDM_INVALID_RESPONSE, frames)); delete[] expected_packet; m_ss.Run(); m_endpoint->Verify(); }
/** * Check that we send messages correctly. */ void DmxterWidgetTest::testSendRDMRequest() { uint8_t RDM_REQUEST_LABEL = 0x80; uint8_t RDM_BROADCAST_REQUEST_LABEL = 0x81; UID source(0x4744, 0x12345678); UID destination(3, 4); UID bcast_destination(3, 0xffffffff); RDMRequest *request = NewRequest(source, destination, NULL, 0); unsigned int size = RDMCommandSerializer::RequiredSize(*request); uint8_t *expected_packet = new uint8_t[size + 1]; expected_packet[0] = 0xcc; OLA_ASSERT(RDMCommandSerializer::Pack(*request, expected_packet + 1, &size)); uint8_t return_packet[] = { 0x00, 14, // response code 'ok' 0xcc, 1, 28, // sub code & length 0x47, 0x44, 0x12, 0x34, 0x56, 0x78, // dst uid 0, 3, 0, 0, 0, 4, // src uid 0, 1, 0, 0, 10, // transaction, port id, msg count & sub device 0x21, 0x1, 0x28, 4, // command, param id, param data length 0x5a, 0x5a, 0x5a, 0x5a, // param data 0x04, 0x50 // checksum }; m_endpoint->AddExpectedUsbProDataAndReturn( RDM_REQUEST_LABEL, expected_packet, size + 1, RDM_REQUEST_LABEL, return_packet, sizeof(return_packet)); m_widget->SendRDMRequest( request, ola::NewSingleCallback(this, &DmxterWidgetTest::ValidateResponse)); m_ss.Run(); m_endpoint->Verify(); // now check broadcast request = NewRequest(source, bcast_destination, NULL, 0); request->SetTransactionNumber(1); OLA_ASSERT(RDMCommandSerializer::Pack(*request, expected_packet + 1, &size)); m_endpoint->AddExpectedUsbProDataAndReturn( RDM_BROADCAST_REQUEST_LABEL, expected_packet, size + 1, RDM_BROADCAST_REQUEST_LABEL, static_cast<uint8_t*>(NULL), 0); RDMFrames frames; m_widget->SendRDMRequest( request, ola::NewSingleCallback(this, &DmxterWidgetTest::ValidateStatus, ola::rdm::RDM_WAS_BROADCAST, frames)); delete[] expected_packet; m_ss.Run(); m_endpoint->Verify(); }
/** * Test that cloning works */ void RDMCommandTest::testPackWithParams() { UID source(1, 2); UID destination(3, 4); UID new_source(7, 8); RDMGetRequest get_command(source, destination, 0, // transaction # 1, // port id 0, // message count 10, // sub device 296, // param id NULL, // data 0); // data length uint8_t *data = new uint8_t[get_command.Size()]; unsigned int length = get_command.Size(); CPPUNIT_ASSERT(get_command.PackWithControllerParams( data, &length, new_source, 99, 10)); RDMRequest *command = RDMRequest::InflateFromData(data, length); CPPUNIT_ASSERT(command); CPPUNIT_ASSERT_EQUAL(new_source, command->SourceUID()); CPPUNIT_ASSERT_EQUAL(destination, command->DestinationUID()); CPPUNIT_ASSERT_EQUAL((uint8_t) 99, command->TransactionNumber()); CPPUNIT_ASSERT_EQUAL((uint8_t) 10, command->PortId()); CPPUNIT_ASSERT_EQUAL((uint8_t) 0, command->MessageCount()); CPPUNIT_ASSERT_EQUAL((uint16_t) 10, command->SubDevice()); CPPUNIT_ASSERT_EQUAL(RDMCommand::GET_COMMAND, command->CommandClass()); CPPUNIT_ASSERT_EQUAL((uint16_t) 296, command->ParamId()); CPPUNIT_ASSERT_EQUAL(static_cast<uint8_t*>(NULL), command->ParamData()); CPPUNIT_ASSERT_EQUAL((unsigned int) 0, command->ParamDataSize()); CPPUNIT_ASSERT_EQUAL((unsigned int) 25, command->Size()); delete[] data; delete command; string packed_request; CPPUNIT_ASSERT(get_command.PackWithControllerParams( &packed_request, new_source, 99, 10)); command = RDMRequest::InflateFromData(packed_request); CPPUNIT_ASSERT(command); CPPUNIT_ASSERT_EQUAL(new_source, command->SourceUID()); CPPUNIT_ASSERT_EQUAL(destination, command->DestinationUID()); CPPUNIT_ASSERT_EQUAL((uint8_t) 99, command->TransactionNumber()); CPPUNIT_ASSERT_EQUAL((uint8_t) 10, command->PortId()); CPPUNIT_ASSERT_EQUAL((uint8_t) 0, command->MessageCount()); CPPUNIT_ASSERT_EQUAL((uint16_t) 10, command->SubDevice()); CPPUNIT_ASSERT_EQUAL(RDMCommand::GET_COMMAND, command->CommandClass()); CPPUNIT_ASSERT_EQUAL((uint16_t) 296, command->ParamId()); CPPUNIT_ASSERT_EQUAL(static_cast<uint8_t*>(NULL), command->ParamData()); CPPUNIT_ASSERT_EQUAL((unsigned int) 0, command->ParamDataSize()); CPPUNIT_ASSERT_EQUAL((unsigned int) 25, command->Size()); delete command; }
/** * Test that cloning works */ void RDMCommandTest::testPack() { UID source(1, 2); UID destination(3, 4); UID new_source(7, 8); RDMGetRequest get_command(source, destination, 0, // transaction # 1, // port id 0, // message count 10, // sub device 296, // param id NULL, // data 0); // data length unsigned int length = RDMCommandSerializer::RequiredSize(get_command); uint8_t *data = new uint8_t[length]; OLA_ASSERT_TRUE(RDMCommandSerializer::Pack( get_command, data, &length, new_source, 99, 10)); RDMRequest *command = RDMRequest::InflateFromData(data, length); OLA_ASSERT_NOT_NULL(command); OLA_ASSERT_EQ(new_source, command->SourceUID()); OLA_ASSERT_EQ(destination, command->DestinationUID()); OLA_ASSERT_EQ((uint8_t) 99, command->TransactionNumber()); OLA_ASSERT_EQ((uint8_t) 10, command->PortId()); OLA_ASSERT_EQ((uint8_t) 0, command->MessageCount()); OLA_ASSERT_EQ((uint16_t) 10, command->SubDevice()); OLA_ASSERT_EQ(RDMCommand::GET_COMMAND, command->CommandClass()); OLA_ASSERT_EQ((uint16_t) 296, command->ParamId()); OLA_ASSERT_EQ(static_cast<uint8_t*>(NULL), command->ParamData()); OLA_ASSERT_EQ(0u, command->ParamDataSize()); OLA_ASSERT_EQ(25u, RDMCommandSerializer::RequiredSize(*command)); delete[] data; delete command; }
/* * Test that we can inflate RDM request messages correctly */ void RDMCommandTest::testRequestInflation() { UID source(1, 2); UID destination(3, 4); RDMRequest *command = RDMRequest::InflateFromData(NULL, 10); CPPUNIT_ASSERT_EQUAL(static_cast<RDMRequest*>(NULL), command); string empty_string; command = RDMRequest::InflateFromData(empty_string); CPPUNIT_ASSERT_EQUAL(static_cast<RDMRequest*>(NULL), command); // now try a proper command but with no length command = RDMRequest::InflateFromData(EXPECTED_GET_BUFFER, 0); CPPUNIT_ASSERT_EQUAL(static_cast<RDMRequest*>(NULL), command); command = RDMRequest::InflateFromData( EXPECTED_GET_BUFFER, sizeof(EXPECTED_GET_BUFFER)); CPPUNIT_ASSERT(NULL != command); RDMGetRequest expected_command(source, destination, 0, // transaction # 1, // port id 0, // message count 10, // sub device 296, // param id NULL, // data 0); // data length CPPUNIT_ASSERT(expected_command == *command); delete command; string get_request_str(reinterpret_cast<char*>(EXPECTED_GET_BUFFER), sizeof(EXPECTED_GET_BUFFER)); command = RDMRequest::InflateFromData(get_request_str); CPPUNIT_ASSERT(NULL != command); CPPUNIT_ASSERT(expected_command == *command); delete command; // now try a set request command = RDMRequest::InflateFromData( EXPECTED_SET_BUFFER, sizeof(EXPECTED_SET_BUFFER)); CPPUNIT_ASSERT(NULL != command); uint8_t expected_data[] = {0xa5, 0xa5, 0xa5, 0xa5}; CPPUNIT_ASSERT_EQUAL((unsigned int) 4, command->ParamDataSize()); CPPUNIT_ASSERT(0 == memcmp(expected_data, command->ParamData(), command->ParamDataSize())); delete command; // set request as a string string set_request_string(reinterpret_cast<char*>(EXPECTED_SET_BUFFER), sizeof(EXPECTED_SET_BUFFER)); command = RDMRequest::InflateFromData(set_request_string); CPPUNIT_ASSERT(NULL != command); CPPUNIT_ASSERT_EQUAL((unsigned int) 4, command->ParamDataSize()); CPPUNIT_ASSERT(0 == memcmp(expected_data, command->ParamData(), command->ParamDataSize())); delete command; // change the param length and make sure the checksum fails uint8_t *bad_packet = new uint8_t[sizeof(EXPECTED_GET_BUFFER)]; memcpy(bad_packet, EXPECTED_GET_BUFFER, sizeof(EXPECTED_GET_BUFFER)); bad_packet[22] = 255; command = RDMRequest::InflateFromData( bad_packet, sizeof(EXPECTED_GET_BUFFER)); CPPUNIT_ASSERT(NULL == command); get_request_str[22] = 255; command = RDMRequest::InflateFromData(get_request_str); CPPUNIT_ASSERT(NULL == command); // now make sure we can't pass a bad param length larger than the buffer UpdateChecksum(bad_packet, sizeof(EXPECTED_GET_BUFFER)); command = RDMRequest::InflateFromData( bad_packet, sizeof(EXPECTED_GET_BUFFER)); CPPUNIT_ASSERT(NULL == command); delete[] bad_packet; // change the param length of another packet and make sure the checksum fails bad_packet = new uint8_t[sizeof(EXPECTED_SET_BUFFER)]; memcpy(bad_packet, EXPECTED_SET_BUFFER, sizeof(EXPECTED_SET_BUFFER)); bad_packet[22] = 5; UpdateChecksum(bad_packet, sizeof(EXPECTED_SET_BUFFER)); command = RDMRequest::InflateFromData( bad_packet, sizeof(EXPECTED_SET_BUFFER)); CPPUNIT_ASSERT(NULL == command); delete[] bad_packet; // now try to inflate a response command = RDMRequest::InflateFromData( EXPECTED_GET_RESPONSE_BUFFER, sizeof(EXPECTED_GET_RESPONSE_BUFFER)); CPPUNIT_ASSERT_EQUAL(static_cast<RDMRequest*>(NULL), command); string response_string(reinterpret_cast<char*>(EXPECTED_GET_RESPONSE_BUFFER), sizeof(EXPECTED_GET_RESPONSE_BUFFER)); command = RDMRequest::InflateFromData(response_string); CPPUNIT_ASSERT_EQUAL(static_cast<RDMRequest*>(NULL), command); }