You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-11-08 03:22:25 +03:00
Enable additional warnings for C builds.
This commit is contained in:
@@ -10,82 +10,84 @@ void testRun()
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
if (testBegin("base64"))
|
||||
{
|
||||
char *source = "string_to_encode\r\n";
|
||||
unsigned char destination[256];
|
||||
unsigned char *encode = (unsigned char *)"string_to_encode\r\n";
|
||||
char destinationEncode[256];
|
||||
|
||||
encodeToStr(encodeBase64, source, 1, destination);
|
||||
TEST_RESULT_STR(destination, "c3==", "1 character encode");
|
||||
TEST_RESULT_INT(encodeToStrSize(encodeBase64, 1), strlen(destination), "check size");
|
||||
encodeToStr(encodeBase64, encode, 1, destinationEncode);
|
||||
TEST_RESULT_STR(destinationEncode, "c3==", "1 character encode");
|
||||
TEST_RESULT_INT(encodeToStrSize(encodeBase64, 1), strlen(destinationEncode), "check size");
|
||||
|
||||
encodeToStr(encodeBase64, source, 2, destination);
|
||||
TEST_RESULT_STR(destination, "c3R=", "2 character encode");
|
||||
TEST_RESULT_INT(encodeToStrSize(encodeBase64, 2), strlen(destination), "check size");
|
||||
encodeToStr(encodeBase64, encode, 2, destinationEncode);
|
||||
TEST_RESULT_STR(destinationEncode, "c3R=", "2 character encode");
|
||||
TEST_RESULT_INT(encodeToStrSize(encodeBase64, 2), strlen(destinationEncode), "check size");
|
||||
|
||||
encodeToStr(encodeBase64, source, 3, destination);
|
||||
TEST_RESULT_STR(destination, "c3Ry", "3 character encode");
|
||||
TEST_RESULT_INT(encodeToStrSize(encodeBase64, 3), strlen(destination), "check size");
|
||||
encodeToStr(encodeBase64, encode, 3, destinationEncode);
|
||||
TEST_RESULT_STR(destinationEncode, "c3Ry", "3 character encode");
|
||||
TEST_RESULT_INT(encodeToStrSize(encodeBase64, 3), strlen(destinationEncode), "check size");
|
||||
|
||||
encodeToStr(encodeBase64, source, strlen(source) - 2, destination);
|
||||
TEST_RESULT_STR(destination, "c3RyaW5nX3RvX2VuY29kZQ==", "encode full string");
|
||||
TEST_RESULT_INT(encodeToStrSize(encodeBase64, strlen(source) - 2), strlen(destination), "check size");
|
||||
encodeToStr(encodeBase64, encode, strlen((char *)encode) - 2, destinationEncode);
|
||||
TEST_RESULT_STR(destinationEncode, "c3RyaW5nX3RvX2VuY29kZQ==", "encode full string");
|
||||
TEST_RESULT_INT(encodeToStrSize(encodeBase64, strlen((char *)encode) - 2), strlen(destinationEncode), "check size");
|
||||
|
||||
encodeToStr(encodeBase64, source, strlen(source), destination);
|
||||
TEST_RESULT_STR(destination, "c3RyaW5nX3RvX2VuY29kZQ0K", "encode full string with \\r\\n");
|
||||
TEST_RESULT_INT(encodeToStrSize(encodeBase64, strlen(source)), strlen(destination), "check size");
|
||||
encodeToStr(encodeBase64, encode, strlen((char *)encode), destinationEncode);
|
||||
TEST_RESULT_STR(destinationEncode, "c3RyaW5nX3RvX2VuY29kZQ0K", "encode full string with \\r\\n");
|
||||
TEST_RESULT_INT(encodeToStrSize(encodeBase64, strlen((char *)encode)), strlen(destinationEncode), "check size");
|
||||
|
||||
encodeToStr(encodeBase64, source, strlen(source) + 1, destination);
|
||||
TEST_RESULT_STR(destination, "c3RyaW5nX3RvX2VuY29kZQ0KAG==", "encode full string with \\r\\n and null");
|
||||
TEST_RESULT_INT(encodeToStrSize(encodeBase64, strlen(source) + 1), strlen(destination), "check size");
|
||||
encodeToStr(encodeBase64, encode, strlen((char *)encode) + 1, destinationEncode);
|
||||
TEST_RESULT_STR(destinationEncode, "c3RyaW5nX3RvX2VuY29kZQ0KAG==", "encode full string with \\r\\n and null");
|
||||
TEST_RESULT_INT(encodeToStrSize(encodeBase64, strlen((char *)encode) + 1), strlen(destinationEncode), "check size");
|
||||
|
||||
TEST_ERROR(encodeToStr(999, source, strlen(source), destination), AssertError, "invalid encode type 999");
|
||||
TEST_ERROR(encodeToStrSize(999, strlen(source)), AssertError, "invalid encode type 999");
|
||||
TEST_ERROR(encodeToStr(999, encode, strlen((char *)encode), destinationEncode), AssertError, "invalid encode type 999");
|
||||
TEST_ERROR(encodeToStrSize(999, strlen((char *)encode)), AssertError, "invalid encode type 999");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
memset(destination, 0xFF, sizeof(destination));
|
||||
char *decode = "c3RyaW5nX3RvX2VuY29kZQ0KAG==";
|
||||
decodeToBin(encodeBase64, decode, destination);
|
||||
TEST_RESULT_STR(destination, source, "full string with \\r\\n and null decode");
|
||||
TEST_RESULT_INT(destination[strlen(source) + 1], 0xFF, "check for overrun");
|
||||
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), strlen(source) + 1, "check size");
|
||||
unsigned char destinationDecode[256];
|
||||
|
||||
memset(destination, 0xFF, sizeof(destination));
|
||||
memset(destinationDecode, 0xFF, sizeof(destinationDecode));
|
||||
const char *decode = "c3RyaW5nX3RvX2VuY29kZQ0KAG==";
|
||||
decodeToBin(encodeBase64, decode, destinationDecode);
|
||||
TEST_RESULT_STR(destinationDecode, encode, "full string with \\r\\n and null decode");
|
||||
TEST_RESULT_INT(destinationDecode[strlen((char *)encode) + 1], 0xFF, "check for overrun");
|
||||
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), strlen((char *)encode) + 1, "check size");
|
||||
|
||||
memset(destinationDecode, 0xFF, sizeof(destinationDecode));
|
||||
decode = "c3RyaW5nX3RvX2VuY29kZQ0K";
|
||||
decodeToBin(encodeBase64, decode, destination);
|
||||
TEST_RESULT_INT(memcmp(destination, source, strlen(source)), 0, "full string with \\r\\n decode");
|
||||
TEST_RESULT_INT(destination[strlen(source)], 0xFF, "check for overrun");
|
||||
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), strlen(source), "check size");
|
||||
decodeToBin(encodeBase64, decode, destinationDecode);
|
||||
TEST_RESULT_INT(memcmp(destinationDecode, encode, strlen((char *)encode)), 0, "full string with \\r\\n decode");
|
||||
TEST_RESULT_INT(destinationDecode[strlen((char *)encode)], 0xFF, "check for overrun");
|
||||
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), strlen((char *)encode), "check size");
|
||||
|
||||
memset(destination, 0xFF, sizeof(destination));
|
||||
memset(destinationDecode, 0xFF, sizeof(destinationDecode));
|
||||
decode = "c3RyaW5nX3RvX2VuY29kZQ==";
|
||||
decodeToBin(encodeBase64, decode, destination);
|
||||
TEST_RESULT_INT(memcmp(destination, source, strlen(source) - 2), 0, "full string decode");
|
||||
TEST_RESULT_INT(destination[strlen(source) - 2], 0xFF, "check for overrun");
|
||||
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), strlen(source) - 2, "check size");
|
||||
decodeToBin(encodeBase64, decode, destinationDecode);
|
||||
TEST_RESULT_INT(memcmp(destinationDecode, encode, strlen((char *)encode) - 2), 0, "full string decode");
|
||||
TEST_RESULT_INT(destinationDecode[strlen((char *)encode) - 2], 0xFF, "check for overrun");
|
||||
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), strlen((char *)encode) - 2, "check size");
|
||||
|
||||
memset(destination, 0xFF, sizeof(destination));
|
||||
memset(destinationDecode, 0xFF, sizeof(destinationDecode));
|
||||
decode = "c3Ry";
|
||||
decodeToBin(encodeBase64, decode, destination);
|
||||
TEST_RESULT_INT(memcmp(destination, source, 3), 0, "3 character decode");
|
||||
TEST_RESULT_INT(destination[3], 0xFF, "check for overrun");
|
||||
decodeToBin(encodeBase64, decode, destinationDecode);
|
||||
TEST_RESULT_INT(memcmp(destinationDecode, encode, 3), 0, "3 character decode");
|
||||
TEST_RESULT_INT(destinationDecode[3], 0xFF, "check for overrun");
|
||||
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), 3, "check size");
|
||||
|
||||
memset(destination, 0xFF, sizeof(destination));
|
||||
memset(destinationDecode, 0xFF, sizeof(destinationDecode));
|
||||
decode = "c3R=";
|
||||
decodeToBin(encodeBase64, decode, destination);
|
||||
TEST_RESULT_INT(memcmp(destination, source, 2), 0, "2 character decode");
|
||||
TEST_RESULT_INT(destination[2], 0xFF, "check for overrun");
|
||||
decodeToBin(encodeBase64, decode, destinationDecode);
|
||||
TEST_RESULT_INT(memcmp(destinationDecode, encode, 2), 0, "2 character decode");
|
||||
TEST_RESULT_INT(destinationDecode[2], 0xFF, "check for overrun");
|
||||
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), 2, "check size");
|
||||
|
||||
memset(destination, 0xFF, sizeof(destination));
|
||||
memset(destinationDecode, 0xFF, sizeof(destinationDecode));
|
||||
decode = "c3==";
|
||||
decodeToBin(encodeBase64, decode, destination);
|
||||
TEST_RESULT_INT(memcmp(destination, source, 1), 0, "1 character decode");
|
||||
TEST_RESULT_INT(destination[1], 0xFF, "check for overrun");
|
||||
decodeToBin(encodeBase64, decode, destinationDecode);
|
||||
TEST_RESULT_INT(memcmp(destinationDecode, encode, 1), 0, "1 character decode");
|
||||
TEST_RESULT_INT(destinationDecode[1], 0xFF, "check for overrun");
|
||||
TEST_RESULT_INT(decodeToBinSize(encodeBase64, decode), 1, "check size");
|
||||
|
||||
TEST_ERROR(decodeToBin(-1, decode, destination), AssertError, "invalid encode type -1");
|
||||
TEST_ERROR(decodeToBin(-1, decode, destinationDecode), AssertError, "invalid encode type -1");
|
||||
TEST_ERROR(decodeToBinSize(-1, decode), AssertError, "invalid encode type -1");
|
||||
TEST_ERROR(decodeToBin(encodeBase64, "cc$=", destination), FormatError, "base64 invalid character found at position 2");
|
||||
TEST_ERROR(decodeToBin(encodeBase64, "cc$=", destinationDecode), FormatError, "base64 invalid character found at position 2");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
TEST_ERROR(decodeToBinValidate(encodeBase64, "c3"), FormatError, "base64 size 2 is not evenly divisible by 4");
|
||||
|
||||
Reference in New Issue
Block a user