yaml-cpp/test/binary_test.cpp
Sean Curtis 53f07b7eee DecodeBase64 returns empty string on *all* errors
It already returns an empty string if it encounters an invalid character.
However, if, instead, it has an incomplete set of characters, it currently
returns a truncated result. Instead, it detects truncation and returns
the empty string.
2025-01-08 10:24:39 -08:00

22 lines
748 B
C++

#include "gtest/gtest.h"
#include <yaml-cpp/binary.h>
TEST(BinaryTest, DecodingSimple) {
std::string input{90, 71, 86, 104, 90, 71, 74, 108, 90, 87, 89, 61};
const std::vector<unsigned char> &result = YAML::DecodeBase64(input);
EXPECT_EQ(std::string(result.begin(), result.end()), "deadbeef");
}
TEST(BinaryTest, DecodingNoCrashOnNegative) {
std::string input{-58, -1, -99, 109};
const std::vector<unsigned char> &result = YAML::DecodeBase64(input);
EXPECT_TRUE(result.empty());
}
TEST(BinaryTest, DecodingIncompleteString) {
// Note: the number of bytes is *not* a multiple of four.
std::string input{90, 71, 86, 104, 90};
const std::vector<unsigned char> &result = YAML::DecodeBase64(input);
EXPECT_TRUE(result.empty());
}