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 <type_traits>
17 #include "gtest/gtest.h"
18
19 #define private public
20 #define protected public
21
22 #include "test/mock/core/common/mock_theme_manager.h"
23 #include "test/mock/core/pipeline/mock_pipeline_context.h"
24 #include "test/mock/core/render/mock_render_context.h"
25 #include "test/mock/core/rosen/mock_canvas.h"
26 #include "test/mock/core/rosen/testing_canvas.h"
27
28 #include "core/components/common/layout/constants.h"
29 #include "core/components/common/layout/grid_system_manager.h"
30 #include "core/components/common/properties/shadow_config.h"
31 #include "core/components/container_modal/container_modal_constants.h"
32 #include "core/components/select/select_theme.h"
33 #include "core/components/theme/shadow_theme.h"
34 #include "core/components_ng/base/view_stack_processor.h"
35 #include "core/components_ng/pattern/image/image_layout_property.h"
36 #include "core/components_ng/pattern/image/image_pattern.h"
37 #include "core/components_ng/pattern/menu/menu_item/menu_item_model_ng.h"
38 #include "core/components_ng/pattern/menu/menu_item/menu_item_pattern.h"
39 #include "core/components_ng/pattern/menu/menu_item/menu_item_layout_property.h"
40 #include "core/components_ng/pattern/menu/menu_item_group/menu_item_group_pattern.h"
41 #include "core/components_ng/pattern/menu/menu_item_group/menu_item_group_view.h"
42 #include "core/components_ng/pattern/menu/menu_model_ng.h"
43 #include "core/components_ng/pattern/menu/menu_pattern.h"
44 #include "core/components_ng/pattern/menu/menu_theme.h"
45 #include "core/components_ng/pattern/menu/menu_view.h"
46 #include "core/components_ng/pattern/menu/multi_menu_layout_algorithm.h"
47 #include "core/components_ng/pattern/menu/preview/menu_preview_layout_algorithm.h"
48 #include "core/components_ng/pattern/menu/preview/menu_preview_pattern.h"
49 #include "core/components_ng/pattern/menu/sub_menu_layout_algorithm.h"
50 #include "core/components_ng/pattern/menu/wrapper/menu_wrapper_pattern.h"
51 #include "core/components_ng/pattern/pattern.h"
52 #include "core/components_ng/pattern/root/root_pattern.h"
53 #include "core/components_ng/pattern/scroll/scroll_pattern.h"
54 #include "core/components_ng/pattern/text/text_layout_property.h"
55 #include "core/components_ng/pattern/text/text_pattern.h"
56 #include "core/components_ng/property/border_property.h"
57 #include "core/components_ng/property/measure_property.h"
58 #include "core/components_ng/syntax/lazy_for_each_model.h"
59 #include "core/components_ng/syntax/lazy_layout_wrapper_builder.h"
60 #include "core/event/touch_event.h"
61
62 using namespace testing;
63 using namespace testing::ext;
64 using namespace OHOS::Ace::Framework;
65
66 namespace OHOS::Ace::NG {
67 namespace {
68 const InspectorFilter filter;
69 constexpr int32_t DEFAULT_SYMBOL_ID = 983242;
70 const std::string EMPTY_TEXT = "";
71 const std::string TEXT_TAG = "text";
72 const std::string MENU_TAG = "menu";
73 const std::string MENU_ITEM_TEXT = "menuItem";
74 const std::string MENU_ITEM_GROUP_TEXT = "menuItemGroup";
75 const std::string MENU_TOUCH_EVENT_TYPE = "1";
76 const std::string IMAGE_SRC_URL = "file://data/data/com.example.test/res/example.svg";
77
78 constexpr float FULL_SCREEN_WIDTH = 720.0f;
79 constexpr float FULL_SCREEN_HEIGHT = 1136.0f;
80 constexpr float TARGET_SIZE_WIDTH = 100.0f;
81 constexpr float TARGET_SIZE_HEIGHT = 100.0f;
82 constexpr float MENU_ITEM_SIZE_WIDTH = 100.0f;
83 constexpr float MENU_ITEM_SIZE_HEIGHT = 50.0f;
84
85 const SizeF FULL_SCREEN_SIZE(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
86 const std::vector<std::string> FONT_FAMILY_VALUE = {"cursive"};
87 const std::vector<SelectParam> CREATE_VALUE = { { "content1", "icon1" }, { "content2", "" },
88 { "", "icon3" }, { "", "" } };
89 const std::vector<SelectParam> CREATE_VALUE_NEW = { { "content1_new", "" }, { "", "icon4_new" },
90 { "", "" }, { "", "icon4_new" } };
91 const V2::ItemDivider ITEM_DIVIDER = { Dimension(5.f), Dimension(10), Dimension(20), Color(0x000000) };
92 } // namespace
93 class MenuItemTestNg : public testing::Test {
94 public:
95 static void SetUpTestCase();
96 static void TearDownTestCase();
97 void SetUp() override;
98 void TearDown() override;
99 void InitMenuItemTestNg();
100 PaintWrapper* GetPaintWrapper(RefPtr<MenuPaintProperty> paintProperty);
101 RefPtr<FrameNode> GetPreviewMenuWrapper(
102 SizeF itemSize = SizeF(0.0f, 0.0f), std::optional<MenuPreviewAnimationOptions> scaleOptions = std::nullopt);
103 RefPtr<FrameNode> menuFrameNode_;
104 RefPtr<MenuAccessibilityProperty> menuAccessibilityProperty_;
105 RefPtr<FrameNode> menuItemFrameNode_;
106 RefPtr<MenuItemPattern> menuItemPattern_;
107 RefPtr<MenuItemAccessibilityProperty> menuItemAccessibilityProperty_;
108 };
109
SetUpTestCase()110 void MenuItemTestNg::SetUpTestCase() {}
111
TearDownTestCase()112 void MenuItemTestNg::TearDownTestCase() {}
113
SetUp()114 void MenuItemTestNg::SetUp()
115 {
116 MockPipelineContext::SetUp();
117 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
118 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
119 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<SelectTheme>()));
120 }
121
TearDown()122 void MenuItemTestNg::TearDown()
123 {
124 MockPipelineContext::TearDown();
125 menuFrameNode_ = nullptr;
126 menuAccessibilityProperty_ = nullptr;
127 menuItemFrameNode_ = nullptr;
128 menuItemPattern_ = nullptr;
129 menuItemAccessibilityProperty_ = nullptr;
130 SystemProperties::SetDeviceType(DeviceType::PHONE);
131 ScreenSystemManager::GetInstance().dipScale_ = 1.0;
132 SystemProperties::orientation_ = DeviceOrientation::PORTRAIT;
133 }
134
InitMenuItemTestNg()135 void MenuItemTestNg::InitMenuItemTestNg()
136 {
137 menuItemFrameNode_ = FrameNode::GetOrCreateFrameNode(V2::MENU_ITEM_ETS_TAG,
138 ViewStackProcessor::GetInstance()->ClaimNodeId(), []() { return AceType::MakeRefPtr<MenuItemPattern>(); });
139 ASSERT_NE(menuItemFrameNode_, nullptr);
140
141 menuItemPattern_ = menuItemFrameNode_->GetPattern<MenuItemPattern>();
142 ASSERT_NE(menuItemPattern_, nullptr);
143
144 menuItemAccessibilityProperty_ = menuItemFrameNode_->GetAccessibilityProperty<MenuItemAccessibilityProperty>();
145 ASSERT_NE(menuItemAccessibilityProperty_, nullptr);
146 }
147
GetPaintWrapper(RefPtr<MenuPaintProperty> paintProperty)148 PaintWrapper* MenuItemTestNg::GetPaintWrapper(RefPtr<MenuPaintProperty> paintProperty)
149 {
150 WeakPtr<RenderContext> renderContext;
151 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
152 PaintWrapper* paintWrapper = new PaintWrapper(renderContext, geometryNode, paintProperty);
153 return paintWrapper;
154 }
155
GetPreviewMenuWrapper(SizeF itemSize,std::optional<MenuPreviewAnimationOptions> scaleOptions)156 RefPtr<FrameNode> MenuItemTestNg::GetPreviewMenuWrapper(
157 SizeF itemSize, std::optional<MenuPreviewAnimationOptions> scaleOptions)
158 {
159 auto rootNode = FrameNode::CreateFrameNode(
160 V2::ROOT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<RootPattern>());
161 CHECK_NULL_RETURN(rootNode, nullptr);
162 auto targetNode = FrameNode::CreateFrameNode(
163 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
164 CHECK_NULL_RETURN(targetNode, nullptr);
165 auto textNode = FrameNode::CreateFrameNode(
166 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
167 CHECK_NULL_RETURN(textNode, nullptr);
168 if (!(LessOrEqual(itemSize.Width(), 0.0) || LessOrEqual(itemSize.Height(), 0.0))) {
169 auto itemGeometryNode = textNode->GetGeometryNode();
170 CHECK_NULL_RETURN(itemGeometryNode, nullptr);
171 itemGeometryNode->SetFrameSize(itemSize);
172 }
173 targetNode->MountToParent(rootNode);
174 MenuParam menuParam;
175 menuParam.type = MenuType::CONTEXT_MENU;
176 menuParam.previewMode = MenuPreviewMode::CUSTOM;
177 if (scaleOptions != std::nullopt) {
178 menuParam.previewAnimationOptions = scaleOptions.value();
179 }
180 auto customNode = FrameNode::CreateFrameNode(
181 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
182 CHECK_NULL_RETURN(customNode, nullptr);
183 auto customGeometryNode = customNode->GetGeometryNode();
184 CHECK_NULL_RETURN(customGeometryNode, nullptr);
185 customGeometryNode->SetFrameSize(SizeF(TARGET_SIZE_WIDTH, TARGET_SIZE_HEIGHT));
186 auto menuWrapperNode =
187 MenuView::Create(textNode, targetNode->GetId(), V2::TEXT_ETS_TAG, menuParam, true, customNode);
188 return menuWrapperNode;
189 }
190
191 /**
192 * @tc.name: MenuItemAccessibilityPropertyGetText001
193 * @tc.desc: Test GetText of menuItem.
194 * @tc.type: FUNC
195 */
196 HWTEST_F(MenuItemTestNg, MenuItemAccessibilityPropertyGetText001, TestSize.Level1)
197 {
198 InitMenuItemTestNg();
199
200 EXPECT_EQ(menuItemAccessibilityProperty_->GetText(), EMPTY_TEXT);
201
202 auto menuItemLayoutProperty = menuItemFrameNode_->GetLayoutProperty<MenuItemLayoutProperty>();
203 ASSERT_NE(menuItemLayoutProperty, nullptr);
204 menuItemLayoutProperty->UpdateContent(MENU_ITEM_TEXT);
205
206 EXPECT_EQ(menuItemAccessibilityProperty_->GetText(), MENU_ITEM_TEXT);
207 }
208
209 /**
210 * @tc.name: MenuItemAccessibilityPropertyIsSelected001
211 * @tc.desc: Test IsSelected of menuitem.
212 * @tc.type: FUNC
213 */
214 HWTEST_F(MenuItemTestNg, MenuItemAccessibilityPropertyIsSelected001, TestSize.Level1)
215 {
216 InitMenuItemTestNg();
217
218 EXPECT_FALSE(menuItemAccessibilityProperty_->IsSelected());
219
220 menuItemPattern_->SetSelected(true);
221 EXPECT_TRUE(menuItemAccessibilityProperty_->IsSelected());
222 }
223
224 /**
225 * @tc.name: MenuItemAccessibilityPropertyGetSupportAction001
226 * @tc.desc: Test GetSupportAction of menuitem.
227 * @tc.type: FUNC
228 */
229 HWTEST_F(MenuItemTestNg, MenuItemAccessibilityPropertyGetSupportAction001, TestSize.Level1)
230 {
231 InitMenuItemTestNg();
232
233 menuItemAccessibilityProperty_->ResetSupportAction();
234 std::unordered_set<AceAction> supportAceActions = menuItemAccessibilityProperty_->GetSupportAction();
235 uint64_t actions = 0, expectActions = 0;
236 expectActions |= 1UL << static_cast<uint32_t>(AceAction::ACTION_SELECT);
237 for (auto action : supportAceActions) {
238 actions |= 1UL << static_cast<uint32_t>(action);
239 }
240 EXPECT_EQ(actions, expectActions);
241 }
242
243 /**
244 * @tc.name: MenuItemGroupAccessibilityPropertyGetText001
245 * @tc.desc: Test GetText of menuItemGroup.
246 * @tc.type: FUNC
247 */
248 HWTEST_F(MenuItemTestNg, MenuItemGroupAccessibilityPropertyGetText001, TestSize.Level1)
249 {
250 auto frameNode = FrameNode::GetOrCreateFrameNode(V2::MENU_ITEM_GROUP_ETS_TAG,
__anon412623ce0302() 251 ViewStackProcessor::GetInstance()->ClaimNodeId(), []() { return AceType::MakeRefPtr<MenuItemGroupPattern>(); });
252 ASSERT_NE(frameNode, nullptr);
253
254 auto menuItemGroupPattern = frameNode->GetPattern<MenuItemGroupPattern>();
255 ASSERT_NE(menuItemGroupPattern, nullptr);
256
257 auto menuItemGroupAccessibilityProperty = frameNode->GetAccessibilityProperty<MenuItemGroupAccessibilityProperty>();
258 ASSERT_NE(menuItemGroupAccessibilityProperty, nullptr);
259 EXPECT_EQ(menuItemGroupAccessibilityProperty->GetText(), EMPTY_TEXT);
260
261 auto content = FrameNode::CreateFrameNode(
262 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
263 ASSERT_NE(content, nullptr);
264 menuItemGroupPattern->AddHeaderContent(content);
265
266 auto textLayoutProperty = content->GetLayoutProperty<TextLayoutProperty>();
267 ASSERT_NE(textLayoutProperty, nullptr);
268 textLayoutProperty->UpdateContent(MENU_ITEM_GROUP_TEXT);
269 EXPECT_EQ(menuItemGroupAccessibilityProperty->GetText(), MENU_ITEM_GROUP_TEXT);
270 }
271
272 /**
273 * @tc.name: MenuItemLayoutPropertyTestNg001
274 * @tc.desc: Verify GetStartIcon.
275 * @tc.type: FUNC
276 */
277 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg001, TestSize.Level1)
278 {
279 MenuItemLayoutProperty property;
280 EXPECT_FALSE(property.GetStartIcon().has_value());
281 property.UpdateStartIcon(ImageSourceInfo(IMAGE_SRC_URL));
282 ASSERT_TRUE(property.GetStartIcon().has_value());
283 EXPECT_EQ(property.GetStartIcon().value().GetSrc(), IMAGE_SRC_URL);
284 }
285
286 /**
287 * @tc.name: MenuItemLayoutPropertyTestNg002
288 * @tc.desc: Verify GetContent.
289 * @tc.type: FUNC
290 */
291 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg002, TestSize.Level1)
292 {
293 MenuItemLayoutProperty property;
294 EXPECT_FALSE(property.GetContent().has_value());
295 property.UpdateContent("content");
296 ASSERT_TRUE(property.GetContent().has_value());
297 EXPECT_EQ(property.GetContent().value(), "content");
298 }
299
300 /**
301 * @tc.name: MenuItemLayoutPropertyTestNg003
302 * @tc.desc: Verify GetEndIcon.
303 * @tc.type: FUNC
304 */
305 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg003, TestSize.Level1)
306 {
307 MenuItemLayoutProperty property;
308 EXPECT_FALSE(property.GetEndIcon().has_value());
309 property.UpdateEndIcon(ImageSourceInfo(IMAGE_SRC_URL));
310 ASSERT_TRUE(property.GetEndIcon().has_value());
311 EXPECT_EQ(property.GetEndIcon().value().GetSrc(), IMAGE_SRC_URL);
312 }
313
314 /**
315 * @tc.name: MenuItemLayoutPropertyTestNg004
316 * @tc.desc: Verify GetLabel.
317 * @tc.type: FUNC
318 */
319 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg004, TestSize.Level1)
320 {
321 MenuItemLayoutProperty property;
322 EXPECT_FALSE(property.GetLabel().has_value());
323 property.UpdateLabel("label");
324 ASSERT_TRUE(property.GetLabel().has_value());
325 EXPECT_EQ(property.GetLabel().value(), "label");
326 }
327
328 /**
329 * @tc.name: MenuItemLayoutPropertyTestNg005
330 * @tc.desc: Verify GetSelectIcon.
331 * @tc.type: FUNC
332 */
333 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg005, TestSize.Level1)
334 {
335 MenuItemLayoutProperty property;
336 EXPECT_FALSE(property.GetSelectIcon().has_value());
337 property.UpdateSelectIcon(true);
338 ASSERT_TRUE(property.GetSelectIcon().has_value());
339 EXPECT_TRUE(property.GetSelectIcon().value());
340 }
341
342 /**
343 * @tc.name: MenuItemLayoutPropertyTestNg006
344 * @tc.desc: Verify GetSelectIconSrc.
345 * @tc.type: FUNC
346 */
347 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg006, TestSize.Level1)
348 {
349 MenuItemLayoutProperty property;
350 EXPECT_FALSE(property.GetSelectIconSrc().has_value());
351 property.UpdateSelectIconSrc("test.png");
352 ASSERT_TRUE(property.GetSelectIconSrc().has_value());
353 EXPECT_EQ(property.GetSelectIconSrc().value(), "test.png");
354 }
355
356 /**
357 * @tc.name: MenuItemLayoutPropertyTestNg007
358 * @tc.desc: Verify GetFontSize.
359 * @tc.type: FUNC
360 */
361 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg007, TestSize.Level1)
362 {
363 MenuItemLayoutProperty property;
364 EXPECT_FALSE(property.GetFontSize().has_value());
365 property.UpdateFontSize(Dimension(25.0f));
366 ASSERT_TRUE(property.GetFontSize().has_value());
367 EXPECT_EQ(property.GetFontSize().value(), Dimension(25.0f));
368 }
369
370 /**
371 * @tc.name: MenuItemLayoutPropertyTestNg008
372 * @tc.desc: Verify GetFontColor.
373 * @tc.type: FUNC
374 */
375 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg008, TestSize.Level1)
376 {
377 MenuItemLayoutProperty property;
378 EXPECT_FALSE(property.GetFontColor().has_value());
379 property.UpdateFontColor(Color::RED);
380 ASSERT_TRUE(property.GetFontColor().has_value());
381 EXPECT_EQ(property.GetFontColor().value(), Color::RED);
382 }
383
384 /**
385 * @tc.name: MenuItemLayoutPropertyTestNg009
386 * @tc.desc: Verify GetFontWeight.
387 * @tc.type: FUNC
388 */
389 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg009, TestSize.Level1)
390 {
391 MenuItemLayoutProperty property;
392 EXPECT_FALSE(property.GetFontWeight().has_value());
393 property.UpdateFontWeight(FontWeight::BOLD);
394 ASSERT_TRUE(property.GetFontWeight().has_value());
395 EXPECT_EQ(property.GetFontWeight().value(), FontWeight::BOLD);
396 }
397
398 /**
399 * @tc.name: MenuItemLayoutPropertyTestNg0010
400 * @tc.desc: Verify GetLabelFontSize.
401 * @tc.type: FUNC
402 */
403 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg0010, TestSize.Level1)
404 {
405 MenuItemLayoutProperty property;
406 EXPECT_FALSE(property.GetLabelFontSize().has_value());
407 property.UpdateLabelFontSize(Dimension(25.0f));
408 ASSERT_TRUE(property.GetLabelFontSize().has_value());
409 EXPECT_EQ(property.GetLabelFontSize().value(), Dimension(25.0f));
410 }
411
412 /**
413 * @tc.name: MenuItemLayoutPropertyTestNg011
414 * @tc.desc: Verify GetLabelFontColor.
415 * @tc.type: FUNC
416 */
417 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg011, TestSize.Level1)
418 {
419 MenuItemLayoutProperty property;
420 EXPECT_FALSE(property.GetLabelFontColor().has_value());
421 property.UpdateLabelFontColor(Color::RED);
422 ASSERT_TRUE(property.GetLabelFontColor().has_value());
423 EXPECT_EQ(property.GetLabelFontColor().value(), Color::RED);
424 }
425
426 /**
427 * @tc.name: MenuItemLayoutPropertyTestNg012
428 * @tc.desc: Verify GetLabelFontWeight.
429 * @tc.type: FUNC
430 */
431 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg012, TestSize.Level1)
432 {
433 MenuItemLayoutProperty property;
434 EXPECT_FALSE(property.GetLabelFontWeight().has_value());
435 property.UpdateLabelFontWeight(FontWeight::BOLD);
436 ASSERT_TRUE(property.GetLabelFontWeight().has_value());
437 EXPECT_EQ(property.GetLabelFontWeight().value(), FontWeight::BOLD);
438 }
439
440 /**
441 * @tc.name: MenuItemLayoutPropertyTestNg013
442 * @tc.desc: Verify Reset.
443 * @tc.type: FUNC
444 */
445 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg013, TestSize.Level1)
446 {
447 MenuItemLayoutProperty property;
448 property.UpdateStartIcon(ImageSourceInfo(IMAGE_SRC_URL));
449 property.UpdateContent("content");
450 property.UpdateEndIcon(ImageSourceInfo(IMAGE_SRC_URL));
451 property.UpdateLabel("label");
452 property.UpdateSelectIcon(true);
453 property.UpdateSelectIconSrc("test.png");
454 property.UpdateFontSize(Dimension(25.0f));
455 property.UpdateFontColor(Color::RED);
456 property.UpdateFontWeight(FontWeight::BOLD);
457 property.UpdateLabelFontSize(Dimension(25.0f));
458 property.UpdateLabelFontColor(Color::RED);
459 property.UpdateLabelFontWeight(FontWeight::BOLD);
460 EXPECT_TRUE(property.GetStartIcon().has_value());
461 EXPECT_TRUE(property.GetContent().has_value());
462 EXPECT_TRUE(property.GetLabel().has_value());
463 EXPECT_TRUE(property.GetEndIcon().has_value());
464 EXPECT_TRUE(property.GetSelectIcon().has_value());
465 EXPECT_TRUE(property.GetSelectIconSrc().has_value());
466 EXPECT_TRUE(property.GetFontSize().has_value());
467 EXPECT_TRUE(property.GetFontColor().has_value());
468 EXPECT_TRUE(property.GetFontWeight().has_value());
469 EXPECT_TRUE(property.GetLabelFontSize().has_value());
470 EXPECT_TRUE(property.GetLabelFontColor().has_value());
471 EXPECT_TRUE(property.GetLabelFontWeight().has_value());
472 property.Reset();
473 EXPECT_FALSE(property.GetStartIcon().has_value());
474 EXPECT_FALSE(property.GetContent().has_value());
475 EXPECT_FALSE(property.GetLabel().has_value());
476 EXPECT_FALSE(property.GetEndIcon().has_value());
477 EXPECT_FALSE(property.GetSelectIcon().has_value());
478 EXPECT_FALSE(property.GetSelectIconSrc().has_value());
479 EXPECT_FALSE(property.GetFontSize().has_value());
480 EXPECT_FALSE(property.GetFontColor().has_value());
481 EXPECT_FALSE(property.GetFontWeight().has_value());
482 EXPECT_FALSE(property.GetLabelFontSize().has_value());
483 EXPECT_FALSE(property.GetLabelFontColor().has_value());
484 EXPECT_FALSE(property.GetLabelFontWeight().has_value());
485 }
486
487 /**
488 * @tc.name: MenuItemLayoutPropertyTestNg014
489 * @tc.desc: Verify Clone.
490 * @tc.type: FUNC
491 */
492 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg014, TestSize.Level1)
493 {
494 MenuItemLayoutProperty property;
495 property.UpdateStartIcon(ImageSourceInfo(IMAGE_SRC_URL));
496 property.UpdateContent("content");
497 property.UpdateEndIcon(ImageSourceInfo(IMAGE_SRC_URL));
498 property.UpdateLabel("label");
499 property.UpdateSelectIcon(true);
500 property.UpdateSelectIconSrc("select.png");
501 property.UpdateFontSize(Dimension(25.0f));
502 property.UpdateFontColor(Color::RED);
503 property.UpdateFontWeight(FontWeight::BOLD);
504 property.UpdateLabelFontSize(Dimension(35.0f));
505 property.UpdateLabelFontColor(Color::BLUE);
506 property.UpdateLabelFontWeight(FontWeight::LIGHTER);
507
508 auto cloneProperty = AceType::DynamicCast<MenuItemLayoutProperty>(property.Clone());
509 ASSERT_NE(cloneProperty, nullptr);
510 EXPECT_EQ(property.GetStartIcon().value(), cloneProperty->GetStartIcon().value());
511 EXPECT_EQ(property.GetContent().value(), cloneProperty->GetContent().value());
512 EXPECT_EQ(property.GetEndIcon().value(), cloneProperty->GetEndIcon().value());
513 EXPECT_EQ(property.GetLabel().value(), cloneProperty->GetLabel().value());
514 EXPECT_EQ(property.GetSelectIcon().value(), cloneProperty->GetSelectIcon().value());
515 EXPECT_EQ(property.GetSelectIconSrc().value(), cloneProperty->GetSelectIconSrc().value());
516 EXPECT_EQ(property.GetFontSize().value(), cloneProperty->GetFontSize().value());
517 EXPECT_EQ(property.GetFontColor().value(), cloneProperty->GetFontColor().value());
518 EXPECT_EQ(property.GetFontWeight().value(), cloneProperty->GetFontWeight().value());
519 EXPECT_EQ(property.GetLabelFontSize().value(), cloneProperty->GetLabelFontSize().value());
520 EXPECT_EQ(property.GetLabelFontColor().value(), cloneProperty->GetLabelFontColor().value());
521 EXPECT_EQ(property.GetLabelFontWeight().value(), cloneProperty->GetLabelFontWeight().value());
522 }
523
524 /**
525 * @tc.name: MenuItemLayoutPropertyTestNg015
526 * @tc.desc: Verify ToJsonValue.
527 * @tc.type: FUNC
528 */
529 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg015, TestSize.Level1)
530 {
531 MenuItemLayoutProperty property;
532 property.UpdateStartIcon(ImageSourceInfo(IMAGE_SRC_URL));
533 property.UpdateContent("content");
534 property.UpdateEndIcon(ImageSourceInfo(IMAGE_SRC_URL));
535 property.UpdateLabel("label");
536 property.UpdateSelectIcon(true);
537 property.UpdateSelectIconSrc("select.png");
538 property.UpdateFontSize(Dimension(25.0f));
539 property.UpdateFontColor(Color::RED);
540 property.UpdateFontWeight(FontWeight::BOLD);
541 property.UpdateLabelFontSize(Dimension(35.0f));
542 property.UpdateLabelFontColor(Color::BLUE);
543 property.UpdateLabelFontWeight(FontWeight::LIGHTER);
544
545 auto json = JsonUtil::Create(true);
546 property.ToJsonValue(json, filter);
547 auto labelFontJson = json->GetObject("labelFont");
548 auto contentFontJson = json->GetObject("contentFont");
549 EXPECT_EQ(json->GetString("startIcon"), IMAGE_SRC_URL);
550 EXPECT_EQ(json->GetString("content"), "content");
551 EXPECT_EQ(json->GetString("endIcon"), IMAGE_SRC_URL);
552 EXPECT_EQ(json->GetString("labelInfo"), "label");
553 EXPECT_EQ(json->GetString("selectIcon"), "select.png");
554 EXPECT_EQ(contentFontJson->GetString("size"), Dimension(25.0f).ToString());
555 EXPECT_EQ(json->GetString("contentFontColor"), Color::RED.ColorToString());
556 EXPECT_EQ(contentFontJson->GetString("weight"), V2::ConvertWrapFontWeightToStirng(FontWeight::BOLD));
557 EXPECT_EQ(labelFontJson->GetString("size"), Dimension(35.0f).ToString());
558 EXPECT_EQ(json->GetString("labelFontColor"), Color::BLUE.ColorToString());
559 EXPECT_EQ(labelFontJson->GetString("weight"), V2::ConvertWrapFontWeightToStirng(FontWeight::LIGHTER));
560 }
561
562 /**
563 * @tc.name: MenuItemLayoutPropertyTestNg016
564 * @tc.desc: Verify ToJsonValue.
565 * @tc.type: FUNC
566 */
567 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg016, TestSize.Level1)
568 {
569 MenuItemLayoutProperty property;
570 property.UpdateSelectIcon(false);
571 property.UpdateSelectIconSrc("select.png");
572
573 auto json = JsonUtil::Create(true);
574 property.ToJsonValue(json, filter);
575 EXPECT_EQ(json->GetString("selectIcon"), "false");
576 }
577
578 /**
579 * @tc.name: MenuItemLayoutPropertyTestNg017
580 * @tc.desc: Verify ToJsonValue.
581 * @tc.type: FUNC
582 */
583 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg017, TestSize.Level1)
584 {
585 MenuItemLayoutProperty property;
586 property.UpdateSelectIcon(true);
587
588 auto json = JsonUtil::Create(true);
589 property.ToJsonValue(json, filter);
590 EXPECT_EQ(json->GetString("selectIcon"), "true");
591 }
592
593 /**
594 * @tc.name: MenuItemLayoutPropertyTestNg018
595 * @tc.desc: Verify ToJsonValue.
596 * @tc.type: FUNC
597 */
598 HWTEST_F(MenuItemTestNg, MenuItemLayoutPropertyTestNg018, TestSize.Level1)
599 {
600 MenuItemModelNG MneuItemModelInstance;
601 MenuItemProperties itemOption;
602 MneuItemModelInstance.Create(itemOption);
603 MneuItemModelInstance.SetSelectIcon(true);
604 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
605 ASSERT_NE(itemNode, nullptr);
606 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
607 ASSERT_NE(itemProperty, nullptr);
608
609 auto json = JsonUtil::Create(true);
610 itemProperty->ToJsonValue(json, filter);
611 EXPECT_EQ(json->GetString("selectIcon"), "true");
612 }
613
614 /**
615 * @tc.name: MenuItemLayoutAlgorithm001
616 * @tc.desc: Test MenuItemLayoutAlgorithm Measure
617 * @tc.type: FUNC
618 */
619 HWTEST_F(MenuItemTestNg, MenuItemLayoutAlgorithm001, TestSize.Level1)
620 {
621 /**
622 * @tc.steps: step1. Create menuItem.
623 */
624 auto wrapperNode =
625 FrameNode::CreateFrameNode(V2::MENU_WRAPPER_ETS_TAG, 1, AceType::MakeRefPtr<MenuWrapperPattern>(1));
626 auto mainMenu = FrameNode::CreateFrameNode(
627 V2::MENU_ETS_TAG, 2, AceType::MakeRefPtr<MenuPattern>(1, TEXT_TAG, MenuType::CONTEXT_MENU));
628 auto subMenu = FrameNode::CreateFrameNode(
629 V2::MENU_ETS_TAG, 3, AceType::MakeRefPtr<MenuPattern>(1, TEXT_TAG, MenuType::SUB_MENU));
630 auto menuItemNode = FrameNode::CreateFrameNode(V2::MENU_ITEM_ETS_TAG, 4, AceType::MakeRefPtr<MenuItemPattern>());
631 auto leftNode = FrameNode::CreateFrameNode("", -1, AceType::MakeRefPtr<Pattern>());
632 auto rightNode = FrameNode::CreateFrameNode("", -1, AceType::MakeRefPtr<Pattern>());
633 menuItemNode->AddChild(leftNode);
634 menuItemNode->AddChild(rightNode);
635 menuItemNode->MountToParent(mainMenu);
636 mainMenu->MountToParent(wrapperNode);
637 subMenu->MountToParent(wrapperNode);
638 auto menuItemPattern = menuItemNode->GetPattern<MenuItemPattern>();
639 ASSERT_NE(menuItemPattern, nullptr);
640 auto algorithm = AceType::DynamicCast<MenuItemLayoutAlgorithm>(menuItemPattern->CreateLayoutAlgorithm());
641 ASSERT_NE(algorithm, nullptr);
642 auto props = menuItemNode->GetLayoutProperty();
643 ASSERT_NE(props, nullptr);
644 SizeF value(MENU_ITEM_SIZE_WIDTH, MENU_ITEM_SIZE_HEIGHT);
645 props->UpdateMarginSelfIdealSize(value);
646 props->UpdateContentConstraint();
647
648 /**
649 * @tc.steps: step2. execute Measure
650 * @tc.expected: prop is set as expected
651 */
652 algorithm->Measure(AceType::RawPtr(menuItemNode));
653 algorithm->Layout(AceType::RawPtr(menuItemNode));
654
655 props->UpdateUserDefinedIdealSize(
656 CalcSize(CalcLength(MENU_ITEM_SIZE_WIDTH), CalcLength(MENU_ITEM_SIZE_HEIGHT)));
657 algorithm->Measure(AceType::RawPtr(menuItemNode));
658 EXPECT_TRUE(props->calcLayoutConstraint_->selfIdealSize.has_value());
659 }
660
661 /**
662 * @tc.name: MenuItemViewTestNgCreate001
663 * @tc.desc: Verify Create.
664 * @tc.type: FUNC
665 */
666 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgCreate001, TestSize.Level1)
667 {
668 MenuItemModelNG MneuItemModelInstance;
669 MenuItemProperties itemOption;
670 MneuItemModelInstance.Create(itemOption);
671 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
672 ASSERT_NE(itemNode, nullptr);
673 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
674 ASSERT_NE(itemPattern, nullptr);
675 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
676 ASSERT_NE(itemProperty, nullptr);
677
678 ASSERT_EQ(itemNode->GetChildren().size(), 2);
679 auto leftRow = AceType::DynamicCast<FrameNode>(itemNode->GetChildAtIndex(0));
680 EXPECT_EQ(leftRow->GetChildren().size(), 0);
681 auto rightRow = AceType::DynamicCast<FrameNode>(itemNode->GetChildAtIndex(1));
682 EXPECT_EQ(rightRow->GetChildren().size(), 0);
683
684 ASSERT_TRUE(itemProperty->GetStartIcon().has_value());
685 EXPECT_EQ(itemProperty->GetStartIcon().value().GetSrc(), "");
686 ASSERT_TRUE(itemProperty->GetEndIcon().has_value());
687 EXPECT_EQ(itemProperty->GetEndIcon().value().GetSrc(), "");
688 ASSERT_TRUE(itemProperty->GetContent().has_value());
689 EXPECT_EQ(itemProperty->GetContent().value(), "");
690 ASSERT_TRUE(itemProperty->GetLabel().has_value());
691 EXPECT_EQ(itemProperty->GetLabel().value(), "");
692 }
693
694 /**
695 * @tc.name: MenuItemViewTestNgCreate002
696 * @tc.desc: Verify Create.
697 * @tc.type: FUNC
698 */
699 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgCreate002, TestSize.Level1)
700 {
701 MenuItemModelNG MneuItemModelInstance;
702 MenuItemProperties itemOption;
703 itemOption.content = "content";
704 itemOption.startIcon = ImageSourceInfo(IMAGE_SRC_URL);
705 itemOption.endIcon = ImageSourceInfo(IMAGE_SRC_URL);
706 itemOption.labelInfo = "label";
707 MneuItemModelInstance.Create(itemOption);
708 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
709 ASSERT_NE(itemNode, nullptr);
710 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
711 ASSERT_NE(itemPattern, nullptr);
712 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
713 ASSERT_NE(itemProperty, nullptr);
714
715 ASSERT_TRUE(itemProperty->GetStartIcon().has_value());
716 EXPECT_EQ(itemProperty->GetStartIcon().value().GetSrc(), IMAGE_SRC_URL);
717 ASSERT_TRUE(itemProperty->GetEndIcon().has_value());
718 EXPECT_EQ(itemProperty->GetEndIcon().value().GetSrc(), IMAGE_SRC_URL);
719 ASSERT_TRUE(itemProperty->GetContent().has_value());
720 EXPECT_EQ(itemProperty->GetContent().value(), "content");
721 ASSERT_TRUE(itemProperty->GetLabel().has_value());
722 EXPECT_EQ(itemProperty->GetLabel().value(), "label");
723 }
724
725 /**
726 * @tc.name: MenuItemViewTestNgCreate003
727 * @tc.desc: Verify GetStartSymbol.
728 * @tc.type: FUNC
729 */
730 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgCreate003, TestSize.Level1)
731 {
732 MenuItemModelNG MenuItemModelInstance;
733 MenuItemProperties itemOption;
734 MenuItemModelInstance.Create(itemOption);
735 MenuItemModelInstance.SetSelected(false);
736
737 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
738 ASSERT_NE(itemNode, nullptr);
739 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
740 ASSERT_NE(itemPattern, nullptr);
741 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
742 ASSERT_NE(itemProperty, nullptr);
743
744 ASSERT_EQ(itemNode->GetChildren().size(), 2u);
745 auto leftRow = AceType::DynamicCast<FrameNode>(itemNode->GetChildAtIndex(0));
746 EXPECT_EQ(leftRow->GetChildren().size(), 0u);
747 auto rightRow = AceType::DynamicCast<FrameNode>(itemNode->GetChildAtIndex(1));
748 EXPECT_EQ(rightRow->GetChildren().size(), 0u);
749
750 auto symbolNode = FrameNode::CreateFrameNode(
751 V2::SYMBOL_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
752 ASSERT_NE(symbolNode, nullptr);
753 auto property = symbolNode->GetLayoutProperty<TextLayoutProperty>();
754
755 auto pipeline = PipelineBase::GetCurrentContext();
756 CHECK_NULL_VOID(pipeline);
757 auto menuTheme = pipeline->GetTheme<MenuTheme>();
758 CHECK_NULL_VOID(menuTheme);
759 uint32_t symbolId = menuTheme->GetSymbolId();
760 ASSERT_NE(symbolId, 0);
761 property->UpdateSymbolSourceInfo(SymbolSourceInfo(symbolId));
762 auto symbolProps = symbolNode->GetLayoutProperty<MenuItemLayoutProperty>();
763 ASSERT_NE(symbolProps, nullptr);
764 EXPECT_EQ(symbolProps->GetStartSymbol(), nullptr);
765 EXPECT_EQ(symbolProps->GetEndSymbol(), nullptr);
766 leftRow = symbolNode;
767 rightRow = symbolNode;
768 EXPECT_NE(symbolProps->GetStartSymbol(), nullptr);
769 EXPECT_NE(symbolProps->GetEndSymbol(), nullptr);
770 }
771
772 /**
773 * @tc.name: MenuItemViewTestNgCreate004
774 * @tc.desc: Verify GetSelectIconSymbol.
775 * @tc.type: FUNC
776 */
777 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgCreate004, TestSize.Level1)
778 {
779 MenuItemModelNG MenuItemModelInstance;
780 MenuItemProperties itemOption;
781 MenuItemModelInstance.Create(itemOption);
782 MenuItemModelInstance.SetSelected(false);
783
784 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
785 ASSERT_NE(itemNode, nullptr);
786 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
787 ASSERT_NE(itemPattern, nullptr);
788 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
789 ASSERT_NE(itemProperty, nullptr);
790
791 ASSERT_EQ(itemNode->GetChildren().size(), 2u);
792 auto leftRow = AceType::DynamicCast<FrameNode>(itemNode->GetChildAtIndex(0));
793 EXPECT_EQ(leftRow->GetChildren().size(), 0u);
794 auto rightRow = AceType::DynamicCast<FrameNode>(itemNode->GetChildAtIndex(1));
795 EXPECT_EQ(rightRow->GetChildren().size(), 0u);
796
797 auto symbolNode = FrameNode::CreateFrameNode(
798 V2::SYMBOL_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<TextPattern>());
799 ASSERT_NE(symbolNode, nullptr);
800 auto property = symbolNode->GetLayoutProperty<TextLayoutProperty>();
801 auto pipeline = PipelineBase::GetCurrentContext();
802 CHECK_NULL_VOID(pipeline);
803 auto menuTheme = pipeline->GetTheme<MenuTheme>();
804 CHECK_NULL_VOID(menuTheme);
805 uint32_t symbolId = menuTheme->GetSymbolId();
806 ASSERT_NE(symbolId, 0);
807 auto symbolProps = symbolNode->GetLayoutProperty<MenuItemLayoutProperty>();
808 MenuItemModelInstance.SetSelected(true);
809
810 property->UpdateSymbolSourceInfo(SymbolSourceInfo(symbolId));
811 EXPECT_EQ(leftRow, symbolNode);
812 property->UpdateSymbolSourceInfo(SymbolSourceInfo(DEFAULT_SYMBOL_ID));
813 EXPECT_NE(leftRow, symbolNode);
814 }
815
816
817 /**
818 * @tc.name: MenuItemViewTestNgSetSelectIcon001
819 * @tc.desc: Verify SetSelectIcon.
820 * @tc.type: FUNC
821 */
822 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetSelectIcon001, TestSize.Level1)
823 {
824 MenuItemModelNG MneuItemModelInstance;
825 MenuItemProperties itemOption;
826 MneuItemModelInstance.Create(itemOption);
827 MneuItemModelInstance.SetSelectIcon(true);
828 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
829 ASSERT_NE(itemNode, nullptr);
830 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
831 ASSERT_NE(itemProperty, nullptr);
832 EXPECT_EQ(itemProperty->GetSelectIcon().value_or(false), true);
833 }
834
835 /**
836 * @tc.name: MenuItemViewTestNgSetSelectIcon002
837 * @tc.desc: Verify SetSelectIcon.
838 * @tc.type: FUNC
839 */
840 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetSelectIcon002, TestSize.Level1)
841 {
842 MenuItemModelNG MneuItemModelInstance;
843 MenuItemProperties itemOption;
844 MneuItemModelInstance.SetSelectIcon(true);
845 MneuItemModelInstance.Create(itemOption);
846 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
847 ASSERT_NE(itemNode, nullptr);
848 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
849 ASSERT_NE(itemProperty, nullptr);
850 EXPECT_FALSE(itemProperty->GetSelectIcon().has_value());
851 }
852
853 /**
854 * @tc.name: MenuItemViewTestNgSetSelectIconSrc001
855 * @tc.desc: Verify SetSelectIconSrc.
856 * @tc.type: FUNC
857 */
858 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetSelectIconSrc001, TestSize.Level1)
859 {
860 MenuItemModelNG MneuItemModelInstance;
861 MenuItemProperties itemOption;
862 MneuItemModelInstance.Create(itemOption);
863 MneuItemModelInstance.SetSelectIconSrc("selectIcon.png");
864 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
865 ASSERT_NE(itemNode, nullptr);
866 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
867 ASSERT_NE(itemPattern, nullptr);
868 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
869 ASSERT_NE(itemProperty, nullptr);
870
871 EXPECT_EQ(itemProperty->GetSelectIconSrc().value_or(""), "selectIcon.png");
872 }
873
874 /**
875 * @tc.name: MenuItemViewTestNgSetSelectIconSrc002
876 * @tc.desc: Verify SetSelectIconSrc.
877 * @tc.type: FUNC
878 */
879 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetSelectIconSrc002, TestSize.Level1)
880 {
881 MenuItemModelNG MneuItemModelInstance;
882 MenuItemProperties itemOption;
883 MneuItemModelInstance.SetSelectIconSrc("selectIcon.png");
884 MneuItemModelInstance.Create(itemOption);
885 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
886 ASSERT_NE(itemNode, nullptr);
887 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
888 ASSERT_NE(itemProperty, nullptr);
889 EXPECT_FALSE(itemProperty->GetSelectIconSrc().has_value());
890 }
891
892 /**
893 * @tc.name: MenuItemViewTestNg001
894 * @tc.desc: Verify MenuItemModelNG methods.
895 * @tc.type: FUNC
896 */
897 HWTEST_F(MenuItemTestNg, MenuItemViewTestNg001, TestSize.Level1)
898 {
899 MenuItemModelNG MneuItemModelInstance;
900 MenuItemProperties itemOption;
901 MneuItemModelInstance.Create(itemOption);
902 MneuItemModelInstance.SetFontSize(Dimension());
__anon412623ce0402(WeakPtr<NG::FrameNode> weakPtr) 903 MneuItemModelInstance.SetSelectIconSymbol([](WeakPtr<NG::FrameNode> weakPtr) {});
__anon412623ce0502(bool onChange) 904 MneuItemModelInstance.SetOnChange([](bool onChange) {});
905 std::vector<std::string> families = {"cursive"};
906 MneuItemModelInstance.SetFontFamily(families);
907 MneuItemModelInstance.SetLabelFontFamily(families);
908
909 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
910 ASSERT_NE(itemNode, nullptr);
911 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
912 ASSERT_NE(itemPattern, nullptr);
913 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
914 ASSERT_NE(itemProperty, nullptr);
915
916 EXPECT_FALSE(itemProperty->GetFontSize().has_value());
917 }
918
919 /**
920 * @tc.name: MenuItemViewTestNg002
921 * @tc.desc: Verify MenuItemModelNG methods with frameNode.
922 * @tc.type: FUNC
923 */
924 HWTEST_F(MenuItemTestNg, MenuItemViewTestNg002, TestSize.Level1)
925 {
926 MenuItemModelNG MneuItemModelInstance;
927 MenuItemProperties itemOption;
928 MneuItemModelInstance.Create(itemOption);
929
930 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
931 ASSERT_NE(itemNode, nullptr);
932 FrameNode *frameNode = itemNode.GetRawPtr();
933 CHECK_NULL_VOID(frameNode);
934 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
935 ASSERT_NE(itemPattern, nullptr);
936 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
937 ASSERT_NE(itemProperty, nullptr);
938
939 MneuItemModelInstance.SetSelected(frameNode, true);
__anon412623ce0602(WeakPtr<NG::FrameNode> weakPtr) 940 MneuItemModelInstance.SetSelectIconSymbol(frameNode, [](WeakPtr<NG::FrameNode> weakPtr) {});
941 std::vector<std::string> families = {"cursive"};
942 MneuItemModelInstance.SetFontFamily(frameNode, families);
943
944 MneuItemModelInstance.SetFontColor(frameNode, Color::RED);
945 EXPECT_EQ(itemProperty->GetFontColor().value(), Color::RED);
946
947 MneuItemModelInstance.SetFontColor(frameNode, std::nullopt);
948 ASSERT_FALSE(itemProperty->GetFontColor().has_value());
949
950 MneuItemModelInstance.SetFontSize(frameNode, Dimension(10));
951 EXPECT_EQ(itemProperty->GetFontSize().value(), Dimension(10));
952
953 MneuItemModelInstance.SetFontSize(frameNode, Dimension(0));
954 EXPECT_FALSE(itemProperty->GetFontSize().has_value());
955
956 MneuItemModelInstance.SetFontWeight(frameNode, FontWeight::BOLD);
957 EXPECT_EQ(itemProperty->GetFontWeight().value(), FontWeight::BOLD);
958
959 MneuItemModelInstance.SetFontStyle(frameNode, Ace::FontStyle::ITALIC);
960 EXPECT_EQ(itemProperty->GetItalicFontStyle().value(), Ace::FontStyle::ITALIC);
961
962 MneuItemModelInstance.SetSelectIcon(frameNode, true);
963 EXPECT_EQ(itemProperty->GetSelectIcon().value_or(false), true);
964
965 MneuItemModelInstance.SetSelectIconSrc(frameNode, "selectIcon.png");
966 EXPECT_EQ(itemProperty->GetSelectIconSrc().value_or(""), "selectIcon.png");
967 }
968
969 /**
970 * @tc.name: MenuItemViewTestNg003
971 * @tc.desc: Verify MenuItemModelNG methods with frameNode about label.
972 * @tc.type: FUNC
973 */
974 HWTEST_F(MenuItemTestNg, MenuItemViewTestNg003, TestSize.Level1)
975 {
976 MenuItemModelNG MneuItemModelInstance;
977 MenuItemProperties itemOption;
978 MneuItemModelInstance.Create(itemOption);
979
980 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
981 ASSERT_NE(itemNode, nullptr);
982 FrameNode *frameNode = itemNode.GetRawPtr();
983 CHECK_NULL_VOID(frameNode);
984 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
985 ASSERT_NE(itemPattern, nullptr);
986 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
987 ASSERT_NE(itemProperty, nullptr);
988
989 std::vector<std::string> families = {"cursive"};
990 MneuItemModelInstance.SetLabelFontFamily(frameNode, families);
991
992 MneuItemModelInstance.SetLabelFontColor(frameNode, Color::RED);
993 EXPECT_EQ(itemProperty->GetLabelFontColor().value(), Color::RED);
994
995 MneuItemModelInstance.SetLabelFontColor(frameNode, std::nullopt);
996 ASSERT_FALSE(itemProperty->GetLabelFontColor().has_value());
997
998 MneuItemModelInstance.SetLabelFontSize(frameNode, Dimension(10));
999 EXPECT_EQ(itemProperty->GetLabelFontSize().value(), Dimension(10));
1000
1001 MneuItemModelInstance.SetLabelFontSize(frameNode, Dimension(0));
1002 EXPECT_FALSE(itemProperty->GetLabelFontSize().has_value());
1003
1004 MneuItemModelInstance.SetLabelFontWeight(frameNode, FontWeight::BOLD);
1005 EXPECT_EQ(itemProperty->GetLabelFontWeight().value(), FontWeight::BOLD);
1006
1007 MneuItemModelInstance.SetLabelFontStyle(frameNode, Ace::FontStyle::ITALIC);
1008 EXPECT_EQ(itemProperty->GetLabelItalicFontStyle().value(), Ace::FontStyle::ITALIC);
1009 }
1010
1011 /**
1012 * @tc.name: MenuItemViewTestNgSetFontSize001
1013 * @tc.desc: Verify SetFontSize.
1014 * @tc.type: FUNC
1015 */
1016 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetFontSize001, TestSize.Level1)
1017 {
1018 MenuItemModelNG MneuItemModelInstance;
1019 MenuItemProperties itemOption;
1020 MneuItemModelInstance.Create(itemOption);
1021 MneuItemModelInstance.SetFontSize(Dimension());
1022 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1023 ASSERT_NE(itemNode, nullptr);
1024 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1025 ASSERT_NE(itemPattern, nullptr);
1026 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1027 ASSERT_NE(itemProperty, nullptr);
1028
1029 EXPECT_FALSE(itemProperty->GetFontSize().has_value());
1030 }
1031
1032 /**
1033 * @tc.name: MenuItemViewTestNgSetFontSize002
1034 * @tc.desc: Verify SetFontSize.
1035 * @tc.type: FUNC
1036 */
1037 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetFontSize002, TestSize.Level1)
1038 {
1039 MenuItemModelNG MneuItemModelInstance;
1040 MenuItemProperties itemOption;
1041 MneuItemModelInstance.Create(itemOption);
1042 MneuItemModelInstance.SetFontSize(Dimension(40.0));
1043 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1044 ASSERT_NE(itemNode, nullptr);
1045 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1046 ASSERT_NE(itemPattern, nullptr);
1047 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1048 ASSERT_NE(itemProperty, nullptr);
1049
1050 ASSERT_TRUE(itemProperty->GetFontSize().has_value());
1051 EXPECT_EQ(itemProperty->GetFontSize().value(), Dimension(40.0));
1052 }
1053
1054 /**
1055 * @tc.name: MenuItemViewTestNgSetFontSize003
1056 * @tc.desc: Verify SetFontSize.
1057 * @tc.type: FUNC
1058 */
1059 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetFontSize003, TestSize.Level1)
1060 {
1061 MenuItemModelNG MneuItemModelInstance;
1062 MenuItemProperties itemOption;
1063 MneuItemModelInstance.SetFontSize(Dimension(40.0));
1064 MneuItemModelInstance.Create(itemOption);
1065 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1066 ASSERT_NE(itemNode, nullptr);
1067 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1068 ASSERT_NE(itemProperty, nullptr);
1069 ASSERT_FALSE(itemProperty->GetFontSize().has_value());
1070 }
1071
1072 /**
1073 * @tc.name: MenuItemViewTestNgSetFontWeight001
1074 * @tc.desc: Verify SetFontWeight.
1075 * @tc.type: FUNC
1076 */
1077 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetFontWeight001, TestSize.Level1)
1078 {
1079 MenuItemModelNG MneuItemModelInstance;
1080 MenuItemProperties itemOption;
1081 MneuItemModelInstance.Create(itemOption);
1082 MneuItemModelInstance.SetFontWeight(FontWeight::BOLD);
1083 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1084 ASSERT_NE(itemNode, nullptr);
1085 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1086 ASSERT_NE(itemPattern, nullptr);
1087 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1088 ASSERT_NE(itemProperty, nullptr);
1089
1090 ASSERT_TRUE(itemProperty->GetFontWeight().has_value());
1091 EXPECT_EQ(itemProperty->GetFontWeight().value(), FontWeight::BOLD);
1092 }
1093
1094 /**
1095 * @tc.name: MenuItemViewTestNgSetFontWeight002
1096 * @tc.desc: Verify SetFontWeight.
1097 * @tc.type: FUNC
1098 */
1099 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetFontWeight002, TestSize.Level1)
1100 {
1101 MenuItemModelNG MneuItemModelInstance;
1102 MenuItemProperties itemOption;
1103 MneuItemModelInstance.SetFontWeight(FontWeight::BOLD);
1104 MneuItemModelInstance.Create(itemOption);
1105 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1106 ASSERT_NE(itemNode, nullptr);
1107 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1108 ASSERT_NE(itemProperty, nullptr);
1109 ASSERT_FALSE(itemProperty->GetFontWeight().has_value());
1110 }
1111
1112 /**
1113 * @tc.name: MenuItemViewTestNgSetFontColor001
1114 * @tc.desc: Verify SetFontColor.
1115 * @tc.type: FUNC
1116 */
1117 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetFontColor001, TestSize.Level1)
1118 {
1119 MenuItemModelNG MneuItemModelInstance;
1120 MenuItemProperties itemOption;
1121 MneuItemModelInstance.Create(itemOption);
1122 MneuItemModelInstance.SetFontColor(Color::RED);
1123 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1124 ASSERT_NE(itemNode, nullptr);
1125 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1126 ASSERT_NE(itemPattern, nullptr);
1127 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1128 ASSERT_NE(itemProperty, nullptr);
1129
1130 ASSERT_TRUE(itemProperty->GetFontColor().has_value());
1131 EXPECT_EQ(itemProperty->GetFontColor().value(), Color::RED);
1132 }
1133
1134 /**
1135 * @tc.name: MenuItemViewTestNgSetFontColor002
1136 * @tc.desc: Verify SetFontColor.
1137 * @tc.type: FUNC
1138 */
1139 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetFontColor002, TestSize.Level1)
1140 {
1141 MenuItemModelNG MneuItemModelInstance;
1142 MenuItemProperties itemOption;
1143 MneuItemModelInstance.SetFontColor(Color::RED);
1144 MneuItemModelInstance.Create(itemOption);
1145 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1146 ASSERT_NE(itemNode, nullptr);
1147 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1148 ASSERT_NE(itemProperty, nullptr);
1149 ASSERT_FALSE(itemProperty->GetFontColor().has_value());
1150 }
1151
1152 /**
1153 * @tc.name: MenuItemViewTestNgSetFontColor003
1154 * @tc.desc: Verify SetFontColor.
1155 * @tc.type: FUNC
1156 */
1157 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetFontColor003, TestSize.Level1)
1158 {
1159 MenuItemModelNG MneuItemModelInstance;
1160 MenuItemProperties itemOption;
1161 MneuItemModelInstance.Create(itemOption);
1162 MneuItemModelInstance.SetFontColor(Color::RED);
1163 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1164 ASSERT_NE(itemNode, nullptr);
1165 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1166 ASSERT_NE(itemPattern, nullptr);
1167 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1168 ASSERT_NE(itemProperty, nullptr);
1169
1170 ASSERT_TRUE(itemProperty->GetFontColor().has_value());
1171 EXPECT_EQ(itemProperty->GetFontColor().value(), Color::RED);
1172
1173 ViewStackProcessor::GetInstance()->Push(itemNode);
1174 MneuItemModelInstance.SetFontColor(std::nullopt);
1175 ASSERT_FALSE(itemProperty->GetFontColor().has_value());
1176 ViewStackProcessor::GetInstance()->Finish();
1177 }
1178
1179 /**
1180 * @tc.name: MenuItemViewTestNgSetLabelFontSize001
1181 * @tc.desc: Verify SetLabelFontSize.
1182 * @tc.type: FUNC
1183 */
1184 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetLabelFontSize001, TestSize.Level1)
1185 {
1186 MenuItemModelNG MneuItemModelInstance;
1187 MenuItemProperties itemOption;
1188 MneuItemModelInstance.Create(itemOption);
1189 MneuItemModelInstance.SetLabelFontSize(Dimension());
1190 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1191 ASSERT_NE(itemNode, nullptr);
1192 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1193 ASSERT_NE(itemPattern, nullptr);
1194 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1195 ASSERT_NE(itemProperty, nullptr);
1196
1197 EXPECT_FALSE(itemProperty->GetLabelFontSize().has_value());
1198 }
1199
1200 /**
1201 * @tc.name: MenuItemViewTestNgSetLabelFontSize002
1202 * @tc.desc: Verify SetLabelFontSize.
1203 * @tc.type: FUNC
1204 */
1205 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetLabelFontSize002, TestSize.Level1)
1206 {
1207 MenuItemModelNG MneuItemModelInstance;
1208 MenuItemProperties itemOption;
1209 MneuItemModelInstance.Create(itemOption);
1210 MneuItemModelInstance.SetLabelFontSize(Dimension(40.0));
1211 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1212 ASSERT_NE(itemNode, nullptr);
1213 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1214 ASSERT_NE(itemPattern, nullptr);
1215 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1216 ASSERT_NE(itemProperty, nullptr);
1217
1218 ASSERT_TRUE(itemProperty->GetLabelFontSize().has_value());
1219 EXPECT_EQ(itemProperty->GetLabelFontSize().value(), Dimension(40.0));
1220 }
1221
1222 /**
1223 * @tc.name: MenuItemViewTestNgSetLabelFontSize003
1224 * @tc.desc: Verify SetLabelFontSize.
1225 * @tc.type: FUNC
1226 */
1227 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetLabelFontSize003, TestSize.Level1)
1228 {
1229 MenuItemModelNG MneuItemModelInstance;
1230 MenuItemProperties itemOption;
1231 MneuItemModelInstance.SetLabelFontSize(Dimension(40.0));
1232 MneuItemModelInstance.Create(itemOption);
1233 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1234 ASSERT_NE(itemNode, nullptr);
1235 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1236 ASSERT_NE(itemProperty, nullptr);
1237 ASSERT_FALSE(itemProperty->GetLabelFontSize().has_value());
1238 }
1239
1240 /**
1241 * @tc.name: MenuItemViewTestNgSetLabelFontWeight001
1242 * @tc.desc: Verify SetLabelFontWeight.
1243 * @tc.type: FUNC
1244 */
1245 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetLabelFontWeight001, TestSize.Level1)
1246 {
1247 MenuItemModelNG MneuItemModelInstance;
1248 MenuItemProperties itemOption;
1249 MneuItemModelInstance.Create(itemOption);
1250 MneuItemModelInstance.SetLabelFontWeight(FontWeight::BOLD);
1251 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1252 ASSERT_NE(itemNode, nullptr);
1253 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1254 ASSERT_NE(itemPattern, nullptr);
1255 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1256 ASSERT_NE(itemProperty, nullptr);
1257
1258 ASSERT_TRUE(itemProperty->GetLabelFontWeight().has_value());
1259 EXPECT_EQ(itemProperty->GetLabelFontWeight().value(), FontWeight::BOLD);
1260 }
1261
1262 /**
1263 * @tc.name: MenuItemViewTestNgSetLabelFontWeight002
1264 * @tc.desc: Verify SetLabelFontWeight.
1265 * @tc.type: FUNC
1266 */
1267 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetLabelFontWeight002, TestSize.Level1)
1268 {
1269 MenuItemModelNG MneuItemModelInstance;
1270 MenuItemProperties itemOption;
1271 MneuItemModelInstance.SetLabelFontWeight(FontWeight::BOLD);
1272 MneuItemModelInstance.Create(itemOption);
1273 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1274 ASSERT_NE(itemNode, nullptr);
1275 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1276 ASSERT_NE(itemProperty, nullptr);
1277 ASSERT_FALSE(itemProperty->GetLabelFontWeight().has_value());
1278 }
1279
1280 /**
1281 * @tc.name: MenuItemViewTestNgSetLabelFontColor001
1282 * @tc.desc: Verify SetLabelFontColor.
1283 * @tc.type: FUNC
1284 */
1285 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetLabelFontColor001, TestSize.Level1)
1286 {
1287 MenuItemModelNG MneuItemModelInstance;
1288 MenuItemProperties itemOption;
1289 MneuItemModelInstance.Create(itemOption);
1290 MneuItemModelInstance.SetLabelFontColor(Color::RED);
1291 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1292 ASSERT_NE(itemNode, nullptr);
1293 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1294 ASSERT_NE(itemPattern, nullptr);
1295 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1296 ASSERT_NE(itemProperty, nullptr);
1297
1298 ASSERT_TRUE(itemProperty->GetLabelFontColor().has_value());
1299 EXPECT_EQ(itemProperty->GetLabelFontColor().value(), Color::RED);
1300 }
1301
1302 /**
1303 * @tc.name: MenuItemViewTestNgSetLabelFontColor002
1304 * @tc.desc: Verify SetLabelFontColor.
1305 * @tc.type: FUNC
1306 */
1307 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetLabelFontColor002, TestSize.Level1)
1308 {
1309 MenuItemModelNG MneuItemModelInstance;
1310 MenuItemProperties itemOption;
1311 MneuItemModelInstance.SetLabelFontColor(Color::RED);
1312 MneuItemModelInstance.Create(itemOption);
1313 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1314 ASSERT_NE(itemNode, nullptr);
1315 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1316 ASSERT_NE(itemProperty, nullptr);
1317 ASSERT_FALSE(itemProperty->GetLabelFontColor().has_value());
1318 }
1319
1320 /**
1321 * @tc.name: MenuItemViewTestNgSetLabelFontColor003
1322 * @tc.desc: Verify SetLabelFontColor.
1323 * @tc.type: FUNC
1324 */
1325 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetLabelFontColor003, TestSize.Level1)
1326 {
1327 MenuItemModelNG MneuItemModelInstance;
1328 MenuItemProperties itemOption;
1329 MneuItemModelInstance.Create(itemOption);
1330 MneuItemModelInstance.SetLabelFontColor(Color::RED);
1331 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1332 ASSERT_NE(itemNode, nullptr);
1333 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1334 ASSERT_NE(itemPattern, nullptr);
1335 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1336 ASSERT_NE(itemProperty, nullptr);
1337
1338 ASSERT_TRUE(itemProperty->GetLabelFontColor().has_value());
1339 EXPECT_EQ(itemProperty->GetLabelFontColor().value(), Color::RED);
1340
1341 ViewStackProcessor::GetInstance()->Push(itemNode);
1342 MneuItemModelInstance.SetLabelFontColor(std::nullopt);
1343 ASSERT_FALSE(itemProperty->GetLabelFontColor().has_value());
1344 ViewStackProcessor::GetInstance()->Finish();
1345 }
1346 /**
1347 * @tc.name: MenuItemSetSelectedChangeEvent001
1348 * @tc.desc: Verify SetFontSize.
1349 * @tc.type: FUNC
1350 */
1351 HWTEST_F(MenuItemTestNg, MenuItemSetSelectedChangeEvent001, TestSize.Level1)
1352 {
1353 MenuItemModelNG MneuItemModelInstance;
1354 bool isSelected = false;
__anon412623ce0702(bool select) 1355 auto changeEvent = [&isSelected](bool select) { isSelected = select; };
1356 MenuItemProperties itemOption;
1357 MneuItemModelInstance.Create(itemOption);
1358 MneuItemModelInstance.SetSelectedChangeEvent(changeEvent);
1359
1360 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1361 ASSERT_NE(itemNode, nullptr);
1362
1363 auto itemProperty = itemNode->GetEventHub<NG::MenuItemEventHub>();
1364 ASSERT_NE(itemProperty, nullptr);
1365 EXPECT_TRUE(itemProperty->GetSelectedChangeEvent());
1366 }
1367
1368 /**
1369 * @tc.name: MenuItemViewTestNgSetLabelFontStyle001
1370 * @tc.desc: Verify SetLabelFontStyle.
1371 * @tc.type: FUNC
1372 */
1373 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetLabelFontStyle001, TestSize.Level1)
1374 {
1375 /**
1376 * @tc.steps: step1. create MenuItemModelNG object and set LabelFontStyle properties.
1377 */
1378 MenuItemModelNG MneuItemModelInstance;
1379 MenuItemProperties itemOption;
1380 MneuItemModelInstance.Create(itemOption);
1381 MneuItemModelInstance.SetLabelFontStyle(Ace::FontStyle::ITALIC);
1382
1383 /**
1384 * @tc.steps: step2. get the frameNode, menuItemPattern and menuItemLayoutProperty.
1385 * @tc.expected: step2. check whether the objects is available.
1386 */
1387 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1388 ASSERT_NE(itemNode, nullptr);
1389 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1390 ASSERT_NE(itemPattern, nullptr);
1391 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1392 ASSERT_NE(itemProperty, nullptr);
1393
1394 /**
1395 * @tc.steps: step3. get the labelFontStyle properties of menuItemLayoutProperty.
1396 * @tc.expected: step3. check whether the labelFontStyle properties is is correct.
1397 */
1398 ASSERT_TRUE(itemProperty->GetLabelItalicFontStyle().has_value());
1399 EXPECT_EQ(itemProperty->GetLabelItalicFontStyle().value(), Ace::FontStyle::ITALIC);
1400 }
1401
1402 /**
1403 * @tc.name: MenuItemViewTestNgSetFontStyle001
1404 * @tc.desc: Verify SetFontStyle.
1405 * @tc.type: FUNC
1406 */
1407 HWTEST_F(MenuItemTestNg, MenuItemViewTestNgSetFontStyle001, TestSize.Level1)
1408 {
1409 /**
1410 * @tc.steps: step1. create MenuItemModelNG object and set FontStyle properties.
1411 */
1412 MenuItemModelNG MneuItemModelInstance;
1413 MenuItemProperties itemOption;
1414 MneuItemModelInstance.Create(itemOption);
1415 MneuItemModelInstance.SetFontStyle(Ace::FontStyle::ITALIC);
1416
1417 /**
1418 * @tc.steps: step2. get the frameNode, menuItemPattern and menuItemLayoutProperty.
1419 * @tc.expected: step2. check whether the objects is available.
1420 */
1421 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1422 ASSERT_NE(itemNode, nullptr);
1423 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1424 ASSERT_NE(itemPattern, nullptr);
1425 auto itemProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1426 ASSERT_NE(itemProperty, nullptr);
1427
1428 /**
1429 * @tc.steps: step3. get the FontStyle properties of menuItemLayoutProperty.
1430 * @tc.expected: step3. check whether the FontStyle properties is is correct.
1431 */
1432 ASSERT_TRUE(itemProperty->GetItalicFontStyle().has_value());
1433 EXPECT_EQ(itemProperty->GetItalicFontStyle().value(), Ace::FontStyle::ITALIC);
1434 }
1435
1436 /**
1437 * @tc.name: MenuItemPaintMethod001
1438 * @tc.desc: Test MenuItem GetOverlayDrawFunction.
1439 * @tc.type: FUNC
1440 */
1441 HWTEST_F(MenuItemTestNg, MenuItemPaintMethod001, TestSize.Level1)
1442 {
1443 /**
1444 * @tc.steps: step1. prepare paint method object.
1445 */
1446 RefPtr<MenuItemPaintProperty> paintProp = AceType::MakeRefPtr<MenuItemPaintProperty>();
1447 RefPtr<MenuItemPaintMethod> paintMethod = AceType::MakeRefPtr<MenuItemPaintMethod>();
1448 Testing::MockCanvas canvas;
1449 EXPECT_CALL(canvas, AttachBrush(_)).WillRepeatedly(ReturnRef(canvas));
1450 EXPECT_CALL(canvas, DetachBrush()).WillRepeatedly(ReturnRef(canvas));
1451 EXPECT_CALL(canvas, DetachBrush()).WillRepeatedly(ReturnRef(canvas));
1452 EXPECT_CALL(canvas, DrawPath(_)).Times(AtLeast(1));
1453 /**
1454 * @tc.steps: step2. update paint property and execute GetOverlayDrawFunction.
1455 * @tc.expected: return value are as expected.
1456 */
1457 WeakPtr<RenderContext> renderContext;
1458 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1459 PaintWrapper* paintWrapper = new PaintWrapper(renderContext, geometryNode, paintProp);
1460 auto result = paintMethod->GetOverlayDrawFunction(paintWrapper);
1461 EXPECT_NE(result, nullptr);
1462 result(canvas);
1463 delete paintWrapper;
1464 paintWrapper = nullptr;
1465 paintProp->UpdateDividerColor(Color::RED);
1466 paintWrapper = new PaintWrapper(renderContext, geometryNode, paintProp);
1467 result = paintMethod->GetOverlayDrawFunction(paintWrapper);
1468 EXPECT_NE(result, nullptr);
1469 result(canvas);
1470 delete paintWrapper;
1471 paintWrapper = nullptr;
1472 paintProp->UpdateNeedDivider(true);
1473 paintWrapper = new PaintWrapper(renderContext, geometryNode, paintProp);
1474 result = paintMethod->GetOverlayDrawFunction(paintWrapper);
1475 EXPECT_NE(result, nullptr);
1476 result(canvas);
1477 delete paintWrapper;
1478 paintWrapper = nullptr;
1479 }
1480
1481 /**
1482 * @tc.name: MenuItemPaintMethod002
1483 * @tc.desc: Test MenuItem GetOverlayDrawFunction.
1484 * @tc.type: FUNC
1485 */
1486 HWTEST_F(MenuItemTestNg, MenuItemPaintMethod002, TestSize.Level1)
1487 {
1488 /**
1489 * @tc.steps: step1. prepare paint method object.
1490 */
1491 RefPtr<MenuItemPaintProperty> paintProp = AceType::MakeRefPtr<MenuItemPaintProperty>();
1492 RefPtr<MenuItemPaintMethod> paintMethod = AceType::MakeRefPtr<MenuItemPaintMethod>();
1493 Testing::MockCanvas canvas;
1494 EXPECT_CALL(canvas, AttachBrush(_)).WillRepeatedly(ReturnRef(canvas));
1495 EXPECT_CALL(canvas, DetachBrush()).WillRepeatedly(ReturnRef(canvas));
1496 EXPECT_CALL(canvas, DetachBrush()).WillRepeatedly(ReturnRef(canvas));
1497 EXPECT_CALL(canvas, DrawPath(_)).Times(AtLeast(1));
1498 /**
1499 * @tc.steps: step2. update paint property and execute GetOverlayDrawFunction.
1500 * @tc.expected: return value are as expected.
1501 */
1502 WeakPtr<RenderContext> renderContext;
1503 RefPtr<GeometryNode> geometryNode = AceType::MakeRefPtr<GeometryNode>();
1504 PaintWrapper* paintWrapper = new PaintWrapper(renderContext, geometryNode, paintProp);
1505 auto result = paintMethod->GetOverlayDrawFunction(paintWrapper);
1506 EXPECT_NE(result, nullptr);
1507 result(canvas);
1508 delete paintWrapper;
1509 paintWrapper = nullptr;
1510 paintProp->UpdatePress(false);
1511 paintProp->UpdateHover(false);
1512 paintProp->UpdateNeedDivider(true);
1513 paintProp->UpdateDividerColor(Color::RED);
1514 paintProp->UpdateStrokeWidth(Dimension(1.0f, DimensionUnit::PX));
1515 paintProp->UpdateStartMargin(Dimension(1.0f, DimensionUnit::PX));
1516 paintProp->UpdateEndMargin(Dimension(1.0f, DimensionUnit::PX));
1517 paintWrapper = new PaintWrapper(renderContext, geometryNode, paintProp);
1518 result = paintMethod->GetOverlayDrawFunction(paintWrapper);
1519 EXPECT_NE(result, nullptr);
1520 result(canvas);
1521 delete paintWrapper;
1522 paintWrapper = nullptr;
1523 }
1524
1525 /**
1526 * @tc.name: MenuItemTestNgTextMaxLines001
1527 * @tc.desc: Verify MenuItem's MaxLines.
1528 * @tc.type: FUNC
1529 */
1530 HWTEST_F(MenuItemTestNg, MenuItemTestNgTextMaxLines001, TestSize.Level1)
1531 {
1532 /**
1533 * @tc.steps: step1. set font scale to 1.75.
1534 */
1535 auto context = MockPipelineContext::GetCurrentContext();
1536 ASSERT_NE(context, nullptr);
1537 context->fontScale_ = 1.75f;
1538
1539 /**
1540 * @tc.steps: step2. create menu and initialize.
1541 */
1542 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1543 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
__anon412623ce0802(ThemeType type) 1544 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly([](ThemeType type) -> RefPtr<Theme> {
1545 if (type == TextTheme::TypeId()) {
1546 return AceType::MakeRefPtr<TextTheme>();
1547 } else if (type == IconTheme::TypeId()) {
1548 return AceType::MakeRefPtr<IconTheme>();
1549 } else if (type == SelectTheme::TypeId()) {
1550 return AceType::MakeRefPtr<SelectTheme>();
1551 } else {
1552 return AceType::MakeRefPtr<MenuTheme>();
1553 }
1554 });
1555 auto pipeline = PipelineBase::GetCurrentContext();
1556 CHECK_NULL_VOID(pipeline);
1557 auto menuTheme = pipeline->GetTheme<MenuTheme>();
1558 CHECK_NULL_VOID(menuTheme);
1559 InitMenuItemTestNg();
1560 InitMenuItemTestNg();
1561 MenuModelNG menuModelInstance;
1562 MenuItemModelNG menuItemModelInstance;
1563 menuModelInstance.Create();
1564 menuModelInstance.SetFontStyle(Ace::FontStyle::ITALIC);
1565 MenuItemProperties itemOption;
1566 itemOption.content = "content";
1567 itemOption.labelInfo = "label";
1568 menuItemModelInstance.Create(itemOption);
1569 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1570 ASSERT_NE(itemNode, nullptr);
1571 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1572 ASSERT_NE(itemPattern, nullptr);
1573 auto menuItemLayoutProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1574 ASSERT_NE(menuItemLayoutProperty, nullptr);
1575 itemPattern->OnModifyDone();
1576
1577 /**
1578 * @tc.steps: step2. get textLayoutProperty and verify maxLines setting.
1579 * @tc.expected: MenuItem's maxLines == MenuTheme's maxLines
1580 */
1581 auto contentNode = itemPattern->GetContentNode();
1582 ASSERT_NE(contentNode, nullptr);
1583 auto textLayoutProperty = contentNode->GetLayoutProperty<TextLayoutProperty>();
1584 ASSERT_NE(textLayoutProperty, nullptr);
1585 }
1586
1587 /**
1588 * @tc.name: MenuItemTestNgText001
1589 * @tc.desc: Verify UpdateNeedDivider.
1590 * @tc.type: FUNC
1591 */
1592 HWTEST_F(MenuItemTestNg, MenuItemTestNgText001, TestSize.Level1)
1593 {
1594 MenuItemModelNG MneuItemModelInstance;
1595 MenuItemProperties itemOption;
1596 MneuItemModelInstance.Create(itemOption);
1597 MneuItemModelInstance.SetFontStyle(Ace::FontStyle::ITALIC);
1598
1599 auto itemNode = AceType::DynamicCast<FrameNode>(ViewStackProcessor::GetInstance()->Finish());
1600 ASSERT_NE(itemNode, nullptr);
1601 auto itemPattern = itemNode->GetPattern<MenuItemPattern>();
1602 ASSERT_NE(itemPattern, nullptr);
1603 auto menu =
1604 FrameNode::CreateFrameNode(V2::MENU_ETS_TAG, 2, AceType::MakeRefPtr<MenuPattern>(1, TEXT_TAG, MenuType::MENU));
1605 CHECK_NULL_VOID(menu);
1606 auto menuProperty = menu->GetLayoutProperty<MenuLayoutProperty>();
1607 CHECK_NULL_VOID(menuProperty);
1608 menuProperty->UpdateItemDivider(ITEM_DIVIDER);
1609 auto menuItemLayoutProperty = itemNode->GetLayoutProperty<MenuItemLayoutProperty>();
1610 ASSERT_NE(menuItemLayoutProperty, nullptr);
1611 itemPattern->UpdateNeedDivider(true);
1612 }
1613 } // namespace OHOS::Ace::NG
1614