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 
17 #define protected public
18 #define private public
19 #include "core/components_ng/base/view_full_update_model.h"
20 #include "core/components_ng/base/view_full_update_model_ng.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS::Ace::NG {
26 namespace {
27     std::string TEST;
28 }; // namespace
29 
30 class ViewFullUpdateModelNgTest : public testing::Test {
31 public:
SetUpTestCase()32     static void SetUpTestCase() {}
TearDownTestCase()33     static void TearDownTestCase() {}
34 };
35 
36 /**
37  * @tc.name: ViewStackProcessorTestNg001
38  * @tc.desc: Test the operation of view_full_update_model_ng
39  * @tc.type: FUNC
40  */
41 HWTEST_F(ViewFullUpdateModelNgTest, ViewFullUpdateModelNgTest001, TestSize.Level1)
42 {
43     /**
44      * @tc.steps: step1. Build a object viewFullUpdateModelNG.
45      * @tc.steps: step2. callback CreateNode.push NodeInfo is null.
46      * @tc.expected: step2. Return expected results..
47      */
48     ViewFullUpdateModelNG viewFullUpdateModelNG;
49     NodeInfo info;
50     RefPtr<AceType> resault = viewFullUpdateModelNG.CreateNode(std::move(info));
51     EXPECT_NE(resault, nullptr);
52 }
53 
54 /**
55  * @tc.name: ViewStackProcessorTestNg002
56  * @tc.desc: Test the operation of view_full_update_model_ng
57  * @tc.type: FUNC
58  */
59 HWTEST_F(ViewFullUpdateModelNgTest, ViewFullUpdateModelNgTest002, TestSize.Level1)
60 {
61     /**
62      * @tc.steps: step1. Build a object viewFullUpdateModelNG.
63      * @tc.steps: step2. callback CreateNode.push NodeInfo is not null.
64      * @tc.expected: step2. Return expected results..
65      */
66     std::string viewId = "id";
67     ViewFullUpdateModelNG viewFullUpdateModelNG;
68 
__anon349f73a20202() 69     auto callback = []() {
70         TEST = "test";
71     };
72     NodeInfo info = { .viewId = viewId,
73         .appearFunc = std::move(callback),
74         .isStatic = true };
75     RefPtr<AceType> resault = viewFullUpdateModelNG.CreateNode(std::move(info));
76     EXPECT_TRUE(resault);
77 }
78 
79 /**
80  * @tc.name: ViewStackProcessorTestNg003
81  * @tc.desc: Test the operation of view_full_update_model_ng
82  * @tc.type: FUNC
83  */
84 HWTEST_F(ViewFullUpdateModelNgTest, ViewFullUpdateModelNgTest003, TestSize.Level1)
85 {
86     /**
87      * @tc.steps: step1. Build a object viewFullUpdateModelNG.
88      * @tc.steps: step2. callback CreateNode.push NodeInfo is not null.
89      * @tc.expected: step2. Return expected results..
90      */
91     std::string viewId = "id";
92     WeakPtr<AceType> viewNode;
93     ViewFullUpdateModelNG viewFullUpdateModelNG;
94 
__anon349f73a20302() 95     auto callback = []() {
96         TEST = "test";
97     };
98 
__anon349f73a20402(const RefPtr<AceType>& node = nullptr) 99     auto updateViewNodeFunction = [&viewNode](const RefPtr<AceType>& node = nullptr) {
100         viewNode = node;
101     };
102 
103     NodeInfo info = { .viewId = viewId,
104         .appearFunc = std::move(callback),
105         .updateNodeFunc = std::move(updateViewNodeFunction),
106         .isStatic = false };
107     RefPtr<AceType> resault = viewFullUpdateModelNG.CreateNode(std::move(info));
108     EXPECT_NE(info.appearFunc, nullptr);
109     EXPECT_TRUE(resault);
110 }
111 
112 /**
113  * @tc.name: ViewStackProcessorTestNg004
114  * @tc.desc: Test the operation of view_full_update_model_ng
115  * @tc.type: FUNC
116  */
117 HWTEST_F(ViewFullUpdateModelNgTest, ViewFullUpdateModelNgTest004, TestSize.Level1)
118 {
119     /**
120      * @tc.steps: step1. Build a object viewFullUpdateModelNG.
121      * @tc.steps: step2. callback CreateNode.push NodeInfo is not null.
122      * @tc.expected: step2. Return expected results..
123      */
124     std::string viewId = "id";
125     WeakPtr<AceType> viewNode;
126     RefPtr<AceType> view;
127     ViewFullUpdateModelNG viewFullUpdateModelNG;
128 
__anon349f73a20502() 129     auto callback = []() {
130         TEST = "test";
131     };
132 
__anon349f73a20602() 133     auto renderFunction = [&view]() -> RefPtr<AceType> {
134         return nullptr;
135     };
136 
__anon349f73a20702(const RefPtr<AceType>& node = nullptr) 137     auto updateViewNodeFunction = [&viewNode](const RefPtr<AceType>& node = nullptr) {
138         viewNode = node;
139     };
140     NodeInfo info = { .viewId = viewId,
141         .appearFunc = std::move(callback),
142         .renderFunc = std::move(renderFunction),
143         .updateNodeFunc = std::move(updateViewNodeFunction),
144         .isStatic = false };
145     RefPtr<AceType> resault = viewFullUpdateModelNG.CreateNode(std::move(info));
146     EXPECT_NE(info.updateNodeFunc, nullptr);
147     EXPECT_TRUE(resault);
148 }
149 } // namespace OHOS::Ace::NG