1 /*
2 * Copyright (c) 2024 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
18 #define private public
19 #include "advanced_security_mode_manager.h"
20 #undef private
21 #include "hilog_tag_wrapper.h"
22 #include "parameters.h"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace AppExecFwk {
29 class AdvancedSecurityModeManagerTest : public testing::Test {
30 public:
31 void SetUp();
32 void TearDown();
33
34 protected:
35 bool deviceAdvSecModeEnabled_ = false;
36 };
37
SetUp()38 void AdvancedSecurityModeManagerTest::SetUp()
39 {
40 int32_t state = OHOS::system::GetIntParameter<int32_t>("ohos.boot.advsecmode.state", 0);
41 deviceAdvSecModeEnabled_ = state > 0;
42 }
43
TearDown()44 void AdvancedSecurityModeManagerTest::TearDown()
45 {}
46
47 /**
48 * @tc.number: AdvancedSecurityModeManager_Init_0100
49 * @tc.desc: Test Init works
50 * @tc.type: FUNC
51 */
52 HWTEST_F(AdvancedSecurityModeManagerTest, AdvancedSecurityModeManager_Init_0100, TestSize.Level0)
53 {
54 TAG_LOGD(AAFwkTag::TEST, "AdvancedSecurityModeManager_Init_0100 start.");
55 auto manager = std::make_shared<AdvancedSecurityModeManager>();
56 manager->Init();
57 EXPECT_EQ(manager->isAdvSecModeEnabled_, deviceAdvSecModeEnabled_);
58 }
59
60 /**
61 * @tc.number: AdvancedSecurityModeManager_IsJITEnabled_0100
62 * @tc.desc: Test IsJITEnabled works
63 * @tc.type: FUNC
64 */
65 HWTEST_F(AdvancedSecurityModeManagerTest, AdvancedSecurityModeManager_IsJITEnabled_0100, TestSize.Level0)
66 {
67 TAG_LOGD(AAFwkTag::TEST, "AdvancedSecurityModeManager_IsJITEnabled_0100 start.");
68 auto manager = std::make_shared<AdvancedSecurityModeManager>();
69 manager->isAdvSecModeEnabled_ = true;
70 EXPECT_EQ(manager->IsJITEnabled(), false);
71 }
72 } // namespace AbilityRuntime
73 } // namespace OHOS
74