[M85 Dev][EFL] Fix crashes at webview launch
[platform/framework/web/chromium-efl.git] / base / base64_unittest.cc
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/base64.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace base {
10
11 TEST(Base64Test, Basic) {
12   const std::string kText = "hello world";
13   const std::string kBase64Text = "aGVsbG8gd29ybGQ=";
14
15   std::string encoded;
16   std::string decoded;
17   bool ok;
18
19   Base64Encode(kText, &encoded);
20   EXPECT_EQ(kBase64Text, encoded);
21
22   ok = Base64Decode(encoded, &decoded);
23   EXPECT_TRUE(ok);
24   EXPECT_EQ(kText, decoded);
25 }
26
27 TEST(Base64Test, Binary) {
28   const uint8_t kData[] = {0x00, 0x01, 0xFE, 0xFF};
29
30   std::string binary_encoded = Base64Encode(make_span(kData));
31
32   // Check that encoding the same data through the StringPiece interface gives
33   // the same results.
34   std::string string_piece_encoded;
35   Base64Encode(StringPiece(reinterpret_cast<const char*>(kData), sizeof(kData)),
36                &string_piece_encoded);
37
38   EXPECT_EQ(binary_encoded, string_piece_encoded);
39 }
40
41 TEST(Base64Test, InPlace) {
42   const std::string kText = "hello world";
43   const std::string kBase64Text = "aGVsbG8gd29ybGQ=";
44   std::string text(kText);
45
46   Base64Encode(text, &text);
47   EXPECT_EQ(kBase64Text, text);
48
49   bool ok = Base64Decode(text, &text);
50   EXPECT_TRUE(ok);
51   EXPECT_EQ(text, kText);
52 }
53
54 }  // namespace base