1 /*
2  * Copyright (c) 2022 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 "acquire_data_manager_test.h"
17 
18 #include "file_ex.h"
19 
20 #include "security_guard_define.h"
21 #include "acquire_data_manager.h"
22 
23 using namespace testing::ext;
24 using namespace OHOS::Security::SecurityGuardTest;
25 
26 namespace OHOS::Security::SecurityGuardTest {
27 
SetUpTestCase()28 void AcquireDataManagerTest::SetUpTestCase()
29 {
30     string isEnforcing;
31     LoadStringFromFile("/sys/fs/selinux/enforce", isEnforcing);
32     if (isEnforcing.compare("1") == 0) {
33         AcquireDataManagerTest::isEnforcing_ = true;
34         SaveStringToFile("/sys/fs/selinux/enforce", "0");
35     }
36 }
37 
TearDownTestCase()38 void AcquireDataManagerTest::TearDownTestCase()
39 {
40     if (AcquireDataManagerTest::isEnforcing_) {
41         SaveStringToFile("/sys/fs/selinux/enforce", "1");
42     }
43 }
44 
SetUp()45 void AcquireDataManagerTest::SetUp()
46 {
47 }
48 
TearDown()49 void AcquireDataManagerTest::TearDown()
50 {
51 }
52 
53 bool AcquireDataManagerTest::isEnforcing_ = false;
54 
55 /**
56  * @tc.name: Subscribe001
57  * @tc.desc: AcquireDataManager Subscribe
58  * @tc.type: FUNC
59  * @tc.require: AR000IENKB
60  */
61 HWTEST_F(AcquireDataManagerTest, Subscribe001, TestSize.Level1)
62 {
63     int ret = SecurityGuard::AcquireDataManager::GetInstance().Subscribe(nullptr);
64     EXPECT_EQ(ret, SecurityGuard::NULL_OBJECT);
65 }
66 
67 /**
68  * @tc.name: Unsubscribe001
69  * @tc.desc: AcquireDataManager Unsubscribe
70  * @tc.type: FUNC
71  * @tc.require: AR000IENKB
72  */
73 HWTEST_F(AcquireDataManagerTest, Unsubscribe001, TestSize.Level1)
74 {
75     int ret = SecurityGuard::AcquireDataManager::GetInstance().Unsubscribe(nullptr);
76     EXPECT_EQ(ret, SecurityGuard::BAD_PARAM);
77 }
78 
79 /**
80  * @tc.name: ReportSecurityInfo007
81  * @tc.desc: AcquireDataManager DeathRecipient OnRemoteDied
82  * @tc.type: FUNC
83  * @tc.require: SR000H96L5
84  */
85 HWTEST_F(AcquireDataManagerTest, DeathRecipient001, TestSize.Level1)
86 {
87     SecurityGuard::AcquireDataManager::DeathRecipient recipient =
88         SecurityGuard::AcquireDataManager::DeathRecipient();
89     recipient.OnRemoteDied(nullptr);
90 }
91 }