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 #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
META_BEGIN_NAMESPACE()25 META_BEGIN_NAMESPACE()
26
27 class AnimationTestBase : public ::testing::Test {
28 protected:
29 void SetUp() override;
30 /**
31 * @brief Gives time stored in manual clock.
32 * @return time of test clock.
33 */
34 TimeSpan Time() const;
35 /**
36 * @brief Increment clock time.
37 * Replacement for sleeping thread to avoid extending test application run time.
38 * @param time Amount of time added to clock time.
39 */
40 void IncrementClockTime(const TimeSpan& time);
41
42 void Update(const TimeSpan& time = TimeSpan::Milliseconds(0));
43
44 /**
45 * @brief Provides interface to test clock
46 * @return Pointer to test clock
47 */
48 IClock::Ptr GetTestClock() const;
49 /**
50 * @brief Updates the view for a configurable number of frames.
51 * @param frames number of frames to process.
52 * @param updateFn Calls updateFn after each update.
53 */
54 void RunFrames(uint32_t frames, std::function<void(uint32_t frame)> updateFn);
55 /**
56 * @brief Steps the given list of animations over for a configurable number of frames.
57 * This function is useful for updating animations that are not part of a view
58 * hierarchy. For animations that animate widget properties, use RunFrames.
59 * @param animations A list of animations to run.
60 * @param frames Number of frames to process.
61 * @param frameStepMs Number of ms to step between each frame
62 * @param updateFn Calls updateFn after each step.
63 */
64 void StepAnimations(const std::vector<IAnimation::Ptr> animations, uint32_t frames, int64_t frameStepMs,
65 std::function<void(uint32_t frame)> updateFn = {});
66 /**
67 * @brief Steps the given list of animations over for a configurable number of frames.
68 * This function is useful for updating animations that are not part of a view
69 * hierarchy. For animations that animate widget properties, use RunFrames.
70 * @param animations A list of animations to run.
71 * @param frames Number of frames to process.
72 * @param updateFn Calls updateFn after each step.
73 */
74 void StepAnimations(
75 const std::vector<IAnimation::Ptr> animations, uint32_t frames, std::function<void(uint32_t frame)> updateFn);
76 /**
77 * @brief Steps the global animation controller.
78 * @param stepMs Milliseconds to step.
79 */
80 void StepAnimationController(int64_t stepMs = 10);
81 /**
82 * @brief Returns the animation controller used by the tests.
83 */
84 IAnimationController::Ptr GetAnimationController();
85
86 private:
87 IManualClock::Ptr clock_;
88 };
89
90 META_END_NAMESPACE()
91
92 #endif // META_TEST_ANIMATION_TEST_BASE_H
93