• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <memory>
16 
17 #include "gtest/gtest.h"
18 #include "core/components_ng/render/adapter/gradient_style_modifier.h"
19 #include "core/components_ng/render/adapter/rosen_render_context.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS::Ace::NG {
25 
26 namespace {
27 constexpr double MAX_COLOR_STOP = 100.0;
28 }
29 
30 class GradientStyleModifierTest : public testing::Test {
31 };
32 
33 /**
34  * @tc.name: gradientPropertyTest007
35  * @tc.desc: LinearGradientToJson
36  * @tc.type: FUNC
37  */
38 HWTEST_F(GradientStyleModifierTest, gradientStyleModifierTest001, TestSize.Level1)
39 {
40     /**
41      * @tc.steps: step1. Create and init Gradient.
42      */
43     Gradient gradient;
44     GradientColor colorBegin;
45     GradientColor colorEnd;
46     colorBegin.SetColor(Color::BLACK);
47     colorBegin.SetDimension(Dimension(0, DimensionUnit::PERCENT));
48     colorEnd.SetColor(Color::RED);
49     colorEnd.SetDimension(Dimension(MAX_COLOR_STOP, DimensionUnit::PERCENT));
50     gradient.AddColor(colorEnd);
51     /**
52      * @tc.steps: step2. create animatable color and color stop .
53      */
54     ColorAnimatableArithmetic colors(gradient);
55     ColorStopAnimatableArithmetic colorStops(gradient);
56     /**
57      * @tc.steps: step3. padding color and color stop .
58      */
59     auto context = RosenRenderContext();
60     auto modifier = std::make_shared<GradientStyleModifier>(AceType::WeakClaim(&context));
61     modifier->SetGradient(gradient);
62     modifier->PaddingColorStops(colorStops, true);
63     auto outputGradient = modifier->GetGradient();
64     /**
65      * @tc.steps: step4. check data size.
66      */
67     EXPECT_EQ(outputGradient.GetColors().size(), gradient.GetColors().size());
68     EXPECT_EQ(outputGradient.GetColors().at(0).GetColor().GetColorSpace(), ColorSpace::SRGB);
69 }
70 } // namespace OHOS::Ace::NG