/* * Test write to an output stream works. */ void RDMCommandTest::testOutputStream() { IOQueue output; OutputStream stream(&output); UID source(1, 2); UID destination(3, 4); RDMGetRequest command(source, destination, 0, // transaction # 1, // port id 0, // message count 10, // sub device 296, // param id NULL, // data 0); // data length command.Write(&stream); uint8_t *raw_command = new uint8_t[output.Size()]; unsigned int raw_command_size = output.Peek(raw_command, output.Size()); OLA_ASSERT_EQ(raw_command_size, RDMCommandSerializer::RequiredSize(command)); ASSERT_DATA_EQUALS(__LINE__, EXPECTED_GET_BUFFER, sizeof(EXPECTED_GET_BUFFER), raw_command, raw_command_size); output.Pop(raw_command_size); OLA_ASSERT_EQ(0u, output.Size()); delete[] raw_command; // 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)); command2.Write(&stream); OLA_ASSERT_EQ(RDMCommandSerializer::RequiredSize(command2), output.Size()); raw_command = new uint8_t[output.Size()]; raw_command_size = output.Peek(raw_command, output.Size()); OLA_ASSERT_EQ(raw_command_size, RDMCommandSerializer::RequiredSize(command2)); ASSERT_DATA_EQUALS(__LINE__, EXPECTED_SET_BUFFER, sizeof(EXPECTED_SET_BUFFER), raw_command, raw_command_size); output.Pop(raw_command_size); OLA_ASSERT_EQ(0u, output.Size()); delete[] raw_command; }
/* * Test that writing to an output stream works. */ void E133PDUTest::testSimpleE133PDUToOutputStream() { const string source = "foo source"; E133Header header(source, 101, 2); E133PDU pdu(TEST_VECTOR, header, NULL); OLA_ASSERT_EQ(71u, pdu.HeaderSize()); OLA_ASSERT_EQ(0u, pdu.DataSize()); OLA_ASSERT_EQ(77u, pdu.Size()); IOQueue output; OutputStream stream(&output); pdu.Write(&stream); OLA_ASSERT_EQ(77u, output.Size()); uint8_t *pdu_data = new uint8_t[output.Size()]; unsigned int pdu_size = output.Peek(pdu_data, output.Size()); OLA_ASSERT_EQ(output.Size(), pdu_size); uint8_t EXPECTED[] = { 0x70, 77, 0, 0, 0, 39, 'f', 'o', 'o', ' ', 's', 'o', 'u', 'r', 'c', 'e', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 101, // seq # 0, 2, // endpoint 0, }; OLA_ASSERT_DATA_EQUALS(EXPECTED, sizeof(EXPECTED), pdu_data, pdu_size); output.Pop(output.Size()); delete[] pdu_data; }
/** * Check that writing an Root PDU to an output stream works */ void RootPDUTest::testSimpleRootPDUToOutputStream() { CID cid = CID::Generate(); RootPDU pdu1(TEST_VECTOR, cid, NULL); OLA_ASSERT(cid == pdu1.Cid()); OLA_ASSERT_EQ(16u, pdu1.HeaderSize()); OLA_ASSERT_EQ(4u, pdu1.VectorSize()); OLA_ASSERT_EQ(0u, pdu1.DataSize()); OLA_ASSERT_EQ(22u, pdu1.Size()); IOQueue output; OutputStream stream(&output); pdu1.Write(&stream); OLA_ASSERT_EQ(22u, output.Size()); uint8_t *raw_pdu = new uint8_t[output.Size()]; unsigned int raw_pdu_size = output.Peek(raw_pdu, output.Size()); OLA_ASSERT_EQ(output.Size(), raw_pdu_size); uint8_t EXPECTED[] = { 0x70, 22, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; cid.Pack(EXPECTED + 6); ASSERT_DATA_EQUALS(__LINE__, EXPECTED, sizeof(EXPECTED), raw_pdu, raw_pdu_size); output.Pop(output.Size()); delete[] raw_pdu; }
/* * Test that packing a RDM PDU works. This uses a command data. */ void RDMPDUTest::testRDMPDUWithDataToOutputStream() { UID source(1, 2); UID destination(3, 4); uint8_t rdm_data[] = {0xa5, 0xa5, 0xa5, 0xa5}; RDMGetRequest *command = new RDMGetRequest( source, destination, 0, // transaction # 1, // port id 0, // message count 10, // sub device 296, // param id rdm_data, // data sizeof(rdm_data)); // data length RDMPDU pdu(command); OLA_ASSERT_EQ(0u, pdu.HeaderSize()); OLA_ASSERT_EQ(29u, pdu.DataSize()); OLA_ASSERT_EQ(32u, pdu.Size()); IOQueue output; OutputStream stream(&output); pdu.Write(&stream); OLA_ASSERT_EQ(32u, output.Size()); uint8_t *pdu_data = new uint8_t[output.Size()]; unsigned int pdu_size = output.Peek(pdu_data, output.Size()); OLA_ASSERT_EQ(output.Size(), pdu_size); uint8_t EXPECTED[] = { 0x70, 0x20, TEST_VECTOR, 1, 0x1c, // sub code & length 0, 3, 0, 0, 0, 4, // dst uid 0, 1, 0, 0, 0, 2, // src uid 0, 1, 0, 0, 10, // transaction, port id, msg count & sub device 0x20, 1, 40, 4, // command, param id, param data length 0xa5, 0xa5, 0xa5, 0xa5, // data 3, 0xdf // checksum }; ASSERT_DATA_EQUALS(__LINE__, EXPECTED, sizeof(EXPECTED), pdu_data, pdu_size); output.Pop(output.Size()); delete[] pdu_data; }
/* * Test writing an empty PDU to an OutputStream works. */ void RDMPDUTest::testEmptyPDUToOutputStream() { RDMPDU pdu(NULL); OLA_ASSERT_EQ(0u, pdu.HeaderSize()); OLA_ASSERT_EQ(0u, pdu.DataSize()); OLA_ASSERT_EQ(3u, pdu.Size()); IOQueue output; OutputStream stream(&output); pdu.Write(&stream); OLA_ASSERT_EQ(3u, output.Size()); uint8_t *pdu_data = new uint8_t[output.Size()]; unsigned int pdu_size = output.Peek(pdu_data, output.Size()); OLA_ASSERT_EQ(output.Size(), pdu_size); const uint8_t EXPECTED[] = {0x70, 3, TEST_VECTOR}; OLA_ASSERT_DATA_EQUALS(EXPECTED, sizeof(EXPECTED), pdu_data, pdu_size); output.Pop(output.Size()); delete[] pdu_data; }
/* * Check that the << operators work */ void OutputStreamTest::testWritePrimatives() { BigEndianOutputStream stream(&m_buffer); OLA_ASSERT_EQ(0u, m_buffer.Size()); stream << 4; OLA_ASSERT_EQ(4u, m_buffer.Size()); stream << (1u << 31); OLA_ASSERT_EQ(8u, m_buffer.Size()); stream << static_cast<uint8_t>(10) << static_cast<uint16_t>(2400); OLA_ASSERT_EQ(11u, m_buffer.Size()); // confirm this matches what we expect const unsigned int DATA_SIZE = 20; uint8_t *output_data = new uint8_t[DATA_SIZE]; uint8_t data1[] = {0, 0, 0, 4, 0x80, 0, 0, 0, 0xa, 0x9, 0x60}; unsigned int output_size = m_buffer.Peek(output_data, m_buffer.Size()); OLA_ASSERT_DATA_EQUALS(data1, sizeof(data1), output_data, output_size); delete[] output_data; }
/* * Test that packing a RootPDU with nested data works */ void RootPDUTest::testNestedRootPDUToOutputStream() { FakePDU pdu1(1); FakePDU pdu2(42); PDUBlock<PDU> block; block.AddPDU(&pdu1); block.AddPDU(&pdu2); CID cid = CID::Generate(); RootPDU pdu(TEST_VECTOR, cid, &block); OLA_ASSERT(cid == pdu.Cid()); OLA_ASSERT_EQ(30u, pdu.Size()); IOQueue output; OutputStream stream(&output); pdu.Write(&stream); OLA_ASSERT_EQ(30u, output.Size()); uint8_t *raw_pdu = new uint8_t[output.Size()]; unsigned int raw_pdu_size = output.Peek(raw_pdu, output.Size()); OLA_ASSERT_EQ(output.Size(), raw_pdu_size); uint8_t EXPECTED[] = { 0x70, 30, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 42 }; cid.Pack(EXPECTED + 6); ASSERT_DATA_EQUALS(__LINE__, EXPECTED, sizeof(EXPECTED), raw_pdu, raw_pdu_size); output.Pop(output.Size()); delete[] raw_pdu; }