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 <parameters.h>
19 #include "util.h"
20 #include "boot_animation_strategy.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS::Rosen {
26 class BootAnimationStrategyTest : 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 BootAnimationStrategyTest::SetUpTestCase() {}
TearDownTestCase()35 void BootAnimationStrategyTest::TearDownTestCase() {}
SetUp()36 void BootAnimationStrategyTest::SetUp() {}
TearDown()37 void BootAnimationStrategyTest::TearDown() {}
38
39 /**
40 * @tc.name: BootAnimationStrategyTest_001
41 * @tc.desc: Verify the CheckExitAniamtion
42 * @tc.type:FUNC
43 */
44 HWTEST_F(BootAnimationStrategyTest, BootAnimationStrategyTest_001, TestSize.Level1)
45 {
46 std::shared_ptr<BootAnimationStrategy> bas1 = std::make_shared<BootAnimationStrategy>();
47 bas1->isAnimationEnd_ = false;
48 bas1->CheckExitAnimation();
49
50 std::shared_ptr<BootAnimationStrategy> bas2 = std::make_shared<BootAnimationStrategy>();
51 bas2->isAnimationEnd_ = true;
52 bas2->CheckExitAnimation();
53
54 std::shared_ptr<BootAnimationStrategy> bas3 = std::make_shared<BootAnimationStrategy>();
55 bas3->isAnimationEnd_ = true;
56 system::SetParameter(BOOT_COMPLETED, "false");
57 EXPECT_EQ(false, system::GetBoolParameter(BOOT_COMPLETED, false));
58 bas3->CheckExitAnimation();
59
60 std::shared_ptr<BootAnimationStrategy> bas4 = std::make_shared<BootAnimationStrategy>();
61 bas4->isAnimationEnd_ = true;
62 system::SetParameter(BOOT_COMPLETED, "true");
63 EXPECT_EQ(true, system::GetBoolParameter(BOOT_COMPLETED, false));
64 bas4->CheckExitAnimation();
65 }
66
67 /**
68 * @tc.name: BootAnimationStrategyTest_002
69 * @tc.desc: Verify the CheckNeedOtaCompile
70 * @tc.type:FUNC
71 */
72 HWTEST_F(BootAnimationStrategyTest, BootAnimationStrategyTest_002, TestSize.Level1)
73 {
74 std::shared_ptr<BootAnimationStrategy> bas1 = std::make_shared<BootAnimationStrategy>();
75 system::SetParameter("const.bms.optimizing_apps.switch", "off");
76 bas1->CheckNeedOtaCompile();
77
78 std::shared_ptr<BootAnimationStrategy> bas2 = std::make_shared<BootAnimationStrategy>();
79 system::SetParameter("const.bms.optimizing_apps.switch", "on");
80 bas2->CheckNeedOtaCompile();
81
82 std::shared_ptr<BootAnimationStrategy> bas3 = std::make_shared<BootAnimationStrategy>();
83 system::SetParameter("const.bms.optimizing_apps.switch", "on");
84 system::SetParameter("persist.dupdate_engine.update_type", "");
85 bas3->CheckNeedOtaCompile();
86
87 std::shared_ptr<BootAnimationStrategy> bas4 = std::make_shared<BootAnimationStrategy>();
88 system::SetParameter("const.bms.optimizing_apps.switch", "on");
89 bool result = system::SetParameter("persist.dupdate_engine.update_type", "manual");
90 EXPECT_EQ(result ? "manual" : "", system::GetParameter("persist.dupdate_engine.update_type", ""));
91 bas4->CheckNeedOtaCompile();
92
93 std::shared_ptr<BootAnimationStrategy> bas5 = std::make_shared<BootAnimationStrategy>();
94 system::SetParameter("const.bms.optimizing_apps.switch", "on");
95 system::SetParameter("persist.dupdate_engine.update_type", "manual");
96 system::SetParameter(BMS_COMPILE_STATUS, "-1");
97 bas5->CheckNeedOtaCompile();
98
99 std::shared_ptr<BootAnimationStrategy> bas6 = std::make_shared<BootAnimationStrategy>();
100 system::SetParameter("const.bms.optimizing_apps.switch", "on");
101 system::SetParameter("persist.dupdate_engine.update_type", "manual");
102 system::SetParameter(BMS_COMPILE_STATUS, BMS_COMPILE_STATUS_END);
103 bas6->CheckNeedOtaCompile();
104 }
105 }
106