Example #1
0
/**
 * 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;
}