1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-13 01:00:23 +02:00

Add ioReadBuf() to easily read into a buffer.

Moves some boilerplate into a function and makes it easier to get coverage in cases where a single buffer read captures all the data.
This commit is contained in:
David Steele
2019-01-18 11:14:44 +02:00
parent 06d41b4dc0
commit 797f8098d1
5 changed files with 59 additions and 1 deletions

View File

@ -228,7 +228,7 @@ testRun(void)
}
// *****************************************************************************************************************************
if (testBegin("IoRead, IoBufferRead, IoBuffer, IoSize, IoFilter, and IoFilterGroup"))
if (testBegin("IoRead, IoBufferRead, IoBuffer, IoSize, IoFilter, IoFilterGroup, and ioReadBuf()"))
{
IoRead *read = NULL;
Buffer *buffer = bufNew(2);
@ -375,6 +375,15 @@ testRun(void)
read = ioBufferReadIo(ioBufferReadNew(bufNewZ("0123456789")));
ioReadOpen(read);
TEST_ERROR(ioReadLine(read), FileReadError, "unable to find line in 10 byte buffer");
// Read IO into a buffer
// -------------------------------------------------------------------------------------------------------------------------
ioBufferSizeSet(8);
bufferRead = ioBufferReadNew(bufNewStr(strNew("a test string")));
ioReadOpen(ioBufferReadIo(bufferRead));
TEST_RESULT_STR(strPtr(strNewBuf(ioReadBuf(ioBufferReadIo(bufferRead)))), "a test string", "read into buffer");
}
// *****************************************************************************************************************************