• 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_load_callback_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, "DlpPermissionLoadCallbackTest"};
31 constexpr int32_t SA_ID_DLP_PERMISSION_SERVICE = 3521;
32 }
33 
SetUpTestCase()34 void DlpPermissionLoadCallbackTest::SetUpTestCase() {}
35 
TearDownTestCase()36 void DlpPermissionLoadCallbackTest::TearDownTestCase() {}
37 
SetUp()38 void DlpPermissionLoadCallbackTest::SetUp() {}
39 
TearDown()40 void DlpPermissionLoadCallbackTest::TearDown() {}
41 
42 /**
43  * @tc.name: OnLoadSystemAbilityFail001
44  * @tc.desc: OnLoadSystemAbilityFail test
45  * @tc.type: FUNC
46  * @tc.require:
47  */
48 HWTEST_F(DlpPermissionLoadCallbackTest, OnLoadSystemAbilityFail001, TestSize.Level1)
49 {
50     DLP_LOG_INFO(LABEL, "OnLoadSystemAbilityFail001");
51 
52     DlpPermissionLoadCallback callback_;
53     int32_t systemAbilityId = 0;
54 
55     callback_.OnLoadSystemAbilityFail(systemAbilityId);
56     ASSERT_NE(SA_ID_DLP_PERMISSION_SERVICE, systemAbilityId);
57 
58     systemAbilityId = SA_ID_DLP_PERMISSION_SERVICE;
59     ASSERT_EQ(SA_ID_DLP_PERMISSION_SERVICE, systemAbilityId);
60 }
61 
62 /**
63  * @tc.name: OnLoadSystemAbilitySuccess001
64  * @tc.desc: OnLoadSystemAbilitySuccess test
65  * @tc.type: FUNC
66  * @tc.require:
67  */
68 HWTEST_F(DlpPermissionLoadCallbackTest, OnLoadSystemAbilitySuccess001, TestSize.Level1)
69 {
70     DLP_LOG_INFO(LABEL, "OnLoadSystemAbilitySuccess001");
71 
72     DlpPermissionLoadCallback callback_;
73     int32_t systemAbilityId = 0;
74     sptr<IRemoteObject> remoteObject = nullptr;
75 
76     callback_.OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject);
77     ASSERT_NE(SA_ID_DLP_PERMISSION_SERVICE, systemAbilityId);
78 
79     systemAbilityId = SA_ID_DLP_PERMISSION_SERVICE;
80     ASSERT_EQ(nullptr, remoteObject);
81 }
82 
83