• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "drawing_bitmap.h"
18 #include "drawing_brush.h"
19 #include "drawing_canvas.h"
20 #include "drawing_color.h"
21 #include "drawing_color_filter.h"
22 #include "drawing_filter.h"
23 #include "drawing_font.h"
24 #include "drawing_image.h"
25 #include "drawing_mask_filter.h"
26 #include "drawing_matrix.h"
27 #include "drawing_memory_stream.h"
28 #include "drawing_path.h"
29 #include "drawing_pen.h"
30 #include "drawing_point.h"
31 #include "drawing_rect.h"
32 #include "drawing_region.h"
33 #include "drawing_round_rect.h"
34 #include "drawing_sampling_options.h"
35 #include "drawing_shader_effect.h"
36 #include "drawing_text_blob.h"
37 #include "drawing_typeface.h"
38 #include "drawing_record_cmd.h"
39 #include <random>
40 #include <thread>
41 #include <iomanip>
42 #include <sstream>
43 using namespace testing;
44 using namespace testing::ext;
45 
46 namespace OHOS {
47 namespace Rosen {
48 namespace Drawing {
49 class DrawingRecordCmdDestroyTest : public testing::Test {
50     protected:
51     // 在每个测试用例执行前调用
SetUp()52     void SetUp() override
53     {
54         // 设置代码
55         std::cout << "DrawingRecordCmdDestroyTest Setup code called before each test case." << std::endl;
56         OH_Drawing_ErrorCodeReset();
57         std::cout << "DrawingRecordCmdDestroyTest errorCodeReset before each test case." << std::endl;
58     }
TearDown()59     void TearDown() override
60     {
61         std::cout << "DrawingRecordCmdDestroyTest Setup code called after each test case." << std::endl;
62         OH_Drawing_ErrorCodeReset();
63         std::cout << "DrawingRecordCmdDestroyTest errorCodeReset after each test case." << std::endl;
64     }
65 };
drawCircle(OH_Drawing_Canvas * canvas,int position)66 void drawCircle(OH_Drawing_Canvas *canvas, int position)
67 {
68     int x = 10;
69     int radius = 200;
70     OH_Drawing_Point *point = OH_Drawing_PointCreate(x * position + radius, x + radius);
71     OH_Drawing_CanvasDrawCircle(canvas, point, radius);
72     OH_Drawing_PointDestroy(point);
73 }
threadFunctionTest1()74 OH_Drawing_RecordCmd *threadFunctionTest1()
75 {
76     int32_t width = 2;
77     int32_t height = 5;
78     OH_Drawing_RecordCmd *recordCmd = nullptr;
79     OH_Drawing_Canvas *canvas = OH_Drawing_CanvasCreate();
80     OH_Drawing_RecordCmdUtils *recordCmdUtils = OH_Drawing_RecordCmdUtilsCreate();
81     OH_Drawing_RecordCmdUtilsBeginRecording(recordCmdUtils, width, height, &canvas);
82     float penWidth = 1.0f; // pen width 1
83     // 创建一个画笔Pen对象,Pen对象用于形状的边框线绘制
84     OH_Drawing_Pen *cPen = OH_Drawing_PenCreate();
85     OH_Drawing_PenSetAntiAlias(cPen, true);
86     OH_Drawing_PenSetColor(cPen, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00));
87     OH_Drawing_PenSetWidth(cPen, penWidth);
88     OH_Drawing_PenSetJoin(cPen, LINE_ROUND_JOIN);
89     // 将Pen画笔设置到canvas中
90     OH_Drawing_CanvasAttachPen(canvas, cPen);
91     // 创建一个画刷Brush对象,Brush对象用于形状的填充
92     OH_Drawing_Brush *cBrush = OH_Drawing_BrushCreate();
93     OH_Drawing_BrushSetColor(cBrush, OH_Drawing_ColorSetArgb(0xFF, 0x00, 0xFF, 0x00));
94     // 将Brush画刷设置到canvas中
95     OH_Drawing_CanvasAttachBrush(canvas, cBrush);
96     drawCircle(canvas, width);
97     OH_Drawing_RecordCmdUtilsFinishRecording(recordCmdUtils, &recordCmd);
98     OH_Drawing_RecordCmdUtilsDestroy(recordCmdUtils);
99     OH_Drawing_BrushDestroy(cBrush);
100     OH_Drawing_PenDestroy(cPen);
101     cBrush = nullptr;
102     cPen = nullptr;
103     return recordCmd;
104 }
105 
106 
107 /*
108  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECORDER_0400
109  * @tc.name: testRecordCmdDestroyNormal
110  * @tc.desc: test for testRecordCmdDestroyNormal.
111  * @tc.size  : SmallTest
112  * @tc.type  : Function
113  * @tc.level : Level 0
114  */
115 HWTEST_F(DrawingRecordCmdDestroyTest, testRecordCmdDestroyNormal, Function | SmallTest | Level0) {
116     // 1. The OH-Drawing-RecordCmdDestroy parameter is not empty
117     OH_Drawing_ErrorCode drawingErrorCode = OH_DRAWING_ERROR_INVALID_PARAMETER;
118     OH_Drawing_RecordCmd *picture = nullptr;
__anon58179ed40102() 119     std::thread thread([&picture, this]() { picture = threadFunctionTest1(); });
120     thread.join();
121     drawingErrorCode = OH_Drawing_RecordCmdDestroy (picture);
122     EXPECT_EQ(drawingErrorCode, OH_DRAWING_SUCCESS);
123 }
124 
125 /*
126  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECORDER_0400
127  * @tc.name: testRecordCmdDestroyNULL
128  * @tc.desc: test for testRecordCmdDestroyNULL.
129  * @tc.size  : SmallTest
130  * @tc.type  : Function
131  * @tc.level : Level 0
132  */
133 HWTEST_F(DrawingRecordCmdDestroyTest, testRecordCmdDestroyNULL, Function | SmallTest | Level0) {
134     // 1. The OH-Drawing-RecordCmdDestroy parameter is not empty
135     OH_Drawing_ErrorCode drawingErrorCode = OH_DRAWING_ERROR_INVALID_PARAMETER;
136     OH_Drawing_RecordCmd *picture = nullptr;
137     drawingErrorCode = OH_Drawing_RecordCmdDestroy (picture);
138     EXPECT_EQ(drawingErrorCode, OH_DRAWING_ERROR_INVALID_PARAMETER);
139 }
140 
141 } // namespace Drawing
142 } // namespace Rosen
143 } // namespace OHOS
144