blob: bff8eeed8e9016ebc3195b60efea2197c1ef1f87 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2012 The Chromium Authors
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
danakj51d26a42024-04-25 14:23:565#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]978df342009-11-24 06:21:5310#include "base/base64.h"
[email protected]24f111a2012-09-23 04:51:0411
Helmut Januschka0fc785b2024-04-17 21:13:3612#include <string_view>
13
David Benjamin48808e22022-09-21 19:39:1214#include "base/numerics/checked_math.h"
Charlie Harrison7b633d92022-11-29 05:23:5015#include "base/strings/escape.h"
David Benjamin48808e22022-09-21 19:39:1216#include "base/test/gtest_util.h"
David Benjamin47bb5ec2022-02-01 23:12:2817#include "testing/gmock/include/gmock/gmock.h"
initial.commit586acc5fe2008-07-26 22:42:5218#include "testing/gtest/include/gtest/gtest.h"
David Benjamin48808e22022-09-21 19:39:1219#include "third_party/modp_b64/modp_b64.h"
initial.commit586acc5fe2008-07-26 22:42:5220
[email protected]24f111a2012-09-23 04:51:0421namespace base {
initial.commit586acc5fe2008-07-26 22:42:5222
23TEST(Base64Test, Basic) {
24 const std::string kText = "hello world";
25 const std::string kBase64Text = "aGVsbG8gd29ybGQ=";
26
[email protected]24f111a2012-09-23 04:51:0427 std::string decoded;
initial.commit586acc5fe2008-07-26 22:42:5228 bool ok;
29
wd l4a70b3ff2023-09-26 20:13:3530 std::string encoded = Base64Encode(kText);
initial.commit586acc5fe2008-07-26 22:42:5231 EXPECT_EQ(kBase64Text, encoded);
32
[email protected]24f111a2012-09-23 04:51:0433 ok = Base64Decode(encoded, &decoded);
initial.commit586acc5fe2008-07-26 22:42:5234 EXPECT_TRUE(ok);
35 EXPECT_EQ(kText, decoded);