1 /* 2 * Copyright (c) 2021 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_TEST_MOCK_MOCK_ANIMATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_TEST_MOCK_MOCK_ANIMATION_H 18 19 #include "core/animation/animator.h" 20 #include "core/animation/curve_animation.h" 21 #include "core/animation/flush_event.h" 22 #include "core/animation/keyframe_animation.h" 23 #include "core/animation/picture_animation.h" 24 #include "core/components/common/properties/color.h" 25 #include "core/components/common/properties/tween_option.h" 26 27 namespace OHOS::Ace { 28 class MockAnimation : public FlushEvent { 29 DECLARE_ACE_TYPE(MockAnimation, FlushEvent); 30 31 public: 32 MockAnimation() = default; 33 ~MockAnimation() override = default; 34 35 void OnPostFlush() override; 36 InitController(const WeakPtr<PipelineContext> & context)37 void InitController(const WeakPtr<PipelineContext>& context) 38 { 39 animator_ = CREATE_ANIMATOR(context); 40 } 41 42 double GetPositionResult() const; 43 const RefPtr<Animator>& GetAnimator() const; 44 45 void SetPositionResult(double positionResult); 46 bool animationStartStatus_ { false }; 47 bool animationStopStatus_ { false }; 48 bool animationIdleStatus_ { false }; 49 bool animationPauseStatus_ { false }; 50 AnimationOperation operation_ { AnimationOperation::PLAY }; 51 52 bool setRepeatSucc_ { false }; 53 int32_t postFlushCallTimes_ { 0 }; 54 int32_t iteration_ { 1 }; 55 int32_t repeatDoneTimes_ { 0 }; 56 int32_t animationIntValue_ { 0 }; 57 int32_t animationIntStopValue_ { 0 }; 58 59 int32_t pictureIntValue_ { 0 }; 60 int32_t animationDuration_ { 0 }; 61 int32_t startDelay_ { 0 }; 62 float animationFloatValue_ { 0.0f }; 63 Color animationColorValue_ { Color::WHITE }; 64 65 float keyframeAnimationValue_ { 0.0f }; 66 std::string pictureStringValue_; 67 RefPtr<CurveAnimation<int32_t>> animationInt_; 68 RefPtr<CurveAnimation<Color>> animationColor_; 69 RefPtr<CurveAnimation<float>> animationFloat_; 70 RefPtr<PictureAnimation<int32_t>> pictureInt_; 71 RefPtr<PictureAnimation<std::string>> pictureString_; 72 RefPtr<KeyframeAnimation<float>> keyframeAnimation_; 73 74 private: 75 void CreatePictureInterpolators(); 76 void CreateInterpolators(); 77 void AddListeners(); 78 void ExecuteOperation(); 79 RefPtr<Animator> animator_; 80 double positionResult_ { 0.0 }; 81 }; 82 } // namespace OHOS::Ace 83 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_ANIMATION_TEST_MOCK_MOCK_ANIMATION_H 84