Exemplo n.º 1
0
/*
 * Check that SetRange works.
 */
void DmxBufferTest::testSetRange() {
  unsigned int data_size = sizeof(TEST_DATA);
  DmxBuffer buffer;
  OLA_ASSERT_FALSE(buffer.SetRange(0, NULL, data_size));
  OLA_ASSERT_FALSE(buffer.SetRange(600, TEST_DATA, data_size));

  // Setting an uninitialized buffer calls blackout first
  OLA_ASSERT_TRUE(buffer.SetRange(0, TEST_DATA, data_size));
  OLA_ASSERT_EQ((unsigned int) DMX_UNIVERSE_SIZE, buffer.Size());
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw(), data_size));

  // try overrunning the buffer
  OLA_ASSERT_TRUE(buffer.SetRange(DMX_UNIVERSE_SIZE - 2, TEST_DATA, data_size));
  OLA_ASSERT_EQ((unsigned int) DMX_UNIVERSE_SIZE, buffer.Size());
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw() + DMX_UNIVERSE_SIZE - 2,
                         2));

  // reset the buffer so that the valid data is 0, and try again
  buffer.Reset();
  OLA_ASSERT_TRUE(buffer.SetRange(0, TEST_DATA, data_size));
  OLA_ASSERT_EQ((unsigned int) data_size, buffer.Size());
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw(), data_size));

  // setting past the end of the valid data should fail
  OLA_ASSERT_FALSE(buffer.SetRange(50, TEST_DATA, data_size));
  OLA_ASSERT_EQ((unsigned int) data_size, buffer.Size());
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw(), buffer.Size()));

  // overwrite part of the valid data
  unsigned int offset = 2;
  OLA_ASSERT_TRUE(buffer.SetRange(offset, TEST_DATA, data_size));
  OLA_ASSERT_EQ((unsigned int) data_size + offset,
                       buffer.Size());
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw(), offset));
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw() + offset,
                         buffer.Size() - offset));

  // now try writing 1 channel past the valid data
  buffer.Reset();
  OLA_ASSERT_TRUE(buffer.SetRange(0, TEST_DATA, data_size));
  OLA_ASSERT_TRUE(buffer.SetRange(data_size, TEST_DATA,
                                 data_size));
  OLA_ASSERT_EQ((unsigned int) data_size * 2, buffer.Size());
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw(), data_size));
  OLA_ASSERT_EQ(0, memcmp(TEST_DATA, buffer.GetRaw() + data_size, data_size));
}
Exemplo n.º 2
0
/*
 * Check that SetRangeToValue works
 */
void DmxBufferTest::testSetRangeToValue() {
  const uint8_t RANGE_DATA[] = {50, 50, 50, 50, 50};
  DmxBuffer buffer;
  OLA_ASSERT_FALSE(buffer.SetRangeToValue(600, 50, 2));

  unsigned int range_size = 5;
  OLA_ASSERT_TRUE(buffer.SetRangeToValue(0, 50, range_size));
  OLA_ASSERT_EQ((unsigned int) DMX_UNIVERSE_SIZE, buffer.Size());
  OLA_ASSERT_EQ(0, memcmp(RANGE_DATA, buffer.GetRaw(), range_size));

  // setting outside the value range should fail
  buffer.Reset();
  OLA_ASSERT_FALSE(buffer.SetRange(10, TEST_DATA, range_size));
}
Exemplo n.º 3
0
/*
 * Test that Blackout() works
 */
void DmxBufferTest::testBlackout() {
  DmxBuffer buffer;
  OLA_ASSERT_TRUE(buffer.Blackout());
  uint8_t *result = new uint8_t[DMX_UNIVERSE_SIZE];
  uint8_t *zero = new uint8_t[DMX_UNIVERSE_SIZE];
  unsigned int result_length = DMX_UNIVERSE_SIZE;
  memset(zero, 0, DMX_UNIVERSE_SIZE);
  buffer.Get(result, &result_length);
  OLA_ASSERT_EQ((unsigned int) DMX_UNIVERSE_SIZE, result_length);
  OLA_ASSERT_EQ(0, memcmp(zero, result, result_length));
  delete[] result;
  delete[] zero;

  buffer.Reset();
  OLA_ASSERT_EQ(0u, buffer.Size());
}