• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-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 #define private public
16 #include "input_method_ability.h"
17 #include "itypes_util.h"
18 #undef private
19 
20 #include <cstdint>
21 #include <gtest/gtest.h>
22 #include <string>
23 
24 #include "global.h"
25 #include "inputmethod_sysevent.h"
26 #include "itypes_util.h"
27 #include "tdd_util.h"
28 
29 using namespace testing::ext;
30 namespace OHOS {
31 namespace MiscServices {
32 class ITypesUtilTest : public testing::Test {
33 public:
34     class InputMethodEngineListenerImpl : public InputMethodEngineListener {
35     public:
36         InputMethodEngineListenerImpl() = default;
37         ~InputMethodEngineListenerImpl() = default;
38 
OnKeyboardStatus(bool isShow)39         void OnKeyboardStatus(bool isShow)
40         {
41             IMSA_HILOGI("InputMethodEngineListenerImpl OnKeyboardStatus");
42         }
43 
OnInputStart()44         void OnInputStart()
45         {
46             IMSA_HILOGI("InputMethodEngineListenerImpl OnInputStart");
47         }
48 
OnInputStop()49         int32_t OnInputStop()
50         {
51             IMSA_HILOGI("InputMethodEngineListenerImpl OnInputStop");
52             return ErrorCode::NO_ERROR;
53         }
54 
OnSetCallingWindow(uint32_t windowId)55         void OnSetCallingWindow(uint32_t windowId)
56         {
57             IMSA_HILOGI("InputMethodEngineListenerImpl OnSetCallingWindow");
58         }
59 
OnSetSubtype(const SubProperty & property)60         void OnSetSubtype(const SubProperty &property)
61         {
62             IMSA_HILOGI("InputMethodEngineListenerImpl OnSetSubtype");
63         }
64 
OnSecurityChange(int32_t security)65         void OnSecurityChange(int32_t security)
66         {
67             IMSA_HILOGI("InputMethodEngineListenerImpl OnSecurityChange");
68         }
69 
ReceivePrivateCommand(const std::unordered_map<std::string,PrivateDataValue> & privateCommand)70         void ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand)
71         {
72             IMSA_HILOGI("InputMethodEngineListenerImpl ReceivePrivateCommand");
73         }
74     };
75 
SetUp()76     void SetUp()
77     {
78         IMSA_HILOGI("ITypesUtilTest::SetUp");
79     }
TearDown()80     void TearDown()
81     {
82         IMSA_HILOGI("ITypesUtilTest::TearDown");
83     }
84 };
85 
86 /**
87  * @tc.name: testMarshallAndUnMarshallUint64
88  * @tc.desc: IMA
89  * @tc.type: FUNC
90  * @tc.require:
91  */
92 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallUint64, TestSize.Level0)
93 {
94     IMSA_HILOGI("ITypesUtilTest testMarshallingUint64 Test START");
95     MessageParcel data;
96     uint64_t input = 10001;
97     data.WriteUint64(input);
98     auto ret = ITypesUtil::Marshalling(input, data);
99     EXPECT_TRUE(ret);
100     ret = ITypesUtil::Unmarshalling(input, data);
101     EXPECT_TRUE(ret);
102 }
103 
104 /**
105  * @tc.name: testMarshallAndUnMarshallProperty
106  * @tc.desc: IMA
107  * @tc.type: FUNC
108  * @tc.require:
109  */
110 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallProperty, TestSize.Level0)
111 {
112     IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallProperty Test START");
113     MessageParcel data;
114     Property input;
115     string name = "test";
116     data.WriteString(name);
117     auto ret = ITypesUtil::Unmarshalling(input, data);
118     EXPECT_FALSE(ret);
119     ret = ITypesUtil::Marshalling(input, data);
120     EXPECT_TRUE(ret);
121 }
122 
123 /**
124  * @tc.name: testMarshallAndUnMarshallSubProperty
125  * @tc.desc: IMA
126  * @tc.type: FUNC
127  * @tc.require:
128  */
129 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallSubProperty, TestSize.Level0)
130 {
131     IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallSubProperty Test START");
132     MessageParcel data;
133     SubProperty input;
134     string name = "test";
135     data.WriteString(name);
136     auto ret = ITypesUtil::Unmarshalling(input, data);
137     EXPECT_FALSE(ret);
138     ret = ITypesUtil::Marshalling(input, data);
139     EXPECT_TRUE(ret);
140 }
141 
142 /**
143  * @tc.name: testMarshallAndUnMarshallInputAttribute
144  * @tc.desc: IMA
145  * @tc.type: FUNC
146  * @tc.require:
147  */
148 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallInputAttribute, TestSize.Level0)
149 {
150     IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallInputAttribute Test START");
151     MessageParcel data;
152     InputAttribute input;
153     string name = "test";
154     data.WriteString(name);
155     auto ret = ITypesUtil::Unmarshalling(input, data);
156     EXPECT_FALSE(ret);
157     ret = ITypesUtil::Marshalling(input, data);
158     EXPECT_TRUE(ret);
159 }
160 
161 /**
162  * @tc.name: testMarshallAndUnMarshallInputAttributeSuccess
163  * @tc.desc: IMA
164  * @tc.type: FUNC
165  * @tc.require:
166  */
167 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallInputAttributeSuccess_WithBundleName, TestSize.Level0)
168 {
169     IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallInputAttributeSuccess Test START");
170     MessageParcel data;
171     InputAttribute attrIn { .bundleName = "MyBundleName" };
172     auto ret = ITypesUtil::Marshalling(attrIn, data);
173     EXPECT_TRUE(ret);
174 
175     InputAttribute attrOut;
176     ret = ITypesUtil::Unmarshalling(attrOut, data);
177     EXPECT_TRUE(ret);
178     EXPECT_EQ(attrIn, attrOut);
179     EXPECT_EQ(attrIn.bundleName, attrOut.bundleName);
180 }
181 
182 /**
183  * @tc.name: testMarshallAndUnMarshallInputAttributeSuccess
184  * @tc.desc: IMA
185  * @tc.type: FUNC
186  * @tc.require:
187  */
188 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallInputAttribute_WithEmptyBundleName, TestSize.Level0)
189 {
190     IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallInputAttributeSuccess Test START");
191     MessageParcel data;
192     InputAttribute attrIn { .bundleName = "" };
193     auto ret = ITypesUtil::Marshalling(attrIn, data);
194     EXPECT_TRUE(ret);
195 
196     InputAttribute attrOut;
197     ret = ITypesUtil::Unmarshalling(attrOut, data);
198     EXPECT_TRUE(ret);
199     EXPECT_EQ(attrIn, attrOut);
200     EXPECT_EQ(attrIn.bundleName, attrOut.bundleName);
201 }
202 
203 /**
204  * @tc.name: testMarshallAndUnMarshallTextTotalConfig
205  * @tc.desc: IMA
206  * @tc.type: FUNC
207  * @tc.require:
208  */
209 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallTextTotalConfig, TestSize.Level0)
210 {
211     IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallTextTotalConfig Test START");
212     MessageParcel data;
213     TextTotalConfig input;
214     auto ret = ITypesUtil::Unmarshalling(input, data);
215     EXPECT_FALSE(ret);
216     ret = ITypesUtil::Marshalling(input, data);
217     EXPECT_TRUE(ret);
218 }
219 
220 /**
221  * @tc.name: testMarshallAndUnMarshallInputClientInfo
222  * @tc.desc: IMA
223  * @tc.type: FUNC
224  * @tc.require:
225  */
226 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallInputClientInfo, TestSize.Level0)
227 {
228     IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallInputClientInfo Test START");
229     MessageParcel data;
230     InputClientInfo input;
231     auto ret = ITypesUtil::Unmarshalling(input, data);
232     EXPECT_FALSE(ret);
233     ret = ITypesUtil::Marshalling(input, data);
234     EXPECT_TRUE(ret);
235 }
236 
237 /**
238  * @tc.name: testMarshallAndUnMarshallImeWindowInfo
239  * @tc.desc: IMA
240  * @tc.type: FUNC
241  * @tc.require:
242  */
243 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallImeWindowInfo, TestSize.Level0)
244 {
245     IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallImeWindowInfo Test START");
246     MessageParcel data;
247     ImeWindowInfo input;
248     auto ret = ITypesUtil::Unmarshalling(input, data);
249     EXPECT_FALSE(ret);
250     ret = ITypesUtil::Marshalling(input, data);
251     EXPECT_TRUE(ret);
252 }
253 
254 /**
255  * @tc.name: testMarshallAndUnMarshallSysPanelStatus
256  * @tc.desc: IMA
257  * @tc.type: FUNC
258  * @tc.require:
259  */
260 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallSysPanelStatus, TestSize.Level0)
261 {
262     IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallSysPanelStatus Test START");
263     MessageParcel data;
264     SysPanelStatus input;
265     auto ret = ITypesUtil::Unmarshalling(input, data);
266     EXPECT_FALSE(ret);
267     ret = ITypesUtil::Marshalling(input, data);
268     EXPECT_TRUE(ret);
269 }
270 
271 /**
272  * @tc.name: testMarshallAndUnMarshallElementName
273  * @tc.desc: IMA
274  * @tc.type: FUNC
275  * @tc.require:
276  */
277 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallElementName, TestSize.Level0)
278 {
279     IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallElementName Test START");
280     MessageParcel data;
281     OHOS::AppExecFwk::ElementName input;
282     auto ret = ITypesUtil::Unmarshalling(input, data);
283     EXPECT_FALSE(ret);
284     ret = ITypesUtil::Marshalling(input, data);
285     EXPECT_TRUE(ret);
286 }
287 
288 /**
289  * @tc.name: testMarshallAndUnMarshallInputType
290  * @tc.type: FUNC
291  * @tc.require:
292  */
293 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallInputType, TestSize.Level0)
294 {
295     IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallInputType Test START");
296     MessageParcel data;
297     InputType input { InputType::NONE };
298     auto ret = ITypesUtil::Unmarshalling(input, data);
299     EXPECT_FALSE(ret);
300     data.WriteInt32(1);
301     ret = ITypesUtil::Unmarshalling(input, data);
302     EXPECT_TRUE(ret);
303     ret = ITypesUtil::Marshalling(input, data);
304     EXPECT_TRUE(ret);
305 }
306 
307 /**
308  * @tc.name: testMarshallAndUnMarshallRange
309  * @tc.type: FUNC
310  * @tc.require:
311  */
312 HWTEST_F(ITypesUtilTest, testMarshallAndUnMarshallRange, TestSize.Level0)
313 {
314     IMSA_HILOGI("ITypesUtilTest testMarshallAndUnMarshallRange Test START");
315     MessageParcel data;
316     Range input;
317     auto ret = ITypesUtil::Unmarshalling(input, data);
318     EXPECT_FALSE(ret);
319     ret = ITypesUtil::Marshalling(input, data);
320     EXPECT_TRUE(ret);
321 }
322 
323 /**
324  * @tc.name: testInputMethodSysEvent
325  * @tc.type: FUNC
326  * @tc.require:
327  */
328 HWTEST_F(ITypesUtilTest, testInputMethodSysEvent, TestSize.Level0)
329 {
330     IMSA_HILOGI("ITypesUtilTest testInputMethodSysEvent Test START");
331     auto ret = InputMethodSysEvent::GetInstance().StartTimerForReport();
332     EXPECT_TRUE(ret);
333 }
334 } // namespace MiscServices
335 } // namespace OHOS
336