1 /* 2 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "gtest/gtest.h" 17 18 #include "DrawingNativeCanvasCommon.h" 19 #include "drawing_bitmap.h" 20 #include "drawing_brush.h" 21 #include "drawing_canvas.h" 22 #include "drawing_color.h" 23 #include "drawing_color_filter.h" 24 #include "drawing_filter.h" 25 #include "drawing_font.h" 26 #include "drawing_image.h" 27 #include "drawing_mask_filter.h" 28 #include "drawing_matrix.h" 29 #include "drawing_memory_stream.h" 30 #include "drawing_path.h" 31 #include "drawing_pen.h" 32 #include "drawing_point.h" 33 #include "drawing_rect.h" 34 #include "drawing_region.h" 35 #include "drawing_round_rect.h" 36 #include "drawing_sampling_options.h" 37 #include "drawing_shader_effect.h" 38 #include "drawing_text_blob.h" 39 #include "drawing_typeface.h" 40 #include "drawing_pixel_map.h" 41 #include "image/pixelmap_native.h" 42 43 #define DRAW_COLORBLUE 0xFF0000FF 44 45 using namespace testing; 46 using namespace testing::ext; 47 48 namespace OHOS { 49 namespace Rosen { 50 namespace Drawing { 51 class DrawingNativeCanvasPart6Test : public testing::Test { 52 protected: 53 // 在每个测试用例执行前调用 SetUp()54 void SetUp() override 55 { 56 // 设置代码 57 std::cout << "DrawingNativeCanvasPart6Test Setup code called before each test case." << std::endl; 58 OH_Drawing_ErrorCodeReset(); 59 std::cout << "DrawingNativeCanvasPart6Test errorCodeReset before each test case." << std::endl; 60 } TearDown()61 void TearDown() override 62 { 63 std::cout << "DrawingNativeCanvasPart6Test Setup code called after each test case." << std::endl; 64 OH_Drawing_ErrorCodeReset(); 65 std::cout << "DrawingNativeCanvasPart6Test errorCodeReset after each test case." << std::endl; 66 } 67 }; 68 69 /* 70 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_5501 71 * @tc.name: testCanvasDrawSingleChaWithFeaturesNormal 72 * @tc.desc: test for testCanvasDrawSingleChaWithFeaturesNormal 73 * @tc.size : SmallTest 74 * @tc.type : Function 75 * @tc.level : Level 0 76 */ 77 HWTEST_F(DrawingNativeCanvasPart6Test, testCanvasDrawSingleChaWithFeaturesNormal, Function | SmallTest | Level0) { 78 OH_Drawing_Canvas* canvas = OH_Drawing_CanvasCreate(); 79 const char *str1 = "1"; 80 const char *str2 = "H"; 81 const char *str3 = "a"; 82 const char *str4 = "你"; 83 const char *str5 = "("; 84 const char *str6 = "("; 85 const char *str7 = "{"; 86 const char *str8 = "龘"; 87 const char *str9 = "無"; 88 OH_Drawing_Font *font = OH_Drawing_FontCreate(); 89 float curX = 100; 90 float curY = 100; 91 OH_Drawing_FontFeatures* features = OH_Drawing_FontFeaturesCreate(); 92 EXPECT_EQ(OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str1, font, curX, curY, features), 93 OH_DRAWING_SUCCESS); 94 EXPECT_EQ(OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str2, font, curX, curY, features), 95 OH_DRAWING_SUCCESS); 96 EXPECT_EQ(OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str3, font, curX, curY, features), 97 OH_DRAWING_SUCCESS); 98 EXPECT_EQ(OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str4, font, curX, curY, features), 99 OH_DRAWING_SUCCESS); 100 EXPECT_EQ(OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str5, font, curX, curY, features), 101 OH_DRAWING_SUCCESS); 102 EXPECT_EQ(OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str6, font, curX, curY, features), 103 OH_DRAWING_SUCCESS); 104 EXPECT_EQ(OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str7, font, curX, curY, features), 105 OH_DRAWING_SUCCESS); 106 EXPECT_EQ(OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str8, font, curX, curY, features), 107 OH_DRAWING_SUCCESS); 108 EXPECT_EQ(OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str9, font, curX, curY, features), 109 OH_DRAWING_SUCCESS); 110 OH_Drawing_FontDestroy(font); 111 OH_Drawing_FontFeaturesDestroy(features); 112 OH_Drawing_CanvasDestroy(canvas); 113 } 114 /* 115 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_5502 116 * @tc.name: testCanvasDrawSingleChaWithFeaturesAbNormal 117 * @tc.desc: test for testCanvasDrawSingleChaWithFeaturesAbNormal 118 * @tc.size : SmallTest 119 * @tc.type : Function 120 * @tc.level : Level 3 121 */ 122 HWTEST_F(DrawingNativeCanvasPart6Test, testCanvasDrawSingleChaWithFeaturesAbNormal, Function | SmallTest | Level3) { 123 float curX = 100.0f; 124 float curY = 100.0f; 125 float textSize = 50.0f; 126 const char *str = "("; 127 OH_Drawing_Canvas* canvas = OH_Drawing_CanvasCreate(); 128 OH_Drawing_Font *font = OH_Drawing_FontCreate(); 129 OH_Drawing_Brush *brush = OH_Drawing_BrushCreate(); 130 OH_Drawing_BrushSetColor(brush, 0xFF0000FF); 131 OH_Drawing_CanvasAttachBrush(canvas, brush); 132 OH_Drawing_FontSetTextSize(font, textSize); 133 OH_Drawing_FontFeatures* feat = OH_Drawing_FontFeaturesCreate(); 134 OH_Drawing_ErrorCode code = OH_Drawing_CanvasDrawSingleCharacterWithFeatures(nullptr, str, font, curX, curY, feat); 135 EXPECT_EQ(code, OH_DRAWING_ERROR_INVALID_PARAMETER); 136 code = OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, nullptr, font, curX, curY, feat); 137 EXPECT_EQ(code, OH_DRAWING_ERROR_INVALID_PARAMETER); 138 code = OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str, nullptr, curX, curY, feat); 139 EXPECT_EQ(code, OH_DRAWING_ERROR_INVALID_PARAMETER); 140 code = OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str, font, -100.0f, curY, feat); 141 EXPECT_EQ(code, OH_DRAWING_SUCCESS); 142 code = OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str, font, curX, -100.0f, feat); 143 EXPECT_EQ(code, OH_DRAWING_SUCCESS); 144 code = OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str, font, curX, curY, nullptr); 145 EXPECT_EQ(code, OH_DRAWING_ERROR_INVALID_PARAMETER); 146 code = OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, "", font, curX, curY, feat); 147 EXPECT_EQ(code, OH_DRAWING_ERROR_INVALID_PARAMETER); 148 OH_Drawing_FontDestroy(font); 149 OH_Drawing_CanvasDetachBrush(canvas); 150 OH_Drawing_BrushDestroy(brush); 151 OH_Drawing_FontFeaturesDestroy(feat); 152 OH_Drawing_CanvasDestroy(canvas); 153 } 154 /* 155 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_FONT_5503 156 * @tc.name: testCanvasDrawSingleChaWithFeaturesCalls 157 * @tc.desc: test for testCanvasDrawSingleChaWithFeaturesCalls 158 * @tc.size : SmallTest 159 * @tc.type : Function 160 * @tc.level : Level 2 161 */ 162 HWTEST_F(DrawingNativeCanvasPart6Test, testCanvasDrawSingleChaWithFeaturesCalls, Function | SmallTest | Level2) { 163 OH_Drawing_Canvas* canvas = OH_Drawing_CanvasCreate(); 164 const char *str1 = "1"; 165 OH_Drawing_Font *font = OH_Drawing_FontCreate(); 166 float curX = 100; 167 float curY = 100; 168 int count = 10; 169 OH_Drawing_FontFeatures* features = OH_Drawing_FontFeaturesCreate(); 170 for (int i = 0; i < count; i++) { 171 EXPECT_EQ(OH_Drawing_CanvasDrawSingleCharacterWithFeatures(canvas, str1, font, curX, curY, features), 172 OH_DRAWING_SUCCESS); 173 } 174 OH_Drawing_FontDestroy(font); 175 OH_Drawing_FontFeaturesDestroy(features); 176 OH_Drawing_CanvasDestroy(canvas); 177 } 178 179 } // namespace Drawing 180 } // namespace Rosen 181 } // namespace OHOS