Beispiel #1
0
/*
 * Check that basic prepending works.
 */
void IOStackTest::testBasicWrite() {
  IOStack stack;
  OLA_ASSERT_EQ(0u, stack.Size());
  OLA_ASSERT_TRUE(stack.Empty());
  uint8_t data1[] = {0, 1};
  uint8_t data2[] = {2};
  uint8_t data3[] = {3, 4};

  stack.Write(data1, sizeof(data1));
  OLA_ASSERT_EQ(2u, stack.Size());
  stack.Write(data2, sizeof(data2));
  OLA_ASSERT_EQ(3u, stack.Size());
  stack.Write(data3, sizeof(data3));
  OLA_ASSERT_EQ(5u, stack.Size());

  std::stringstream str;
  stack.Dump(&str);
  OLA_ASSERT_EQ(
      string("03 04 02 00 01           .....\n"),
      str.str());

  unsigned int data_size = stack.Size();
  uint8_t output[data_size];
  OLA_ASSERT_EQ(data_size, stack.Read(output, data_size));

  const uint8_t expected_data[] = {3, 4, 2, 0, 1};
  ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data),
                     output, data_size);
}
/*
 * Test writing to an IOStack works.
 */
void RDMCommandTest::testIOStack() {
  IOStack output;
  UID source(1, 2);
  UID destination(3, 4);
  IOStack stack;

  RDMGetRequest command(source,
                        destination,
                        0,  // transaction #
                        1,  // port id
                        0,  // message count
                        10,  // sub device
                        296,  // param id
                        NULL,  // data
                        0);  // data length
  OLA_ASSERT_TRUE(RDMCommandSerializer::Write(command, &stack));

  unsigned int raw_command_size = stack.Size();
  OLA_ASSERT_EQ(raw_command_size, RDMCommandSerializer::RequiredSize(command));
  uint8_t raw_command[raw_command_size];
  OLA_ASSERT_EQ(raw_command_size, stack.Read(raw_command, raw_command_size));
  OLA_ASSERT_EQ(0u, stack.Size());

  ASSERT_DATA_EQUALS(__LINE__,
                     EXPECTED_GET_BUFFER,
                     sizeof(EXPECTED_GET_BUFFER),
                     raw_command,
                     raw_command_size);

  // now try a command with data
  uint32_t data_value = 0xa5a5a5a5;
  RDMSetRequest command2(source,
                         destination,
                         0,  // transaction #
                         1,  // port id
                         0,  // message count
                         10,  // sub device
                         296,  // param id
                         reinterpret_cast<uint8_t*>(&data_value),  // data
                         sizeof(data_value));  // data length

  OLA_ASSERT_EQ(29u, RDMCommandSerializer::RequiredSize(command2));
  OLA_ASSERT_TRUE(RDMCommandSerializer::Write(command2, &stack));

  raw_command_size = stack.Size();
  OLA_ASSERT_EQ(raw_command_size, RDMCommandSerializer::RequiredSize(command2));
  uint8_t raw_command2[raw_command_size];
  OLA_ASSERT_EQ(raw_command_size, stack.Read(raw_command2, raw_command_size));
  OLA_ASSERT_EQ(0u, stack.Size());

  ASSERT_DATA_EQUALS(__LINE__,
                     EXPECTED_SET_BUFFER,
                     sizeof(EXPECTED_SET_BUFFER),
                     raw_command2,
                     raw_command_size);
}