1 /*
2  * Copyright (c) 2020-2022 Huawei Device 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 #ifndef UI_TEST_CANVAS_H
17 #define UI_TEST_CANVAS_H
18 
19 #include "components/ui_canvas.h"
20 #include "components/ui_label_button.h"
21 #include "components/ui_scroll_view.h"
22 #include "layout/grid_layout.h"
23 #include "ui_test.h"
24 namespace OHOS {
25 class UITestCanvas : public UITest {
26 public:
UITestCanvas()27     UITestCanvas()
28     {}
~UITestCanvas()29     ~UITestCanvas() override
30     {}
31     void SetUp() override;
32     void TearDown() override;
33     const UIView* GetTestView() override;
34     void UIKitCanvasTestDraw();
35     void DrawLineSegment(UICanvas *canvas, const int16_t line1,
36                          const int16_t line2, const int16_t line3, const int16_t line4);
37     void DrawRectangle(UICanvas *canvas, const int16_t line1,
38                        const int16_t line2, const int16_t line3, const int16_t line4);
39     void DrawRotate001(UICanvas *canvas, Paint paint, const int16_t line1, const int16_t line2);
40     void UIKitCanvasTestDrawLine001();
41     void UIKitCanvasTestDrawLine002();
42     void UIKitCanvasTestDrawCurve001();
43     void UIKitCanvasTestDrawCurve002();
44     void UIKitCanvasTestDrawRect001();
45     void UIKitCanvasTestDrawRect002();
46     void UIKitCanvasTestDrawRect003();
47     void UIKitCanvasTestDrawCircle001();
48     void UIKitCanvasTestDrawCircle002();
49     void UIKitCanvasTestDrawCircle003();
50     void UIKitCanvasTestDrawArc001();
51     void UIKitCanvasTestDrawImage001();
52     void UIKitCanvasTestDrawImage002();
53     void UIKitCanvasTestDrawLabel001();
54     void UIKitCanvasTestDrawSector001();
55     void UIKitCanvasTestClear001();
56     void UIKitCanvasTestDrawPath001();
57     void UIKitCanvasTestDrawPath002();
58     void UIKitCanvasTestDrawPath003();
59     void UIKitCanvasTestDrawPath004();
60     void UIKitCanvasTestDrawPath005();
61     void UIKitCanvasTestDrawPath006();
62     void UIKitCanvasTestDrawPath007();
63     void UIKitCanvasTestDrawPath008();
64     void UIKitCanvasTestDrawPath009();
65     void UIKitCanvasTestDrawPath010();
66     void UIKitCanvasTestDrawPath011();
67     void UIKitCanvasTestDrawPath012();
68     void UIKitCanvasTestDrawPath013();
69     void UIKitCanvasTestDrawPath014();
70     void UIKitCanvasTestDrawPath015();
71     void UIKitCanvasTestDrawPath016();
72     void UIKitCanvasTestDrawPath017();
73     void UIKitCanvasTestDrawPath018();
74     void UIKitCanvasTestDrawPath019();
75     void UIKitCanvasTestDrawPath020();
76     void UIKitCanvasTestDrawPath021();
77     void UIKitCanvasTestDrawPath022();
78     void UIKitCanvasTestDrawPath023();
79     void UIKitCanvasTestDrawPath024();
80     void UIKitCanvasTestDrawPath025();
81     void UIKitCanvasTestDrawPath026();
82     void UIKitCanvasTestDrawPath027();
83     void UIKitCanvasTestDrawPath028();
84     void UIKitCanvasTestDrawPath029();
85     void UIKitCanvasTestDrawPath030();
86     void UIKitCanvasTestDrawPath031();
87     void UIKitCanvasTestDrawPath032();
88     void UIKitCanvasTestDrawPath033();
89     void UIKitCanvasTestDrawPath034();
90     void RM008UIKitCanvasTest001();
91     void RM008UIKitCanvasTest002();
92     void RM008UIKitCanvasTest003();
93     void RM008UIKitCanvasTest004();
94     void RM008UIKitCanvasTest005();
95     void RM008UIKitCanvasTest006();
96     void RM008UIKitCanvasTest007();
97     void RM008UIKitCanvasShadowTest008();
98     void RM009LineCapDrawPath();
99     void RM009LineJoinDrawPath();
100     void RM009LineDashDrawPath();
101     void RM009StrokeAndClearRectDrawPath();
102     void RM011StrokeText001();
103     void RM011CanvasScale001();
104     void RM011CanvasRotate001();
105     void RM012globalAlpha001();
106     void RM012GlobalCompositeOperationSourceOver();
107     void RM012GlobalCompositeOperationSourceAtop();
108     void RM012GlobalCompositeOperationSourceIn();
109     void RM012GlobalCompositeOperationSourceOut();
110     void RM012GlobalCompositeOperationDestinationOver();
111     void RM012GlobalCompositeOperationDestinationAtop();
112     void RM012GlobalCompositeOperationDestinationIn();
113     void RM012GlobalCompositeOperationDestinationOut();
114     void RM012GlobalCompositeOperationLIGHTER();
115     void RM012GlobalCompositeOperationCopy();
116     void RM012GlobalCompositeOperationXOR();
117     void RM012SaveOrRestore002();
118 private:
119     void CreateTitleLabel(const char* title);
120     UICanvas* CreateCanvas();
121 
122     UIScrollView* container_ = nullptr;
123 
124     const int16_t GAP = 10;
125     const int16_t TITLE_HEIGHT = 29;
126     const uint16_t CANVAS_WIDTH = 454;
127     const uint16_t CANVAS_HEIGHT = 200;
128     const int16_t START1_X = 10;
129     const int16_t START1_Y = 10;
130     const int16_t START2_X = 80;
131     const int16_t START2_Y = 10;
132     const int16_t LINE1_X = 40;
133     const int16_t LINE1_Y = 100;
134     const int16_t LINE2_X = 100;
135     const int16_t LINE2_Y = 120;
136     const int16_t CENTER_X = 150;
137     const int16_t CENTER_Y = 150;
138     const int16_t RADIUS = 50;
139     const int16_t START_ANGLE = 30;
140     const int16_t END_ANGLE = 250;
141     const int16_t RECT_X = 250;
142     const int16_t RECT_Y = 50;
143     const int16_t RECT_WIDTH = 100;
144     const int16_t RECT_HEIGHT = 50;
145     const int16_t LINE3_X = 5;
146     const int16_t LINE3_Y = 35;
147     const int16_t LINE4_X = 50;
148     const int16_t LINE4_Y = 5;
149     const int16_t LINE6_X = 60;
150     const int16_t LINE6_Y = 15;
151     const int16_t LINE7_Y = 45;
152     const int16_t LINE8_X = 15;
153     const int16_t LINE8_Y = 45;
154     const int16_t LINE9_X = 230;
155     const int16_t LINE10_Y = 60;
156     const int16_t LINE11_X = 20;
157     const int16_t LINE11_Y = 80;
158     const int16_t LINE12_X = 150;
159     const int16_t LINE13_Y = 20;
160     const int16_t LINE14_X = 180;
161     const int16_t LINE14_Y = 160;
162     const int16_t LINE15_X = 310;
163     const int16_t LINE17_X = 80;
164     const int16_t LINE18_X = 240;
165     const int16_t LINE19_X = 40;
166     const int16_t LINE21_X = 260;
167     const int16_t LINE22_X = 60;
168     const int16_t LINE23_Y = 140;
169     const int16_t LINE24_X = 300;
170     const int16_t LINE25_X = 40;
171     const int16_t LINE25_Y = 40;
172     const int16_t LINE26_X = 120;
173     const int16_t LINE26_Y = 180;
174     const int16_t LINE27_X = 140;
175     const int16_t LINE27_Y = 130;
176     const int16_t LINE28_X = 200;
177     const int16_t LINE29_X = 220;
178     const int16_t LINE30_X = 280;
179     const int16_t LINE31_X = 330;
180     const int16_t LINE32_X = 270;
181     const int16_t LINE33_X = 215;
182     const int16_t LINE34_X = 250;
183     const int16_t TRANSLATE_X = 50;
184     const int16_t TRANSLATE_Y = 50;
185     const uint16_t STROKE3_WIDTH = 3;
186     const uint16_t ARC_RADIUS = 80;
187     const int16_t START1_ANGLE = 0;
188     const int16_t END1_ANGLE = 180;
189     const int16_t HEIGHT_GAP = 8;
190     const int16_t LINE_WIDTH5 = 5;
191     const int16_t LINE_WIDTH10 = 10;
192     const int16_t LINE_WIDTH30 = 30;
193     const int16_t START_X = 50;
194     const int16_t START_Y = 10;
195     const int16_t LINE_CURVE_Y = 50;
196     const int16_t LINE_RECT_Y50 = 50;
197     const int16_t LINE_RECT_X300 = 300;
198     const int16_t LINE_RECT_Y10 = 10;
199     const int16_t LINE_RECT_WIDTH50 = 50;
200     const int16_t LINE_RECT_HEIGHT50 = 50;
201     const int16_t OPARCITY_127 = 127;
202     const int16_t LINE_CURVE_X100 = 100;
203     const int16_t LINE_CURVE_X200 = 200;
204     const int16_t LINE_CURVE_X300 = 300;
205     const int16_t LINE_CURVE_Y100 = 100;
206     const int16_t LINE_CURVE_R30 = 30;
207     const int16_t ARC_X100 = 100;
208     const int16_t ARC_Y150 = 1500;
209     const int16_t ARC_R50 = 50;
210     const int16_t ARC_R100 = 100;
211     const int16_t ARC_ANGLE135 = 135;
212     const int16_t ARC_ANGLE270 = 270;
213     const int16_t ROTATE20 = 20;
214     const int16_t ROTATE_20 = -20;
215     const int16_t ROTATE45 = 45;
216     const int16_t IMAGE_START60 = 60;
217     const int16_t IMAGE_START100 = 100;
218     const int16_t IMAGE_START20 = 20;
219     const int16_t IMAGE_WIDTH100 = 100;
220     const int16_t IMAGE_HEIGHT100 = 100;
221     const int16_t FONT_SIZE30 = 30;
222     const int16_t FONT_SIZE15 = 15;
223     const int16_t FONT_LETTERSPACE = 10;
224     const int16_t FONT_LETTERSPACE2 = 2;
225     const int16_t LABEL_START50 = 50;
226     const int16_t LABEL_WIDTH100 = 100;
227     const int16_t END_ANGLE30 = 30;
228     const int16_t START_X350 = 350;
229     const int16_t START_Y150 = 150;
230     const float DASH10 = 10.0f;
231     const int16_t DASH_COUNT = 4;
232     const int16_t DASH_LINE_WIDTH2 = 2;
233     const int16_t MOVETO5 = 5;
234     const int16_t MOVETO20 = 20;
235     const int16_t MOVETO30 = 30;
236     const int16_t MOVETO60 = 60;
237     const int16_t LINET020 = 20;
238     const int16_t LINET050 = 50;
239     const int16_t LINET035 = 35;
240     const int16_t LINET080 = 80;
241     const int16_t LINET0200 = 200;
242     const int16_t LINET0120 = 120;
243     const int16_t LINET0180 = 180;
244     const int16_t LINE_DASH_OFFSET5 = 5;
245     const int16_t STROKEWIDTH2 = 2;
246     const int16_t STROKEWIDTH3 = 3;
247     const int16_t STROKEWIDTH8 = 8;
248     const int16_t RECT40 = 40;
249     const int16_t RECT50 = 50;
250     const int16_t RECT70 = 70;
251     const int16_t RECT80 = 80;
252     const int16_t RECT100 = 100;
253     const int16_t LINEARGRADIENT50 = 50;
254     const int16_t LINEARGRADIENT150 = 150;
255     const int16_t LINEARGRADIENT140 = 140;
256     const int16_t LINEARGRADIENT5 = 5;
257     const int16_t LINEARGRADIENT300 = 300;
258     const int16_t LINEARGRADIENT100 = 100;
259     const int16_t LINEARGRADIENT80 = 80;
260     const int16_t LINEARGRADIENT270 = 270;
261     const int16_t OFFSETX10 = 10;
262     const int16_t OFFSETX20 = 20;
263     const int16_t SHADOWBLUR15 = 15;
264     const int16_t SHADOWBLUR5 = 5;
265     const int16_t HEIGHT_Y20 = 20;
266     const int16_t HEIGHT_Y40 = 40;
267     const int16_t HEIGHT_Y60 = 60;
268     const int16_t HEIGHT_Y80 = 80;
269     const int16_t HEIGHT_Y100 = 100;
270     const int16_t HEIGHT_Y120 = 120;
271     const int16_t HEIGHT_Y140 = 140;
272     const int16_t HEIGHT_Y160 = 160;
273     const int16_t HEIGHT_Y180 = 180;
274     const int16_t HEIGHT_Y200 = 200;
275     const int16_t SCALE2 = 2;
276     const int16_t SCALE4 = 4;
277     const int16_t STROKE_WIDTH12 = 12;
278     const int16_t STROKE_WIDTH10 = 10;
279     const int16_t STROKE_WIDTH8 = 8;
280     const int16_t MITERLIMIT4 = 4;
281     const int16_t RADIAL_GRADIENT300 = 300;
282     const int16_t RADIAL_GRADIENT140 = 140;
283     const int16_t RADIAL_GRADIENT5 = 5;
284     const int16_t RADIAL_GRADIENT270 = 270;
285     const int16_t RADIAL_GRADIENT100 = 100;
286     const int16_t RADIAL_GRADIENT80 = 80;
287     const int16_t DRAWIMAGE_WIDTH = 50;
288     const int16_t DRAWIMAGE_HEIGHT = 50;
289     const float SCALE_X = 0.5f;
290     const float SCALE_Y = 0.5f;
291     const float ROTATE_ANGLE = 20;
292     const float SCALE1_X = 1;
293     const float SCALE1_Y = 1;
294     const float SCALE2_Y = 2;
295     const float SHEAR_X = 0.5f;
296     const float SHEAR_Y = 0.5f;
297     const float TRANSLATE1_X = 0;
298     const float TRANSLATE1_Y = 0;
299     const float SHEAR1_X = 0;
300     const float SHEAR1_Y = 0;
301     const float DASH5 = 5.0f;
302     const float DASH2 = 2.0f;
303     const float GLOBALALPHA5 = 0.5f;
304     const float GLOBALALPHA2 = 0.2f;
305     const float COLOR_STOP3 = 0.3f;
306     const float COLOR_STOP6 = 0.6f;
307 };
308 } // namespace OHOS
309 #endif // UI_TEST_CANVAS_H
310