Avi Drissman | e4622aa | 2022-09-08 20:36:06 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
danakj | 51d26a4 | 2024-04-25 14:23:56 | [diff] [blame] | 5 | #ifdef UNSAFE_BUFFERS_BUILD |
6 | // TODO(crbug.com/40284755): Remove this and spanify to fix the errors. | ||||
7 | #pragma allow_unsafe_buffers | ||||
8 | #endif | ||||
9 | |||||
[email protected] | 978df34 | 2009-11-24 06:21:53 | [diff] [blame] | 10 | #include "base/base64.h" |
[email protected] | 24f111a | 2012-09-23 04:51:04 | [diff] [blame] | 11 | |
Helmut Januschka | 0fc785b | 2024-04-17 21:13:36 | [diff] [blame] | 12 | #include <string_view> |
13 | |||||
David Benjamin | 48808e2 | 2022-09-21 19:39:12 | [diff] [blame] | 14 | #include "base/numerics/checked_math.h" |
Charlie Harrison | 7b633d9 | 2022-11-29 05:23:50 | [diff] [blame] | 15 | #include "base/strings/escape.h" |
David Benjamin | 48808e2 | 2022-09-21 19:39:12 | [diff] [blame] | 16 | #include "base/test/gtest_util.h" |
David Benjamin | 47bb5ec | 2022-02-01 23:12:28 | [diff] [blame] | 17 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 18 | #include "testing/gtest/include/gtest/gtest.h" |
David Benjamin | 48808e2 | 2022-09-21 19:39:12 | [diff] [blame] | 19 | #include "third_party/modp_b64/modp_b64.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 20 | |
[email protected] | 24f111a | 2012-09-23 04:51:04 | [diff] [blame] | 21 | namespace base { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 22 | |
23 | TEST(Base64Test, Basic) { | ||||
24 | const std::string kText = "hello world"; | ||||
25 | const std::string kBase64Text = "aGVsbG8gd29ybGQ="; | ||||
26 | |||||
[email protected] | 24f111a | 2012-09-23 04:51:04 | [diff] [blame] | 27 | std::string decoded; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 28 | bool ok; |
29 | |||||
wd l | 4a70b3ff | 2023-09-26 20:13:35 | [diff] [blame] | 30 | std::string encoded = Base64Encode(kText); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 31 | EXPECT_EQ(kBase64Text, encoded); |
32 | |||||
[email protected] | 24f111a | 2012-09-23 04:51:04 | [diff] [blame] | 33 | ok = Base64Decode(encoded, &decoded); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 34 | EXPECT_TRUE(ok); |
35 | EXPECT_EQ(kText, decoded); | ||||