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 #define private public
18 #define protected public
19 #include "core/interfaces/native/node/extension_custom_node.h"
20 #include "test/mock/core/pipeline/mock_pipeline_context.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS::Ace {
26 class ExtensionCustomNodeTestNg : public testing::Test {
27 public:
SetUpTestSuite()28 static void SetUpTestSuite()
29 {
30 NG::MockPipelineContext::SetUp();
31 }
TearDownTestSuite()32 static void TearDownTestSuite()
33 {
34 NG::MockPipelineContext::TearDown();
35 }
36 };
37
38 /**
39 * @tc.name: ExtensionCustomNodeTestNg001
40 * @tc.desc: test ExtensionCustomNode SetMeasureCallback, SetLayoutCallback, OnMeasure and OnLayout
41 * @tc.type: FUNC
42 */
HWTEST_F(ExtensionCustomNodeTestNg, ExtensionCustomNodeTestNg001, TestSize.Level1)43 HWTEST_F(ExtensionCustomNodeTestNg, ExtensionCustomNodeTestNg001, TestSize.Level1)
44 {
45 /**
46 * @tc.steps1: initialize parameters.
47 */
48 auto customNode = AceType::MakeRefPtr<NG::ExtensionCustomNode>();
49 auto param = NG::LayoutConstraintF();
50 param.minSize = NG::SizeF(50, 50);
51 param.maxSize = NG::SizeF(100, 100);
52 param.percentReference = NG::SizeF(100, 100);
53 auto extensionLayoutConstraint = NG::ExtensionLayoutConstraint::Create(param);
54
55 /**
56 * @tc.steps2: Call the function SetMeasureCallback, SetLayoutCallback, OnMeasure and OnLayout.
57 * @tc.expected: The function is run ok.
58 */
59 customNode->SetMeasureCallback([](NG::LayoutConstraintF& layoutConstraint)->void {});
60 customNode->SetLayoutCallback([](NG::OffsetF& position)->void {});
61 customNode->OnMeasure(extensionLayoutConstraint);
62 customNode->OnLayout(100, 100, 10, 10);
63 EXPECT_NE(customNode, nullptr);
64 }
65 } // namespace OHOS::Ace