[email protected] | 24f111a | 2012-09-23 04:51:04 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
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 | |
[email protected] | 978df34 | 2009-11-24 06:21:53 | [diff] [blame] | 5 | #include "base/base64.h" |
[email protected] | 24f111a | 2012-09-23 04:51:04 | [diff] [blame] | 6 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 7 | #include "testing/gtest/include/gtest/gtest.h" |
| 8 | |
[email protected] | 24f111a | 2012-09-23 04:51:04 | [diff] [blame] | 9 | namespace base { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 10 | |
| 11 | TEST(Base64Test, Basic) { |
| 12 | const std::string kText = "hello world"; |
| 13 | const std::string kBase64Text = "aGVsbG8gd29ybGQ="; |
| 14 | |
[email protected] | 24f111a | 2012-09-23 04:51:04 | [diff] [blame] | 15 | std::string encoded; |
| 16 | std::string decoded; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 17 | bool ok; |
| 18 | |
[email protected] | 33fca12 | 2013-12-11 01:48:50 | [diff] [blame] | 19 | Base64Encode(kText, &encoded); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 20 | EXPECT_EQ(kBase64Text, encoded); |
| 21 | |
[email protected] | 24f111a | 2012-09-23 04:51:04 | [diff] [blame] | 22 | ok = Base64Decode(encoded, &decoded); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 23 | EXPECT_TRUE(ok); |
| 24 | EXPECT_EQ(kText, decoded); |
| 25 | } |
[email protected] | 24f111a | 2012-09-23 04:51:04 | [diff] [blame] | 26 | |
georgesak | 85e05a73 | 2014-11-11 17:19:43 | [diff] [blame] | 27 | TEST(Base64Test, InPlace) { |
| 28 | const std::string kText = "hello world"; |
| 29 | const std::string kBase64Text = "aGVsbG8gd29ybGQ="; |
| 30 | std::string text(kText); |
| 31 | |
| 32 | Base64Encode(text, &text); |
| 33 | EXPECT_EQ(kBase64Text, text); |
| 34 | |
| 35 | bool ok = Base64Decode(text, &text); |
| 36 | EXPECT_TRUE(ok); |
| 37 | EXPECT_EQ(text, kText); |
| 38 | } |
| 39 | |
[email protected] | 24f111a | 2012-09-23 04:51:04 | [diff] [blame] | 40 | } // namespace base |