From 51484a008f1172b51c2296974de7bfcd37ab24b8 Mon Sep 17 00:00:00 2001 From: David Steele Date: Wed, 26 Sep 2018 18:46:52 +0100 Subject: [PATCH] Add bufNewZ() to Buffer object. This constructor creates a Buffer object directly from a zero-terminated string. The old way was to create a String object first, then convert that to a Buffer using bufNewStr(). Updated in all places that used the old pattern. --- doc/xml/release.xml | 4 + src/common/type/buffer.c | 20 +++ src/common/type/buffer.h | 1 + test/src/module/archive/commonTest.c | 15 +- test/src/module/archive/getTest.c | 65 ++++---- test/src/module/archive/pushTest.c | 5 +- test/src/module/common/ioTest.c | 12 +- test/src/module/common/typeBufferTest.c | 25 +-- test/src/module/config/parseTest.c | 200 ++++++++++++------------ test/src/module/crypto/hashTest.c | 8 +- test/src/module/storage/posixTest.c | 16 +- 11 files changed, 200 insertions(+), 171 deletions(-) diff --git a/doc/xml/release.xml b/doc/xml/release.xml index 004ab4476..c35f0248d 100644 --- a/doc/xml/release.xml +++ b/doc/xml/release.xml @@ -90,6 +90,10 @@

Add helper for repository storage.

+ +

Add bufNewZ() to Buffer object.

