1 /* 2 * Copyright (c) 2023 iSoftStone Information Technology (Group) 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 #include "gtest/gtest.h" 16 #include "core/components_ng/base/extension_handler.h" 17 #include "core/pipeline_ng/pipeline_context.h" 18 #include "core/components_ng/pattern/navigation/navigation_group_node.h" 19 #include "core/components_ng/base/modifier.h" 20 21 using namespace testing; 22 using namespace testing::ext; 23 24 namespace OHOS::Ace::NG { 25 26 class ExtensionHandlerTestNg : public testing::Test { 27 }; 28 29 /** 30 * @tc.name: ExtensionHandlerTest001 31 * @tc.desc: Measure 32 * @tc.type: FUNC 33 */ 34 HWTEST_F(ExtensionHandlerTestNg, ExtensionHandlerTest001, TestSize.Level1) 35 { 36 class ExtensionHandler test; 37 struct ExtensionLayoutConstraint layoutConstraint; 38 layoutConstraint.maxWidth = 10; 39 test.Measure(layoutConstraint); 40 int32_t width = 0; __anone3dc7c670102(const ExtensionLayoutConstraint& layout) 41 test.SetInnerMeasureImpl([&width](const ExtensionLayoutConstraint& layout) { width = layout.maxWidth; }); 42 test.Measure(layoutConstraint); 43 EXPECT_EQ(layoutConstraint.maxWidth, 10); 44 } 45 46 /** 47 * @tc.name: ExtensionHandlerTest002 48 * @tc.desc: Layout 49 * @tc.type: FUNC 50 */ 51 HWTEST_F(ExtensionHandlerTestNg, ExtensionHandlerTest002, TestSize.Level1) 52 { 53 class ExtensionHandler test; 54 int32_t width = 10; 55 int32_t height = 10; 56 int32_t positionX = 10; 57 int32_t positionY = 10; 58 int32_t count = 0; 59 test.Layout(width, height, positionX, positionY); 60 test.SetInnerLayoutImpl([&count](int32_t width, int32_t height, int32_t positionX, int32_t positionY) __anone3dc7c670202(int32_t width, int32_t height, int32_t positionX, int32_t positionY) 61 { count = height; }); 62 test.Layout(width, height, positionX, positionY); 63 EXPECT_EQ(count, 10); 64 } 65 66 /** 67 * @tc.name: ExtensionHandlerTest003 68 * @tc.desc: Draw 69 * @tc.type: FUNC 70 */ 71 HWTEST_F(ExtensionHandlerTestNg, ExtensionHandlerTest003, TestSize.Level1) 72 { 73 class ExtensionHandler test; 74 RSCanvas canvas; 75 float width = 0; 76 float height = 0; 77 DrawingContext context {canvas, width, height}; 78 test.Draw(context); 79 int32_t res = 5; __anone3dc7c670302(DrawingContext& context) 80 test.SetInnerDrawImpl([&res](DrawingContext& context) { res = context.width; }); 81 test.Draw(context); 82 EXPECT_EQ(context.width, 0); 83 } 84 85 /** 86 * @tc.name: ExtensionHandlerTest004 87 * @tc.desc: ForegroundDraw 88 * @tc.type: FUNC 89 */ 90 HWTEST_F(ExtensionHandlerTestNg, ExtensionHandlerTest004, TestSize.Level1) 91 { 92 class ExtensionHandler test; 93 RSCanvas canvas; 94 float width = 0; 95 float height = 0; 96 DrawingContext context {canvas, width, height}; 97 test.ForegroundDraw(context); 98 int32_t res = 5; __anone3dc7c670402(DrawingContext& context) 99 test.SetInnerForegroundDrawImpl([&res](DrawingContext& context) { res = context.width; }); 100 test.ForegroundDraw(context); 101 EXPECT_EQ(context.height, 0); 102 } 103 104 /** 105 * @tc.name: ExtensionHandlerTest005 106 * @tc.desc: OverlayDraw 107 * @tc.type: FUNC 108 */ 109 HWTEST_F(ExtensionHandlerTestNg, ExtensionHandlerTest005, TestSize.Level1) 110 { 111 class ExtensionHandler test; 112 RSCanvas canvas; 113 float width = 0; 114 float height = 0; 115 DrawingContext context {canvas, width, height}; 116 test.OverlayDraw(context); 117 int32_t res = 5; __anone3dc7c670502(DrawingContext& context) 118 test.SetInnerOverlayDrawImpl([&res](DrawingContext& context) { res = context.width; }); 119 test.OverlayDraw(context); 120 EXPECT_EQ(context.width, 0); 121 } 122 123 /** 124 * @tc.name: ExtensionHandlerTest006 125 * @tc.desc: OverlayDraw 126 * @tc.type: FUNC 127 */ 128 HWTEST_F(ExtensionHandlerTestNg, ExtensionHandlerTest006, TestSize.Level1) 129 { 130 class ExtensionHandler test; 131 RSCanvas canvas; 132 float width = 0; 133 float height = 0; 134 DrawingContext context { canvas, width, height }; 135 bool isFunc = false; 136 RefPtr<NG::DrawModifier> drawModifier = AceType::MakeRefPtr<NG::DrawModifier>(); __anone3dc7c670602(NG::DrawingContext& drawingContext) 137 drawModifier->drawForegroundFunc = [&isFunc](NG::DrawingContext& drawingContext) { isFunc = true; }; 138 test.SetDrawModifier(drawModifier); 139 test.ForegroundDraw(context); 140 EXPECT_TRUE(isFunc); 141 } 142 }