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_color.h"
17f6603c60Sopenharmony_ci#include "drawing_color_filter.h"
18f6603c60Sopenharmony_ci#include "drawing_filter.h"
19f6603c60Sopenharmony_ci#include "drawing_image.h"
20f6603c60Sopenharmony_ci#include "drawing_matrix.h"
21f6603c60Sopenharmony_ci#include "drawing_path.h"
22f6603c60Sopenharmony_ci#include "drawing_path_effect.h"
23f6603c60Sopenharmony_ci#include "drawing_pen.h"
24f6603c60Sopenharmony_ci#include "drawing_point.h"
25f6603c60Sopenharmony_ci#include "drawing_rect.h"
26f6603c60Sopenharmony_ci#include "drawing_region.h"
27f6603c60Sopenharmony_ci#include "drawing_round_rect.h"
28f6603c60Sopenharmony_ci#include "utils/scalar.h"
29f6603c60Sopenharmony_ci#include "gtest/gtest.h"
30f6603c60Sopenharmony_ci
31f6603c60Sopenharmony_ciusing namespace testing;
32f6603c60Sopenharmony_ciusing namespace testing::ext;
33f6603c60Sopenharmony_ci
34f6603c60Sopenharmony_cinamespace OHOS {
35f6603c60Sopenharmony_cinamespace Rosen {
36f6603c60Sopenharmony_cinamespace Drawing {
37f6603c60Sopenharmony_ciclass DrawingNativePathEffectTest : public testing::Test {};
38f6603c60Sopenharmony_ci
39f6603c60Sopenharmony_ci/*
40f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_EFFECT_0100
41f6603c60Sopenharmony_ci * @tc.name: testCreateDashPathEffectNormal
42f6603c60Sopenharmony_ci * @tc.desc: test for testCreateDashPathEffectNormal.
43f6603c60Sopenharmony_ci * @tc.size  : SmallTest
44f6603c60Sopenharmony_ci * @tc.type  : Function
45f6603c60Sopenharmony_ci * @tc.level : Level 0
46f6603c60Sopenharmony_ci */
47f6603c60Sopenharmony_ciHWTEST_F(DrawingNativePathEffectTest, testCreateDashPathEffectNormal, TestSize.Level0) {
48f6603c60Sopenharmony_ci    // 1. OH_Drawing_CreateDashPathEffect
49f6603c60Sopenharmony_ci    float intervals[] = {1, 1, 1};
50f6603c60Sopenharmony_ci    OH_Drawing_PathEffect *pathEffect = OH_Drawing_CreateDashPathEffect(intervals, 3, 0.0);
51f6603c60Sopenharmony_ci    // 2. Free memory
52f6603c60Sopenharmony_ci    OH_Drawing_PathEffectDestroy(pathEffect);
53f6603c60Sopenharmony_ci}
54f6603c60Sopenharmony_ci
55f6603c60Sopenharmony_ci/*
56f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_EFFECT_0101
57f6603c60Sopenharmony_ci * @tc.name: testCreateDashPathEffectNull
58f6603c60Sopenharmony_ci * @tc.desc: test for testCreateDashPathEffectNull.
59f6603c60Sopenharmony_ci * @tc.size  : SmallTest
60f6603c60Sopenharmony_ci * @tc.type  : Function
61f6603c60Sopenharmony_ci * @tc.level : Level 3
62f6603c60Sopenharmony_ci */
63f6603c60Sopenharmony_ciHWTEST_F(DrawingNativePathEffectTest, testCreateDashPathEffectNull, TestSize.Level3) {
64f6603c60Sopenharmony_ci    float intervals[] = {1, 1};
65f6603c60Sopenharmony_ci    // 1. OH_Drawing_CreateDashPathEffect with nullptr as the first parameter, check the error code with
66f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
67f6603c60Sopenharmony_ci    OH_Drawing_PathEffect *pathEffect1 = OH_Drawing_CreateDashPathEffect(nullptr, 2, 1.0);
68f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
69f6603c60Sopenharmony_ci    // 2. OH_Drawing_CreateDashPathEffect with 0 as the second parameter, check the error code with
70f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
71f6603c60Sopenharmony_ci    OH_Drawing_PathEffect *pathEffect2 = OH_Drawing_CreateDashPathEffect(intervals, 0, 1.0);
72f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
73f6603c60Sopenharmony_ci    // 3. OH_Drawing_CreateDashPathEffect with 0.0 as the third parameter
74f6603c60Sopenharmony_ci    OH_Drawing_PathEffect *pathEffect3 = OH_Drawing_CreateDashPathEffect(intervals, 2, 0.0);
75f6603c60Sopenharmony_ci    // 4. Free memory
76f6603c60Sopenharmony_ci    OH_Drawing_PathEffectDestroy(pathEffect1);
77f6603c60Sopenharmony_ci    OH_Drawing_PathEffectDestroy(pathEffect2);
78f6603c60Sopenharmony_ci    OH_Drawing_PathEffectDestroy(pathEffect3);
79f6603c60Sopenharmony_ci}
80f6603c60Sopenharmony_ci
81f6603c60Sopenharmony_ci/*
82f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_EFFECT_0102
83f6603c60Sopenharmony_ci * @tc.name: testCreateDashPathEffectAbnormal
84f6603c60Sopenharmony_ci * @tc.desc: test for testCreateDashPathEffectAbnormal.
85f6603c60Sopenharmony_ci * @tc.size  : SmallTest
86f6603c60Sopenharmony_ci * @tc.type  : Function
87f6603c60Sopenharmony_ci * @tc.level : Level 3
88f6603c60Sopenharmony_ci */
89f6603c60Sopenharmony_ciHWTEST_F(DrawingNativePathEffectTest, testCreateDashPathEffectAbnormal, TestSize.Level3) {
90f6603c60Sopenharmony_ci    float intervals[] = {1, 1, 1};
91f6603c60Sopenharmony_ci    // 1. OH_Drawing_CreateDashPathEffect with the first parameter not being even
92f6603c60Sopenharmony_ci    OH_Drawing_PathEffect *pathEffect1 = OH_Drawing_CreateDashPathEffect(intervals, 3, 1.0);
93f6603c60Sopenharmony_ci    // 2. OH_Drawing_CreateDashPathEffect with the second parameter being negative, check the error code with
94f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
95f6603c60Sopenharmony_ci    OH_Drawing_PathEffect *pathEffect2 = OH_Drawing_CreateDashPathEffect(intervals, -3, 1.0);
96f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
97f6603c60Sopenharmony_ci    // 3. OH_Drawing_CreateDashPathEffect with the second parameter being 1
98f6603c60Sopenharmony_ci    OH_Drawing_PathEffect *pathEffect3 = OH_Drawing_CreateDashPathEffect(intervals, 1, 1.0);
99f6603c60Sopenharmony_ci    // 4. OH_Drawing_CreateDashPathEffect with the third parameter being negative
100f6603c60Sopenharmony_ci    OH_Drawing_PathEffect *pathEffect4 = OH_Drawing_CreateDashPathEffect(intervals, 3, -1.0);
101f6603c60Sopenharmony_ci    // 5. Free memory
102f6603c60Sopenharmony_ci    OH_Drawing_PathEffectDestroy(pathEffect1);
103f6603c60Sopenharmony_ci    OH_Drawing_PathEffectDestroy(pathEffect2);
104f6603c60Sopenharmony_ci    OH_Drawing_PathEffectDestroy(pathEffect3);
105f6603c60Sopenharmony_ci    OH_Drawing_PathEffectDestroy(pathEffect4);
106f6603c60Sopenharmony_ci}
107f6603c60Sopenharmony_ci
108f6603c60Sopenharmony_ci/*
109f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_EFFECT_0104
110f6603c60Sopenharmony_ci * @tc.name: testCreateDashPathEffectMultipleCalls
111f6603c60Sopenharmony_ci * @tc.desc: test for testCreateDashPathEffectMultipleCalls.
112f6603c60Sopenharmony_ci * @tc.size  : SmallTest
113f6603c60Sopenharmony_ci * @tc.type  : Function
114f6603c60Sopenharmony_ci * @tc.level : Level 3
115f6603c60Sopenharmony_ci */
116f6603c60Sopenharmony_ciHWTEST_F(DrawingNativePathEffectTest, testCreateDashPathEffectMultipleCalls, TestSize.Level3) {
117f6603c60Sopenharmony_ci    float intervals[] = {1, 1};
118f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_CreateDashPathEffect 10 times
119f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
120f6603c60Sopenharmony_ci        OH_Drawing_PathEffect *pathEffect = OH_Drawing_CreateDashPathEffect(intervals, 2, 1.0);
121f6603c60Sopenharmony_ci        // 2. Free memory
122f6603c60Sopenharmony_ci        OH_Drawing_PathEffectDestroy(pathEffect);
123f6603c60Sopenharmony_ci    }
124f6603c60Sopenharmony_ci}
125f6603c60Sopenharmony_ci
126f6603c60Sopenharmony_ci/*
127f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_EFFECT_0200
128f6603c60Sopenharmony_ci * @tc.name: testPathEffectDestroyNormal
129f6603c60Sopenharmony_ci * @tc.desc: test for testPathEffectDestroyNormal.
130f6603c60Sopenharmony_ci * @tc.size  : SmallTest
131f6603c60Sopenharmony_ci * @tc.type  : Function
132f6603c60Sopenharmony_ci * @tc.level : Level 0
133f6603c60Sopenharmony_ci */
134f6603c60Sopenharmony_ciHWTEST_F(DrawingNativePathEffectTest, testPathEffectDestroyNormal, TestSize.Level0) {
135f6603c60Sopenharmony_ci    float intervals[] = {1, 1, 1};
136f6603c60Sopenharmony_ci    // 1. OH_Drawing_CreateDashPathEffect
137f6603c60Sopenharmony_ci    OH_Drawing_PathEffect *pathEffect = OH_Drawing_CreateDashPathEffect(intervals, 3, 0.0);
138f6603c60Sopenharmony_ci    // 2. OH_Drawing_PathEffectDestroy
139f6603c60Sopenharmony_ci    OH_Drawing_PathEffectDestroy(pathEffect);
140f6603c60Sopenharmony_ci}
141f6603c60Sopenharmony_ci
142f6603c60Sopenharmony_ci/*
143f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_EFFECT_0201
144f6603c60Sopenharmony_ci * @tc.name: testPathEffectDestroyNull
145f6603c60Sopenharmony_ci * @tc.desc: test for testPathEffectDestroyNull.
146f6603c60Sopenharmony_ci * @tc.size  : SmallTest
147f6603c60Sopenharmony_ci * @tc.type  : Function
148f6603c60Sopenharmony_ci * @tc.level : Level 3
149f6603c60Sopenharmony_ci */
150f6603c60Sopenharmony_ciHWTEST_F(DrawingNativePathEffectTest, testPathEffectDestroyNull, TestSize.Level3) {
151f6603c60Sopenharmony_ci    // 1. OH_Drawing_PathEffectDestroy with nullptr as the parameter
152f6603c60Sopenharmony_ci    OH_Drawing_PathEffectDestroy(nullptr);
153f6603c60Sopenharmony_ci}
154f6603c60Sopenharmony_ci
155f6603c60Sopenharmony_ci} // namespace Drawing
156f6603c60Sopenharmony_ci} // namespace Rosen
157f6603c60Sopenharmony_ci} // namespace OHOS