• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Level0)
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.Level0)
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.Level0)
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.Level0)
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.Level0)
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     DlpPermissionClient::GetInstance().OnRemoteDiedHandle();
121 }
122 
123 /**
124  * @tc.name: GetProxyFromRemoteObject001
125  * @tc.desc: GetProxyFromRemoteObject test
126  * @tc.type: FUNC
127  * @tc.require:
128  */
129 HWTEST_F(DlpPermissionClientTest, GetProxyFromRemoteObject001, TestSize.Level0)
130 {
131     DLP_LOG_INFO(LABEL, "GetProxyFromRemoteObject001");
132 
133     sptr<IRemoteObject> remoteObject;
134     DlpPermissionClient::GetInstance().GetProxyFromRemoteObject(remoteObject);
135     ASSERT_EQ(nullptr, remoteObject);
136 }
137 
138 /**
139  * @tc.name: SetReadFlag001
140  * @tc.desc: SetReadFlag test
141  * @tc.type: FUNC
142  * @tc.require:
143  */
144 HWTEST_F(DlpPermissionClientTest, SetReadFlag001, TestSize.Level0)
145 {
146     DLP_LOG_INFO(LABEL, "SetReadFlag001");
147 
148     sptr<IRemoteObject> remoteObject;
149     uint32_t uid = 0;
150     int32_t ret = DlpPermissionClient::GetInstance().SetReadFlag(uid);
151     ASSERT_TRUE(ret != DLP_CALLBACK_SA_WORK_ABNORMAL);
152 }
153 
154 /**
155  * @tc.name: SetDlpFeature001
156  * @tc.desc: SetDlpFeature test
157  * @tc.type: FUNC
158  * @tc.require:
159  */
160 HWTEST_F(DlpPermissionClientTest, SetDlpFeature001, TestSize.Level0)
161 {
162     DLP_LOG_INFO(LABEL, "SetDlpFeature001");
163     uint32_t dlpFeatureInfo = 0;
164     bool statusSetInfo;
165     int32_t ret = DlpPermissionClient::GetInstance().SetDlpFeature(dlpFeatureInfo, statusSetInfo);
166     ASSERT_TRUE(ret != DLP_CALLBACK_SA_WORK_ABNORMAL);
167 }
168 
169 /**
170  * @tc.name: SetDlpFeature002
171  * @tc.desc: SetDlpFeature test
172  * @tc.type: FUNC
173  * @tc.require:
174  */
175 HWTEST_F(DlpPermissionClientTest, SetDlpFeature002, TestSize.Level0)
176 {
177     DLP_LOG_INFO(LABEL, "SetDlpFeature002");
178     uint32_t dlpFeatureInfo = 1;
179     bool statusSetInfo;
180     int32_t ret = DlpPermissionClient::GetInstance().SetDlpFeature(dlpFeatureInfo, statusSetInfo);
181     ASSERT_TRUE(ret != DLP_CALLBACK_SA_WORK_ABNORMAL);
182 }