1 /*
2 * Copyright (c) 2025 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 <gtest/gtest.h>
17 #include <fcntl.h>
18 #include <memory>
19 #include <string>
20
21 #define private public
22 #include "json_parse_loader.h"
23 #undef private
24
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace Security {
29 namespace AccessToken {
30 namespace {
31 constexpr const char* TEST_FILE_PATH = "/data/test/abcdefg.txt";
32 }
33
34 class JsonParseLoaderTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38
39 void SetUp();
40 void TearDown();
41 };
42
SetUpTestCase()43 void JsonParseLoaderTest::SetUpTestCase() {}
TearDownTestCase()44 void JsonParseLoaderTest::TearDownTestCase() {}
SetUp()45 void JsonParseLoaderTest::SetUp() {}
TearDown()46 void JsonParseLoaderTest::TearDown() {}
47
48 /*
49 * @tc.name: IsDirExsit
50 * @tc.desc: IsDirExsit
51 * @tc.type: FUNC
52 * @tc.require: TDD coverage
53 */
54 HWTEST_F(JsonParseLoaderTest, IsDirExsitTest001, TestSize.Level4)
55 {
56 ConfigPolicLoader loader;
57 EXPECT_FALSE(loader.IsDirExsit(""));
58 int32_t fd = open(TEST_FILE_PATH, O_RDWR | O_CREAT);
59 EXPECT_NE(-1, fd);
60
61 EXPECT_FALSE(loader.IsDirExsit(TEST_FILE_PATH));
62 }
63
64 #ifdef CUSTOMIZATION_CONFIG_POLICY_ENABLE
65 /*
66 * @tc.name: GetConfigValueFromFile
67 * @tc.desc: GetConfigValueFromFile
68 * @tc.type: FUNC
69 * @tc.require: TDD coverage
70 */
71 HWTEST_F(JsonParseLoaderTest, GetConfigValueFromFileTest001, TestSize.Level4)
72 {
73 ConfigPolicLoader loader;
74 AccessTokenConfigValue config;
75 EXPECT_FALSE(loader.GetConfigValueFromFile(ServiceType::ACCESSTOKEN_SERVICE, "", config));
76 }
77 #endif // CUSTOMIZATION_CONFIG_POLICY_ENABLE
78
79 /*
80 * @tc.name: ParserNativeRawData
81 * @tc.desc: ParserNativeRawData
82 * @tc.type: FUNC
83 * @tc.require: TDD coverage
84 */
85 HWTEST_F(JsonParseLoaderTest, ParserNativeRawDataTest001, TestSize.Level4)
86 {
87 ConfigPolicLoader loader;
88 std::vector<NativeTokenInfoBase> tokenInfos;
89 EXPECT_FALSE(loader.ParserNativeRawData("", tokenInfos));
90 }
91
92 /*
93 * @tc.name: ParserDlpPermsRawData
94 * @tc.desc: ParserDlpPermsRawData
95 * @tc.type: FUNC
96 * @tc.require: TDD coverage
97 */
98 HWTEST_F(JsonParseLoaderTest, ParserDlpPermsRawDataTest001, TestSize.Level4)
99 {
100 ConfigPolicLoader loader;
101 std::vector<PermissionDlpMode> dlpPerms;
102 EXPECT_FALSE(loader.ParserDlpPermsRawData("", dlpPerms));
103 }
104 } // namespace AccessToken
105 } // namespace Security
106 } // namespace OHOS
107