Merge pull request #2195 from dbermond/fix-test-base-64

tests: fix test-base-64
This commit is contained in:
orignal 2025-06-03 06:11:54 -04:00 committed by GitHub
commit db67126581
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,8 +11,7 @@ int main() {
char out[16];
/* bytes -> b64 */
assert(ByteStreamToBase64(NULL, 0, NULL, 0) == 0);
assert(ByteStreamToBase64(NULL, 0, out, sizeof(out)) == 0);
assert(ByteStreamToBase64(NULL, 0) == "");
assert(Base64EncodingBufferSize(2) == 4);
assert(Base64EncodingBufferSize(4) == 8);
@ -23,19 +22,20 @@ int main() {
assert(Base64EncodingBufferSize(12) == 16);
assert(Base64EncodingBufferSize(13) == 20);
assert(ByteStreamToBase64((uint8_t *) in, in_len, out, sizeof(out)) == 8);
assert(memcmp(out, "dGVzdA==", 8) == 0);
const std::string out_str(ByteStreamToBase64((uint8_t *) in, in_len));
assert(out_str.size() == 8);
assert(out_str == "dGVzdA==");
/* b64 -> bytes */
assert(Base64ToByteStream(NULL, 0, NULL, 0) == 0);
assert(Base64ToByteStream(NULL, 0, (uint8_t *) out, sizeof(out)) == 0);
assert(Base64ToByteStream("", NULL, 0) == 0);
assert(Base64ToByteStream("", (uint8_t *) out, sizeof(out)) == 0);
in = "dGVzdA=="; /* valid b64 */
assert(Base64ToByteStream(in, strlen(in), (uint8_t *) out, sizeof(out)) == 4);
assert(Base64ToByteStream(in, (uint8_t *) out, sizeof(out)) == 4);
assert(memcmp(out, "test", 4) == 0);
in = "dGVzdA="; /* invalid b64 : not padded */
assert(Base64ToByteStream(in, strlen(in), (uint8_t *) out, sizeof(out)) == 0);
assert(Base64ToByteStream(in, (uint8_t *) out, sizeof(out)) == 0);
in = "dG/z.A=="; /* invalid b64 : char not from alphabet */
// assert(Base64ToByteStream(in, strlen(in), (uint8_t *) out, sizeof(out)) == 0);