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 #include <memory>
16
17 #include "gtest/gtest.h"
18 #define private public
19 #define protected public
20 #include "deeplink_reserve_config.h"
21 #undef private
22 #undef protected
23
24
25 namespace OHOS {
26 namespace AAFwk {
27 using namespace testing::ext;
28 class DeepLinkReserveConfigTest : public testing::Test {
29 public:
30 DeepLinkReserveConfigTest() = default;
31 virtual ~DeepLinkReserveConfigTest() = default;
32
33 static void SetUpTestCase(void);
34 static void TearDownTestCase(void);
35 void SetUp();
36 void TearDown();
37 };
SetUpTestCase(void)38 void DeepLinkReserveConfigTest::SetUpTestCase(void)
39 {}
TearDownTestCase(void)40 void DeepLinkReserveConfigTest::TearDownTestCase(void)
41 {}
SetUp()42 void DeepLinkReserveConfigTest::SetUp()
43 {}
TearDown()44 void DeepLinkReserveConfigTest::TearDown()
45 {}
46
47 /*
48 * Feature: deepLinkReserveConfig
49 * Function: LoadConfiguration
50 * SubFunction: NA
51 * FunctionPoints: deepLinkReserveConfig LoadConfiguration
52 * EnvConditions: NA
53 * CaseDescription: Verify that the deepLinkReserveConfig LoadConfiguration is normal.
54 */
55 HWTEST_F(DeepLinkReserveConfigTest, AaFwk_DeepLinkReserveConfigTest_0100, TestSize.Level1)
56 {
57 GTEST_LOG_(INFO) << "AaFwk_DeepLinkReserveConfigTest_0100 start";
58 DeepLinkReserveConfig deepLinkReserveConfig;
59 EXPECT_EQ(deepLinkReserveConfig.LoadConfiguration(), false);
60 GTEST_LOG_(INFO) << "AaFwk_DeepLinkReserveConfigTest_0100 end";
61 }
62
63 /*
64 * Feature: deepLinkReserveConfig
65 * Function: isLinkReserved
66 * SubFunction: NA
67 * FunctionPoints: deepLinkReserveConfig isLinkReserved
68 * EnvConditions: NA
69 * CaseDescription: Verify that the deepLinkReserveConfig isLinkReserved is normal.
70 */
71 HWTEST_F(DeepLinkReserveConfigTest, AaFwk_DeepLinkReserveConfigTest_0200, TestSize.Level1)
72 {
73 GTEST_LOG_(INFO) << "AaFwk_DeepLinkReserveConfigTest_0200 start";
74 DeepLinkReserveConfig deepLinkReserveConfig;
75 const nlohmann::json DEFAULT_CONFIG = R"(
76 {
77 "deepLinkReservedUri": [
78 {
79 "bundleName": "bundleName",
80 "uris": [
81 {
82 "scheme": "http",
83 "host": "www.xxx.com",
84 "port": "80",
85 "path": "path",
86 "pathStartWith": "pathStartWith",
87 "pathRegex": "pathRegex",
88 "type": "type",
89 "utd": "utd"
90 }
91 ]
92 }
93 ]
94 }
95 )"_json;
96 deepLinkReserveConfig.LoadReservedUriList(DEFAULT_CONFIG);
97 std::string linkString = "http://www.xxx.com:80/pathRegex";
98 std::string bundleName = "just a test";
99 auto ans = deepLinkReserveConfig.isLinkReserved(linkString, bundleName);
100 EXPECT_EQ(ans, true);
101 GTEST_LOG_(INFO) << "AaFwk_DeepLinkReserveConfigTest_0200 end";
102 }
103
104 } // namespace AAFwk
105 } // namespace OHOS
106