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 #include "boot_animation_controller.h"
19 #include <if_system_ability_manager.h>
20 #include <iservice_registry.h>
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS::Rosen {
26 class BootAnimationControllerTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp() override;
31 void TearDown() override;
32 };
33
SetUpTestCase()34 void BootAnimationControllerTest::SetUpTestCase() {}
TearDownTestCase()35 void BootAnimationControllerTest::TearDownTestCase() {}
SetUp()36 void BootAnimationControllerTest::SetUp() {}
TearDown()37 void BootAnimationControllerTest::TearDown() {}
38
39 /**
40 * @tc.name: BootAnimationControllerTest_001
41 * @tc.desc: Verify the CreateDefaultBootConfig
42 * @tc.type:FUNC
43 */
44 HWTEST_F(BootAnimationControllerTest, BootAnimationControllerTest_001, TestSize.Level1)
45 {
46 BootAnimationController controller;
47 controller.CreateDefaultBootConfig();
48 EXPECT_EQ(1, controller.animationConfigs_.size());
49 }
50
51 /**
52 * @tc.name: BootAnimationControllerTest_002
53 * @tc.desc: Verify the GetBootType
54 * @tc.type:FUNC
55 */
56 HWTEST_F(BootAnimationControllerTest, BootAnimationControllerTest_002, TestSize.Level0)
57 {
58 BootAnimationController controller;
59 controller.isCompatible_ = true;
60 BootStrategyType type = controller.GetBootType();
61 EXPECT_EQ(type, BootStrategyType::COMPATIBLE);
62 }
63
64 /**
65 * @tc.name: BootAnimationControllerTest_003
66 * @tc.desc: Verify the GetBootType
67 * @tc.type:FUNC
68 */
69 HWTEST_F(BootAnimationControllerTest, BootAnimationControllerTest_003, TestSize.Level0)
70 {
71 BootAnimationController controller;
72 controller.isMultiDisplay_ = true;
73 BootStrategyType type = controller.GetBootType();
74 EXPECT_EQ(type, BootStrategyType::INDEPENDENT);
75 }
76
77 /**
78 * @tc.name: BootAnimationControllerTest_004
79 * @tc.desc: Verify the GetBootType
80 * @tc.type:FUNC
81 */
82 HWTEST_F(BootAnimationControllerTest, BootAnimationControllerTest_004, TestSize.Level0)
83 {
84 BootAnimationController controller;
85 BootAnimationConfig config;
86 controller.animationConfigs_.emplace_back(config);
87 BootStrategyType type = controller.GetBootType();
88 EXPECT_EQ(type, BootStrategyType::INDEPENDENT);
89 }
90
91 /**
92 * @tc.name: BootAnimationControllerTest_005
93 * @tc.desc: Verify the GetBootType
94 * @tc.type:FUNC
95 */
96 HWTEST_F(BootAnimationControllerTest, BootAnimationControllerTest_005, TestSize.Level0)
97 {
98 BootAnimationController controller;
99 BootAnimationConfig first_config;
100 controller.animationConfigs_.emplace_back(first_config);
101 BootAnimationConfig second_config;
102 controller.animationConfigs_.emplace_back(second_config);
103 BootStrategyType type = controller.GetBootType();
104 EXPECT_EQ(type, BootStrategyType::ASSOCIATIVE);
105 }
106
107 /**
108 * @tc.name: BootAnimationControllerTest_006
109 * @tc.desc: Verify the GetBootType
110 * @tc.type:FUNC
111 */
112 HWTEST_F(BootAnimationControllerTest, BootAnimationControllerTest_006, TestSize.Level1)
113 {
114 std::shared_ptr<BootAnimationController> controller = std::make_shared<BootAnimationController>();
115 std::string path = controller->GetConfigFilePath();
116 std::string filePath = "/sys_prod/etc/bootanimation/bootanimation_custom_config.json";
117 bool isFileExist = OHOS::IsFileExisted(filePath);
118 EXPECT_EQ(path.empty(), isFileExist ? false : true);
119 }
120
121 /**
122 * @tc.name: BootAnimationControllerTest_007
123 * @tc.desc: Verify the WaitRenderServiceInit
124 * @tc.type:FUNC
125 */
126 HWTEST_F(BootAnimationControllerTest, BootAnimationControllerTest_007, TestSize.Level1)
127 {
128 std::shared_ptr<BootAnimationController> controller = std::make_shared<BootAnimationController>();
129 controller->WaitRenderServiceInit();
130 sptr<ISystemAbilityManager> saMgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
131 EXPECT_TRUE(saMgr);
132 }
133 }
134