• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2024 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 <string_view>
17 #include <utility>
18 
19 #include "gtest/gtest.h"
20 
21 #include "evaluation/base64.h"
22 
23 // NOLINTBEGIN
24 
25 namespace ark::tooling::inspector::test {
26 
27 class Base64DecoderTest : public testing::Test {
28 public:
29     static constexpr std::array TEST_CASES = {
30         std::pair<std::string_view, std::string_view> {"bGlnaHQgd29yay4=", "light work."},
31         std::pair<std::string_view, std::string_view> {"bGlnaHQgd29yaw==", "light work"},
32         std::pair<std::string_view, std::string_view> {"bGlnaHQgd29y", "light wor"},
33         std::pair<std::string_view, std::string_view> {"TWFueSBoYW5kcyBtYWtlIGxpZ2h0IHdvcmsu",
34                                                        "Many hands make light work."},
35     };
36 };
37 
CheckTestCase(std::string_view encoded,std::string_view decoded)38 static void CheckTestCase(std::string_view encoded, std::string_view decoded)
39 {
40     Span encodedData {reinterpret_cast<const uint8_t *>(encoded.data()), encoded.size()};
41     auto decodedSize = Base64Decoder::DecodedSize(encodedData);
42     ASSERT_TRUE(decodedSize.has_value());
43     ASSERT_EQ(*decodedSize, decoded.size());
44     std::string decodedBuffer(decoded.size(), 0);
45     ASSERT_TRUE(Base64Decoder::Decode(reinterpret_cast<uint8_t *>(decodedBuffer.data()), encodedData));
46     ASSERT_EQ(decodedBuffer, decoded);
47 }
48 
TEST_F(Base64DecoderTest,TestDecoding)49 TEST_F(Base64DecoderTest, TestDecoding)
50 {
51     for (auto [encoded, decoded] : TEST_CASES) {
52         CheckTestCase(encoded, decoded);
53     }
54 }
55 
56 }  // namespace ark::tooling::inspector::test
57 
58 // NOLINTEND
59