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_sampling_options.h"
17f6603c60Sopenharmony_ci#include "drawing_types.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 DrawingNativeSamplingOptionsTest : public testing::Test {};
28f6603c60Sopenharmony_ci
29f6603c60Sopenharmony_ci/*
30f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SAMPLING_OPTIONS_0100
31f6603c60Sopenharmony_ci * @tc.name: testSamplingOptionsCreateDestroyDestroyNormal
32f6603c60Sopenharmony_ci * @tc.desc: test for testSamplingOptionsCreateDestroyDestroyNormal.
33f6603c60Sopenharmony_ci * @tc.size  : SmallTest
34f6603c60Sopenharmony_ci * @tc.type  : Function
35f6603c60Sopenharmony_ci * @tc.level : Level 0
36f6603c60Sopenharmony_ci */
37f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeSamplingOptionsTest, testSamplingOptionsCreateDestroyDestroyNormal, TestSize.Level0) {
38f6603c60Sopenharmony_ci    OH_Drawing_FilterMode filterModes[] = {
39f6603c60Sopenharmony_ci        FILTER_MODE_NEAREST,
40f6603c60Sopenharmony_ci        FILTER_MODE_LINEAR,
41f6603c60Sopenharmony_ci    };
42f6603c60Sopenharmony_ci    OH_Drawing_MipmapMode mipmapModes[] = {
43f6603c60Sopenharmony_ci        MIPMAP_MODE_NONE,
44f6603c60Sopenharmony_ci        MIPMAP_MODE_NEAREST,
45f6603c60Sopenharmony_ci        MIPMAP_MODE_LINEAR,
46f6603c60Sopenharmony_ci    };
47f6603c60Sopenharmony_ci    // 1. Enumerate OH_Drawing_FilterMode and OH_Drawing_MipmapMode values with cross iteration
48f6603c60Sopenharmony_ci    for (OH_Drawing_FilterMode filterMode : filterModes) {
49f6603c60Sopenharmony_ci        for (OH_Drawing_MipmapMode mipmapMode : mipmapModes) {
50f6603c60Sopenharmony_ci            OH_Drawing_SamplingOptions *options = OH_Drawing_SamplingOptionsCreate(filterMode, mipmapMode);
51f6603c60Sopenharmony_ci            EXPECT_NE(options, nullptr);
52f6603c60Sopenharmony_ci            // 2. Destroy the objects created in step 1 with OH_Drawing_SamplingOptionsDestroy
53f6603c60Sopenharmony_ci            OH_Drawing_SamplingOptionsDestroy(options);
54f6603c60Sopenharmony_ci        }
55f6603c60Sopenharmony_ci    }
56f6603c60Sopenharmony_ci}
57f6603c60Sopenharmony_ci
58f6603c60Sopenharmony_ci/*
59f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SAMPLING_OPTIONS_0101
60f6603c60Sopenharmony_ci * @tc.name: testSamplingOptionsCreateDestroyDestroyNull
61f6603c60Sopenharmony_ci * @tc.desc: test for testSamplingOptionsCreateDestroyDestroyNull.
62f6603c60Sopenharmony_ci * @tc.size  : SmallTest
63f6603c60Sopenharmony_ci * @tc.type  : Function
64f6603c60Sopenharmony_ci * @tc.level : Level 3
65f6603c60Sopenharmony_ci */
66f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeSamplingOptionsTest, testSamplingOptionsCreateDestroyDestroyNull, TestSize.Level3) {
67f6603c60Sopenharmony_ci    // 1. OH_Drawing_SamplingOptionsDestroy with empty parameter
68f6603c60Sopenharmony_ci    OH_Drawing_SamplingOptionsDestroy(nullptr);
69f6603c60Sopenharmony_ci}
70f6603c60Sopenharmony_ci
71f6603c60Sopenharmony_ci/*
72f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_SAMPLING_OPTIONS_0102
73f6603c60Sopenharmony_ci * @tc.name: testSamplingOptionsCreateDestroyDestroyMultipleCalls
74f6603c60Sopenharmony_ci * @tc.desc: test for testSamplingOptionsCreateDestroyDestroyMultipleCalls.
75f6603c60Sopenharmony_ci * @tc.size  : SmallTest
76f6603c60Sopenharmony_ci * @tc.type  : Function
77f6603c60Sopenharmony_ci * @tc.level : Level 3
78f6603c60Sopenharmony_ci */
79f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeSamplingOptionsTest, testSamplingOptionsCreateDestroyDestroyMultipleCalls, TestSize.Level3) {
80f6603c60Sopenharmony_ci    // 1. Call OH_Drawing_SamplingOptionsCreate 10 times with random enum values
81f6603c60Sopenharmony_ci    std::random_device rd;
82f6603c60Sopenharmony_ci    std::mt19937 gen(rd());
83f6603c60Sopenharmony_ci    std::uniform_int_distribution<int> dis(0, 10);
84f6603c60Sopenharmony_ci    OH_Drawing_SamplingOptions *options[10];
85f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
86f6603c60Sopenharmony_ci        int random = dis(gen);
87f6603c60Sopenharmony_ci        OH_Drawing_FilterMode filterMode = static_cast<OH_Drawing_FilterMode>(random % 2);
88f6603c60Sopenharmony_ci        OH_Drawing_MipmapMode mipmapMode = static_cast<OH_Drawing_MipmapMode>(random % 3);
89f6603c60Sopenharmony_ci        options[i] = OH_Drawing_SamplingOptionsCreate(filterMode, mipmapMode);
90f6603c60Sopenharmony_ci        EXPECT_NE(options[i], nullptr);
91f6603c60Sopenharmony_ci    }
92f6603c60Sopenharmony_ci    // 2. Call OH_Drawing_SamplingOptionsDestroy 10 times
93f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
94f6603c60Sopenharmony_ci        OH_Drawing_SamplingOptionsDestroy(options[i]);
95f6603c60Sopenharmony_ci    }
96f6603c60Sopenharmony_ci    // 3. Call OH_Drawing_SamplingOptionsCreate and OH_Drawing_SamplingOptionsDestroy alternately 10 times
97f6603c60Sopenharmony_ci    for (int i = 0; i < 10; i++) {
98f6603c60Sopenharmony_ci        int random = dis(gen);
99f6603c60Sopenharmony_ci        OH_Drawing_FilterMode filterMode = static_cast<OH_Drawing_FilterMode>(random % 2);
100f6603c60Sopenharmony_ci        OH_Drawing_MipmapMode mipmapMode = static_cast<OH_Drawing_MipmapMode>(random % 3);
101f6603c60Sopenharmony_ci        OH_Drawing_SamplingOptions *options = OH_Drawing_SamplingOptionsCreate(filterMode, mipmapMode);
102f6603c60Sopenharmony_ci        EXPECT_NE(options, nullptr);
103f6603c60Sopenharmony_ci        OH_Drawing_SamplingOptionsDestroy(options);
104f6603c60Sopenharmony_ci    }
105f6603c60Sopenharmony_ci}
106f6603c60Sopenharmony_ci
107f6603c60Sopenharmony_ci} // namespace Drawing
108f6603c60Sopenharmony_ci} // namespace Rosen
109f6603c60Sopenharmony_ci} // namespace OHOS