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_bitmap.h" 17f6603c60Sopenharmony_ci#include "drawing_brush.h" 18f6603c60Sopenharmony_ci#include "drawing_canvas.h" 19f6603c60Sopenharmony_ci#include "drawing_color.h" 20f6603c60Sopenharmony_ci#include "drawing_color_filter.h" 21f6603c60Sopenharmony_ci#include "drawing_filter.h" 22f6603c60Sopenharmony_ci#include "drawing_font.h" 23f6603c60Sopenharmony_ci#include "drawing_image.h" 24f6603c60Sopenharmony_ci#include "drawing_mask_filter.h" 25f6603c60Sopenharmony_ci#include "drawing_matrix.h" 26f6603c60Sopenharmony_ci#include "drawing_memory_stream.h" 27f6603c60Sopenharmony_ci#include "drawing_path.h" 28f6603c60Sopenharmony_ci#include "drawing_pen.h" 29f6603c60Sopenharmony_ci#include "drawing_point.h" 30f6603c60Sopenharmony_ci#include "drawing_rect.h" 31f6603c60Sopenharmony_ci#include "drawing_region.h" 32f6603c60Sopenharmony_ci#include "drawing_round_rect.h" 33f6603c60Sopenharmony_ci#include "drawing_sampling_options.h" 34f6603c60Sopenharmony_ci#include "drawing_shader_effect.h" 35f6603c60Sopenharmony_ci#include "drawing_text_blob.h" 36f6603c60Sopenharmony_ci#include "drawing_typeface.h" 37f6603c60Sopenharmony_ci#include "utils/scalar.h" 38f6603c60Sopenharmony_ci#include "gtest/gtest.h" 39f6603c60Sopenharmony_ci#include <random> 40f6603c60Sopenharmony_ci 41f6603c60Sopenharmony_ci#define NUMBER_10 10 42f6603c60Sopenharmony_ci#define NUMBER_100 100 43f6603c60Sopenharmony_ci#define NUMBER_400_1 400.1 44f6603c60Sopenharmony_ci#define NUMBER_900 900 45f6603c60Sopenharmony_ci#define NUMBER_1000000 1000000 46f6603c60Sopenharmony_ci 47f6603c60Sopenharmony_ci 48f6603c60Sopenharmony_ciusing namespace testing; 49f6603c60Sopenharmony_ciusing namespace testing::ext; 50f6603c60Sopenharmony_ci 51f6603c60Sopenharmony_cinamespace OHOS { 52f6603c60Sopenharmony_cinamespace Rosen { 53f6603c60Sopenharmony_cinamespace Drawing { 54f6603c60Sopenharmony_ciclass DrawingNativeFontTest : public testing::Test {}; 55f6603c60Sopenharmony_ci 56f6603c60Sopenharmony_ci/* 57f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_2000 58f6603c60Sopenharmony_ci * @tc.name: testFontArgumentsCreateNormal 59f6603c60Sopenharmony_ci * @tc.desc: Test for testFontArgumentsCreateNormal. 60f6603c60Sopenharmony_ci * @tc.size : SmallTest 61f6603c60Sopenharmony_ci * @tc.type : Function 62f6603c60Sopenharmony_ci * @tc.level : Level 0 63f6603c60Sopenharmony_ci */ 64f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontArgumentsCreateNormal, TestSize.Level0) { 65f6603c60Sopenharmony_ci // 1. OH_Drawing_FontArgumentsCreate 66f6603c60Sopenharmony_ci OH_Drawing_FontArguments *fontArguments = OH_Drawing_FontArgumentsCreate(); 67f6603c60Sopenharmony_ci OH_Drawing_FontArgumentsDestroy(fontArguments); 68f6603c60Sopenharmony_ci} 69f6603c60Sopenharmony_ci 70f6603c60Sopenharmony_ci/* 71f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_2100 72f6603c60Sopenharmony_ci * @tc.name: testFontArgumentsAddVariationNormal 73f6603c60Sopenharmony_ci * @tc.desc: test for testFontArgumentsAddVariationNormal. 74f6603c60Sopenharmony_ci * @tc.size : SmallTest 75f6603c60Sopenharmony_ci * @tc.type : Function 76f6603c60Sopenharmony_ci * @tc.level : Level 3 77f6603c60Sopenharmony_ci */ 78f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontArgumentsAddVariationNormal, TestSize.Level0) { 79f6603c60Sopenharmony_ci // 1. OH_Drawing_FontArgumentsCreate 80f6603c60Sopenharmony_ci OH_Drawing_FontArguments *fontArguments = OH_Drawing_FontArgumentsCreate(); 81f6603c60Sopenharmony_ci // 2. OH_Drawing_FontArgumentsAddVariation, should return OH_DRAWING_SUCCESS 82f6603c60Sopenharmony_ci OH_Drawing_ErrorCode drawingErrorCode = OH_DRAWING_ERROR_INVALID_PARAMETER; 83f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "wght", 0); 84f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 85f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "wght", -1); 86f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 87f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "wght", NUMBER_100); 88f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 89f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "wght", NUMBER_400_1); 90f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 91f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "wght", NUMBER_900); 92f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 93f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "wght", NUMBER_1000000); 94f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 95f6603c60Sopenharmony_ci} 96f6603c60Sopenharmony_ci 97f6603c60Sopenharmony_ci/* 98f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_2101 99f6603c60Sopenharmony_ci * @tc.name: testFontArgumentsAddVariationNull 100f6603c60Sopenharmony_ci * @tc.desc: test for testFontArgumentsAddVariationNull. 101f6603c60Sopenharmony_ci * @tc.size : SmallTest 102f6603c60Sopenharmony_ci * @tc.type : Function 103f6603c60Sopenharmony_ci * @tc.level : Level 3 104f6603c60Sopenharmony_ci */ 105f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontArgumentsAddVariationNull, TestSize.Level3) { 106f6603c60Sopenharmony_ci // 1. OH_Drawing_FontArgumentsCreate 107f6603c60Sopenharmony_ci OH_Drawing_FontArguments *fontArguments = OH_Drawing_FontArgumentsCreate(); 108f6603c60Sopenharmony_ci // 2. OH_Drawing_FontArgumentsAddVariation, the first parameter is nullptr 109f6603c60Sopenharmony_ci OH_Drawing_ErrorCode drawingErrorCode = OH_DRAWING_SUCCESS; 110f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(nullptr, "wght", NUMBER_100); 111f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER); 112f6603c60Sopenharmony_ci // 3. OH_Drawing_FontArgumentsAddVariation, the second parameter is nullptr 113f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, nullptr, NUMBER_100); 114f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER); 115f6603c60Sopenharmony_ci} 116f6603c60Sopenharmony_ci 117f6603c60Sopenharmony_ci/* 118f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_2102 119f6603c60Sopenharmony_ci * @tc.name: testFontArgumentsAddVariationAbnormal 120f6603c60Sopenharmony_ci * @tc.desc: test for testFontArgumentsAddVariationAbnormal. 121f6603c60Sopenharmony_ci * @tc.size : SmallTest 122f6603c60Sopenharmony_ci * @tc.type : Function 123f6603c60Sopenharmony_ci * @tc.level : Level 3 124f6603c60Sopenharmony_ci */ 125f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontArgumentsAddVariationAbnormal, TestSize.Level3) { 126f6603c60Sopenharmony_ci // 1. OH_Drawing_FontArgumentsCreate 127f6603c60Sopenharmony_ci OH_Drawing_FontArguments *fontArguments = OH_Drawing_FontArgumentsCreate(); 128f6603c60Sopenharmony_ci // 2. OH_Drawing_FontArgumentsAddVariation, the second parameter is error 129f6603c60Sopenharmony_ci OH_Drawing_ErrorCode drawingErrorCode = OH_DRAWING_SUCCESS; 130f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "WGHT", NUMBER_100); 131f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 132f6603c60Sopenharmony_ci // 3. OH_Drawing_FontArgumentsAddVariation, the second parameter is error 133f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "w", NUMBER_100); 134f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER); 135f6603c60Sopenharmony_ci} 136f6603c60Sopenharmony_ci 137f6603c60Sopenharmony_ci/* 138f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_2103 139f6603c60Sopenharmony_ci * @tc.name: testFontArgumentsAddVariationMultipleCalls 140f6603c60Sopenharmony_ci * @tc.desc: test for testFontArgumentsAddVariationMultipleCalls. 141f6603c60Sopenharmony_ci * @tc.size : SmallTest 142f6603c60Sopenharmony_ci * @tc.type : Function 143f6603c60Sopenharmony_ci * @tc.level : Level 3 144f6603c60Sopenharmony_ci */ 145f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontArgumentsAddVariationMultipleCalls, TestSize.Level3) { 146f6603c60Sopenharmony_ci // 1. OH_Drawing_FontArgumentsCreate 147f6603c60Sopenharmony_ci OH_Drawing_FontArguments *fontArguments = OH_Drawing_FontArgumentsCreate(); 148f6603c60Sopenharmony_ci // 2. OH_Drawing_FontArgumentsAddVariation, should return OH_DRAWING_SUCCESS 149f6603c60Sopenharmony_ci OH_Drawing_ErrorCode drawingErrorCode = OH_DRAWING_ERROR_INVALID_PARAMETER; 150f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "wght", NUMBER_100); 151f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "wght", NUMBER_900); 152f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 153f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "wght", NUMBER_100); 154f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "wght", 0.0f); 155f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 156f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "wght", NUMBER_100); 157f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsAddVariation(fontArguments, "wght", -1); 158f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 159f6603c60Sopenharmony_ci} 160f6603c60Sopenharmony_ci 161f6603c60Sopenharmony_ci/* 162f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_2200 163f6603c60Sopenharmony_ci * @tc.name: testFontArgumentsDestoryNormal 164f6603c60Sopenharmony_ci * @tc.desc: test for testFontArgumentsDestoryNormal. 165f6603c60Sopenharmony_ci * @tc.size : SmallTest 166f6603c60Sopenharmony_ci * @tc.type : Function 167f6603c60Sopenharmony_ci * @tc.level : Level 3 168f6603c60Sopenharmony_ci */ 169f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontArgumentsDestoryNormal, TestSize.Level0) { 170f6603c60Sopenharmony_ci // 1. OH_Drawing_FontArgumentsCreate 171f6603c60Sopenharmony_ci OH_Drawing_FontArguments *fontArguments = OH_Drawing_FontArgumentsCreate(); 172f6603c60Sopenharmony_ci // 2. OH_Drawing_FontArgumentsDestroy 173f6603c60Sopenharmony_ci OH_Drawing_ErrorCode drawingErrorCode = OH_DRAWING_ERROR_INVALID_PARAMETER; 174f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsDestroy(fontArguments); 175f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS); 176f6603c60Sopenharmony_ci} 177f6603c60Sopenharmony_ci 178f6603c60Sopenharmony_ci/* 179f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_2201 180f6603c60Sopenharmony_ci * @tc.name: testFontArgumentsDestoryNull 181f6603c60Sopenharmony_ci * @tc.desc: test for testFontArgumentsDestoryNull. 182f6603c60Sopenharmony_ci * @tc.size : SmallTest 183f6603c60Sopenharmony_ci * @tc.type : Function 184f6603c60Sopenharmony_ci * @tc.level : Level 3 185f6603c60Sopenharmony_ci */ 186f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontArgumentsDestoryNull, TestSize.Level0) { 187f6603c60Sopenharmony_ci // 1. OH_Drawing_FontArgumentsCreate 188f6603c60Sopenharmony_ci OH_Drawing_FontArguments *fontArguments = OH_Drawing_FontArgumentsCreate(); 189f6603c60Sopenharmony_ci // 2. OH_Drawing_FontArgumentsDestroy, parameter is null 190f6603c60Sopenharmony_ci OH_Drawing_ErrorCode drawingErrorCode = OH_DRAWING_SUCCESS; 191f6603c60Sopenharmony_ci drawingErrorCode = OH_Drawing_FontArgumentsDestroy(nullptr); 192f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER); 193f6603c60Sopenharmony_ci OH_Drawing_FontArgumentsDestroy(fontArguments); 194f6603c60Sopenharmony_ci} 195f6603c60Sopenharmony_ci 196f6603c60Sopenharmony_ci/* 197f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_2202 198f6603c60Sopenharmony_ci * @tc.name: testFontArgumentsDestoryMultiplieCalls 199f6603c60Sopenharmony_ci * @tc.desc: test for testFontArgumentsDestoryMultiplieCalls. 200f6603c60Sopenharmony_ci * @tc.size : SmallTest 201f6603c60Sopenharmony_ci * @tc.type : Function 202f6603c60Sopenharmony_ci * @tc.level : Level 3 203f6603c60Sopenharmony_ci */ 204f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeFontTest, testFontArgumentsDestoryMultiplieCalls, TestSize.Level0) { 205f6603c60Sopenharmony_ci // 1. OH_Drawing_FontCreate 206f6603c60Sopenharmony_ci OH_Drawing_FontArguments *fontArguments = nullptr; 207f6603c60Sopenharmony_ci for (int i = 0; i < NUMBER_10; i++) 208f6603c60Sopenharmony_ci { 209f6603c60Sopenharmony_ci fontArguments = OH_Drawing_FontArgumentsCreate(); 210f6603c60Sopenharmony_ci } 211f6603c60Sopenharmony_ci // 2. OH_Drawing_FontCreate, OH_Drawing_FontArgumentsAddVariation 212f6603c60Sopenharmony_ci OH_Drawing_ErrorCode drawingErrorCode1 = OH_DRAWING_ERROR_INVALID_PARAMETER; 213f6603c60Sopenharmony_ci for (size_t i = 0; i < NUMBER_10; i++) 214f6603c60Sopenharmony_ci { 215f6603c60Sopenharmony_ci OH_Drawing_FontArguments *fontArguments1 = OH_Drawing_FontArgumentsCreate(); 216f6603c60Sopenharmony_ci drawingErrorCode1 = OH_Drawing_FontArgumentsDestroy(fontArguments1); 217f6603c60Sopenharmony_ci EXPECT_EQ(drawingErrorCode1, OH_DRAWING_SUCCESS); 218f6603c60Sopenharmony_ci } 219f6603c60Sopenharmony_ci} 220f6603c60Sopenharmony_ci} // namespace Drawing 221f6603c60Sopenharmony_ci} // namespace Rosen 222f6603c60Sopenharmony_ci} // namespace OHOS