1 /*
2 * Copyright (c) 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, Hardware
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 "c/drawing_color.h"
19 #include "c/drawing_pen.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class NativeDrawingPenTest : public testing::Test {
28 public:
29 static void SetUpTestCase();
30 static void TearDownTestCase();
31 void SetUp() override;
32 void TearDown() override;
33 };
34
SetUpTestCase()35 void NativeDrawingPenTest::SetUpTestCase() {}
TearDownTestCase()36 void NativeDrawingPenTest::TearDownTestCase() {}
SetUp()37 void NativeDrawingPenTest::SetUp() {}
TearDown()38 void NativeDrawingPenTest::TearDown() {}
39
40 /*
41 * @tc.name: NativeDrawingPenTest_pen001
42 * @tc.desc: test for create drawing_pen.
43 * @tc.type: FUNC
44 * @tc.require: AR000GTO5R
45 */
46 HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen001, TestSize.Level1)
47 {
48 OH_Drawing_Pen* pen = OH_Drawing_PenCreate();
49 EXPECT_EQ(pen == nullptr, false);
50 OH_Drawing_PenDestroy(pen);
51 }
52
53 /*
54 * @tc.name: NativeDrawingPenTest_pen002
55 * @tc.desc: test for the get and set methods about AntiAlias for a pen.
56 * @tc.type: FUNC
57 * @tc.require: AR000GTO5R
58 */
59 HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen002, TestSize.Level1)
60 {
61 OH_Drawing_Pen* pen1 = OH_Drawing_PenCreate();
62 OH_Drawing_PenSetAntiAlias(pen1, true);
63 EXPECT_EQ(OH_Drawing_PenIsAntiAlias(pen1), true);
64 OH_Drawing_PenSetAntiAlias(pen1, false);
65 EXPECT_EQ(OH_Drawing_PenIsAntiAlias(pen1), false);
66 OH_Drawing_PenDestroy(pen1);
67 }
68
69 /*
70 * @tc.name: NativeDrawingPenTest_pen003
71 * @tc.desc: test for the get and set methods about the color for a pen.
72 * @tc.type: FUNC
73 * @tc.require: AR000GTO5R
74 */
75 HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen003, TestSize.Level1)
76 {
77 OH_Drawing_Pen* pen2 = OH_Drawing_PenCreate();
78 OH_Drawing_PenSetColor(pen2, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00));
79 EXPECT_EQ(OH_Drawing_PenGetColor(pen2), 0xFFFF0000);
80 OH_Drawing_PenDestroy(pen2);
81 }
82
83 /*
84 * @tc.name: NativeDrawingPenTest_pen004
85 * @tc.desc: test for the get and set methods about the width for a pen.
86 * @tc.type: FUNC
87 * @tc.require: AR000GTO5R
88 */
89 HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen004, TestSize.Level1)
90 {
91 OH_Drawing_Pen* pen3 = OH_Drawing_PenCreate();
92 OH_Drawing_PenSetWidth(pen3, 10);
93 EXPECT_EQ(OH_Drawing_PenGetWidth(pen3), 10);
94 OH_Drawing_PenDestroy(pen3);
95 }
96
97 /*
98 * @tc.name: NativeDrawingPenTest_pen005
99 * @tc.desc: test for the get and set methods about the miterLimit for a pen.
100 * @tc.type: FUNC
101 * @tc.require: AR000GTO5R
102 */
103 HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen005, TestSize.Level1)
104 {
105 OH_Drawing_Pen* pen4 = OH_Drawing_PenCreate();
106 OH_Drawing_PenSetMiterLimit(pen4, 5);
107 EXPECT_EQ(OH_Drawing_PenGetMiterLimit(pen4), 5);
108 OH_Drawing_PenDestroy(pen4);
109 }
110
111 /*
112 * @tc.name: NativeDrawingPenTest_pen006
113 * @tc.desc: test for the get and set methods about the line cap style for a pen.
114 * @tc.type: FUNC
115 * @tc.require: AR000GTO5R
116 */
117 HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen006, TestSize.Level1)
118 {
119 OH_Drawing_Pen* pen5 = OH_Drawing_PenCreate();
120 OH_Drawing_PenSetCap(pen5, OH_Drawing_PenLineCapStyle::LINE_SQUARE_CAP);
121 EXPECT_EQ(OH_Drawing_PenGetCap(pen5), OH_Drawing_PenLineCapStyle::LINE_SQUARE_CAP);
122 OH_Drawing_PenSetCap(pen5, OH_Drawing_PenLineCapStyle::LINE_FLAT_CAP);
123 EXPECT_EQ(OH_Drawing_PenGetCap(pen5), OH_Drawing_PenLineCapStyle::LINE_FLAT_CAP);
124 OH_Drawing_PenSetCap(pen5, OH_Drawing_PenLineCapStyle::LINE_ROUND_CAP);
125 EXPECT_EQ(OH_Drawing_PenGetCap(pen5), OH_Drawing_PenLineCapStyle::LINE_ROUND_CAP);
126 OH_Drawing_PenDestroy(pen5);
127 }
128
129 /*
130 * @tc.name: NativeDrawingPenTest_pen007
131 * @tc.desc: test for the get and set methods about the line join style for a pen.
132 * @tc.type: FUNC
133 * @tc.require: AR000GTO5R
134 */
135 HWTEST_F(NativeDrawingPenTest, NativeDrawingPenTest_pen007, TestSize.Level1)
136 {
137 OH_Drawing_Pen* pen6 = OH_Drawing_PenCreate();
138 OH_Drawing_PenSetJoin(pen6, OH_Drawing_PenLineJoinStyle::LINE_ROUND_JOIN);
139 EXPECT_EQ(OH_Drawing_PenGetJoin(pen6), OH_Drawing_PenLineJoinStyle::LINE_ROUND_JOIN);
140 OH_Drawing_PenSetJoin(pen6, OH_Drawing_PenLineJoinStyle::LINE_MITER_JOIN);
141 EXPECT_EQ(OH_Drawing_PenGetJoin(pen6), OH_Drawing_PenLineJoinStyle::LINE_MITER_JOIN);
142 OH_Drawing_PenSetJoin(pen6, OH_Drawing_PenLineJoinStyle::LINE_BEVEL_JOIN);
143 EXPECT_EQ(OH_Drawing_PenGetJoin(pen6), OH_Drawing_PenLineJoinStyle::LINE_BEVEL_JOIN);
144 OH_Drawing_PenDestroy(pen6);
145 }
146
147 /*
148 * @tc.name: NativeDrawingPenTest_pen008
149 * @tc.desc: test for the get and set alpha for a pen.
150 * @tc.type: FUNC
151 * @tc.require: AR000GTO5R
152 */
153 HWTEST_F(NativeDrawingPenTest, NativeDrawingPenAlphaTest001, TestSize.Level1)
154 {
155 OH_Drawing_Pen* pen7 = OH_Drawing_PenCreate();
156 OH_Drawing_PenSetColor(pen7, OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0x00, 0x00));
157 OH_Drawing_PenSetAlpha(pen7, 128);
158 EXPECT_EQ(OH_Drawing_PenGetAlpha(pen7), 128);
159 OH_Drawing_PenDestroy(pen7);
160 }
161 } // namespace Drawing
162 } // namespace Rosen
163 } // namespace OHOS