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 "animate_impl.h"
17 #include "core/interfaces/arkoala/arkoala_api.h"
18 #include "dialog_model.h"
19 #include "error_code.h"
20 #include "event_converter.h"
21 #include "gtest/gtest.h"
22 #include "native_animate.h"
23 #include "native_interface.h"
24 #include "native_node.h"
25 #include "node_extened.h"
26 #include "node_model.h"
27 
28 using namespace testing;
29 using namespace testing::ext;
30 using namespace OHOS::Ace::DialogModel;
31 
32 class DialogModelTest : public testing::Test {
33 public:
SetUpTestCase()34     static void SetUpTestCase() {};
TearDownTestCase()35     static void TearDownTestCase() {};
36 };
37 
OnWillDismissEvent(int32_t reason)38 bool OnWillDismissEvent(int32_t reason)
39 {
40     return true;
41 }
42 
43 /**
44  * @tc.name: DialogModelTest001
45  * @tc.desc: Test Create function.
46  * @tc.type: FUNC
47  */
48 HWTEST_F(DialogModelTest, DialogModelTest001, TestSize.Level1)
49 {
50     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
51     ASSERT_EQ(nativeDialogHandle, nullptr);
52 
53     Dispose(nativeDialogHandle);
54 }
55 
56 /**
57  * @tc.name: DialogModelTest002
58  * @tc.desc: Test Create function.
59  * @tc.type: FUNC
60  */
61 HWTEST_F(DialogModelTest, DialogModelTest002, TestSize.Level1)
62 {
63     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
64     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
65     ASSERT_NE(nativeDialogHandle, nullptr);
66 
67     Dispose(nativeDialogHandle);
68     nativeDialogHandle = nullptr;
69 }
70 
71 /**
72  * @tc.name: DialogModelTest003
73  * @tc.desc: Test SetContent function.
74  * @tc.type: FUNC
75  */
76 HWTEST_F(DialogModelTest, DialogModelTest003, TestSize.Level1)
77 {
78     int32_t ret = SetContent(nullptr, nullptr);
79     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
80 }
81 
82 /**
83  * @tc.name: DialogModelTest004
84  * @tc.desc: Test SetContent function.
85  * @tc.type: FUNC
86  */
87 HWTEST_F(DialogModelTest, DialogModelTest004, TestSize.Level1)
88 {
89     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
90     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
91     ASSERT_NE(nativeDialogHandle, nullptr);
92     ArkUI_NodeHandle nodeHandle = new ArkUI_Node();
93     int32_t ret = SetContent(nativeDialogHandle, nodeHandle);
94     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
95     Dispose(nativeDialogHandle);
96     nativeDialogHandle = nullptr;
97     delete nodeHandle;
98 }
99 
100 /**
101  * @tc.name: DialogModelTest005
102  * @tc.desc: Test RemoveContent function.
103  * @tc.type: FUNC
104  */
105 HWTEST_F(DialogModelTest, DialogModelTest005, TestSize.Level1)
106 {
107     int32_t ret = RemoveContent(nullptr);
108     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
109 }
110 
111 /**
112  * @tc.name: DialogModelTest006
113  * @tc.desc: Test RemoveContent function.
114  * @tc.type: FUNC
115  */
116 HWTEST_F(DialogModelTest, DialogModelTest006, TestSize.Level1)
117 {
118     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
119     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
120     ASSERT_NE(nativeDialogHandle, nullptr);
121     int32_t ret = RemoveContent(nativeDialogHandle);
122     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
123     Dispose(nativeDialogHandle);
124     nativeDialogHandle = nullptr;
125 }
126 
127 /**
128  * @tc.name: DialogModelTest007
129  * @tc.desc: Test SetContentAlignment function.
130  * @tc.type: FUNC
131  */
132 HWTEST_F(DialogModelTest, DialogModelTest007, TestSize.Level1)
133 {
134     int32_t ret = SetContentAlignment(nullptr, 0, 0.0f, 0.0f);
135     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
136 }
137 
138 /**
139  * @tc.name: DialogModelTest008
140  * @tc.desc: Test SetContentAlignment function.
141  * @tc.type: FUNC
142  */
143 HWTEST_F(DialogModelTest, DialogModelTest008, TestSize.Level1)
144 {
145     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
146     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
147     ASSERT_NE(nativeDialogHandle, nullptr);
148     int32_t ret = SetContentAlignment(nativeDialogHandle, 0, 0.0f, 0.0f);
149     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
150     Dispose(nativeDialogHandle);
151     nativeDialogHandle = nullptr;
152 }
153 
154 /**
155  * @tc.name: DialogModelTest009
156  * @tc.desc: Test ResetContentAlignment function.
157  * @tc.type: FUNC
158  */
159 HWTEST_F(DialogModelTest, DialogModelTest009, TestSize.Level1)
160 {
161     int32_t ret = ResetContentAlignment(nullptr);
162     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
163 }
164 
165 /**
166  * @tc.name: DialogModelTest010
167  * @tc.desc: Test SetContentAlignment function.
168  * @tc.type: FUNC
169  */
170 HWTEST_F(DialogModelTest, DialogModelTest010, TestSize.Level1)
171 {
172     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
173     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
174     ASSERT_NE(nativeDialogHandle, nullptr);
175     int32_t ret = ResetContentAlignment(nativeDialogHandle);
176     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
177     Dispose(nativeDialogHandle);
178     nativeDialogHandle = nullptr;
179 }
180 
181 /**
182  * @tc.name: DialogModelTest011
183  * @tc.desc: Test SetModalMode function.
184  * @tc.type: FUNC
185  */
186 HWTEST_F(DialogModelTest, DialogModelTest011, TestSize.Level1)
187 {
188     int32_t ret = SetModalMode(nullptr, true);
189     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
190 }
191 
192 /**
193  * @tc.name: DialogModelTest012
194  * @tc.desc: Test SetModalMode function.
195  * @tc.type: FUNC
196  */
197 HWTEST_F(DialogModelTest, DialogModelTest012, TestSize.Level1)
198 {
199     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
200     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
201     ASSERT_NE(nativeDialogHandle, nullptr);
202     int32_t ret = SetModalMode(nativeDialogHandle, true);
203     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
204     Dispose(nativeDialogHandle);
205     nativeDialogHandle = nullptr;
206 }
207 
208 /**
209  * @tc.name: DialogModelTest013
210  * @tc.desc: Test SetAutoCancel function.
211  * @tc.type: FUNC
212  */
213 HWTEST_F(DialogModelTest, DialogModelTest013, TestSize.Level1)
214 {
215     int32_t ret = SetAutoCancel(nullptr, true);
216     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
217 }
218 
219 /**
220  * @tc.name: DialogModelTest014
221  * @tc.desc: Test SetAutoCancel function.
222  * @tc.type: FUNC
223  */
224 HWTEST_F(DialogModelTest, DialogModelTest014, TestSize.Level1)
225 {
226     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
227     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
228     ASSERT_NE(nativeDialogHandle, nullptr);
229     int32_t ret = SetAutoCancel(nativeDialogHandle, true);
230     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
231     Dispose(nativeDialogHandle);
232     nativeDialogHandle = nullptr;
233 }
234 
235 /**
236  * @tc.name: DialogModelTest015
237  * @tc.desc: Test SetMask function.
238  * @tc.type: FUNC
239  */
240 HWTEST_F(DialogModelTest, DialogModelTest015, TestSize.Level1)
241 {
242     int32_t ret = SetMask(nullptr, 0, nullptr);
243     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
244 }
245 
246 /**
247  * @tc.name: DialogModelTest016
248  * @tc.desc: Test SetMask function.
249  * @tc.type: FUNC
250  */
251 HWTEST_F(DialogModelTest, DialogModelTest016, TestSize.Level1)
252 {
253     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
254     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
255     ASSERT_NE(nativeDialogHandle, nullptr);
256     ArkUI_Rect rect = {0.0f, 0.0f, 0.0f, 0.0f};
257     int32_t ret = SetMask(nativeDialogHandle, 0, &rect);
258     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
259     Dispose(nativeDialogHandle);
260     nativeDialogHandle = nullptr;
261 }
262 
263 /**
264  * @tc.name: DialogModelTest017
265  * @tc.desc: Test SetMask function.
266  * @tc.type: FUNC
267  */
268 HWTEST_F(DialogModelTest, DialogModelTest017, TestSize.Level1)
269 {
270     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
271     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
272     ASSERT_NE(nativeDialogHandle, nullptr);
273     int32_t ret = SetMask(nativeDialogHandle, 0, nullptr);
274     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
275     Dispose(nativeDialogHandle);
276     nativeDialogHandle = nullptr;
277 }
278 
279 /**
280  * @tc.name: DialogModelTest018
281  * @tc.desc: Test SetBackgroundColor function.
282  * @tc.type: FUNC
283  */
284 HWTEST_F(DialogModelTest, DialogModelTest018, TestSize.Level1)
285 {
286     int32_t ret = SetBackgroundColor(nullptr, 0);
287     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
288 }
289 
290 /**
291  * @tc.name: DialogModelTest019
292  * @tc.desc: Test SetBackgroundColor function.
293  * @tc.type: FUNC
294  */
295 HWTEST_F(DialogModelTest, DialogModelTest019, TestSize.Level1)
296 {
297     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
298     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
299     ASSERT_NE(nativeDialogHandle, nullptr);
300     int32_t ret = SetBackgroundColor(nativeDialogHandle, 0);
301     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
302     Dispose(nativeDialogHandle);
303     nativeDialogHandle = nullptr;
304 }
305 
306 /**
307  * @tc.name: DialogModelTest020
308  * @tc.desc: Test SetCornerRadius function.
309  * @tc.type: FUNC
310  */
311 HWTEST_F(DialogModelTest, DialogModelTest020, TestSize.Level1)
312 {
313     int32_t ret = SetCornerRadius(nullptr, 0.0f, 0.0f, 0.0f, 0.0f);
314     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
315 }
316 
317 /**
318  * @tc.name: DialogModelTest021
319  * @tc.desc: Test SetCornerRadius function.
320  * @tc.type: FUNC
321  */
322 HWTEST_F(DialogModelTest, DialogModelTest021, TestSize.Level1)
323 {
324     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
325     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
326     ASSERT_NE(nativeDialogHandle, nullptr);
327     int32_t ret = SetCornerRadius(nativeDialogHandle, 0.0f, 0.0f, 0.0f, 0.0f);
328     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
329     Dispose(nativeDialogHandle);
330     nativeDialogHandle = nullptr;
331 }
332 
333 /**
334  * @tc.name: DialogModelTest022
335  * @tc.desc: Test SetGridColumnCount function.
336  * @tc.type: FUNC
337  */
338 HWTEST_F(DialogModelTest, DialogModelTest022, TestSize.Level1)
339 {
340     int32_t ret = SetGridColumnCount(nullptr, 0);
341     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
342 }
343 
344 /**
345  * @tc.name: DialogModelTest023
346  * @tc.desc: Test SetGridColumnCount function.
347  * @tc.type: FUNC
348  */
349 HWTEST_F(DialogModelTest, DialogModelTest023, TestSize.Level1)
350 {
351     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
352     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
353     ASSERT_NE(nativeDialogHandle, nullptr);
354     int32_t ret = SetGridColumnCount(nativeDialogHandle, 0);
355     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
356     Dispose(nativeDialogHandle);
357     nativeDialogHandle = nullptr;
358 }
359 
360 /**
361  * @tc.name: DialogModelTest024
362  * @tc.desc: Test EnableCustomStyle function.
363  * @tc.type: FUNC
364  */
365 HWTEST_F(DialogModelTest, DialogModelTest024, TestSize.Level1)
366 {
367     int32_t ret = EnableCustomStyle(nullptr, true);
368     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
369 }
370 
371 /**
372  * @tc.name: DialogModelTest025
373  * @tc.desc: Test EnableCustomStyle function.
374  * @tc.type: FUNC
375  */
376 HWTEST_F(DialogModelTest, DialogModelTest025, TestSize.Level1)
377 {
378     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
379     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
380     ASSERT_NE(nativeDialogHandle, nullptr);
381     int32_t ret = EnableCustomStyle(nativeDialogHandle, true);
382     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
383     Dispose(nativeDialogHandle);
384     nativeDialogHandle = nullptr;
385 }
386 
387 /**
388  * @tc.name: DialogModelTest026
389  * @tc.desc: Test EnableCustomAnimation function.
390  * @tc.type: FUNC
391  */
392 HWTEST_F(DialogModelTest, DialogModelTest026, TestSize.Level1)
393 {
394     int32_t ret = EnableCustomAnimation(nullptr, true);
395     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
396 }
397 
398 /**
399  * @tc.name: DialogModelTest027
400  * @tc.desc: Test EnableCustomAnimation function.
401  * @tc.type: FUNC
402  */
403 HWTEST_F(DialogModelTest, DialogModelTest027, TestSize.Level1)
404 {
405     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
406     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
407     ASSERT_NE(nativeDialogHandle, nullptr);
408     int32_t ret = EnableCustomAnimation(nativeDialogHandle, true);
409     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
410     Dispose(nativeDialogHandle);
411     nativeDialogHandle = nullptr;
412 }
413 
414 /**
415  * @tc.name: DialogModelTest028
416  * @tc.desc: Test Show function.
417  * @tc.type: FUNC
418  */
419 HWTEST_F(DialogModelTest, DialogModelTest028, TestSize.Level1)
420 {
421     int32_t ret = Show(nullptr, true);
422     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
423 }
424 
425 /**
426  * @tc.name: DialogModelTest029
427  * @tc.desc: Test Show function.
428  * @tc.type: FUNC
429  */
430 HWTEST_F(DialogModelTest, DialogModelTest029, TestSize.Level1)
431 {
432     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
433     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
434     ASSERT_NE(nativeDialogHandle, nullptr);
435     int32_t ret = Show(nativeDialogHandle, false);
436     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
437     Dispose(nativeDialogHandle);
438     nativeDialogHandle = nullptr;
439 }
440 
441 /**
442  * @tc.name: DialogModelTest030
443  * @tc.desc: Test Close function.
444  * @tc.type: FUNC
445  */
446 HWTEST_F(DialogModelTest, DialogModelTest030, TestSize.Level1)
447 {
448     int32_t ret = Close(nullptr);
449     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
450 }
451 
452 /**
453  * @tc.name: DialogModelTest031
454  * @tc.desc: Test Close function.
455  * @tc.type: FUNC
456  */
457 HWTEST_F(DialogModelTest, DialogModelTest031, TestSize.Level1)
458 {
459     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
460     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
461     ASSERT_NE(nativeDialogHandle, nullptr);
462     int32_t ret = Close(nativeDialogHandle);
463     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
464     Dispose(nativeDialogHandle);
465     nativeDialogHandle = nullptr;
466 }
467 
468 /**
469  * @tc.name: DialogModelTest032
470  * @tc.desc: Test RegisterOnWillDismiss function.
471  * @tc.type: FUNC
472  */
473 HWTEST_F(DialogModelTest, DialogModelTest032, TestSize.Level1)
474 {
475     int32_t ret = RegisterOnWillDismiss(nullptr, nullptr);
476     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_PARAM_INVALID);
477 }
478 
479 /**
480  * @tc.name: DialogModelTest033
481  * @tc.desc: Test RegisterOnWillDismiss function.
482  * @tc.type: FUNC
483  */
484 HWTEST_F(DialogModelTest, DialogModelTest033, TestSize.Level1)
485 {
486     ASSERT_TRUE(OHOS::Ace::NodeModel::InitialFullImpl());
487     ArkUI_NativeDialogHandle nativeDialogHandle = Create();
488     ASSERT_NE(nativeDialogHandle, nullptr);
489     ArkUI_OnWillDismissEvent eventHandler = OnWillDismissEvent;
490     int32_t ret = RegisterOnWillDismiss(nativeDialogHandle, eventHandler);
491     ASSERT_EQ(ret, OHOS::Ace::ERROR_CODE_NO_ERROR);
492     Dispose(nativeDialogHandle);
493     nativeDialogHandle = nullptr;
494 }