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 #include <gmock/gmock-matchers.h> 16 #include <gtest/gtest.h> 17 18 #include <meta/api/animation.h> 19 #include <meta/interface/property/construct_property.h> 20 21 #include "TestRunner.h" 22 #include "helpers/animation_test_base.h" 23 #include "helpers/testing_objects.h" 24 25 using namespace testing; 26 using namespace testing::ext; 27 28 META_BEGIN_NAMESPACE() 29 30 class SequentialAnimationTest : public AnimationTestBase { 31 public: SetUpTestSuite()32 static void SetUpTestSuite() 33 { 34 SetTest(); 35 } TearDownTestSuite()36 static void TearDownTestSuite() 37 { 38 TearDownTest(); 39 } 40 }; 41 42 /** 43 * @tc.name: SeekingSequentialAnimation 44 * @tc.desc: test SeekingSequentialAnimation 45 * @tc.type: FUNC 46 */ 47 HWTEST_F(SequentialAnimationTest, SeekingSequentialAnimationTest, TestSize.Level1) 48 { 49 // given 50 auto property1 = ConstructProperty("Property1", 0.0F); 51 auto property2 = ConstructProperty("Property2", 0.0F); 52 53 auto animation = SequentialAnimation(CreateInstance(ClassId::SequentialAnimation)) 54 .Add(KeyframeAnimation<float>(CreateInstance(ClassId::KeyframeAnimation)) 55 .SetFrom(0.0F) 56 .SetTo(1.0F) 57 .SetProperty(property1) 58 .SetDuration(TimeSpan::Milliseconds(1000))) 59 .Add(KeyframeAnimation<float>(CreateInstance(ClassId::KeyframeAnimation)) 60 .SetFrom(0.0F) 61 .SetTo(1.0F) 62 .SetProperty(property2) 63 .SetDuration(TimeSpan::Milliseconds(1000))); 64 // when 65 animation.Seek(0.25F); 66 animation.Start(); 67 animation.Pause(); 68 auto progress25Property1Value = property1->GetValue(); 69 auto progress25Property2Value = property2->GetValue(); 70 71 animation.Seek(0.5F); 72 animation.Start(); 73 animation.Pause(); 74 75 auto progress50Property1Value = property1->GetValue(); 76 auto progress50Property2Value = property2->GetValue(); 77 78 animation.Seek(0.75F); 79 animation.Start(); 80 animation.Pause(); 81 82 auto progress75Property1Value = property1->GetValue(); 83 auto progress75Property2Value = property2->GetValue(); 84 85 // expected 86 EXPECT_THAT(progress25Property1Value, testing::Eq(0.5F)); 87 EXPECT_THAT(progress25Property2Value, testing::Eq(0.0F)); 88 89 EXPECT_THAT(progress50Property1Value, testing::Eq(1.0F)); 90 EXPECT_THAT(progress50Property2Value, testing::Eq(0.0F)); 91 92 EXPECT_THAT(progress75Property1Value, testing::Eq(1.0F)); 93 EXPECT_THAT(progress75Property2Value, testing::Eq(0.5F)); 94 } 95 96 /** 97 * @tc.name: SeekingSequentialAnimationAndPause 98 * @tc.desc: test SeekingSequentialAnimationAndPause 99 * @tc.type: FUNC 100 */ 101 HWTEST_F(SequentialAnimationTest, SeekingSequentialAnimationAndPause, TestSize.Level1) 102 { 103 // given 104 auto property1 = ConstructProperty("Property1", 0.0F); 105 auto property2 = ConstructProperty("Property2", 0.0F); 106 107 auto animation = SequentialAnimation(CreateInstance(ClassId::SequentialAnimation)) 108 .Add(KeyframeAnimation<float>(CreateInstance(ClassId::KeyframeAnimation)) 109 .SetFrom(0.0F) 110 .SetTo(1.0F) 111 .SetProperty(property1) 112 .SetDuration(TimeSpan::Milliseconds(1000))) 113 .Add(KeyframeAnimation<float>(CreateInstance(ClassId::KeyframeAnimation)) 114 .SetFrom(0.0F) 115 .SetTo(1.0F) 116 .SetProperty(property2) 117 .SetDuration(TimeSpan::Milliseconds(1000))); 118 119 // when 120 animation.Start(); 121 animation.Seek(0.25F); 122 animation.Pause(); 123 124 auto progress25Property1Value = property1->GetValue(); 125 auto progress25Property2Value = property2->GetValue(); 126 127 animation.Start(); 128 animation.Seek(0.5F); 129 animation.Pause(); 130 131 auto progress50Property1Value = property1->GetValue(); 132 auto progress50Property2Value = property2->GetValue(); 133 134 animation.Start(); 135 animation.Seek(0.75F); 136 animation.Pause(); 137 138 auto progress75Property1Value = property1->GetValue(); 139 auto progress75Property2Value = property2->GetValue(); 140 141 // expected 142 EXPECT_THAT(progress25Property1Value, testing::Eq(0.5F)); 143 EXPECT_THAT(progress25Property2Value, testing::Eq(0.0F)); 144 145 EXPECT_THAT(progress50Property1Value, testing::Eq(1.0F)); 146 EXPECT_THAT(progress50Property2Value, testing::Eq(0.0F)); 147 148 EXPECT_THAT(progress75Property1Value, testing::Eq(1.0F)); 149 EXPECT_THAT(progress75Property2Value, testing::Eq(0.5F)); 150 } 151 152 META_END_NAMESPACE() 153