• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 #include "gtest/gtest.h"
17 #include "paint_record.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 using namespace OHOS::Rosen::SPText;
22 
23 namespace txt {
24 class PaintRecordTest : public testing::Test {
25 public:
26     static void SetUpTestCase();
27     static void TearDownTestCase();
28     static inline std::shared_ptr<PaintRecord> paintRecord_ = nullptr;
29 };
30 
SetUpTestCase()31 void PaintRecordTest::SetUpTestCase()
32 {
33     paintRecord_ = std::make_shared<PaintRecord>();
34     if (!paintRecord_) {
35         std::cout << "PaintRecordTest::SetUpTestCase error paintRecord_ is nullptr" << std::endl;
36     }
37 }
38 
TearDownTestCase()39 void PaintRecordTest::TearDownTestCase()
40 {
41 }
42 
43 /*
44  * @tc.name: PaintRecordTest001
45  * @tc.desc: test for SetColor
46  * @tc.type: FUNC
47  */
48 HWTEST_F(PaintRecordTest, PaintRecordTest001, TestSize.Level0)
49 {
50     EXPECT_EQ(paintRecord_ != nullptr, true);
51     RSBrush brush;
52     RSPen pen;
53     PaintRecord paintRecord(brush, pen);
54     PaintRecord::RSColor color(0, 0, 0, 255); // 255 just fot test
55     paintRecord.SetColor(color);
56     EXPECT_EQ(paintRecord.color.GetAlpha() != 0, true);
57 }
58 
59 /*
60  * @tc.name: PaintRecordTest002
61  * @tc.desc: test for SetColor
62  * @tc.type: FUNC
63  */
64 HWTEST_F(PaintRecordTest, PaintRecordTest002, TestSize.Level0)
65 {
66     EXPECT_EQ(paintRecord_ != nullptr, true);
67     RSBrush rsBrush;
68     RSPen rsPen;
69     std::optional<RSBrush> brush(rsBrush);
70     std::optional<RSPen> pen(rsPen);
71     PaintRecord paintRecord(brush, pen);
72     SkColor color = 255; // 255 just fot test
73     paintRecord.SetColor(color);
74     EXPECT_EQ(paintRecord.color.GetBlue() != 0, true);
75 }
76 
77 /*
78  * @tc.name: PaintRecordTest003
79  * @tc.desc: test for Equal
80  * @tc.type: FUNC
81  */
82 HWTEST_F(PaintRecordTest, PaintRecordTest003, TestSize.Level0)
83 {
84     EXPECT_EQ(paintRecord_ != nullptr, true);
85     RSBrush brush;
86     RSPen pen;
87     PaintRecord paintRecord(brush, pen);
88     EXPECT_EQ(paintRecord == (*paintRecord_), false);
89 }
90 
91 /*
92  * @tc.name: PaintRecordTest004
93  * @tc.desc: test for Unequal
94  * @tc.type: FUNC
95  */
96 HWTEST_F(PaintRecordTest, PaintRecordTest004, TestSize.Level0)
97 {
98     EXPECT_EQ(paintRecord_ != nullptr, true);
99     RSBrush brush;
100     RSPen pen;
101     PaintRecord paintRecord(brush, pen);
102     EXPECT_EQ(paintRecord != (*paintRecord_), true);
103 }
104 } // namespace txt