1f6603c60Sopenharmony_ci/*
2f6603c60Sopenharmony_ci * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License.
5f6603c60Sopenharmony_ci * You may obtain a copy of the License at
6f6603c60Sopenharmony_ci *
7f6603c60Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8f6603c60Sopenharmony_ci *
9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and
13f6603c60Sopenharmony_ci * limitations under the License.
14f6603c60Sopenharmony_ci */
15f6603c60Sopenharmony_ci
16f6603c60Sopenharmony_ci#include "drawing_error_code.h"
17f6603c60Sopenharmony_ci#include "drawing_shadow_layer.h"
18f6603c60Sopenharmony_ci#include "gtest/gtest.h"
19f6603c60Sopenharmony_ci#include <random>
20f6603c60Sopenharmony_ci
21f6603c60Sopenharmony_ciusing namespace testing;
22f6603c60Sopenharmony_ciusing namespace testing::ext;
23f6603c60Sopenharmony_ci
24f6603c60Sopenharmony_cinamespace OHOS {
25f6603c60Sopenharmony_cinamespace Rosen {
26f6603c60Sopenharmony_cinamespace Drawing {
27f6603c60Sopenharmony_ciclass DrawingNativeShadowLayerTest : public testing::Test {};
28f6603c60Sopenharmony_ci
29f6603c60Sopenharmony_ci/*
30f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SHADOW_LAYER_0100
31f6603c60Sopenharmony_ci * @tc.name: testShadowLayerCreateNormal
32f6603c60Sopenharmony_ci * @tc.desc: test for testShadowLayerCreateNormal.
33f6603c60Sopenharmony_ci * @tc.size  : SmallTest
34f6603c60Sopenharmony_ci * @tc.type  : Function
35f6603c60Sopenharmony_ci * @tc.level : Level 0
36f6603c60Sopenharmony_ci */
37f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeShadowLayerTest, testShadowLayerCreateNormal, TestSize.Level0) {
38f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_ShadowLayerCreate with integer values for blurRadius, x, and y
39f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow = OH_Drawing_ShadowLayerCreate(3, -3, 3, 0xFF00FF00);
40f6603c60Sopenharmony_ci    EXPECT_NE(shadow, nullptr);
41f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow);
42f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_ShadowLayerCreate with floating-point values for blurRadius, x, and y
43f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow2 = OH_Drawing_ShadowLayerCreate(3.f, -3.f, 3.f, 0xFF00FF00);
44f6603c60Sopenharmony_ci    EXPECT_NE(shadow2, nullptr);
45f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow2);
46f6603c60Sopenharmony_ci}
47f6603c60Sopenharmony_ci
48f6603c60Sopenharmony_ci/*
49f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SHADOW_LAYER_0101
50f6603c60Sopenharmony_ci * @tc.name: testShadowLayerCreateNull
51f6603c60Sopenharmony_ci * @tc.desc: test for testShadowLayerCreateNull.
52f6603c60Sopenharmony_ci * @tc.size  : SmallTest
53f6603c60Sopenharmony_ci * @tc.type  : Function
54f6603c60Sopenharmony_ci * @tc.level : Level 3
55f6603c60Sopenharmony_ci */
56f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeShadowLayerTest, testShadowLayerCreateNull, TestSize.Level3) {
57f6603c60Sopenharmony_ci    // 1. OH_Drawing_ShadowLayerCreate with the first parameter being empty, check the error code using
58f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
59f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow = OH_Drawing_ShadowLayerCreate(0, -3, 3, 0xFF00FF00);
60f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE);
61f6603c60Sopenharmony_ci    // 2. OH_Drawing_ShadowLayerCreate with the second parameter being empty
62f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow2 = OH_Drawing_ShadowLayerCreate(3, 0, 3, 0xFF00FF00);
63f6603c60Sopenharmony_ci    EXPECT_NE(shadow2, nullptr);
64f6603c60Sopenharmony_ci    // 3. OH_Drawing_ShadowLayerCreate with the third parameter being empty
65f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow3 = OH_Drawing_ShadowLayerCreate(3, -3, 0, 0xFF00FF00);
66f6603c60Sopenharmony_ci    EXPECT_NE(shadow3, nullptr);
67f6603c60Sopenharmony_ci    // 4. OH_Drawing_ShadowLayerCreate with the fourth parameter being empty
68f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow4 = OH_Drawing_ShadowLayerCreate(3, -3, 3, 0);
69f6603c60Sopenharmony_ci    EXPECT_NE(shadow4, nullptr);
70f6603c60Sopenharmony_ci    // 5. Free memory
71f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow);
72f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow2);
73f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow3);
74f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow4);
75f6603c60Sopenharmony_ci}
76f6603c60Sopenharmony_ci
77f6603c60Sopenharmony_ci/*
78f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SHADOW_LAYER_0102
79f6603c60Sopenharmony_ci * @tc.name: testShadowLayerCreateAbnormal
80f6603c60Sopenharmony_ci * @tc.desc: test for testShadowLayerCreateAbnormal.
81f6603c60Sopenharmony_ci * @tc.size  : SmallTest
82f6603c60Sopenharmony_ci * @tc.type  : Function
83f6603c60Sopenharmony_ci * @tc.level : Level 3
84f6603c60Sopenharmony_ci */
85f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeShadowLayerTest, testShadowLayerCreateAbnormal, TestSize.Level3) {
86f6603c60Sopenharmony_ci    // 1. OH_Drawing_ShadowLayerCreate with the first parameter as a negative number, check the error code using
87f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
88f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow = OH_Drawing_ShadowLayerCreate(-3, 3, 3, 0xFF00FF00);
89f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE);
90f6603c60Sopenharmony_ci    // 2. OH_Drawing_ShadowLayerCreate with the second parameter as a negative number
91f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow2 = OH_Drawing_ShadowLayerCreate(3, -3, 3, 0xFF00FF00);
92f6603c60Sopenharmony_ci    EXPECT_NE(shadow2, nullptr);
93f6603c60Sopenharmony_ci    // 3. OH_Drawing_ShadowLayerCreate with the third parameter as a negative number
94f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow3 = OH_Drawing_ShadowLayerCreate(3, 3, -3, 0xFF00FF00);
95f6603c60Sopenharmony_ci    EXPECT_NE(shadow3, nullptr);
96f6603c60Sopenharmony_ci    // 4. OH_Drawing_ShadowLayerCreate with the fourth parameter as a negative number
97f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow4 = OH_Drawing_ShadowLayerCreate(3, 3, 3, -0xFF00FF00);
98f6603c60Sopenharmony_ci    EXPECT_NE(shadow4, nullptr);
99f6603c60Sopenharmony_ci    // 5. Free memory
100f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow);
101f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow2);
102f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow3);
103f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow4);
104f6603c60Sopenharmony_ci}
105f6603c60Sopenharmony_ci
106f6603c60Sopenharmony_ci/*
107f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SHADOW_LAYER_0103
108f6603c60Sopenharmony_ci * @tc.name: testShadowLayerCreateMaximum
109f6603c60Sopenharmony_ci * @tc.desc: test for testShadowLayerCreateMaximum.
110f6603c60Sopenharmony_ci * @tc.size  : SmallTest
111f6603c60Sopenharmony_ci * @tc.type  : Function
112f6603c60Sopenharmony_ci * @tc.level : Level 3
113f6603c60Sopenharmony_ci */
114f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeShadowLayerTest, testShadowLayerCreateMaximum, TestSize.Level3) {
115f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_ShadowLayerCreate with the first parameter as the maximum value
116f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow = OH_Drawing_ShadowLayerCreate(FLT_MAX, 3, 3, 0xFF00FF00);
117f6603c60Sopenharmony_ci    EXPECT_NE(shadow, nullptr);
118f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_ShadowLayerCreate with the second parameter as the maximum value
119f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow2 = OH_Drawing_ShadowLayerCreate(3, FLT_MAX, 3, 0xFF00FF00);
120f6603c60Sopenharmony_ci    EXPECT_NE(shadow2, nullptr);
121f6603c60Sopenharmony_ci    // 3. Call OH_Drawing_ShadowLayerCreate with the third parameter as the maximum value
122f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow3 = OH_Drawing_ShadowLayerCreate(3, 3, FLT_MAX, 0xFF00FF00);
123f6603c60Sopenharmony_ci    EXPECT_NE(shadow3, nullptr);
124f6603c60Sopenharmony_ci    // 4. Call OH_Drawing_ShadowLayerCreate with the fourth parameter as the maximum value
125f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow4 = OH_Drawing_ShadowLayerCreate(3, 3, 3, UINT32_MAX);
126f6603c60Sopenharmony_ci    EXPECT_NE(shadow4, nullptr);
127f6603c60Sopenharmony_ci    // 5. Free memory
128f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow);
129f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow2);
130f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow3);
131f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow4);
132f6603c60Sopenharmony_ci}
133f6603c60Sopenharmony_ci
134f6603c60Sopenharmony_ci/*
135f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SHADOW_LAYER_0104
136f6603c60Sopenharmony_ci * @tc.name: testShadowLayerCreateMultipleCalls
137f6603c60Sopenharmony_ci * @tc.desc: test for testShadowLayerCreateMultipleCalls.
138f6603c60Sopenharmony_ci * @tc.size  : SmallTest
139f6603c60Sopenharmony_ci * @tc.type  : Function
140f6603c60Sopenharmony_ci * @tc.level : Level 3
141f6603c60Sopenharmony_ci */
142f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeShadowLayerTest, testShadowLayerCreateMultipleCalls, TestSize.Level3) {
143f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_ShadowLayerCreate 10 times with random values for blurRadius, x, y, and different colors
144f6603c60Sopenharmony_ci    std::random_device rd;
145f6603c60Sopenharmony_ci    std::mt19937 gen(rd());
146f6603c60Sopenharmony_ci    std::uniform_real_distribution<float> dis(0, 100);
147f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
148f6603c60Sopenharmony_ci        float blurRadius = dis(gen);
149f6603c60Sopenharmony_ci        float x = dis(gen);
150f6603c60Sopenharmony_ci        float y = dis(gen);
151f6603c60Sopenharmony_ci        uint32_t color = dis(gen);
152f6603c60Sopenharmony_ci        OH_Drawing_ShadowLayer *shadow = OH_Drawing_ShadowLayerCreate(blurRadius, x, y, color);
153f6603c60Sopenharmony_ci        EXPECT_NE(shadow, nullptr);
154f6603c60Sopenharmony_ci        OH_Drawing_ShadowLayerDestroy(shadow);
155f6603c60Sopenharmony_ci    }
156f6603c60Sopenharmony_ci}
157f6603c60Sopenharmony_ci
158f6603c60Sopenharmony_ci/*
159f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SHADOW_LAYER_0200
160f6603c60Sopenharmony_ci * @tc.name: testShadowLayerDestroyNormal
161f6603c60Sopenharmony_ci * @tc.desc: test for testShadowLayerDestroyNormal.
162f6603c60Sopenharmony_ci * @tc.size  : SmallTest
163f6603c60Sopenharmony_ci * @tc.type  : Function
164f6603c60Sopenharmony_ci * @tc.level : Level 0
165f6603c60Sopenharmony_ci */
166f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeShadowLayerTest, testShadowLayerDestroyNormal, TestSize.Level0) {
167f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_ShadowLayerCreate
168f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayer *shadow = OH_Drawing_ShadowLayerCreate(3, 3, 3, 0xFF00FF00);
169f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_ShadowLayerDestroy
170f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(shadow);
171f6603c60Sopenharmony_ci}
172f6603c60Sopenharmony_ci
173f6603c60Sopenharmony_ci/*
174f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SHADOW_LAYER_0201
175f6603c60Sopenharmony_ci * @tc.name: testShadowLayerDestroyNull
176f6603c60Sopenharmony_ci * @tc.desc: test for testShadowLayerDestroyNull.
177f6603c60Sopenharmony_ci * @tc.size  : SmallTest
178f6603c60Sopenharmony_ci * @tc.type  : Function
179f6603c60Sopenharmony_ci * @tc.level : Level 3
180f6603c60Sopenharmony_ci */
181f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeShadowLayerTest, testShadowLayerDestroyNull, TestSize.Level3) {
182f6603c60Sopenharmony_ci    // 1. OH_Drawing_ShadowLayerDestroy with null parameter
183f6603c60Sopenharmony_ci    OH_Drawing_ShadowLayerDestroy(nullptr);
184f6603c60Sopenharmony_ci}
185f6603c60Sopenharmony_ci
186f6603c60Sopenharmony_ci} // namespace Drawing
187f6603c60Sopenharmony_ci} // namespace Rosen
188f6603c60Sopenharmony_ci} // namespace OHOS