10 #include <CTraitsTest.h>    16 #include <gtest/gtest.h>    18 template class mrpt::CTraitsTest<mrpt::containers::circular_buffer<char>>;
    22 TEST(circular_buffer_tests, EmptyPop)
    26     EXPECT_THROW(cb.
pop(ret), std::exception);
    28 TEST(circular_buffer_tests, EmptyPopAfterPushes)
    30     constexpr 
size_t LEN = 20;
    32     for (
size_t nWr = 0; nWr < LEN; nWr++)
    34         for (
size_t i = 0; i < nWr; i++) cb.
push(12);
    36         for (
size_t i = 0; i < nWr; i++) cb.
pop(ret);
    38         EXPECT_THROW(cb.
pop(ret), std::exception);
    42 TEST(circular_buffer_tests, RandomWriteAndPeek)
    44     constexpr 
size_t LEN = 20;
    47     for (
size_t iter = 0; iter < 1000; iter++)
    51         for (
size_t i = 0; i < nWr; i++) cb.
push(i);
    53         for (
size_t i = 0; i < nWr; i++)
    58         for (
size_t i = 0; i < nWr; i++)
    65 TEST(circular_buffer_tests, RandomWriteManyAndPeek)
    67     constexpr 
size_t LEN = 20;
    69     std::vector<cb_t> dum_buf;
    71     for (
size_t iter = 0; iter < 1000; iter++)
    81             for (
size_t i = 0; i < nWr; i++) ret = cb.
peek(i);
    90             for (
size_t i = 0; i < nWr; i++) cb.
pop(ret);
    99 TEST(circular_buffer_tests, RandomWriteAndPeekOverrun)
   101     constexpr 
size_t LEN = 20;
   104     for (
size_t iter = 0; iter < 100; iter++)
   108         for (
size_t i = 0; i < nWr; i++) cb.
push(i);
   110         for (
unsigned k = 0; k < 5; k++)
   112             EXPECT_ANY_THROW(ret = cb.
peek(nWr + k););
   114         for (
size_t i = 0; i < nWr; i++) cb.
pop(ret);
   118 TEST(circular_buffer_tests, Size)
   121     for (
size_t i = 0; i < cb.
capacity() - 1; i++)
   126     EXPECT_ANY_THROW(cb.
push(0));
   127     for (
size_t i = 0; i < cb.
capacity() - 1; i++)
   134 template <
typename T>
   137     constexpr T LEN = 20;
   140     for (T i = 0; i < LEN; i++) cb.
push(i);
   142     std::array<T, LEN> peek_vals;
   145     for (T i = 0; i < LEN; i++)
   146         EXPECT_EQ(static_cast<int>(peek_vals[i]), static_cast<int>(i));
   149 TEST(circular_buffer_tests, WritePeekCheck_uint8_t)
   151     impl_WritePeekCheck<uint8_t>();
   153 TEST(circular_buffer_tests, WritePeekCheck_uint16_t)
   155     impl_WritePeekCheck<uint16_t>();
   157 TEST(circular_buffer_tests, WritePeekCheck_uint32_t)
   159     impl_WritePeekCheck<uint32_t>();
   161 TEST(circular_buffer_tests, WritePeekCheck_uint64_t)
   163     impl_WritePeekCheck<uint64_t>();
 uint32_t drawUniform32bit()
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, in the whole range of 32-bit integers. 
size_t capacity() const
Return the maximum capacity of the buffer. 
TEST(circular_buffer_tests, EmptyPop)
void impl_WritePeekCheck()
T pop()
Retrieve an element from the buffer. 
T peek() const
Peek (see without modifying) what is to be read from the buffer if pop() was to be called...
size_t size() const
Return the number of elements available for read ("pop") in the buffer (this is NOT the maximum size ...
void pop_many(T *out_array, size_t count)
Pop a number of elements into a user-provided array. 
void peek_many(T *out_array, size_t count) const
Like peek(), for multiple elements, storing a number of elements into a user-provided array...
A circular buffer of fixed size (defined at construction-time), implemented with a std::vector as the...
EXPECT_EQ(out.image_pair_was_used.size(), NUM_IMGS)
void push_many(T *array_elements, size_t count)
Insert an array of elements in the buffer. 
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications. 
void push(T d)
Insert a copy of the given element in the buffer. 
#define MRPT_UNUSED_PARAM(a)
Determines whether this is an X86 or AMD64 platform.