+
+ diff --git a/src/common/type/buffer.c b/src/common/type/buffer.c index ea1136fdb..f0cfea7b6 100644 --- a/src/common/type/buffer.c +++ b/src/common/type/buffer.c @@ -89,6 +89,26 @@ bufNewStr(const String *string) FUNCTION_TEST_RESULT(BUFFER, this); } +/*********************************************************************************************************************************** +Create a new buffer from a zero-terminated string +***********************************************************************************************************************************/ +Buffer * +bufNewZ(const char *string) +{ + FUNCTION_TEST_BEGIN(); + FUNCTION_TEST_PARAM(STRINGZ, string); + + FUNCTION_TEST_ASSERT(string != NULL); + FUNCTION_TEST_END(); + + // Create object and copy string + Buffer *this = bufNew(strlen(string)); + memcpy(this->buffer, string, strlen(string)); + this->used = this->size; + + FUNCTION_TEST_RESULT(BUFFER, this); +} + /*********************************************************************************************************************************** Append the contents of another buffer ***********************************************************************************************************************************/ diff --git a/src/common/type/buffer.h b/src/common/type/buffer.h index 7142b7b73..73bc95b28 100644 --- a/src/common/type/buffer.h +++ b/src/common/type/buffer.h @@ -18,6 +18,7 @@ Functions Buffer *bufNew(size_t size); Buffer *bufNewC(size_t size, const void *buffer); Buffer *bufNewStr(const String *string); +Buffer *bufNewZ(const char *string); Buffer *bufCat(Buffer *this, const Buffer *cat); Buffer *bufCatC(Buffer *this, const unsigned char *cat, size_t catOffset, size_t catSize); diff --git a/test/src/module/archive/commonTest.c b/test/src/module/archive/commonTest.c index 21fa78d29..0f14da610 100644 --- a/test/src/module/archive/commonTest.c +++ b/test/src/module/archive/commonTest.c @@ -48,20 +48,20 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- storagePutNP( storageNewWriteNP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.ok", strPtr(segment))), - bufNewStr(strNew(BOGUS_STR))); + bufNewZ(BOGUS_STR)); TEST_ERROR( archiveAsyncStatus(archiveModePush, segment, false), FormatError, "000000010000000100000001.ok content must have at least two lines"); storagePutNP( storageNewWriteNP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.ok", strPtr(segment))), - bufNewStr(strNew(BOGUS_STR "\n"))); + bufNewZ(BOGUS_STR "\n")); TEST_ERROR( archiveAsyncStatus(archiveModePush, segment, false), FormatError, "000000010000000100000001.ok message must be > 0"); storagePutNP( storageNewWriteNP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.ok", strPtr(segment))), - bufNewStr(strNew(BOGUS_STR "\nmessage"))); + bufNewZ(BOGUS_STR "\nmessage")); TEST_ERROR(archiveAsyncStatus(archiveModePush, segment, false), FormatError, "unable to convert string 'BOGUS' to int"); storagePutNP(storageNewWriteNP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.ok", strPtr(segment))), NULL); @@ -69,21 +69,20 @@ testRun(void) storagePutNP( storageNewWriteNP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.ok", strPtr(segment))), - bufNewStr(strNew("0\nwarning"))); + bufNewZ("0\nwarning")); TEST_RESULT_BOOL(archiveAsyncStatus(archiveModePush, segment, false), true, "ok file with warning"); harnessLogResult("P00 WARN: warning"); storagePutNP( storageNewWriteNP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.ok", strPtr(segment))), - bufNewStr(strNew("25\nerror"))); + bufNewZ("25\nerror")); TEST_RESULT_BOOL(archiveAsyncStatus(archiveModePush, segment, false), true, "error status renamed to ok"); harnessLogResult( "P00 WARN: WAL segment '000000010000000100000001' was not pushed due to error [25] and was manually skipped: error"); // ------------------------------------------------------------------------------------------------------------------------- storagePutNP( - storageNewWriteNP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.error", strPtr(segment))), - bufNewStr(strNew(""))); + storageNewWriteNP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.error", strPtr(segment))), bufNew(0)); TEST_ERROR( archiveAsyncStatus(archiveModePush, segment, false), AssertError, strPtr( @@ -97,7 +96,7 @@ testRun(void) storagePutNP( storageNewWriteNP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_OUT "/%s.error", strPtr(segment))), - bufNewStr(strNew("25\nmessage"))); + bufNewZ("25\nmessage")); TEST_ERROR(archiveAsyncStatus(archiveModePush, segment, true), AssertError, "message"); TEST_RESULT_BOOL(archiveAsyncStatus(archiveModePush, segment, false), false, "suppress error"); diff --git a/test/src/module/archive/getTest.c b/test/src/module/archive/getTest.c index 3019337c6..0199b4af0 100644 --- a/test/src/module/archive/getTest.c +++ b/test/src/module/archive/getTest.c @@ -41,15 +41,14 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- storagePutNP( storageNewWriteNP(storageTest, strNew("repo/archive/test1/archive.info")), - bufNewStr( - strNew( - "[backrest]\n" - "backrest-checksum=\"0a415a03fa3faccb4ac171759895478469e9e19e\"\n" - "backrest-format=5\n" - "backrest-version=\"2.06\"\n" - "\n" - "[db:history]\n" - "1={\"db-id\":5555555555555555555,\"db-version\":\"9.4\"}\n"))); + bufNewZ( + "[backrest]\n" + "backrest-checksum=\"0a415a03fa3faccb4ac171759895478469e9e19e\"\n" + "backrest-format=5\n" + "backrest-version=\"2.06\"\n" + "\n" + "[db:history]\n" + "1={\"db-id\":5555555555555555555,\"db-version\":\"9.4\"}\n")); TEST_ERROR( archiveGetCheck(strNew("876543218765432187654321")), ArchiveMismatchError, @@ -59,18 +58,17 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- storagePutNP( storageNewWriteNP(storageTest, strNew("repo/archive/test1/archive.info")), - bufNewStr( - strNew( - "[backrest]\n" - "backrest-checksum=\"f7617b5c4c9f212f40b9bc3d8ec7f97edbbf96af\"\n" - "backrest-format=5\n" - "backrest-version=\"2.06\"\n" - "\n" - "[db:history]\n" - "1={\"db-id\":5555555555555555555,\"db-version\":\"9.4\"}\n" - "2={\"db-id\":18072658121562454734,\"db-version\":\"10\"}\n" - "3={\"db-id\":18072658121562454734,\"db-version\":\"9.6\"}\n" - "4={\"db-id\":18072658121562454734,\"db-version\":\"10\"}"))); + bufNewZ( + "[backrest]\n" + "backrest-checksum=\"f7617b5c4c9f212f40b9bc3d8ec7f97edbbf96af\"\n" + "backrest-format=5\n" + "backrest-version=\"2.06\"\n" + "\n" + "[db:history]\n" + "1={\"db-id\":5555555555555555555,\"db-version\":\"9.4\"}\n" + "2={\"db-id\":18072658121562454734,\"db-version\":\"10\"}\n" + "3={\"db-id\":18072658121562454734,\"db-version\":\"9.6\"}\n" + "4={\"db-id\":18072658121562454734,\"db-version\":\"10\"}")); TEST_RESULT_PTR(archiveGetCheck(strNew("876543218765432187654321")), NULL, "no segment found"); @@ -129,15 +127,14 @@ testRun(void) // Create archive.info storagePutNP( storageNewWriteNP(storageTest, strNew("repo/archive/test1/archive.info")), - bufNewStr( - strNew( - "[backrest]\n" - "backrest-checksum=\"8a041a4128eaa2c08a23dd1f04934627795946ff\"\n" - "backrest-format=5\n" - "backrest-version=\"2.06\"\n" - "\n" - "[db:history]\n" - "1={\"db-id\":18072658121562454734,\"db-version\":\"10\"}"))); + bufNewZ( + "[backrest]\n" + "backrest-checksum=\"8a041a4128eaa2c08a23dd1f04934627795946ff\"\n" + "backrest-format=5\n" + "backrest-version=\"2.06\"\n" + "\n" + "[db:history]\n" + "1={\"db-id\":18072658121562454734,\"db-version\":\"10\"}")); // Nothing to copy // ------------------------------------------------------------------------------------------------------------------------- @@ -242,7 +239,7 @@ testRun(void) walSegmentSize = 1024 * 1024; queueSize = walSegmentSize * 5; - storagePutNP(storageNewWriteNP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_IN "/junk")), bufNewStr(strNew("JUNK"))); + storagePutNP(storageNewWriteNP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_IN "/junk")), bufNewZ("JUNK")); storagePutNP( storageNewWriteNP( storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_IN "/000000010000000A00000FFE")), walSegmentBuffer); @@ -368,7 +365,7 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- storagePutNP( storageNewWriteNP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_IN "/%s", strPtr(walSegment))), - bufNewStr(strNew("SHOULD-BE-A-REAL-WAL-FILE"))); + bufNewZ("SHOULD-BE-A-REAL-WAL-FILE")); TEST_RESULT_VOID(cmdArchiveGet(), "successful get"); harnessLogResult("P00 INFO: found 000000010000000100000001 in the archive"); @@ -385,10 +382,10 @@ testRun(void) storagePutNP( storageNewWriteNP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_IN "/%s", strPtr(walSegment))), - bufNewStr(strNew("SHOULD-BE-A-REAL-WAL-FILE"))); + bufNewZ("SHOULD-BE-A-REAL-WAL-FILE")); storagePutNP( storageNewWriteNP(storageSpoolWrite(), strNewFmt(STORAGE_SPOOL_ARCHIVE_IN "/%s", strPtr(walSegment2))), - bufNewStr(strNew("SHOULD-BE-A-REAL-WAL-FILE"))); + bufNewZ("SHOULD-BE-A-REAL-WAL-FILE")); TEST_RESULT_VOID(cmdArchiveGet(), "successful get"); harnessLogResult("P00 INFO: found 000000010000000100000001 in the archive"); diff --git a/test/src/module/archive/pushTest.c b/test/src/module/archive/pushTest.c index 2dc4e78a6..ec1cd538b 100644 --- a/test/src/module/archive/pushTest.c +++ b/test/src/module/archive/pushTest.c @@ -60,7 +60,7 @@ testRun(void) storagePathRemoveNP(storageTest, strNewFmt("%s/db/archive_status", testPath())); String *errorFile = storagePathNP(storageSpool(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000001.error")); - storagePutNP(storageNewWriteNP(storageSpoolWrite(), errorFile), bufNewStr(strNew("25\n" BOGUS_STR))); + storagePutNP(storageNewWriteNP(storageSpoolWrite(), errorFile), bufNewZ("25\n" BOGUS_STR)); TEST_ERROR(cmdArchivePush(), AssertError, BOGUS_STR); @@ -69,8 +69,7 @@ testRun(void) // Write out a valid ok file and test for success // ------------------------------------------------------------------------------------------------------------------------- storagePutNP( - storageNewWriteNP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000001.ok")), - bufNewStr(strNew(""))); + storageNewWriteNP(storageSpoolWrite(), strNew(STORAGE_SPOOL_ARCHIVE_OUT "/000000010000000100000001.ok")), bufNew(0)); TEST_RESULT_VOID(cmdArchivePush(), "successful push"); harnessLogResult("P00 INFO: pushed WAL segment 000000010000000100000001 asynchronously"); diff --git a/test/src/module/common/ioTest.c b/test/src/module/common/ioTest.c index 95fca6f56..92f97bb88 100644 --- a/test/src/module/common/ioTest.c +++ b/test/src/module/common/ioTest.c @@ -21,7 +21,7 @@ static size_t testIoRead(void *driver, Buffer *buffer) { ASSERT(driver == (void *)999); - bufCat(buffer, bufNewStr(strNew("Z"))); + bufCat(buffer, bufNewZ("Z")); return 1; } @@ -251,7 +251,7 @@ testRun(void) IoBufferRead *bufferRead = NULL; ioBufferSizeSet(2); buffer = bufNew(2); - Buffer *bufferOriginal = bufNewStr(strNew("123")); + Buffer *bufferOriginal = bufNewZ("123"); MEM_CONTEXT_TEMP_BEGIN() { @@ -332,7 +332,7 @@ testRun(void) TEST_RESULT_VOID(ioWriteOpen(write), " open io object"); TEST_RESULT_BOOL(testIoWriteOpenCalled, true, " check io object open"); - TEST_RESULT_VOID(ioWrite(write, bufNewStr(strNew("ABC"))), " write 3 bytes"); + TEST_RESULT_VOID(ioWrite(write, bufNewZ("ABC")), " write 3 bytes"); TEST_RESULT_VOID(ioWriteClose(write), " close io object"); TEST_RESULT_BOOL(testIoWriteCloseCalled, true, " check io object closed"); @@ -359,12 +359,12 @@ testRun(void) TEST_RESULT_VOID(ioWriteFilterGroupSet(ioBufferWriteIo(bufferWrite), filterGroup), " add filter group to write io"); TEST_RESULT_VOID(ioWriteOpen(ioBufferWriteIo(bufferWrite)), " open buffer write object"); - TEST_RESULT_VOID(ioWrite(ioBufferWriteIo(bufferWrite), bufNewStr(strNew("ABC"))), " write 3 bytes"); - TEST_RESULT_VOID(ioWrite(ioBufferWriteIo(bufferWrite), bufNewStr(strNew(""))), " write 0 bytes"); + TEST_RESULT_VOID(ioWrite(ioBufferWriteIo(bufferWrite), bufNewZ("ABC")), " write 3 bytes"); + TEST_RESULT_VOID(ioWrite(ioBufferWriteIo(bufferWrite), bufNew(0)), " write 0 bytes"); TEST_RESULT_VOID(ioWrite(ioBufferWriteIo(bufferWrite), NULL), " write 0 bytes"); TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "AABBCC", " check write"); - TEST_RESULT_VOID(ioWrite(ioBufferWriteIo(bufferWrite), bufNewStr(strNew("12345"))), " write 4 bytes"); + TEST_RESULT_VOID(ioWrite(ioBufferWriteIo(bufferWrite), bufNewZ("12345")), " write 4 bytes"); TEST_RESULT_STR(strPtr(strNewBuf(buffer)), "AABBCC112233445", " check write"); TEST_RESULT_VOID(ioWriteClose(ioBufferWriteIo(bufferWrite)), " close buffer write object"); diff --git a/test/src/module/common/typeBufferTest.c b/test/src/module/common/typeBufferTest.c index c6f6e2a62..83d80c3b0 100644 --- a/test/src/module/common/typeBufferTest.c +++ b/test/src/module/common/typeBufferTest.c @@ -11,7 +11,7 @@ testRun(void) FUNCTION_HARNESS_VOID(); // ***************************************************************************************************************************** - if (testBegin("bufNew(), bugNewC, bufNewStr(), bufMove(), bufSize(), bufPtr(), and bufFree()")) + if (testBegin("bufNew(), bugNewC, bufNewStr(), bufNewZ(), bufMove(), bufSize(), bufPtr(), and bufFree()")) { Buffer *buffer = NULL; @@ -28,6 +28,9 @@ testRun(void) TEST_ASSIGN(buffer, bufNewStr(strNew("TEST-STR")), "new buffer from string"); TEST_RESULT_BOOL(memcmp(bufPtr(buffer), "TEST-STR", 8) == 0, true, "check buffer"); + TEST_ASSIGN(buffer, bufNewZ("TEST-STRZ"), "new buffer from zero-terminated string"); + TEST_RESULT_BOOL(memcmp(bufPtr(buffer), "TEST-STRZ", 9) == 0, true, "check buffer"); + TEST_RESULT_VOID(bufFree(buffer), "free buffer"); TEST_RESULT_VOID(bufFree(bufNew(0)), "free empty buffer"); TEST_RESULT_VOID(bufFree(NULL), "free null buffer"); @@ -104,26 +107,26 @@ testRun(void) // ***************************************************************************************************************************** if (testBegin("bufEq()")) { - TEST_RESULT_BOOL(bufEq(bufNewStr(strNew("123")), bufNewStr(strNew("1234"))), false, "buffer sizes not equal"); - TEST_RESULT_BOOL(bufEq(bufNewStr(strNew("321")), bufNewStr(strNew("123"))), false, "buffer sizes equal"); - TEST_RESULT_BOOL(bufEq(bufNewStr(strNew("123")), bufNewStr(strNew("123"))), true, "buffers equal"); + TEST_RESULT_BOOL(bufEq(bufNewZ("123"), bufNewZ("1234")), false, "buffer sizes not equal"); + TEST_RESULT_BOOL(bufEq(bufNewZ("321"), bufNewZ("123")), false, "buffer sizes equal"); + TEST_RESULT_BOOL(bufEq(bufNewZ("123"), bufNewZ("123")), true, "buffers equal"); } // ***************************************************************************************************************************** if (testBegin("bufCat*()")) { - TEST_RESULT_STR(strPtr(strNewBuf(bufCat(bufNewStr(strNew("123")), NULL))), "123", "cat null buffer"); - TEST_RESULT_STR(strPtr(strNewBuf(bufCat(bufNewStr(strNew("123")), bufNew(0)))), "123", "cat empty buffer"); - TEST_RESULT_STR(strPtr(strNewBuf(bufCat(bufNewStr(strNew("123")), bufNewStr(strNew("ABC"))))), "123ABC", "cat buffer"); + TEST_RESULT_STR(strPtr(strNewBuf(bufCat(bufNewZ("123"), NULL))), "123", "cat null buffer"); + TEST_RESULT_STR(strPtr(strNewBuf(bufCat(bufNewZ("123"), bufNew(0)))), "123", "cat empty buffer"); + TEST_RESULT_STR(strPtr(strNewBuf(bufCat(bufNewZ("123"), bufNewZ("ABC")))), "123ABC", "cat buffer"); - TEST_RESULT_STR(strPtr(strNewBuf(bufCatSub(bufNewStr(strNew("123")), NULL, 0, 0))), "123", "cat sub null buffer"); - TEST_RESULT_STR(strPtr(strNewBuf(bufCatSub(bufNewStr(strNew("123")), bufNew(0), 0, 0))), "123", "cat sub empty buffer"); + TEST_RESULT_STR(strPtr(strNewBuf(bufCatSub(bufNewZ("123"), NULL, 0, 0))), "123", "cat sub null buffer"); + TEST_RESULT_STR(strPtr(strNewBuf(bufCatSub(bufNewZ("123"), bufNew(0), 0, 0))), "123", "cat sub empty buffer"); TEST_RESULT_STR( - strPtr(strNewBuf(bufCatSub(bufNewStr(strNew("123")), bufNewStr(strNew("ABC")), 1, 2))), "123BC", "cat sub buffer"); + strPtr(strNewBuf(bufCatSub(bufNewZ("123"), bufNewZ("ABC"), 1, 2))), "123BC", "cat sub buffer"); Buffer *buffer = NULL; TEST_ASSIGN(buffer, bufNew(2), "new buffer with space"); - TEST_RESULT_STR(strPtr(strNewBuf(bufCat(buffer, bufNewStr(strNew("AB"))))), "AB", "cat buffer with space"); + TEST_RESULT_STR(strPtr(strNewBuf(bufCat(buffer, bufNewZ("AB")))), "AB", "cat buffer with space"); } // ***************************************************************************************************************************** diff --git a/test/src/module/config/parseTest.c b/test/src/module/config/parseTest.c index c51b1bf17..198a110bd 100644 --- a/test/src/module/config/parseTest.c +++ b/test/src/module/config/parseTest.c @@ -64,41 +64,40 @@ testRun(void) strLstAdd(argList, strNew(TEST_COMMAND_BACKUP)); storagePut( - storageNewWriteNP(storageLocalWrite(), configFile), bufNewStr( - strNew( - "[global]\n" - "compress-level=3\n" - "spool-path=/path/to/spool\n"))); + storageNewWriteNP(storageLocalWrite(), configFile), + bufNewZ( + "[global]\n" + "compress-level=3\n" + "spool-path=/path/to/spool\n")); storagePut( - storageNewWriteNP( - storageLocalWrite(), strNewFmt("%s/global-backup.conf", strPtr(configIncludePath))), bufNewStr( - strNew( - "[global:backup]\n" - "repo1-hardlink=y\n" - "bogus=bogus\n" - "no-compress=y\n" - "reset-compress=y\n" - "archive-copy=y\n" - "online=y\n" - "pg1-path=/not/path/to/db\n" - "backup-standby=y\n" - "buffer-size=65536\n"))); + storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/global-backup.conf", strPtr(configIncludePath))), + bufNewZ( + "[global:backup]\n" + "repo1-hardlink=y\n" + "bogus=bogus\n" + "no-compress=y\n" + "reset-compress=y\n" + "archive-copy=y\n" + "online=y\n" + "pg1-path=/not/path/to/db\n" + "backup-standby=y\n" + "buffer-size=65536\n")); storagePut( - storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/db-backup.conf", strPtr(configIncludePath))), bufNewStr( - strNew( - "[db:backup]\n" - "compress=n\n" - "recovery-option=a=b\n"))); + storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/db-backup.conf", strPtr(configIncludePath))), + bufNewZ( + "[db:backup]\n" + "compress=n\n" + "recovery-option=a=b\n")); storagePut( - storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/stanza.db.conf", strPtr(configIncludePath))), bufNewStr( - strNew( - "[db]\n" - "pg1-host=db\n" - "pg1-path=/path/to/db\n" - "recovery-option=c=d\n"))); + storageNewWriteNP(storageLocalWrite(), strNewFmt("%s/stanza.db.conf", strPtr(configIncludePath))), + bufNewZ( + "[db]\n" + "pg1-host=db\n" + "pg1-path=/path/to/db\n" + "recovery-option=c=d\n")); TEST_RESULT_VOID( configParse(strLstSize(argList), strLstPtr(argList), false), TEST_COMMAND_BACKUP " command with config-include"); @@ -225,11 +224,10 @@ testRun(void) mkdir(strPtr(strPath(oldConfigDefault)), 0750); storagePut( - storageNewWriteNP( - storageLocalWrite(), oldConfigDefault), bufNewStr( - strNew( - "[global:backup]\n" - "buffer-size=65536\n"))); + storageNewWriteNP(storageLocalWrite(), oldConfigDefault), + bufNewZ( + "[global:backup]\n" + "buffer-size=65536\n")); // Pass actual location of config files as "default" - not setting valueList above, so these are the only possible values // to choose. @@ -907,10 +905,11 @@ testRun(void) strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile))); strLstAdd(argList, strNew(TEST_COMMAND_BACKUP)); - storagePutNP(storageNewWriteNP(storageLocalWrite(), configFile), bufNewStr(strNew( - "[global]\n" - "compress=bogus\n" - ))); + storagePutNP( + storageNewWriteNP(storageLocalWrite(), configFile), + bufNewZ( + "[global]\n" + "compress=bogus\n")); TEST_ERROR(configParse( strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError, @@ -923,10 +922,11 @@ testRun(void) strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile))); strLstAdd(argList, strNew(TEST_COMMAND_BACKUP)); - storagePutNP(storageNewWriteNP(storageLocalWrite(), configFile), bufNewStr(strNew( - "[global]\n" - "compress=\n" - ))); + storagePutNP( + storageNewWriteNP(storageLocalWrite(), configFile), + bufNewZ( + "[global]\n" + "compress=\n")); TEST_ERROR(configParse( strLstSize(argList), strLstPtr(argList), false), OptionInvalidValueError, @@ -939,11 +939,12 @@ testRun(void) strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile))); strLstAdd(argList, strNew(TEST_COMMAND_BACKUP)); - storagePutNP(storageNewWriteNP(storageLocalWrite(), configFile), bufNewStr(strNew( - "[db]\n" - "pg1-path=/path/to/db\n" - "db-path=/also/path/to/db\n" - ))); + storagePutNP( + storageNewWriteNP(storageLocalWrite(), configFile), + bufNewZ( + "[db]\n" + "pg1-path=/path/to/db\n" + "db-path=/also/path/to/db\n")); TEST_ERROR(configParse( strLstSize(argList), strLstPtr(argList), false), OptionInvalidError, @@ -956,11 +957,12 @@ testRun(void) strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile))); strLstAdd(argList, strNew(TEST_COMMAND_BACKUP)); - storagePutNP(storageNewWriteNP(storageLocalWrite(), configFile), bufNewStr(strNew( - "[db]\n" - "pg1-path=/path/to/db\n" - "pg1-path=/also/path/to/db\n" - ))); + storagePutNP( + storageNewWriteNP(storageLocalWrite(), configFile), + bufNewZ( + "[db]\n" + "pg1-path=/path/to/db\n" + "pg1-path=/also/path/to/db\n")); TEST_ERROR(configParse(strLstSize(argList), strLstPtr(argList), false), OptionInvalidError, @@ -1082,32 +1084,33 @@ testRun(void) setenv("PGBACKREST_START_FAST", "n", true); setenv("PGBACKREST_PG1_SOCKET_PATH", "/path/to/socket", true); - storagePutNP(storageNewWriteNP(storageLocalWrite(), configFile), bufNewStr(strNew( - "[global]\n" - "compress-level=3\n" - "spool-path=/path/to/spool\n" - "\n" - "[global:backup]\n" - "repo1-hardlink=y\n" - "bogus=bogus\n" - "no-compress=y\n" - "reset-compress=y\n" - "archive-copy=y\n" - "start-fast=y\n" - "online=y\n" - "pg1-path=/not/path/to/db\n" - "backup-standby=y\n" - "buffer-size=65536\n" - "\n" - "[db:backup]\n" - "compress=n\n" - "recovery-option=a=b\n" - "\n" - "[db]\n" - "pg1-host=db\n" - "pg1-path=/path/to/db\n" - "recovery-option=c=d\n" - ))); + storagePutNP( + storageNewWriteNP(storageLocalWrite(), configFile), + bufNewZ( + "[global]\n" + "compress-level=3\n" + "spool-path=/path/to/spool\n" + "\n" + "[global:backup]\n" + "repo1-hardlink=y\n" + "bogus=bogus\n" + "no-compress=y\n" + "reset-compress=y\n" + "archive-copy=y\n" + "start-fast=y\n" + "online=y\n" + "pg1-path=/not/path/to/db\n" + "backup-standby=y\n" + "buffer-size=65536\n" + "\n" + "[db:backup]\n" + "compress=n\n" + "recovery-option=a=b\n" + "\n" + "[db]\n" + "pg1-host=db\n" + "pg1-path=/path/to/db\n" + "recovery-option=c=d\n")); TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), TEST_COMMAND_BACKUP " command"); harnessLogResult( @@ -1162,10 +1165,11 @@ testRun(void) strLstAdd(argList, strNew("--buffer-size=2MB")); strLstAdd(argList, strNew("archive-push")); - storagePutNP(storageNewWriteNP(storageLocalWrite(), configFile), bufNewStr(strNew( - "[global]\n" - "spool-path=/path/to/spool\n" - ))); + storagePutNP( + storageNewWriteNP(storageLocalWrite(), configFile), + bufNewZ( + "[global]\n" + "spool-path=/path/to/spool\n")); TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), "archive-push command"); @@ -1235,14 +1239,15 @@ testRun(void) strLstAdd(argList, strNew("--stanza=db")); strLstAdd(argList, strNew(TEST_COMMAND_RESTORE)); - storagePutNP(storageNewWriteNP(storageLocalWrite(), configFile), bufNewStr(strNew( - "[global:restore]\n" - "recovery-option=f=g\n" - "recovery-option=hijk=l\n" - "\n" - "[db]\n" - "pg1-path=/path/to/db\n" - ))); + storagePutNP( + storageNewWriteNP(storageLocalWrite(), configFile), + bufNewZ( + "[global:restore]\n" + "recovery-option=f=g\n" + "recovery-option=hijk=l\n" + "\n" + "[db]\n" + "pg1-path=/path/to/db\n")); TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), TEST_COMMAND_RESTORE " command"); @@ -1280,13 +1285,14 @@ testRun(void) strLstAdd(argList, strNewFmt("--config=%s", strPtr(configFile))); strLstAdd(argList, strNew("info")); - storagePutNP(storageNewWriteNP(storageLocalWrite(), configFile), bufNewStr(strNew( - "[global]\n" - "repo1-path=/path/to/repo\n" - "\n" - "[db]\n" - "repo1-path=/not/the/path\n" - ))); + storagePutNP( + storageNewWriteNP(storageLocalWrite(), configFile), + bufNewZ( + "[global]\n" + "repo1-path=/path/to/repo\n" + "\n" + "[db]\n" + "repo1-path=/not/the/path\n")); TEST_RESULT_VOID(configParse(strLstSize(argList), strLstPtr(argList), false), "info command"); TEST_RESULT_STR(strPtr(cfgOptionStr(cfgOptRepoPath)), "/path/to/repo", "check repo1-path option"); diff --git a/test/src/module/crypto/hashTest.c b/test/src/module/crypto/hashTest.c index 8211b448a..c56c6312d 100644 --- a/test/src/module/crypto/hashTest.c +++ b/test/src/module/crypto/hashTest.c @@ -34,9 +34,9 @@ testRun(void) TEST_ASSIGN(hashFilter, cryptoHashFilter(hash), "create sha1 hash"); TEST_RESULT_VOID(cryptoHashProcessC(hash, (const unsigned char *)"1", 1), " add 1"); TEST_RESULT_VOID(cryptoHashProcessStr(hash, strNew("2")), " add 2"); - TEST_RESULT_VOID(ioFilterProcessIn(hashFilter, bufNewStr(strNew("3"))), " add 3"); - TEST_RESULT_VOID(ioFilterProcessIn(hashFilter, bufNewStr(strNew("4"))), " add 4"); - TEST_RESULT_VOID(ioFilterProcessIn(hashFilter, bufNewStr(strNew("5"))), " add 5"); + TEST_RESULT_VOID(ioFilterProcessIn(hashFilter, bufNewZ("3")), " add 3"); + TEST_RESULT_VOID(ioFilterProcessIn(hashFilter, bufNewZ("4")), " add 4"); + TEST_RESULT_VOID(ioFilterProcessIn(hashFilter, bufNewZ("5")), " add 5"); TEST_RESULT_STR( strPtr(varStr(ioFilterResult(hashFilter))), "8cb2237d0679ca88db6464eac60da96345513964", " check small hash"); @@ -57,7 +57,7 @@ testRun(void) if (testBegin("cryptoHashOne*()")) { TEST_RESULT_STR( - strPtr(cryptoHashOne(strNew(HASH_TYPE_SHA1), bufNewStr(strNew("12345")))), "8cb2237d0679ca88db6464eac60da96345513964", + strPtr(cryptoHashOne(strNew(HASH_TYPE_SHA1), bufNewZ("12345"))), "8cb2237d0679ca88db6464eac60da96345513964", " check small hash"); TEST_RESULT_STR( strPtr(cryptoHashOneStr(strNew(HASH_TYPE_SHA1), strNew("12345"))), "8cb2237d0679ca88db6464eac60da96345513964", diff --git a/test/src/module/storage/posixTest.c b/test/src/module/storage/posixTest.c index 7b7e6e2b8..57fe60670 100644 --- a/test/src/module/storage/posixTest.c +++ b/test/src/module/storage/posixTest.c @@ -198,7 +198,7 @@ testRun(void) TEST_RESULT_INT(info.mode, 0770, " check mode"); // ------------------------------------------------------------------------------------------------------------------------- - Buffer *buffer = bufNewStr(strNew("TESTFILE")); + Buffer *buffer = bufNewZ("TESTFILE"); TEST_RESULT_VOID(storagePutNP(storageNewWriteNP(storageTest, fileName), buffer), "put test file"); TEST_ASSIGN(info, storageInfoNP(storageTest, fileName), "get file info"); @@ -254,13 +254,13 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- TEST_RESULT_VOID( - storagePutNP(storageNewWriteNP(storageTest, strNew("aaa.txt")), bufNewStr(strNew("aaa"))), "write aaa.text"); + storagePutNP(storageNewWriteNP(storageTest, strNew("aaa.txt")), bufNewZ("aaa")), "write aaa.text"); TEST_RESULT_STR( strPtr(strLstJoin(storageListNP(storageTest, NULL), ", ")), "aaa.txt, noperm", "dir list"); TEST_RESULT_VOID( - storagePutNP(storageNewWriteNP(storageTest, strNew("bbb.txt")), bufNewStr(strNew("bbb"))), "write bbb.text"); + storagePutNP(storageNewWriteNP(storageTest, strNew("bbb.txt")), bufNewZ("bbb")), "write bbb.text"); TEST_RESULT_STR( strPtr(strLstJoin(storageListP(storageTest, NULL, .expression = strNew("^bbb")), ", ")), "bbb.txt", "dir list"); } @@ -284,7 +284,7 @@ testRun(void) TEST_RESULT_BOOL(storageCopyNP(source, destination), false, "copy and ignore missing file"); // ------------------------------------------------------------------------------------------------------------------------- - Buffer *expectedBuffer = bufNewStr(strNew("TESTFILE\n")); + Buffer *expectedBuffer = bufNewZ("TESTFILE\n"); TEST_RESULT_VOID(storagePutNP(storageNewWriteNP(storageTest, sourceFile), expectedBuffer), "write source file"); source = storageNewReadNP(storageTest, sourceFile); @@ -319,7 +319,7 @@ testRun(void) "unable to move '%s' to '%s': [13] Permission denied", strPtr(fileNoPerm), strPtr(destinationFile)); // ------------------------------------------------------------------------------------------------------------------------- - Buffer *buffer = bufNewStr(strNew("TESTFILE")); + Buffer *buffer = bufNewZ("TESTFILE"); storagePutNP(storageNewWriteNP(storageTest, sourceFile), buffer); source = storageNewReadNP(storageTest, sourceFile); @@ -604,7 +604,7 @@ testRun(void) TEST_RESULT_BOOL(storageExistsNP(storageTest, emptyFile), true, "check empty file exists"); // ------------------------------------------------------------------------------------------------------------------------- - Buffer *buffer = bufNewStr(strNew("TESTFILE\n")); + Buffer *buffer = bufNewZ("TESTFILE\n"); TEST_RESULT_VOID( storagePutNP(storageNewWriteNP(storageTest, strNewFmt("%s/test.txt", testPath())), buffer), "put test file"); @@ -695,7 +695,7 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- Buffer *outBuffer = bufNew(2); - Buffer *expectedBuffer = bufNewStr(strNew("TESTFILE\n")); + Buffer *expectedBuffer = bufNewZ("TESTFILE\n"); TEST_RESULT_VOID(storagePutNP(storageNewWriteNP(storageTest, fileName), expectedBuffer), "write test file"); TEST_ASSIGN(file, storageNewReadNP(storageTest, fileName), "new read file"); @@ -805,7 +805,7 @@ testRun(void) // ------------------------------------------------------------------------------------------------------------------------- String *fileTmp = strNewFmt("%s.pgbackrest.tmp", strPtr(fileName)); ioBufferSizeSet(10); - Buffer *buffer = bufNewStr(strNew("TESTFILE\n")); + Buffer *buffer = bufNewZ("TESTFILE\n"); TEST_ASSIGN(file, storageNewWriteNP(storageTest, fileName), "new write file"); TEST_RESULT_STR(strPtr(storageFileWriteName(file)), strPtr(fileName), " check file name");