| 50 | } |
| 51 | |
| 52 | void TestBase64(const string& input, const string& expected_encoded) { |
| 53 | string intermediate; |
| 54 | Base64Encode(input, &intermediate); |
| 55 | if (!expected_encoded.empty()) { |
| 56 | EXPECT_EQ(intermediate, expected_encoded); |
| 57 | } |
| 58 | int64_t out_max = 0; |
| 59 | EXPECT_TRUE(Base64DecodeBufLen(intermediate.c_str(), intermediate.size(), &out_max)); |
| 60 | string output(out_max, '\0'); |
| 61 | unsigned out_len = 0; |
| 62 | EXPECT_TRUE(Base64Decode(intermediate.c_str(), intermediate.size(), |
| 63 | out_max, const_cast<char*>(output.c_str()), &out_len)); |
| 64 | output.resize(out_len); |
| 65 | EXPECT_EQ(input, output); |
| 66 | |
| 67 | // Convert string to vector and try that also |
| 68 | vector<uint8_t> input_vector; |
| 69 | input_vector.resize(input.size()); |
| 70 | memcpy(input_vector.data(), input.c_str(), input.size()); |
| 71 | string intermediate2; |
| 72 | Base64Encode(input_vector, &intermediate2); |
| 73 | EXPECT_EQ(intermediate, intermediate2); |
| 74 | } |
| 75 | |
| 76 | // Test Base64 encoding when the variables in which the calculated maximal output size and |
| 77 | // the actual output size are stored have specific initial values (regression test for |
no test coverage detected