1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <map>
17 
18 #include "gtest/gtest.h"
19 
20 #include "base64_utils.h"
21 
22 namespace OHOS {
23 namespace NetStack {
24 using namespace Base64;
25 using namespace testing::ext;
26 namespace {
27 const std::string TEST_TEXT[] = {
28     "We are supporting a community where more than 28 million* people learn, share, and work together "
29     "to build software. ",
30     "这是一段用来测试的文本,测试加密内容。",
31     "\\C6y\\83u\\F9C\\8As\\C8\\D1j.\\CFi\\83\\E2#Z:\\FB \\A7m\\8B\\D9\\E5ܫ\\E4\\D7PMY\\D6\\CF\\F0"
32     "É",
33 };
34 
35 const std::map<std::string, std::string> CODE_MAP = {
36     {"abcde", "YWJjZGU="},
37     {"测试加密解密", "5rWL6K+V5Yqg5a+G6Kej5a+G"},
38     {"\\C6y\\83u\\F9C\\8As\\C8\\D1j.\\CFi\\83\\E2#Z:", "XEM2eVw4M3VcRjlDXDhBcxtcQzhcRDFqLlxDRmkeXDgzElxFMiNaETo="},
39 };
40 } // namespace
41 
42 class Base64Test : public testing::Test {
43 public:
SetUpTestCase()44     static void SetUpTestCase() {}
45 
TearDownTestCase()46     static void TearDownTestCase() {}
47 
SetUp()48     void SetUp() {}
49 
TearDown()50     void TearDown() {}
51 };
52 
53 HWTEST_F(Base64Test, EncodeAndDecodeTest, TestSize.Level1)
54 {
55     for (const auto &str : TEST_TEXT) {
56         EXPECT_EQ(Decode(Encode(str)), str);
57     }
58 
59     for (const auto &test : CODE_MAP) {
60         EXPECT_EQ(Encode(test.first), test.second);
61         EXPECT_EQ(Decode(test.second), test.first);
62     }
63 }
64 } // namespace NetStack
65 } // namespace OHOS
66