/* * Send and receive some packets on this universe. */ void ShowNetNodeTest::SendAndReceiveForUniverse(unsigned int universe) { const uint8_t TEST_DATA[] = {1, 2, 2, 3, 0, 0, 0, 1, 3, 3, 3, 1, 2}; const uint8_t TEST_DATA2[] = {0, 0, 0, 0, 6, 5, 4, 3, 3, 3}; DmxBuffer zero_buffer; zero_buffer.Blackout(); DmxBuffer buffer1(TEST_DATA, sizeof(TEST_DATA)); DmxBuffer buffer2(TEST_DATA2, sizeof(TEST_DATA2)); unsigned int size; shownet_packet packet; DmxBuffer received_data; m_node->SetHandler( universe, &received_data, ola::NewCallback(this, &ShowNetNodeTest::UpdateData, universe)); // zero first size = m_node->BuildCompressedPacket(&packet, universe, zero_buffer); m_node->HandlePacket(&packet, size); OLA_ASSERT(received_data == zero_buffer); // send a test packet size = m_node->BuildCompressedPacket(&packet, universe, buffer1); m_node->HandlePacket(&packet, size); OLA_ASSERT_EQ( 0, memcmp(buffer1.GetRaw(), received_data.GetRaw(), buffer1.Size())); // send another test packet size = m_node->BuildCompressedPacket(&packet, universe, buffer2); m_node->HandlePacket(&packet, size); OLA_ASSERT_EQ( 0, memcmp(buffer2.GetRaw(), received_data.GetRaw(), buffer2.Size())); // check that we don't mix up universes size = m_node->BuildCompressedPacket(&packet, universe + 1, buffer1); m_node->HandlePacket(&packet, size); OLA_ASSERT_EQ( 0, memcmp(buffer2.GetRaw(), received_data.GetRaw(), buffer2.Size())); }
/* * Check the packet construction code. */ void ShowNetNodeTest::testPopulatePacket() { unsigned int universe = 0; const string NAME = "foobarbaz"; const string DMX_DATA = "abc"; DmxBuffer buffer(DMX_DATA); shownet_packet packet; m_node->SetName(NAME); unsigned int size = m_node->BuildCompressedPacket(&packet, universe, buffer); ASSERT_DATA_EQUALS(__LINE__, EXPECTED_PACKET, sizeof(EXPECTED_PACKET), reinterpret_cast<const uint8_t*>(&packet), size); // now send for a different universe universe = 1; size = m_node->BuildCompressedPacket(&packet, universe, buffer); ASSERT_DATA_EQUALS(__LINE__, EXPECTED_PACKET2, sizeof(EXPECTED_PACKET2), reinterpret_cast<const uint8_t*>(&packet), size); }