1 /* 2 * Copyright (c) 2025 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 #define protected public 20 #include "test/mock/core/common/mock_container.h" 21 #include "test/mock/core/pipeline/mock_pipeline_context.h" 22 #include "ui/animation/animation_utils.h" 23 24 using namespace testing; 25 using namespace testing::ext; 26 namespace OHOS::Ace { 27 class AnimationKitTest : public testing::Test { 28 public: SetUpTestSuite()29 static void SetUpTestSuite() 30 { 31 NG::MockPipelineContext::SetUp(); 32 MockContainer::SetUp(); 33 MockContainer::Current()->pipelineContext_ = PipelineBase::GetCurrentContext(); 34 } TearDownTestSuite()35 static void TearDownTestSuite() 36 { 37 MockContainer::Current()->pipelineContext_ = nullptr; 38 NG::MockPipelineContext::TearDown(); 39 } SetUp()40 void SetUp() {}; TearDown()41 void TearDown() {}; 42 }; 43 44 /** 45 * @tc.name: StartAnimation_ShouldReturnAnimation_WhenOptionIsValid 46 * @tc.desc: Test StartAnimation function when option is valid 47 * @tc.type: Func 48 */ 49 HWTEST_F(AnimationKitTest, AnimationKitTest001, TestSize.Level1) 50 { 51 AnimationOption option; __anonaddeaaf00102() 52 Kit::AnimationCallback callback = []() { return; }; __anonaddeaaf00202() 53 Kit::AnimationCallback finishCallback = []() { return; }; __anonaddeaaf00302() 54 Kit::AnimationCallback repeatCallback = []() { return; }; 55 bool flushUITasks = true; 56 57 auto animation = Kit::AnimationUtils::StartAnimation(option, 58 callback, finishCallback, repeatCallback, flushUITasks); 59 EXPECT_NE(animation, nullptr); 60 } 61 62 /** 63 * @tc.name: StartAnimation_ShouldReturnNull_WhenOptionIsValid 64 * @tc.desc: Test StartAnimation function when option is valid 65 * @tc.type: Func 66 */ 67 HWTEST_F(AnimationKitTest, AnimationKitTest002, TestSize.Level1) 68 { 69 AnimationOption option; __anonaddeaaf00402() 70 Kit::AnimationCallback callback = []() { return; }; __anonaddeaaf00502() 71 Kit::AnimationCallback finishCallback = []() { return; }; __anonaddeaaf00602() 72 Kit::AnimationCallback repeatCallback = []() { return; }; 73 bool flushUITasks = false; 74 75 auto animation = Kit::AnimationUtils::StartAnimation(option, 76 callback, finishCallback, repeatCallback, flushUITasks); 77 EXPECT_NE(animation, nullptr); 78 } 79 80 /** 81 * @tc.name: StartAnimation_ShouldStopAnimation_WhenAnimationIsNotNull 82 * @tc.desc: Test StopAnimation method when animation is not null 83 * @tc.type: FUNC 84 */ 85 HWTEST_F(AnimationKitTest, AnimationKitTest003, TestSize.Level1) 86 { 87 AnimationOption option; __anonaddeaaf00702() 88 Kit::AnimationCallback callback = []() { return; }; __anonaddeaaf00802() 89 Kit::AnimationCallback finishCallback = []() { return; }; __anonaddeaaf00902() 90 Kit::AnimationCallback repeatCallback = []() { return; }; 91 bool flushUITasks = true; 92 93 auto animation = Kit::AnimationUtils::StartAnimation(option, 94 callback, finishCallback, repeatCallback, flushUITasks); 95 96 Kit::AnimationUtils::StopAnimation(animation); 97 EXPECT_NE(animation, nullptr); 98 } 99 } // namespace OHOS::Ace 100