コード例 #1
0
ファイル: RDMCommandTest.cpp プロジェクト: Siliconsoul/ola
/**
 * 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;
}
コード例 #2
0
/**
 * 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;
}
コード例 #3
0
ファイル: RDMCommandTest.cpp プロジェクト: Siliconsoul/ola
/*
 * 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);
}