From c04dcc2e7d834218ef2d4194331e383402495ae1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 20:07:22 +0200 Subject: Adding upstream version 2:20.4+dfsg. Signed-off-by: Daniel Baumann --- .../Source/Tests/RingBuffer1/RingBufferTest1.cpp | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 lib/libUPnP/Neptune/Source/Tests/RingBuffer1/RingBufferTest1.cpp (limited to 'lib/libUPnP/Neptune/Source/Tests/RingBuffer1/RingBufferTest1.cpp') diff --git a/lib/libUPnP/Neptune/Source/Tests/RingBuffer1/RingBufferTest1.cpp b/lib/libUPnP/Neptune/Source/Tests/RingBuffer1/RingBufferTest1.cpp new file mode 100644 index 0000000..4347182 --- /dev/null +++ b/lib/libUPnP/Neptune/Source/Tests/RingBuffer1/RingBufferTest1.cpp @@ -0,0 +1,113 @@ +/***************************************************************** +| +| RingBuffer Test Program 1 +| +| (c) 2001-2005 Gilles Boccon-Gibod +| Author: Gilles Boccon-Gibod (bok@bok.net) +| + ****************************************************************/ + +/*---------------------------------------------------------------------- +| includes ++---------------------------------------------------------------------*/ +#include "Neptune.h" +#include + +#if defined(WIN32) +#include +#endif + +const unsigned int BUFFER_SIZE = 17; + +/*---------------------------------------------------------------------- +| ReadChunk ++---------------------------------------------------------------------*/ +static NPT_Result +ReadChunk(NPT_RingBuffer& buffer) +{ + static unsigned int total_read = 0; + unsigned int chunk = rand()%BUFFER_SIZE; + unsigned int can_read = buffer.GetAvailable(); + if (chunk > can_read) chunk = can_read; + if (chunk == 0) return NPT_SUCCESS; + + // read a chunk + unsigned char bytes[BUFFER_SIZE]; + NPT_CHECK(buffer.Read(bytes, chunk)); + + // check values + for (unsigned int i=0; i can_write) chunk = can_write; + if (chunk == 0) return NPT_SUCCESS; + + // generate buffer + unsigned char bytes[BUFFER_SIZE]; + for (unsigned int i=0; i