• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <thread>
17 #include <chrono>
18 #define private public
19 #include "interfaces/inner_api/form_render/include/form_renderer.h"
20 #include "interfaces/inner_api/form_render/include/form_renderer_dispatcher_stub.h"
21 #undef private
22 #include "test/mock/interfaces/mock_form_renderer_dispatcher_stub.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS::Ace {
28 namespace {
29 class FormRendererDispatcherStubTest : public testing::Test {
30 public:
SetUpTestCase()31     static void SetUpTestCase() {};
32 
TearDownTestCase()33     static void TearDownTestCase() {};
34 };
35 
36 /**
37  * @tc.number: FormRendererDispatcherStubTest_001
38  * @tc.name: OnRemoteRequest
39  * @tc.desc:
40  */
41 HWTEST_F(FormRendererDispatcherStubTest, FormRendererDispatcherStubTest_001, TestSize.Level1)
42 {
43     sptr<AppExecFwk::MockFormRendererDispatherStub> renderDispather = new AppExecFwk::MockFormRendererDispatherStub();
44     MessageParcel data;
45     MessageParcel reply;
46     MessageOption option;
47     uint32_t code = 9;
48     std::u16string name = u"form_render_dispatcher_stub";
49     data.WriteInterfaceToken(name);
50     EXPECT_EQ(renderDispather->OnRemoteRequest(code, data, reply, option), ERR_INVALID_VALUE);
51 
52     std::u16string descriptor = FormRendererDispatcherStub::GetDescriptor();
53     data.WriteInterfaceToken(descriptor);
54     bool flag = false;
55     auto itFunc = renderDispather->memberFuncMap_.find(code);
56     if (itFunc != renderDispather->memberFuncMap_.end()) {
57         auto memberFunc = itFunc->second;
58         if (memberFunc != nullptr) {
59             flag = true;
60         }
61     }
62     EXPECT_FALSE(flag);
63 
64     code = 3;
65     itFunc = renderDispather->memberFuncMap_.find(code);
66     if (itFunc != renderDispather->memberFuncMap_.end()) {
67         auto memberFunc = itFunc->second;
68         if (memberFunc != nullptr) {
69             flag = true;
70         }
71     }
72     EXPECT_TRUE(flag);
73     flag = false;
74 
75     itFunc = renderDispather->memberFuncMap_.find(code);
76     itFunc->second = nullptr;
77     if (itFunc != renderDispather->memberFuncMap_.end()) {
78         auto memberFunc = itFunc->second;
79         if (memberFunc != nullptr) {
80             flag = true;
81         }
82     }
83     EXPECT_FALSE(flag);
84 }
85 
86 /**
87  * @tc.number: FormRendererDispatcherStubTest_002
88  * @tc.name: HandleDispatchPointerEvent
89  * @tc.desc:
90  */
91 HWTEST_F(FormRendererDispatcherStubTest, FormRendererDispatcherStubTest_002, TestSize.Level1)
92 {
93     sptr<AppExecFwk::MockFormRendererDispatherStub> renderDispather = new AppExecFwk::MockFormRendererDispatherStub();
94     MessageParcel data;
95     MessageParcel reply;
96 
97     EXPECT_EQ(renderDispather->HandleDispatchPointerEvent(data, reply), ERR_INVALID_VALUE);
98 
99     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
100     ASSERT_TRUE(pointerEvent);
101     bool flag = false;
102     pointerEvent->WriteToParcel(data);
103     if (pointerEvent->ReadFromParcel(data)) {
104         flag = true;
105     }
106 
107     EXPECT_TRUE(flag);
108 }
109 
110 /**
111  * @tc.number: FormRendererDispatcherStubTest_003
112  * @tc.name: HandleSetAllowUpdate, HandleDispatchSurfaceChangeEvent, HandleSetObscured,
113  *           HandleOnAccessibilityChildTreeRegister, HandleOnAccessibilityChildTreeDeregister,
114  *           HandleOnAccessibilityDumpChildInfo
115  * @tc.desc:
116  */
117 HWTEST_F(FormRendererDispatcherStubTest, FormRendererDispatcherStubTest_003, TestSize.Level1)
118 {
119     sptr<AppExecFwk::MockFormRendererDispatherStub> renderDispather = new AppExecFwk::MockFormRendererDispatherStub();
120     MessageParcel data;
121     MessageParcel reply;
122 
123     EXPECT_EQ(renderDispather->HandleSetAllowUpdate(data, reply), ERR_OK);
124     EXPECT_EQ(renderDispather->HandleDispatchSurfaceChangeEvent(data, reply), ERR_OK);
125     EXPECT_EQ(renderDispather->HandleSetObscured(data, reply), ERR_OK);
126     EXPECT_EQ(renderDispather->HandleOnAccessibilityChildTreeRegister(data, reply), ERR_OK);
127     EXPECT_EQ(renderDispather->HandleOnAccessibilityChildTreeDeregister(data, reply), ERR_OK);
128     EXPECT_EQ(renderDispather->HandleOnAccessibilityDumpChildInfo(data, reply), ERR_OK);
129 }
130 
131 /**
132  * @tc.number: FormRendererDispatcherStubTest_004
133  * @tc.name: HandleOnAccessibilityTransferHoverEvent
134  * @tc.desc:
135  */
136 HWTEST_F(FormRendererDispatcherStubTest, FormRendererDispatcherStubTest_004, TestSize.Level1)
137 {
138     sptr<AppExecFwk::MockFormRendererDispatherStub> renderDispather = new AppExecFwk::MockFormRendererDispatherStub();
139     MessageParcel data;
140     MessageParcel reply;
141     EXPECT_EQ(renderDispather->HandleOnAccessibilityTransferHoverEvent(data, reply), ERR_INVALID_VALUE);
142 
143     float point = 0.0;
144     int32_t type = 0;
145     int64_t time = 0;
146     data.WriteFloat(point);
147     data.WriteInt32(type);
148     data.WriteInt64(time);
149     EXPECT_TRUE(data.ReadFloat(point));
150     EXPECT_TRUE(data.ReadInt32(type));
151     EXPECT_TRUE(data.ReadInt64(time));
152 }
153 }
154 }