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 "gtest/gtest.h"
17f6603c60Sopenharmony_ci
18f6603c60Sopenharmony_ci#include "drawing_bitmap.h"
19f6603c60Sopenharmony_ci#include "drawing_color.h"
20f6603c60Sopenharmony_ci#include "drawing_color_filter.h"
21f6603c60Sopenharmony_ci#include "drawing_error_code.h"
22f6603c60Sopenharmony_ci#include "drawing_image.h"
23f6603c60Sopenharmony_ci#include "drawing_image_filter.h"
24f6603c60Sopenharmony_ci#include "drawing_mask_filter.h"
25f6603c60Sopenharmony_ci#include "drawing_memory_stream.h"
26f6603c60Sopenharmony_ci
27f6603c60Sopenharmony_ciusing namespace testing;
28f6603c60Sopenharmony_ciusing namespace testing::ext;
29f6603c60Sopenharmony_ci
30f6603c60Sopenharmony_cinamespace OHOS {
31f6603c60Sopenharmony_cinamespace Rosen {
32f6603c60Sopenharmony_cinamespace Drawing {
33f6603c60Sopenharmony_ciclass DrawingNativeMemoryStreamTest : public testing::Test {};
34f6603c60Sopenharmony_ci
35f6603c60Sopenharmony_ci/*
36f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MEMORY_STREAM_0100
37f6603c60Sopenharmony_ci * @tc.name: testMemoryStreamCreateNormal
38f6603c60Sopenharmony_ci * @tc.desc: Test for creating memory stream with normal parameters.
39f6603c60Sopenharmony_ci * @tc.size  : SmallTest
40f6603c60Sopenharmony_ci * @tc.type  : Function
41f6603c60Sopenharmony_ci * @tc.level : Level 0
42f6603c60Sopenharmony_ci */
43f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeMemoryStreamTest, testMemoryStreamCreateNormal, TestSize.Level0) {
44f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_MemoryStreamCreate with copyData set to true
45f6603c60Sopenharmony_ci    char data[10] = {0};
46f6603c60Sopenharmony_ci    OH_Drawing_MemoryStream *stream = OH_Drawing_MemoryStreamCreate(data, 10, true);
47f6603c60Sopenharmony_ci    OH_Drawing_MemoryStreamDestroy(stream);
48f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_MemoryStreamCreate with copyData set to false
49f6603c60Sopenharmony_ci    stream = OH_Drawing_MemoryStreamCreate(data, 10, false);
50f6603c60Sopenharmony_ci    OH_Drawing_MemoryStreamDestroy(stream);
51f6603c60Sopenharmony_ci}
52f6603c60Sopenharmony_ci
53f6603c60Sopenharmony_ci/*
54f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MEMORY_STREAM_0101
55f6603c60Sopenharmony_ci * @tc.name: testMemoryStreamCreateNull
56f6603c60Sopenharmony_ci * @tc.desc: Test for creating memory stream with NULL or invalid parameters.
57f6603c60Sopenharmony_ci * @tc.size  : SmallTest
58f6603c60Sopenharmony_ci * @tc.type  : Function
59f6603c60Sopenharmony_ci * @tc.level : Level 3
60f6603c60Sopenharmony_ci */
61f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeMemoryStreamTest, testMemoryStreamCreateNull, TestSize.Level3) {
62f6603c60Sopenharmony_ci    char data[10] = {0};
63f6603c60Sopenharmony_ci    // 1. OH_Drawing_MemoryStreamCreate with the first parameter set to nullptr, check the error code using
64f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
65f6603c60Sopenharmony_ci    OH_Drawing_MemoryStream *stream = OH_Drawing_MemoryStreamCreate(nullptr, 10, true);
66f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
67f6603c60Sopenharmony_ci    // 2. OH_Drawing_MemoryStreamCreate with the second parameter set to 0, check the error code using
68f6603c60Sopenharmony_ci    // OH_Drawing_ErrorCodeGet
69f6603c60Sopenharmony_ci    stream = OH_Drawing_MemoryStreamCreate(data, 0, true);
70f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
71f6603c60Sopenharmony_ci    // 3. Free memory
72f6603c60Sopenharmony_ci    OH_Drawing_MemoryStreamDestroy(stream);
73f6603c60Sopenharmony_ci}
74f6603c60Sopenharmony_ci
75f6603c60Sopenharmony_ci/*
76f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MEMORY_STREAM_0102
77f6603c60Sopenharmony_ci * @tc.name: testMemoryStreamCreateAbnormal
78f6603c60Sopenharmony_ci * @tc.desc: Test for creating memory stream with abnormal parameters (negative values).
79f6603c60Sopenharmony_ci * @tc.size  : SmallTest
80f6603c60Sopenharmony_ci * @tc.type  : Function
81f6603c60Sopenharmony_ci * @tc.level : Level 3
82f6603c60Sopenharmony_ci */
83f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeMemoryStreamTest, testMemoryStreamCreateAbnormal, TestSize.Level3) {
84f6603c60Sopenharmony_ci    // 1. OH_Drawing_MemoryStreamCreate with a negative value as the second parameter
85f6603c60Sopenharmony_ci    OH_Drawing_MemoryStream *stream = OH_Drawing_MemoryStreamCreate(nullptr, -10, true);
86f6603c60Sopenharmony_ci    // 2. Free memory
87f6603c60Sopenharmony_ci    OH_Drawing_MemoryStreamDestroy(stream);
88f6603c60Sopenharmony_ci}
89f6603c60Sopenharmony_ci
90f6603c60Sopenharmony_ci/*
91f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MEMORY_STREAM_0103
92f6603c60Sopenharmony_ci * @tc.name: testMemoryStreamCreateMultipleCalls
93f6603c60Sopenharmony_ci * @tc.desc: Test for creating memory stream with multiple calls using different data segments.
94f6603c60Sopenharmony_ci * @tc.size  : SmallTest
95f6603c60Sopenharmony_ci * @tc.type  : Function
96f6603c60Sopenharmony_ci * @tc.level : Level 3
97f6603c60Sopenharmony_ci */
98f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeMemoryStreamTest, testMemoryStreamCreateMultipleCalls, TestSize.Level3) {
99f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_MemoryStreamCreate 10 times, passing different data segments
100f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
101f6603c60Sopenharmony_ci        char data[10] = {i};
102f6603c60Sopenharmony_ci        OH_Drawing_MemoryStream *stream = OH_Drawing_MemoryStreamCreate(data, 10, true);
103f6603c60Sopenharmony_ci        OH_Drawing_MemoryStreamDestroy(stream);
104f6603c60Sopenharmony_ci    }
105f6603c60Sopenharmony_ci}
106f6603c60Sopenharmony_ci
107f6603c60Sopenharmony_ci} // namespace Drawing
108f6603c60Sopenharmony_ci} // namespace Rosen
109f6603c60Sopenharmony_ci} // namespace OHOS