1 /*
2 * Copyright (c) 2022-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 "test/mock/core/common/mock_theme_manager.h"
18 #include "test/mock/core/pipeline/mock_pipeline_context.h"
19
20 #include "core/components/common/properties/color.h"
21 #include "core/components_ng/base/frame_node.h"
22 #include "core/components_ng/event/focus_box.h"
23 #include "core/components_ng/manager/focus/focus_view.h"
24 #include "core/components_ng/pattern/flex/flex_layout_pattern.h"
25 #include "core/components_ng/pattern/list/list_pattern.h"
26 #include "core/components_ng/pattern/pattern.h"
27 #include "core/pipeline_ng/pipeline_context.h"
28
29 namespace OHOS::Ace::NG {
30 namespace {
31 const std::string RESULT_SUCCESS_ONE = "sucess1";
32 const std::string RESULT_SUCCESS_TWO = "sucess2";
33 } // namespace
34
35 class FocusBoxTestNg : public testing::Test {
36 public:
37 static void SetUpTestSuite();
38 static void TearDownTestSuite();
39 void SetUp() override;
40 void TearDown() override;
41 };
42 } // namespace OHOS::Ace::NG
43
44 using namespace testing;
45 using namespace testing::ext;
46
47 namespace OHOS::Ace::NG {
SetUpTestSuite()48 void FocusBoxTestNg::SetUpTestSuite()
49 {
50 MockPipelineContext::SetUp();
51 }
52
TearDownTestSuite()53 void FocusBoxTestNg::TearDownTestSuite()
54 {
55 MockPipelineContext::TearDown();
56 }
57
SetUp()58 void FocusBoxTestNg::SetUp() {}
59
TearDown()60 void FocusBoxTestNg::TearDown() {}
61
62 /**
63 * @tc.name: FocusBoxTest001
64 * @tc.desc: Create SetStyle.
65 * @tc.type: FUNC
66 */
67 HWTEST_F(FocusBoxTestNg, FocusBoxTest001, TestSize.Level1)
68 {
69 auto focusBox = AceType::MakeRefPtr<FocusBox>();
70 NG::FocusBoxStyle style;
71 style.margin = 1.0f;
72 style.strokeWidth = 1.0f;
73
74 focusBox->SetStyle(style);
75
76 EXPECT_EQ(RESULT_SUCCESS_ONE, "sucess1");
77 }
78
79 /**
80 * @tc.name: FocusBoxTest002
81 * @tc.desc: Create SetStyle.
82 * @tc.type: FUNC
83 */
84 HWTEST_F(FocusBoxTestNg, FocusBoxTest002, TestSize.Level1)
85 {
86 auto focusBox = AceType::MakeRefPtr<FocusBox>();
87 NG::FocusBoxStyle style;
88 style.margin = 1.0f;
89 style.strokeWidth = -1.0f;
90
91 focusBox->SetStyle(style);
92
93 EXPECT_EQ(RESULT_SUCCESS_ONE, "sucess1");
94 }
95
96 /**
97 * @tc.name: FocusBoxTest003
98 * @tc.desc: Create SetStyle.
99 * @tc.type: FUNC
100 */
101 HWTEST_F(FocusBoxTestNg, FocusBoxTest003, TestSize.Level1)
102 {
103 auto focusBox = AceType::MakeRefPtr<FocusBox>();
104 NG::FocusBoxStyle style;
105
106 focusBox->SetStyle(style);
107
108 EXPECT_EQ(RESULT_SUCCESS_ONE, "sucess1");
109 }
110
111 /**
112 * @tc.name: FocusBoxTest004
113 * @tc.desc: Create SetStyle.
114 * @tc.type: FUNC
115 */
116 HWTEST_F(FocusBoxTestNg, FocusBoxTest004, TestSize.Level1)
117 {
118 auto focusBox = AceType::MakeRefPtr<FocusBox>();
119 NG::FocusBoxStyle style;
120 style.margin = 1.0f;
121
122 focusBox->SetStyle(style);
123
124 EXPECT_EQ(RESULT_SUCCESS_ONE, "sucess1");
125 }
126
127 /**
128 * @tc.name: FocusBoxTest005
129 * @tc.desc: Create SetStyle.
130 * @tc.type: FUNC
131 */
132 HWTEST_F(FocusBoxTestNg, FocusBoxTest005, TestSize.Level1)
133 {
134 auto focusBox = AceType::MakeRefPtr<FocusBox>();
135 NG::FocusBoxStyle style;
136 style.strokeColor = Color::WHITE;
137 focusBox->SetStyle(style);
138
139 EXPECT_EQ(RESULT_SUCCESS_ONE, "sucess1");
140 }
141
142 /**
143 * @tc.name: FocusBoxTest006
144 * @tc.desc: Create SetStyle.
145 * @tc.type: FUNC
146 */
147 HWTEST_F(FocusBoxTestNg, FocusBoxTest006, TestSize.Level1)
148 {
149 auto focusBox = AceType::MakeRefPtr<FocusBox>();
150 NG::FocusBoxStyle style;
151 style.strokeWidth = 0.0f;
152 focusBox->SetStyle(style);
153 EXPECT_EQ(RESULT_SUCCESS_ONE, "sucess1");
154 }
155
156 /**
157 * @tc.name: FocusBoxTest007
158 * @tc.desc: Create ToJsonValue.
159 * @tc.type: FUNC
160 */
161 HWTEST_F(FocusBoxTestNg, FocusBoxTest007, TestSize.Level1)
162 {
163 auto focusBox = AceType::MakeRefPtr<FocusBox>();
164 NG::FocusBoxStyle style;
165 style.strokeColor = Color::WHITE;
166 style.margin = 1.0f;
167 style.strokeWidth = 1.0f;
168 focusBox->SetStyle(style);
169 focusBox->ToJsonValue(*focusBox);
170 EXPECT_EQ(RESULT_SUCCESS_ONE, "sucess1");
171 }
172
173 /**
174 * @tc.name: FocusBoxTest008
175 * @tc.desc: Create ToJsonValue.
176 * @tc.type: FUNC
177 */
178 HWTEST_F(FocusBoxTestNg, FocusBoxTest008, TestSize.Level1)
179 {
180 auto focusBox = AceType::MakeRefPtr<FocusBox>();
181 NG::FocusBoxStyle style;
182 style.strokeColor = Color::WHITE;
183 focusBox->SetStyle(style);
184 focusBox->ToJsonValue(*focusBox);
185 EXPECT_EQ(RESULT_SUCCESS_ONE, "sucess1");
186 }
187
188 /**
189 * @tc.name: FocusBoxTest009
190 * @tc.desc: Create ToJsonValue.
191 * @tc.type: FUNC
192 */
193 HWTEST_F(FocusBoxTestNg, FocusBoxTest009, TestSize.Level1)
194 {
195 auto focusBox = AceType::MakeRefPtr<FocusBox>();
196 NG::FocusBoxStyle style;
197 style.strokeWidth = 1.0f;
198 focusBox->SetStyle(style);
199 focusBox->ToJsonValue(*focusBox);
200 EXPECT_EQ(RESULT_SUCCESS_ONE, "sucess1");
201 }
202
203 /**
204 * @tc.name: FocusBoxTest010
205 * @tc.desc: Create ToJsonValue.
206 * @tc.type: FUNC
207 */
208 HWTEST_F(FocusBoxTestNg, FocusBoxTest010, TestSize.Level1)
209 {
210 auto focusBox = AceType::MakeRefPtr<FocusBox>();
211 focusBox->ToJsonValue(*focusBox);
212 EXPECT_EQ(RESULT_SUCCESS_ONE, "sucess1");
213 }
214 } // namespace OHOS::Ace::NG
215