1 /*
2 * Copyright (c) 2023 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 "dlp_permission_client_test.h"
17 #include <cerrno>
18 #include <gtest/gtest.h>
19 #include <securec.h>
20 #include "dlp_permission.h"
21 #include "dlp_permission_log.h"
22
23 using namespace testing::ext;
24 using namespace OHOS;
25 using namespace OHOS::Security::DlpPermission;
26 using namespace std;
27
28 namespace {
29 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
30 LOG_CORE, SECURITY_DOMAIN_DLP_PERMISSION, "DlpPermissionClientTest"};
31 }
32
SetUpTestCase()33 void DlpPermissionClientTest::SetUpTestCase() {}
34
TearDownTestCase()35 void DlpPermissionClientTest::TearDownTestCase() {}
36
SetUp()37 void DlpPermissionClientTest::SetUp() {}
38
TearDown()39 void DlpPermissionClientTest::TearDown() {}
40
41 /**
42 * @tc.name: RegisterOpenDlpFileCallback001
43 * @tc.desc: RegisterOpenDlpFileCallback test
44 * @tc.type: FUNC
45 * @tc.require:
46 */
47 HWTEST_F(DlpPermissionClientTest, RegisterOpenDlpFileCallback001, TestSize.Level1)
48 {
49 DLP_LOG_INFO(LABEL, "RegisterOpenDlpFileCallback001");
50
51 std::shared_ptr<OpenDlpFileCallbackCustomize> callback = nullptr;
52
53 int32_t ret = DlpPermissionClient::GetInstance().RegisterOpenDlpFileCallback(callback);
54 ASSERT_EQ(DLP_SERVICE_ERROR_VALUE_INVALID, ret);
55 }
56
57 /**
58 * @tc.name: UnRegisterOpenDlpFileCallback001
59 * @tc.desc: UnRegisterOpenDlpFileCallback test
60 * @tc.type: FUNC
61 * @tc.require:
62 */
63 HWTEST_F(DlpPermissionClientTest, UnRegisterOpenDlpFileCallback001, TestSize.Level1)
64 {
65 DLP_LOG_INFO(LABEL, "UnRegisterOpenDlpFileCallback001");
66
67 std::shared_ptr<OpenDlpFileCallbackCustomize> callback;
68
69 int32_t ret = DlpPermissionClient::GetInstance().UnRegisterOpenDlpFileCallback(callback);
70 ASSERT_EQ(DLP_SERVICE_ERROR_VALUE_INVALID, ret);
71 }
72
73 /**
74 * @tc.name: GetRetentionSandboxList001
75 * @tc.desc: GetRetentionSandboxList test
76 * @tc.type: FUNC
77 * @tc.require:
78 */
79 HWTEST_F(DlpPermissionClientTest, GetRetentionSandboxList001, TestSize.Level1)
80 {
81 DLP_LOG_INFO(LABEL, "GetRetentionSandboxList001");
82
83 std::string bundleName = "";
84 std::vector<RetentionSandBoxInfo> retentionSandBoxInfoVec;
85
86 int32_t ret = DlpPermissionClient::GetInstance().GetRetentionSandboxList(bundleName, retentionSandBoxInfoVec);
87 ASSERT_EQ(DLP_SERVICE_ERROR_VALUE_INVALID, ret);
88 }
89
90 /**
91 * @tc.name: GetDLPFileVisitRecord001
92 * @tc.desc: GetDLPFileVisitRecord test
93 * @tc.type: FUNC
94 * @tc.require:
95 */
96 HWTEST_F(DlpPermissionClientTest, GetDLPFileVisitRecord001, TestSize.Level1)
97 {
98 DLP_LOG_INFO(LABEL, "GetDLPFileVisitRecord001");
99
100 std::vector<VisitedDLPFileInfo> infoVec;
101
102 int32_t ret = DlpPermissionClient::GetInstance().GetDLPFileVisitRecord(infoVec);
103 ASSERT_EQ(DLP_SERVICE_ERROR_VALUE_INVALID, ret);
104 }
105
106 /**
107 * @tc.name: GetProxy001
108 * @tc.desc: GetProxy test
109 * @tc.type: FUNC
110 * @tc.require:
111 */
112 HWTEST_F(DlpPermissionClientTest, GetProxy001, TestSize.Level1)
113 {
114 DLP_LOG_INFO(LABEL, "GetProxy001");
115
116 bool doLoadSa = false;
117
118 sptr<IDlpPermissionService> service_ = DlpPermissionClient::GetInstance().GetProxy(doLoadSa);
119 ASSERT_EQ(DlpPermissionClient::GetInstance().proxy_, service_);
120 }
121
122 /**
123 * @tc.name: FinishStartSAFail001
124 * @tc.desc: FinishStartSAFail test
125 * @tc.type: FUNC
126 * @tc.require:
127 */
128 HWTEST_F(DlpPermissionClientTest, FinishStartSAFail001, TestSize.Level1)
129 {
130 DLP_LOG_INFO(LABEL, "FinishStartSAFail001");
131
132 DlpPermissionClient::GetInstance().FinishStartSAFail();
133 ASSERT_TRUE(DlpPermissionClient::GetInstance().readyFlag_);
134 }
135
136 /**
137 * @tc.name: OnRemoteDiedHandle001
138 * @tc.desc: OnRemoteDiedHandle test
139 * @tc.type: FUNC
140 * @tc.require:
141 */
142 HWTEST_F(DlpPermissionClientTest, OnRemoteDiedHandle001, TestSize.Level1)
143 {
144 DLP_LOG_INFO(LABEL, "OnRemoteDiedHandle001");
145
146 DlpPermissionClient::GetInstance().OnRemoteDiedHandle();
147 ASSERT_FALSE(DlpPermissionClient::GetInstance().readyFlag_);
148 }
149
150 /**
151 * @tc.name: GetProxyFromRemoteObject001
152 * @tc.desc: GetProxyFromRemoteObject test
153 * @tc.type: FUNC
154 * @tc.require:
155 */
156 HWTEST_F(DlpPermissionClientTest, GetProxyFromRemoteObject001, TestSize.Level1)
157 {
158 DLP_LOG_INFO(LABEL, "GetProxyFromRemoteObject001");
159
160 sptr<IRemoteObject> remoteObject;
161 DlpPermissionClient::GetInstance().GetProxyFromRemoteObject(remoteObject);
162 ASSERT_EQ(nullptr, remoteObject);
163 }
164
165 /**
166 * @tc.name: SetReadFlag001
167 * @tc.desc: SetReadFlag test
168 * @tc.type: FUNC
169 * @tc.require:
170 */
171 HWTEST_F(DlpPermissionClientTest, SetReadFlag001, TestSize.Level1)
172 {
173 DLP_LOG_INFO(LABEL, "SetReadFlag001");
174
175 sptr<IRemoteObject> remoteObject;
176 uint32_t uid = 0;
177 int32_t ret = DlpPermissionClient::GetInstance().SetReadFlag(uid);
178 ASSERT_TRUE(ret != DLP_CALLBACK_SA_WORK_ABNORMAL);
179 }