|
28 | 28 | #include "arrow/testing/gtest_util.h" |
29 | 29 | #include "arrow/util/regex.h" |
30 | 30 | #include "arrow/util/string.h" |
| 31 | +#include "arrow/util/base64.h" |
31 | 32 |
|
32 | 33 | namespace arrow { |
33 | 34 | namespace internal { |
@@ -232,12 +233,79 @@ TEST(ToChars, FloatingPoint) { |
232 | 233 | // to std::to_string which may make ad hoc formatting choices, so we cannot |
233 | 234 | // really test much about the result. |
234 | 235 | auto result = ToChars(0.0f); |
235 | | - ASSERT_TRUE(result.starts_with("0")) << result; |
| 236 | + ASSERT_TRUE(result.rfind("0", 0) == 0) << result; |
236 | 237 | result = ToChars(0.25); |
237 | | - ASSERT_TRUE(result.starts_with("0.25")) << result; |
| 238 | + ASSERT_TRUE(result.rfind("0.25", 0) == 0) << result; |
238 | 239 | } |
239 | 240 | } |
240 | 241 |
|
| 242 | +TEST(Base64DecodeTest, ValidInputs) { |
| 243 | + auto r1 = arrow::util::base64_decode("Zg=="); |
| 244 | + ASSERT_TRUE(r1.ok()); |
| 245 | + EXPECT_EQ(r1.ValueOrDie(), "f"); |
| 246 | + auto r2 = arrow::util::base64_decode("Zm8="); |
| 247 | + ASSERT_TRUE(r2.ok()); |
| 248 | + EXPECT_EQ(r2.ValueOrDie(), "fo"); |
| 249 | + auto r3 = arrow::util::base64_decode("Zm9v"); |
| 250 | + ASSERT_TRUE(r3.ok()); |
| 251 | + EXPECT_EQ(r3.ValueOrDie(), "foo"); |
| 252 | + auto r4 = arrow::util::base64_decode("aGVsbG8gd29ybGQ="); |
| 253 | + ASSERT_TRUE(r4.ok()); |
| 254 | + EXPECT_EQ(r4.ValueOrDie(), "hello world"); |
| 255 | +} |
| 256 | + |
| 257 | +TEST(Base64DecodeTest, InvalidLength) { |
| 258 | + auto r1 = arrow::util::base64_decode("abc"); |
| 259 | + ASSERT_FALSE(r1.ok()); |
| 260 | + auto r2 = arrow::util::base64_decode("abcde"); |
| 261 | + ASSERT_FALSE(r2.ok()); |
| 262 | +} |
| 263 | + |
| 264 | +TEST(Base64DecodeTest, InvalidCharacters) { |
| 265 | + auto r1 = arrow::util::base64_decode("ab$="); |
| 266 | + ASSERT_FALSE(r1.ok()); |
| 267 | + auto r2 = arrow::util::base64_decode("Zm9v*"); |
| 268 | + ASSERT_FALSE(r2.ok()); |
| 269 | + auto r3 = arrow::util::base64_decode("abcd$AAA"); |
| 270 | + ASSERT_FALSE(r3.ok()); |
| 271 | +} |
| 272 | + |
| 273 | +TEST(Base64DecodeTest, InvalidPadding) { |
| 274 | + auto r1 = arrow::util::base64_decode("ab=c"); |
| 275 | + ASSERT_FALSE(r1.ok()); |
| 276 | + auto r2 = arrow::util::base64_decode("abc==="); |
| 277 | + ASSERT_FALSE(r2.ok()); |
| 278 | + auto r3 = arrow::util::base64_decode("abcd=AAA"); |
| 279 | + ASSERT_FALSE(r3.ok()); |
| 280 | + auto r4 = arrow::util::base64_decode("Zm=9v"); |
| 281 | + ASSERT_FALSE(r4.ok()); |
| 282 | +} |
| 283 | + |
| 284 | +TEST(Base64DecodeTest, EdgeCases) { |
| 285 | + auto r1 = arrow::util::base64_decode("===="); |
| 286 | + ASSERT_FALSE(r1.ok()); |
| 287 | + auto r2 = arrow::util::base64_decode("TQ=="); |
| 288 | + ASSERT_TRUE(r2.ok()); |
| 289 | + EXPECT_EQ(r2.ValueOrDie(), "M"); |
| 290 | +} |
| 291 | + |
| 292 | +TEST(Base64DecodeTest, EmptyInput) { |
| 293 | + auto r = arrow::util::base64_decode(""); |
| 294 | + ASSERT_TRUE(r.ok()); |
| 295 | + EXPECT_EQ(r.ValueOrDie(), ""); |
| 296 | +} |
| 297 | + |
| 298 | +TEST(Base64DecodeTest, NonAsciiInput) { |
| 299 | + std::string input = std::string("abcd") + char(0xFF) + "=="; |
| 300 | + auto r = arrow::util::base64_decode(input); |
| 301 | + ASSERT_FALSE(r.ok()); |
| 302 | +} |
| 303 | + |
| 304 | +TEST(Base64DecodeTest, PartialCorruption) { |
| 305 | + auto r = arrow::util::base64_decode("aGVs$G8gd29ybGQ="); |
| 306 | + ASSERT_FALSE(r.ok()); |
| 307 | +} |
| 308 | + |
241 | 309 | #if !defined(_WIN32) || defined(NDEBUG) |
242 | 310 |
|
243 | 311 | TEST(ToChars, LocaleIndependent) { |
|
0 commit comments