1 /*
2 * Copyright (c) 2023 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 <gmock/gmock.h>
18
19 #include "texgine_path.h"
20
21 using namespace testing;
22 using namespace testing::ext;
23
24 struct MockVars {
25 #ifndef USE_ROSEN_DRAWING
26 std::shared_ptr<SkPath> skPath_ = std::make_shared<SkPath>();
27 #else
28 std::shared_ptr<RSPath> skPath_ = std::make_shared<RSPath>();
29 #endif
30 };
31
32 namespace {
33 struct MockVars g_tphMockvars;
34
InitTphMockVars(struct MockVars && vars)35 void InitTphMockVars(struct MockVars &&vars)
36 {
37 g_tphMockvars = std::move(vars);
38 }
39
40 } // namespace
41
42 namespace OHOS {
43 namespace Rosen {
44 namespace TextEngine {
45 class TexginePathTest : public testing::Test {
46 };
47
48 /**
49 * @tc.name:SetAndGet
50 * @tc.desc: Verify the SetAndGet
51 * @tc.type:FUNC
52 */
53 HWTEST_F(TexginePathTest, SetAndGet, TestSize.Level1)
54 {
55 std::shared_ptr<TexginePath> tp = std::make_shared<TexginePath>();
56 EXPECT_NO_THROW({
57 InitTphMockVars({});
58 tp->SetPath(g_tphMockvars.skPath_);
59 EXPECT_EQ(tp->GetPath(), g_tphMockvars.skPath_);
60 });
61 }
62
63 /**
64 * @tc.name:MoveTo
65 * @tc.desc: Verify the MoveTo
66 * @tc.type:FUNC
67 */
68 HWTEST_F(TexginePathTest, MoveTo, TestSize.Level1)
69 {
70 std::shared_ptr<TexginePath> tp = std::make_shared<TexginePath>();
71 #ifndef USE_ROSEN_DRAWING
72 std::shared_ptr<SkPath> sp = nullptr;
73 #else
74 std::shared_ptr<RSPath> sp = nullptr;
75 #endif
76 TexginePoint p = {0.0, 0.0};
77 EXPECT_NO_THROW({
78 tp->MoveTo(p);
79 tp->SetPath(sp);
80 tp->MoveTo(p);
81 });
82 }
83
84 /**
85 * @tc.name:QuadTo
86 * @tc.desc: Verify the QuadTo
87 * @tc.type:FUNC
88 */
89 HWTEST_F(TexginePathTest, QuadTo, TestSize.Level1)
90 {
91 std::shared_ptr<TexginePath> tp = std::make_shared<TexginePath>();
92 #ifndef USE_ROSEN_DRAWING
93 std::shared_ptr<SkPath> sp = nullptr;
94 #else
95 std::shared_ptr<RSPath> sp = nullptr;
96 #endif
97 TexginePoint p1 = {0.0, 0.0};
98 TexginePoint p2 = {0.0, 0.0};
99 EXPECT_NO_THROW({
100 tp->QuadTo(p1, p2);
101 tp->SetPath(sp);
102 tp->QuadTo(p1, p2);
103 });
104 }
105
106 /**
107 * @tc.name:LineTo
108 * @tc.desc: Verify the LineTo
109 * @tc.type:FUNC
110 */
111 HWTEST_F(TexginePathTest, LineTo, TestSize.Level1)
112 {
113 std::shared_ptr<TexginePath> tp = std::make_shared<TexginePath>();
114 #ifndef USE_ROSEN_DRAWING
115 std::shared_ptr<SkPath> sp = nullptr;
116 #else
117 std::shared_ptr<RSPath> sp = nullptr;
118 #endif
119 TexginePoint p = {0.0, 0.0};
120 EXPECT_NO_THROW({
121 tp->LineTo(p);
122 tp->SetPath(sp);
123 tp->LineTo(p);
124 });
125 }
126 } // namespace TextEngine
127 } // namespace Rosen
128 } // namespace OHOS
129