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 #ifndef META_TEST_ANIMATION_TEST_BASE_H
17 #define META_TEST_ANIMATION_TEST_BASE_H
18 
19 #include <gtest/gtest.h>
20 
21 #include <meta/base/time_span.h>
22 #include <meta/interface/animation/intf_animation.h>
23 #include <meta/interface/intf_manual_clock.h>
24 
25 META_BEGIN_NAMESPACE()
26 
27 class AnimationTestBase : public ::testing::Test {
28 protected:
29     void SetUp() override;
30 
31     TimeSpan Time() const;
32 
33     void IncrementClockTime(const TimeSpan& time);
34 
35     void Update(const TimeSpan& time = TimeSpan::Milliseconds(0));
36 
37     IClock::Ptr GetTestClock() const;
38 
39     void RunFrames(uint32_t frames, std::function<void(uint32_t frame)> updateFn);
40 
41     void StepAnimations(const std::vector<IAnimation::Ptr> animations, uint32_t frames, int64_t frameStepMs,
42         std::function<void(uint32_t frame)> updateFn = {});
43 
44     void StepAnimations(
45         const std::vector<IAnimation::Ptr> animations, uint32_t frames, std::function<void(uint32_t frame)> updateFn);
46 
47     void StepAnimationController(int64_t stepMs = 10);
48 
49     IAnimationController::Ptr GetAnimationController();
50 
51 private:
52     IManualClock::Ptr clock_;
53 };
54 
55 META_END_NAMESPACE()
56 
57 #endif