/* * Test UDP sockets with an IOQueue work correctly. * The client connects and the server sends some data. The client checks the * data matches and then closes the connection. */ void SocketTest::testIOQueueUDPSend() { IPV4SocketAddress socket_address(IPV4Address::Loopback(), 9010); UDPSocket socket; OLA_ASSERT_TRUE(socket.Init()); OLA_ASSERT_FALSE(socket.Init()); OLA_ASSERT_TRUE(socket.Bind(socket_address)); OLA_ASSERT_FALSE(socket.Bind(socket_address)); socket.SetOnData( ola::NewCallback(this, &SocketTest::UDPReceiveAndSend, &socket)); OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&socket)); UDPSocket client_socket; OLA_ASSERT_TRUE(client_socket.Init()); OLA_ASSERT_FALSE(client_socket.Init()); client_socket.SetOnData( ola::NewCallback( this, &SocketTest::UDPReceiveAndTerminate, static_cast<UDPSocket*>(&client_socket))); OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&client_socket)); IOQueue output; output.Write(static_cast<const uint8_t*>(test_cstring), sizeof(test_cstring)); ssize_t bytes_sent = client_socket.SendTo(&output, socket_address); OLA_ASSERT_EQ(static_cast<ssize_t>(sizeof(test_cstring)), bytes_sent); m_ss->Run(); m_ss->RemoveReadDescriptor(&socket); m_ss->RemoveReadDescriptor(&client_socket); }
/* * Check that BuildServiceRequest() works. */ void PacketBuilderTest::testBuildServiceRequest() { set<IPV4Address> pr_list; IPV4Address first_ip, second_ip; OLA_ASSERT_TRUE(IPV4Address::FromString("1.1.1.2", &first_ip)); OLA_ASSERT_TRUE(IPV4Address::FromString("1.1.1.8", &second_ip)); pr_list.insert(first_ip); pr_list.insert(second_ip); ScopeSet scopes("ACN,MYORG\\2c"); SLPPacketBuilder::BuildServiceRequest(&output, xid, true, EN_LANGUAGE_TAG, pr_list, "rdmnet-device", scopes); OLA_ASSERT_EQ(66u, ioqueue.Size()); { unsigned int data_size; uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size); uint8_t expected_data[] = { 2, 1, 0, 0, 66, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n', 0, 15, '1', '.', '1', '.', '1', '.', '2', ',', '1', '.', '1', '.', '1', '.', '8', // pr-llist 0, 13, 'r', 'd', 'm', 'n', 'e', 't', '-', 'd', 'e', 'v', 'i', 'c', 'e', 0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c', 0, 0, // pred string 0, 0, // SPI string }; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_data; } // try a different language SLPPacketBuilder::BuildServiceRequest(&output, xid, true, "en-AU", pr_list, "rdmnet-device", scopes); OLA_ASSERT_EQ(69u, ioqueue.Size()); { unsigned int data_size; uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size); uint8_t expected_data[] = { 2, 1, 0, 0, 69, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 5, 'e', 'n', '-', 'A', 'U', 0, 15, '1', '.', '1', '.', '1', '.', '2', ',', '1', '.', '1', '.', '1', '.', '8', // pr-llist 0, 13, 'r', 'd', 'm', 'n', 'e', 't', '-', 'd', 'e', 'v', 'i', 'c', 'e', 0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c', 0, 0, // pred string 0, 0, // SPI string }; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_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 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; }
static void test_thread_safety() { std::atomic<int> count(0); std::atomic<int> push_count(0); IOQueue<std::function<void()>> queue; auto consumer = std::thread( [&queue, &count] { while (count.load() < 9000000) { if (queue) { queue.front()(); queue.pop(); } } } ); auto producer_func = [&queue, &push_count, &count] { while (push_count.fetch_add(1) < 9000000) { queue.push([&count] { ++count; }); } }; auto producer_1 = std::thread([&producer_func]{ producer_func(); }); auto producer_2 = std::thread([&producer_func]{ producer_func(); }); auto producer_3 = std::thread([&producer_func]{ producer_func(); }); auto producer_4 = std::thread([&producer_func]{ producer_func(); }); auto producer_5 = std::thread([&producer_func]{ producer_func(); }); auto producer_6 = std::thread([&producer_func]{ producer_func(); }); auto producer_7 = std::thread([&producer_func]{ producer_func(); }); producer_1.join(); producer_2.join(); producer_3.join(); producer_4.join(); producer_5.join(); producer_6.join(); producer_7.join(); consumer.join(); }
/** * Check that BuildServiceDeRegistration() works. */ void PacketBuilderTest::testBuildServiceDeRegistration() { ScopeSet service_scopes("ACN,MYORG,FOO"); ScopeSet scopes("ACN,MYORG"); ServiceEntry service_entry(service_scopes, "service:foo://1.1.1.1", 0x1234); SLPPacketBuilder::BuildServiceDeRegistration(&output, xid, scopes, service_entry); OLA_ASSERT_EQ(56u, ioqueue.Size()); unsigned int data_size; uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size); uint8_t expected_data[] = { 2, 4, 0, 0, 0x38, 0x0, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n', // scope list 0, 0x9, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', // entry 1 0, 0x12, 0x34, 0, 21, 's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', ':', '/', '/', '1', '.', '1', '.', '1', '.', '1', 0, // # of URL auths 0, 0 // tag list length }; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_data; }
/** * Check that BuildServiceRegistration() works. */ void PacketBuilderTest::testBuildServiceRegistration() { ScopeSet service_scopes("ACN,MYORG,FOO"); ScopeSet scopes("ACN,MYORG\\2c"); ServiceEntry service_entry(service_scopes, "service:foo://1.1.1.1", 0x1234); SLPPacketBuilder::BuildServiceRegistration(&output, xid, true, scopes, service_entry); OLA_ASSERT_EQ(73u, ioqueue.Size()); unsigned int data_size; uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size); uint8_t expected_data[] = { 2, 3, 0, 0, 0x49, 0x40, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n', // entry 1 0, 0x12, 0x34, 0, 21, 's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', ':', '/', '/', '1', '.', '1', '.', '1', '.', '1', 0, // # of auth blocks 0, 0xb, 's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', 0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c', 0, 0, 0, // attr auths }; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_data; // now test a re-registration SLPPacketBuilder::BuildServiceRegistration(&output, xid + 1, false, scopes, service_entry); OLA_ASSERT_EQ(73u, ioqueue.Size()); output_data = WriteToBuffer(&ioqueue, &data_size); expected_data[5] = 0; expected_data[11] = 0x35; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_data; }
/* * 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; }
/* * Check that BuildDAAdvert() works. */ void PacketBuilderTest::testBuildDAAdvert() { ScopeSet scopes("ACN,MYORG\\2c"); SLPPacketBuilder::BuildDAAdvert(&output, xid, true, 12, 0x12345678, "service:foo", scopes); OLA_ASSERT_EQ(54u, ioqueue.Size()); unsigned int data_size; uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size); uint8_t expected_data[] = { 2, 8, 0, 0, 0x36, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n', 0, 0, // error code is zeroed out if multicast 0x12, 0x34, 0x56, 0x78, // boot timestamp 0, 11, 's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', // service 0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c', 0, 0, // attr list 0, 0, // SPI list 0 // auth blocks }; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_data; // try with a non-multicast packet SLPPacketBuilder::BuildDAAdvert(&output, xid, false, 12, 0x12345678, "service:foo", scopes); OLA_ASSERT_EQ(54u, ioqueue.Size()); output_data = WriteToBuffer(&ioqueue, &data_size); expected_data[5] = 0; // update error code expected_data[17] = 0xc; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_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 basic appending works. */ void OutputStreamTest::testBasicWrite() { BigEndianOutputStream stream(&m_buffer); OLA_ASSERT_EQ(0u, m_buffer.Size()); uint8_t data1[] = {0, 1, 2, 3, 4}; stream.Write(data1, sizeof(data1)); OLA_ASSERT_EQ(5u, m_buffer.Size()); m_buffer.Pop(1); OLA_ASSERT_EQ(4u, m_buffer.Size()); m_buffer.Pop(4); OLA_ASSERT_EQ(0u, m_buffer.Size()); }
/* * 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; }
/* * Check that BuildServiceTypeReply() works. */ void PacketBuilderTest::testBuildServiceTypeReply() { ScopeSet scopes("ACN,MYORG\\2c"); vector<string> service_types; service_types.push_back("lpr"); service_types.push_back("foo,bar"); // check escaping SLPPacketBuilder::BuildServiceTypeReply(&output, xid, 0, service_types); OLA_ASSERT_EQ(33u, ioqueue.Size()); unsigned int data_size; uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size); uint8_t expected_data[] = { 2, 10, 0, 0, 0x21, 0x0, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n', 0, 0, // error code 0, 13, 'l', 'p', 'r', ',', 'f', 'o', 'o', '\\', '2', 'c', 'b', 'a', 'r' }; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_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; }
static void test_basic_operations() { IOQueue<int> queue; assert(!queue); queue.push(1); assert(queue); assert(queue.front() == 1); assert(queue.size() == 1); queue.pop(); assert(!queue); assert(queue.size() == 0); queue.push(2); assert(queue); assert(queue.front() == 2); assert(queue.size() == 1); queue.push(3); assert(queue); assert(queue.front() == 2); assert(queue.size() == 2); queue.pop(); assert(queue); assert(queue.front() == 3); assert(queue.size() == 1); queue.pop(); assert(!queue); assert(queue.size() == 0); }
static void test(uint32_t size) { requestdata_t *input = new requestdata_t[size]; requestdata_t *output = new requestdata_t[size]; for(int k = 0; k < 10; ++k) { IOQueue q; uint32_t i, j; iorequest_t req(NULL); assert(size); debug_randomize(input, intsizeof(requestdata_t[size])); debug_randomize(output, intsizeof(requestdata_t[size])); // push all for(i = 0; i < size; ++i) { q.push(iorequest_t(&input[i])); } // pop all for(i = 0; i < size; ++i) { assert(q.tryPop(&req)); output[i].offset = req.getOffset(); } assert(q.empty()); //test_print(output, size); // check order for(i = 0; i < size-1; ++i) { ASSERT(output[i].offset <= output[i+1].offset, cerr << '[' << i << "]:" << output[i].offset << " > [" << i+1 << "]:" << output[i+1].offset << endl); } // ordered push partial j = RAND()%size; for(i = 0; i < j; ++i) { q.push(iorequest_t(&output[i])); } // pop and push for(i = 0; i < j; ++i) { assert(q.tryPop(&req)); assert(output[i].offset == req.getOffset()); if (rand()%2 == 0 && j < size) { q.push(iorequest_t(&output[j])); j++; } } } delete [] output; delete [] input; }
/* * Check that BuildServiceTypeRequest() works. */ void PacketBuilderTest::testBuildServiceTypeRequest() { set<IPV4Address> pr_list; IPV4Address first_ip, second_ip; OLA_ASSERT_TRUE(IPV4Address::FromString("1.1.1.2", &first_ip)); OLA_ASSERT_TRUE(IPV4Address::FromString("1.1.1.8", &second_ip)); pr_list.insert(first_ip); pr_list.insert(second_ip); ScopeSet scopes("ACN,MYORG\\2c"); { // request for all service-types SLPPacketBuilder::BuildAllServiceTypeRequest(&output, xid, true, pr_list, scopes); OLA_ASSERT_EQ(49u, ioqueue.Size()); unsigned int data_size; uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size); uint8_t expected_data[] = { 2, 9, 0, 0, 0x31, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n', 0, 15, '1', '.', '1', '.', '1', '.', '2', ',', '1', '.', '1', '.', '1', '.', '8', // pr-list 0xff, 0xff, // naming auth length 0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c' }; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_data; } { // request for IANA types SLPPacketBuilder::BuildServiceTypeRequest(&output, xid, true, pr_list, "", scopes); OLA_ASSERT_EQ(49u, ioqueue.Size()); unsigned int data_size; uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size); uint8_t expected_data[] = { 2, 9, 0, 0, 0x31, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n', 0, 15, '1', '.', '1', '.', '1', '.', '2', ',', '1', '.', '1', '.', '1', '.', '8', // pr-list 0x0, 0x0, // naming auth length 0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c' }; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_data; } { // request for a specific naming auth SLPPacketBuilder::BuildServiceTypeRequest(&output, xid, true, pr_list, "foo", scopes); OLA_ASSERT_EQ(52u, ioqueue.Size()); unsigned int data_size; uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size); uint8_t expected_data[] = { 2, 9, 0, 0, 0x34, 0x20, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n', 0, 15, '1', '.', '1', '.', '1', '.', '2', ',', '1', '.', '1', '.', '1', '.', '8', // pr-list 0x0, 0x3, 'f', 'o', 'o', // naming auth length 0, 0xc, 'a', 'c', 'n', ',', 'm', 'y', 'o', 'r', 'g', '\\', '2', 'c' }; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_data; } }
/** * Check that BuildServiceReply() works. */ void PacketBuilderTest::testBuildServiceReply() { URLEntry entry1("service:foo://1.1.1.1", 0x1234); URLEntry entry2("service:foo://1.1.1.10", 0x5678); URLEntries url_entries; url_entries.push_back(entry1); url_entries.push_back(entry2); SLPPacketBuilder::BuildServiceReply(&output, xid, EN_LANGUAGE_TAG, 12, url_entries); OLA_ASSERT_EQ(75u, ioqueue.Size()); { unsigned int data_size; uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size); uint8_t expected_data[] = { 2, 2, 0, 0, 0x4b, 0, 0, 0, 0, 0, 0x12, 0x34, 0, 2, 'e', 'n', 0, 12, // error code 0, 2, // url entry count // entry 1 0, 0x12, 0x34, 0, 21, 's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', ':', '/', '/', '1', '.', '1', '.', '1', '.', '1', 0, // # of auth blocks // entry 2 0, 0x56, 0x78, 0, 22, 's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', ':', '/', '/', '1', '.', '1', '.', '1', '.', '1', '0', 0, // # of auth blocks }; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_data; } // try a different language SLPPacketBuilder::BuildServiceReply(&output, xid, "en-AU", 12, url_entries); OLA_ASSERT_EQ(78u, ioqueue.Size()); { unsigned int data_size; uint8_t *output_data = WriteToBuffer(&ioqueue, &data_size); uint8_t expected_data[] = { 2, 2, 0, 0, 0x4e, 0, 0, 0, 0, 0, 0x12, 0x34, 0, 5, 'e', 'n', '-', 'A', 'U', 0, 12, // error code 0, 2, // url entry count // entry 1 0, 0x12, 0x34, 0, 21, 's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', ':', '/', '/', '1', '.', '1', '.', '1', '.', '1', 0, // # of auth blocks // entry 2 0, 0x56, 0x78, 0, 22, 's', 'e', 'r', 'v', 'i', 'c', 'e', ':', 'f', 'o', 'o', ':', '/', '/', '1', '.', '1', '.', '1', '.', '1', '0', 0, // # of auth blocks }; ASSERT_DATA_EQUALS(__LINE__, expected_data, sizeof(expected_data), output_data, data_size); delete[] output_data; } }
/* * 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; }