/* * Check that basic appending works. */ void IOQueueTest::testBasicWrite() { OLA_ASSERT_EQ(0u, m_buffer->Size()); uint8_t data1[] = {0, 1, 2, 3, 4}; m_buffer->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 Pop behaves */ void IOQueueTest::testPop() { uint8_t data1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; m_buffer->Write(data1, sizeof(data1)); OLA_ASSERT_EQ(9u, m_buffer->Size()); OLA_ASSERT_FALSE(m_buffer->Empty()); m_buffer->Pop(9); OLA_ASSERT_EQ(0u, m_buffer->Size()); OLA_ASSERT_TRUE(m_buffer->Empty()); // try to pop off more data m_buffer->Pop(1); OLA_ASSERT_EQ(0u, m_buffer->Size()); OLA_ASSERT_TRUE(m_buffer->Empty()); // add the data back, then try to pop off more than we have m_buffer->Write(data1, sizeof(data1)); OLA_ASSERT_EQ(9u, m_buffer->Size()); OLA_ASSERT_FALSE(m_buffer->Empty()); m_buffer->Pop(10); OLA_ASSERT_EQ(0u, m_buffer->Size()); OLA_ASSERT_TRUE(m_buffer->Empty()); // one more time m_buffer->Write(data1, sizeof(data1)); OLA_ASSERT_EQ(9u, m_buffer->Size()); // Now try a buffer with smaller blocks MemoryBlockPool pool(4); IOQueue queue(&pool); queue.Write(data1, sizeof(data1)); OLA_ASSERT_EQ(9u, queue.Size()); // pop the same amount as the first block size queue.Pop(4); OLA_ASSERT_EQ(5u, queue.Size()); OLA_ASSERT_FALSE(queue.Empty()); // now pop more than the buffer size queue.Pop(6); OLA_ASSERT_EQ(0u, queue.Size()); OLA_ASSERT_TRUE(queue.Empty()); // test the block boundry uint8_t *output_data = new uint8_t[4]; m_buffer.reset(new IOQueue(&pool)); queue.Write(data1, 4); OLA_ASSERT_EQ(4u, queue.Size()); unsigned int output_size = queue.Peek(output_data, 4); ASSERT_DATA_EQUALS(__LINE__, data1, 4, output_data, output_size); queue.Pop(4); OLA_ASSERT_TRUE(queue.Empty()); // now add some more data queue.Write(data1 + 4, 4); OLA_ASSERT_EQ(4u, queue.Size()); output_size = queue.Peek(output_data, 4); ASSERT_DATA_EQUALS(__LINE__, data1 + 4, 4, output_data, output_size); queue.Pop(4); OLA_ASSERT_TRUE(queue.Empty()); delete[] output_data; }