• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 <string.h>
17 #include <unistd.h>
18 #include <semaphore.h>
19 
20 #include "adapter.h"
21 #include "hctest.h"
22 #include "securec.h"
23 #include "bundle_info.h"
24 #include "bundle_manager.h"
25 #include "want.h"
26 
27 #define nullptr NULL
28 #define DIR_PATH_MAX 256
29 #define PREPARED_APP_BUNDLE_NAME  "com.example.testdemo1"
30 #define PREPARED_APP_ABILITY_NAME "entry_MainAbility"
31 #define INSTALL_APP_BUNDLE_NAME   "com.example.testdemo2"
32 #define PREPARED_APP_BIN_NAME     "/user/testdemo1.bin"
33 #define INSTALL_APP_BIN_NAME      "/user/testdemo2.bin"
34 
35 const uint8_t OPERATION_DOING = 200;
36 static uint8_t g_errCode = 0;
37 static sem_t g_sem;
38 
39 /* *
40  * @brief  install/uninstall callback function
41  * @param  resultCode - install/unsintall result code
42  * @param  resultMessage - install/unsintall result message
43  */
TestInstallerCallback(const uint8_t resultCode,const void * resultMessage)44 static void TestInstallerCallback(const uint8_t resultCode, const void *resultMessage)
45 {
46     printf("----TestInstallerCallback resultCode: %u\n", (uint32_t)resultCode);
47 
48     if (resultCode == OPERATION_DOING) {
49         return;
50     }
51     g_errCode = resultCode;
52     sem_post(&g_sem);
53 }
54 
55 /**
56 * @brief  register a test suit named BundleMgrTestSuite
57 * @param  subsystem name is appexecfwk
58 * @param  module name is  bundlemgr
59 * @param  test suit name is BundleMgrTestSuite
60 */
61 LITE_TEST_SUIT(appexecfwk, bundlemgr, BundleMgrTestSuite);
62 
BundleMgrTestSuiteSetUp(void)63 static BOOL BundleMgrTestSuiteSetUp(void)
64 {
65     printf("----------test case with BundleMgrTest start-------------\n");
66 
67     InstallParam installParam = {
68         .installLocation = 1,
69         .keepData = false
70     };
71     sem_init(&g_sem, 0, 0);
72     bool ret = Install(PREPARED_APP_BIN_NAME, &installParam, TestInstallerCallback);
73     sem_wait(&g_sem);
74     printf("install testdemo1 result is %d err %u\n", ret, g_errCode);
75 
76     return TRUE;
77 }
78 
BundleMgrTestSuiteTearDown(void)79 static BOOL BundleMgrTestSuiteTearDown(void)
80 {
81     InstallParam installParam = {
82         .installLocation = 1,
83         .keepData = false
84     };
85     sem_init(&g_sem, 0, 0);
86     bool ret = Uninstall(PREPARED_APP_BUNDLE_NAME, &installParam, TestInstallerCallback);
87     sem_wait(&g_sem);
88     printf("uninstall testdemo1 result is %d err %u\n", ret, g_errCode);
89 
90     printf("----------test case with BundleMgrTest end-------------\n");
91     return TRUE;
92 }
93 
94 /**
95  * @tc.number    : SUB_APPEXECFWK_0001
96  * @tc.name      : testClearAbilityInfoLegal
97  * @tc.desc      : testClearAbilityInfo parameter legal test with bundle name
98  */
99 LITE_TEST_CASE(BundleMgrTestSuite, testClearAbilityInfoLegal, Function | MediumTest | Level2)
100 {
101     printf("------start testClearAbilityInfoLegal------\n");
102     AbilityInfo abilityInfo;
103     int result = memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo));
104     TEST_ASSERT_TRUE(result == 0);
105     char *name = "com.openharmony.testjsdemo";
106     size_t len = strlen(name);
107     abilityInfo.bundleName = (char *)(AdapterMalloc(len + 1));
108     TEST_ASSERT_NOT_NULL(abilityInfo.bundleName);
109     errno_t err = strncpy_s(abilityInfo.bundleName, len + 1, name, len);
110     TEST_ASSERT_EQUAL(err, EOK);
111     TEST_ASSERT_EQUAL_STRING(abilityInfo.bundleName, name);
112     ClearAbilityInfo(&abilityInfo);
113     TEST_ASSERT_EQUAL_STRING(abilityInfo.bundleName, NULL);
114     printf("------end testClearAbilityInfoLegal------\n");
115 }
116 
117 /**
118  * @tc.number    : SUB_APPEXECFWK_0002
119  * @tc.name      : testClearAbilityInfoIllegal
120  * @tc.desc      : testClearAbilityInfo parameter illegal test
121  */
122 LITE_TEST_CASE(BundleMgrTestSuite, testClearAbilityInfoIllegal, Function | MediumTest | Level2)
123 {
124     printf("------start testClearAbilityInfoIllegal------\n");
125     AbilityInfo abilityInfo = { 0 };
126     int result = memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo));
127     TEST_ASSERT_TRUE(result == 0);
128     char *name = "com.openharmony.testjsdemo";
129     size_t len = strlen(name);
130     abilityInfo.bundleName = (char *)(AdapterMalloc(len + 1));
131     TEST_ASSERT_NOT_NULL(abilityInfo.bundleName);
132     errno_t err = strncpy_s(abilityInfo.bundleName, len + 1, name, len);
133     TEST_ASSERT_EQUAL(err, EOK);
134     ClearAbilityInfo(NULL);
135     TEST_ASSERT_EQUAL_STRING(abilityInfo.bundleName, name);
136     AdapterFree(abilityInfo.bundleName);
137     printf("------end testClearAbilityInfoIllegal------\n");
138 }
139 
140 /**
141  * @tc.number    : SUB_APPEXECFWK_0003
142  * @tc.name      : testClearBundleInfoLegal
143  * @tc.desc      : testClearBundleInfo parameter legal test with bundle name
144  */
145 LITE_TEST_CASE(BundleMgrTestSuite, testClearBundleInfoLegal, Function | MediumTest | Level2)
146 {
147     printf("------start testClearBundleInfoLegal------\n");
148     BundleInfo bundleInfo = { 0 };
149     int result = memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo));
150     TEST_ASSERT_TRUE(result == 0);
151     char *name = "com.openharmony.testjsdemo";
152     size_t len = strlen(name);
153     bundleInfo.bundleName = (char *)(AdapterMalloc(len + 1));
154     TEST_ASSERT_NOT_NULL(bundleInfo.bundleName);
155     errno_t err = strncpy_s(bundleInfo.bundleName, len + 1, name, len);
156     TEST_ASSERT_EQUAL(err, EOK);
157     TEST_ASSERT_EQUAL_STRING(bundleInfo.bundleName, name);
158     ClearBundleInfo(&bundleInfo);
159     TEST_ASSERT_EQUAL_STRING(bundleInfo.bundleName, NULL);
160     printf("------end testClearBundleInfoLegal------\n");
161 }
162 
163 /**
164  * @tc.number    : SUB_APPEXECFWK_0004
165  * @tc.name      : testClearBundleInfoIllegal
166  * @tc.desc      : testClearBundleInfo parameter illegal test
167  */
168 LITE_TEST_CASE(BundleMgrTestSuite, testClearBundleInfoIllegal, Function | MediumTest | Level2)
169 {
170     printf("------start testClearBundleInfoIllegal------\n");
171     BundleInfo bundleInfo;
172     int result = memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo));
173     TEST_ASSERT_TRUE(result == 0);
174     char *name = "com.openharmony.testjsdemo";
175     size_t len = strlen(name);
176     bundleInfo.bundleName = (char *)(AdapterMalloc(len + 1));
177     TEST_ASSERT_NOT_NULL(bundleInfo.bundleName);
178     errno_t err = strncpy_s(bundleInfo.bundleName, len + 1, name, len);
179     TEST_ASSERT_EQUAL(err, EOK);
180     ClearBundleInfo(NULL);
181     TEST_ASSERT_EQUAL_STRING(bundleInfo.bundleName, name);
182     AdapterFree(bundleInfo.bundleName);
183     printf("------end testClearBundleInfoIllegal------\n");
184 }
185 
186 /**
187  * @tc.number    : SUB_APPEXECFWK_0005
188  * @tc.name      : testClearModuleInfoLegal
189  * @tc.desc      : ClearAbilityInfo parameter legal test with module info
190  */
191 LITE_TEST_CASE(BundleMgrTestSuite, testClearModuleInfoLegal, Function | MediumTest | Level1)
192 {
193     printf("------start testClearModuleInfoLegal------\n");
194     ModuleInfo moduleInfo = { 0 };
195     int result = memset_s(&moduleInfo, sizeof(moduleInfo), 0, sizeof(moduleInfo));
196     TEST_ASSERT_TRUE(result == 0);
197     char *name = "test";
198     size_t len = strlen(name);
199     moduleInfo.moduleName = (char *)(AdapterMalloc(len + 1));
200     TEST_ASSERT_NOT_NULL(moduleInfo.moduleName);
201     errno_t err = strncpy_s(moduleInfo.moduleName, len + 1, name, len);
202     TEST_ASSERT_EQUAL(err, EOK);
203     TEST_ASSERT_EQUAL_STRING(moduleInfo.moduleName, name);
204     ClearModuleInfo(&moduleInfo);
205     TEST_ASSERT_EQUAL_STRING(moduleInfo.moduleName, NULL);
206     printf("------end testClearModuleInfoLegal------\n");
207 }
208 
209 /**
210  * @tc.number    : SUB_APPEXECFWK_0006
211  * @tc.name      : testClearModuleInfoIllegal
212  * @tc.desc      : ClearAbilityInfo parameter illegal test
213  */
214 LITE_TEST_CASE(BundleMgrTestSuite, testClearModuleInfoIllegal, Function | MediumTest | Level1)
215 {
216     printf("------start testClearModuleInfoIllegal------\n");
217     ModuleInfo moduleInfo = { 0 };
218     int result = memset_s(&moduleInfo, sizeof(moduleInfo), 0, sizeof(moduleInfo));
219     TEST_ASSERT_TRUE(result == 0);
220     char *name = "test";
221     size_t len = strlen(name);
222     moduleInfo.moduleName = (char *)(AdapterMalloc(len + 1));
223     TEST_ASSERT_NOT_NULL(moduleInfo.moduleName);
224     errno_t err = strncpy_s(moduleInfo.moduleName, len + 1, name, len);
225     TEST_ASSERT_EQUAL(err, EOK);
226     ClearModuleInfo(NULL);
227     TEST_ASSERT_EQUAL_STRING(moduleInfo.moduleName, name);
228     AdapterFree(moduleInfo.moduleName);
229     printf("------end testClearModuleInfoIllegal------\n");
230 }
231 
232 /**
233  * @tc.number    : SUB_APPEXECFWK_0007
234  * @tc.name      : testSetElementAbilityNameLegal
235  * @tc.desc      : testSetElementAbilityName parameter legal test
236  */
237 LITE_TEST_CASE(BundleMgrTestSuite, testSetElementAbilityNameLegal, Function | MediumTest | Level0)
238 {
239     printf("------start testSetElementAbilityNameLegal------\n");
240     Want want = { 0 };
241     ElementName element = { 0 };
242     SetElementAbilityName(&element, "SecondAbility");
243     SetWantElement(&want, element);
244     char *aName = "SecondAbility";
245     TEST_ASSERT_EQUAL_STRING(want.element->abilityName, aName);
246     ClearElement(&element);
247     ClearWant(&want);
248     printf("------end testSetElementAbilityNameLegal------\n");
249 }
250 
251 /**
252  * @tc.number    : SUB_APPEXECFWK_0008
253  * @tc.name      : testSetElementAbilityNameIllegal
254  * @tc.desc      : testSetElementAbilityName parameter illegal test
255  */
256 LITE_TEST_CASE(BundleMgrTestSuite, testSetElementAbilityNameIllegal, Function | MediumTest | Level2)
257 {
258     printf("------start testSetElementAbilityNameIllegal------\n");
259     Want want = { 0 };
260     ElementName element = { 0 };
261     char *aName = "";
262     SetElementAbilityName(&element, aName);
263     SetWantElement(&want, element);
264     TEST_ASSERT_EQUAL_STRING(want.element->abilityName, "");
265     SetElementAbilityName(&element, NULL);
266     SetWantElement(&want, element);
267     TEST_ASSERT_EQUAL_STRING(want.element->abilityName, NULL);
268     int ret = SetElementAbilityName(NULL, aName);
269     TEST_ASSERT_FALSE(ret);
270     ClearElement(&element);
271     ClearWant(&want);
272     printf("------end testSetElementAbilityNameIllegal------\n");
273 }
274 
275 /**
276  * @tc.number    : SUB_APPEXECFWK_0009
277  * @tc.name      : testSetElementBundleNameLegal
278  * @tc.desc      : testSetElementBundleName parameter legal test
279  */
280 LITE_TEST_CASE(BundleMgrTestSuite, testSetElementBundleNameLegal, Function | MediumTest | Level0)
281 {
282     printf("------start testSetElementBundleNameLegal------\n");
283     Want want = { 0 };
284     ElementName element = { 0 };
285     SetElementBundleName(&element, "com.openharmony.testjsdemo");
286     SetWantElement(&want, element);
287     char *bName = "com.openharmony.testjsdemo";
288     TEST_ASSERT_EQUAL_STRING(want.element->bundleName, bName);
289     ClearElement(&element);
290     ClearWant(&want);
291     printf("------end testSetElementBundleNameLegal------\n");
292 }
293 
294 /**
295  * @tc.number    : SUB_APPEXECFWK_0010
296  * @tc.name      : testSetElementBundleNameIllegal
297  * @tc.desc      : testSetElementBundleName parameter illegal test
298  */
299 LITE_TEST_CASE(BundleMgrTestSuite, testSetElementBundleNameIllegal, Function | MediumTest | Level2)
300 {
301     printf("------start testSetElementBundleNameIllegal------\n");
302     Want want = { 0 };
303     ElementName element = { 0 };
304     SetElementBundleName(&element, "");
305     SetWantElement(&want, element);
306     char *bName = "";
307     TEST_ASSERT_EQUAL_STRING(want.element->bundleName, bName);
308     SetElementBundleName(&element, NULL);
309     SetWantElement(&want, element);
310     TEST_ASSERT_EQUAL_STRING(want.element->bundleName, NULL);
311     bool ret = SetElementBundleName(NULL, bName);
312     TEST_ASSERT_FALSE(ret);
313     ClearElement(&element);
314     ClearWant(&want);
315     printf("------end testSetElementBundleNameIllegal------\n");
316 }
317 /**
318  * @tc.number    : SUB_APPEXECFWK_0011
319  * @tc.name      : testSetElementDeviceIDLegal
320  * @tc.desc      : testSetElementDeviceID parameter legal test
321  */
322 LITE_TEST_CASE(BundleMgrTestSuite, testSetElementDeviceIDLegal, Function | MediumTest | Level0)
323 {
324     printf("------start testSetElementDeviceIDLegal------\n");
325     Want want = { 0 };
326     ElementName element = { 0 };
327     SetElementDeviceID(&element, "0001000");
328     SetWantElement(&want, element);
329     char *dID = "0001000";
330     TEST_ASSERT_EQUAL_STRING(want.element->deviceId, dID);
331     ClearElement(&element);
332     ClearWant(&want);
333     printf("------end testSetElementDeviceIDLegal------\n");
334 }
335 
336 /**
337  * @tc.number    : SUB_APPEXECFWK_0012
338  * @tc.name      : testSetElementDeviceIDIllegal
339  * @tc.desc      : testSetElementDeviceID parameter illegal test
340  */
341 LITE_TEST_CASE(BundleMgrTestSuite, testSetElementDeviceIDIllegal, Function | MediumTest | Level2)
342 {
343     printf("------start testSetElementDeviceIDIllegal------\n");
344     Want want = { 0 };
345     ElementName element = { 0 };
346     SetElementDeviceID(&element, "");
347     SetWantElement(&want, element);
348     char *dID = "";
349     TEST_ASSERT_EQUAL_STRING(want.element->deviceId, dID);
350     SetElementDeviceID(&element, NULL);
351     SetWantElement(&want, element);
352     TEST_ASSERT_EQUAL_STRING(want.element->deviceId, NULL);
353     int ret = SetElementDeviceID(NULL, "0001000");
354     TEST_ASSERT_FALSE(ret);
355     ClearElement(&element);
356     ClearWant(&want);
357     printf("------end testSetElementDeviceIDIllegal------\n");
358 }
359 
360 /**
361  * @tc.number    : SUB_APPEXECFWK_0013
362  * @tc.name      : testGetBundleInfoIllegal
363  * @tc.desc      : GetBundleInfo parameter illegal test
364  */
365 LITE_TEST_CASE(BundleMgrTestSuite, testGetBundleInfoIllegal, Function | MediumTest | Level2)
366 {
367     printf("------start testGetBundleInfoIllegal------\n");
368     BundleInfo bundleInfo;
369     int result = memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo));
370     TEST_ASSERT_TRUE(result == 0);
371     const char *bundleName = "com.openharmony.nothishap";
372     int flags = 0;
373     uint8_t ret = GetBundleInfo(bundleName, flags, &bundleInfo);
374     TEST_ASSERT_TRUE(ret == 2);
375     ret = GetBundleInfo(NULL, flags, &bundleInfo);
376     printf("abilityInfo2 is %d \n", ret);
377     TEST_ASSERT_TRUE(ret == 1);
378     ret = GetBundleInfo("", flags, &bundleInfo);
379     TEST_ASSERT_TRUE(ret == 2);
380     ret = GetBundleInfo("com.openharmony.testjsdemo", 2, &bundleInfo);
381     TEST_ASSERT_TRUE(ret == 2);
382     printf("------end testGetBundleInfoIllegal------\n");
383 }
384 
385 /**
386  * @tc.number    : SUB_APPEXECFWK_0014
387  * @tc.name      : testGetBundleInfosIllegal
388  * @tc.desc      : GetBundleInfos parameter illegal test
389  */
390 LITE_TEST_CASE(BundleMgrTestSuite, testGetBundleInfosIllegal, Function | MediumTest | Level2)
391 {
392     printf("------start testGetBundleInfosIllegal------\n");
393     BundleInfo *bundleInfos = {NULL};
394     int *length = NULL;
395     int flags = 0;
396     uint8_t ret = GetBundleInfos(flags, NULL, length);
397     TEST_ASSERT_TRUE(ret == 1);
398     ret = GetBundleInfos(flags, &bundleInfos, NULL);
399     printf("ret is %d \n", ret);
400     TEST_ASSERT_TRUE(ret == 2);
401     ret = GetBundleInfos(2, &bundleInfos, length);
402     printf("ret is %d \n", ret);
403     TEST_ASSERT_TRUE(ret == 2);
404     printf("------end testGetBundleInfosIllegal------\n");
405 }
406 
407 /**
408  * @tc.number    : SUB_APPEXECFWK_0015
409  * @tc.name      : testGetBundleInfoLegal
410  * @tc.desc      : GetBundleInfo parameter legal test
411  */
412 LITE_TEST_CASE(BundleMgrTestSuite, testGetBundleInfoLegal, Function | MediumTest | Level2)
413 {
414     printf("------start testGetBundleInfoLegal------\n");
415     BundleInfo bundleInfo;
416     int result = memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo));
417     TEST_ASSERT_TRUE(result == 0);
418 
419     int flags = 0;
420     const char *bundleName = PREPARED_APP_BUNDLE_NAME;
421     uint8_t ret = GetBundleInfo(PREPARED_APP_BUNDLE_NAME, flags, &bundleInfo);
422     TEST_ASSERT_TRUE(ret == 0);
423     TEST_ASSERT_EQUAL_STRING(bundleInfo.bundleName, bundleName);
424 
425     printf("------end testGetBundleInfoLegal------\n");
426 }
427 
428 /**
429  * @tc.number    : SUB_APPEXECFWK_0016
430  * @tc.name      : testQueryAbilityInfoLegal
431  * @tc.desc      : QueryAbilityInfo parameter legal test
432  */
433 LITE_TEST_CASE(BundleMgrTestSuite, testQueryAbilityInfoLegal, Function | MediumTest | Level0)
434 {
435     printf("------start testQueryAbilityInfoLegal------\n");
436     Want want = { 0 };
437     ElementName element = { 0 };
438     SetElementAbilityName(&element, PREPARED_APP_ABILITY_NAME);
439     SetElementBundleName(&element, PREPARED_APP_BUNDLE_NAME);
440     SetWantElement(&want, element);
441 
442     AbilityInfo abilityInfo;
443     int32_t ret = memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo));
444     TEST_ASSERT_TRUE(ret == 0);
445     uint8_t result = QueryAbilityInfo(&want, &abilityInfo);
446     printf("QueryAbilityInfo result is %d \n", result);
447     printf("abilityInfo.bundleName is %s \n", abilityInfo.bundleName);
448     TEST_ASSERT_TRUE(result == 1);
449 
450     ClearAbilityInfo(&abilityInfo);
451     ClearElement(&element);
452     ClearWant(&want);
453     printf("------end testQueryAbilityInfoLegal------\n");
454 }
455 
456 /**
457  * @tc.number    : SUB_APPEXECFWK_0017
458  * @tc.name      : testQueryAbilityInfoWithNullptr
459  * @tc.desc      : QueryAbilityInfo parameter nullptr test
460  */
461 LITE_TEST_CASE(BundleMgrTestSuite, testQueryAbilityInfoWithNullptr, Function | MediumTest | Level2)
462 {
463     printf("------start testQueryAbilityInfoWithNullptr------\n");
464 
465     AbilityInfo abilityInfo;
466     int32_t ret = memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo));
467     TEST_ASSERT_TRUE(ret == 0);
468 
469     // want is nullptr
470     uint8_t result = QueryAbilityInfo(nullptr, &abilityInfo);
471     printf("when want is null, query ability info result is %u\n", (uint32_t)result);
472     TEST_ASSERT_TRUE(result == 1);
473 
474     Want want = { 0 };
475     ElementName element = {0};
476     SetElementAbilityName(&element, PREPARED_APP_ABILITY_NAME);
477     SetElementBundleName(&element, PREPARED_APP_BUNDLE_NAME);
478     SetWantElement(&want, element);
479     SetWantData(&want, "test", 4);
480 
481     // abilityInfo is nullptr
482     result = QueryAbilityInfo(&want, nullptr);
483     printf("when abilityInfo is null, query ability info result is %u\n", (uint32_t)result);
484     TEST_ASSERT_TRUE(result == 1);
485 
486     ClearElement(&element);
487     ClearWant(&want);
488     printf("------end testQueryAbilityInfoWithNullptr------\n");
489 }
490 
491 /**
492  * @tc.number    : SUB_APPEXECFWK_0018
493  * @tc.name      : testQueryAbilityInfoIllegal
494  * @tc.desc      : QueryAbilityInfo parameter illegal test
495  */
496 LITE_TEST_CASE(BundleMgrTestSuite, testQueryAbilityInfoIllegal, Function | MediumTest | Level2)
497 {
498     printf("------start testQueryAbilityInfoIllegal------\n");
499 
500     // content of want is null string
501     Want want = {0};
502     ElementName element = {0};
503     SetElementBundleName(&element, "");
504     SetElementAbilityName(&element, "");
505     SetWantElement(&want, element);
506 
507     AbilityInfo abilityInfo;
508     uint8_t result = QueryAbilityInfo(&want, &abilityInfo);
509     printf("query ability info result is %u\n", (uint32_t)result);
510     TEST_ASSERT_TRUE(result == 0);
511 
512     ClearElement(&element);
513     ClearWant(&want);
514     printf("------end testQueryAbilityInfoIllegal------\n");
515 }
516 
517 /**
518  * @tc.number    : SUB_APPEXECFWK_0019
519  * @tc.name      : testInstallWithNullptr
520  * @tc.desc      : Install parameter nullptr test
521  */
522 LITE_TEST_CASE(BundleMgrTestSuite, testInstallWithNullptr, Function | MediumTest | Level2)
523 {
524     printf("------start testInstallWithNullptr------\n");
525 
526     InstallParam installParam = {
527         .installLocation = 1,
528         .keepData = false
529     };
530     bool isInstallSuccess = Install(nullptr, &installParam, TestInstallerCallback);
531     TEST_ASSERT_FALSE(isInstallSuccess);
532     printf("install result is %d\n", isInstallSuccess);
533 
534     printf("------end testInstallWithNullptr------\n");
535 }
536 
537 /**
538  * @tc.number    : SUB_APPEXECFWK_0020
539  * @tc.name      : testInstallWithErrorPath
540  * @tc.desc      : Install parameter illegal path test
541  */
542 LITE_TEST_CASE(BundleMgrTestSuite, testInstallWithErrorPath, Function | MediumTest | Level2)
543 {
544     printf("------start testInstallWithErrorPath------\n");
545 
546     InstallParam installParam = {
547         .installLocation = 1,
548         .keepData = false
549     };
550     sem_init(&g_sem, 0, 0);
551     bool ret = Install("/user/nothishap.bin", &installParam, TestInstallerCallback);
552     sem_wait(&g_sem);
553 
554     bool isInstallSuccess = (g_errCode == 0) ? true : false;
555     TEST_ASSERT_FALSE(isInstallSuccess);
556     printf("install nothishap result is %d err %u\n", ret, g_errCode);
557 
558     printf("------end testInstallWithErrorPath------\n");
559 }
560 
561 /**
562  * @tc.number    : SUB_APPEXECFWK_0021
563  * @tc.name      : testInstallWithEmptyPath
564  * @tc.desc      : Install parameter illegal path test
565  */
566 LITE_TEST_CASE(BundleMgrTestSuite, testInstallWithEmptyPath, Function | MediumTest | Level2)
567 {
568     printf("------start testInstallWithEmptyPath------\n");
569 
570     InstallParam installParam = {
571         .installLocation = 1,
572         .keepData = false
573     };
574     sem_init(&g_sem, 0, 0);
575     bool ret = Install("", &installParam, TestInstallerCallback);
576     sem_wait(&g_sem);
577 
578     bool isInstallSuccess = (g_errCode == 0) ? true : false;
579     TEST_ASSERT_FALSE(isInstallSuccess);
580     printf("install result is %d err %u\n", ret, g_errCode);
581 
582     printf("------end testInstallWithEmptyPath------\n");
583 }
584 
585 /**
586  * @tc.number    : SUB_APPEXECFWK_0022
587  * @tc.name      : testInstallLegal
588  * @tc.desc      : Install parameter legal test
589  */
590 LITE_TEST_CASE(BundleMgrTestSuite, testInstallLegal, Function | MediumTest | Level0)
591 {
592     printf("------start testInstallLegal------\n");
593 
594     InstallParam installParam = {
595         .installLocation = 1,
596         .keepData = false
597     };
598     sem_init(&g_sem, 0, 0);
599     bool ret = Install(INSTALL_APP_BIN_NAME, &installParam, TestInstallerCallback);
600     sem_wait(&g_sem);
601 
602     bool isInstallSuccess = (g_errCode == 0) ? true : false;
603     TEST_ASSERT_TRUE(isInstallSuccess);
604     printf("install testdemo2 result is %d err %u\n", ret, g_errCode);
605 
606     sleep(1);
607     sem_init(&g_sem, 0, 0);
608     ret = Uninstall(INSTALL_APP_BUNDLE_NAME, &installParam, TestInstallerCallback);
609     sem_wait(&g_sem);
610     printf("uninstall testdemo2 result is %d err %u\n", ret, g_errCode);
611 
612     printf("------end testInstallLegal------\n");
613 }
614 
615 /**
616  * @tc.number    : SUB_APPEXECFWK_0023
617  * @tc.name      : testUninstallNullBundleName
618  * @tc.desc      : Uninstall parameter illegal test that bundleName is null
619  */
620 LITE_TEST_CASE(BundleMgrTestSuite, testUninstallNullBundleName, Function | MediumTest | Level2)
621 {
622     printf("------start testUninstallNullBundleName------\n");
623 
624     InstallParam installParam = {
625         .installLocation = 1,
626         .keepData = false
627     };
628     bool isSuccess = Uninstall(nullptr, &installParam, TestInstallerCallback);
629     TEST_ASSERT_FALSE(isSuccess);
630     printf("uninstall result is %d err %u\n", isSuccess, g_errCode);
631 
632     printf("------end testUninstallNullBundleName------\n");
633 }
634 
635 /**
636  * @tc.number    : SUB_APPEXECFWK_0024
637  * @tc.name      : testUninstallErrBundleName
638  * @tc.desc      : Uninstall parameter illegal test that bundleName is wrong
639  */
640 LITE_TEST_CASE(BundleMgrTestSuite, testUninstallErrBundleName, Function | MediumTest | Level2)
641 {
642     printf("------start testUninstallErrBundleName------\n");
643 
644     InstallParam installParam = {
645         .installLocation = 1,
646         .keepData = false
647     };
648     sem_init(&g_sem, 0, 0);
649     bool ret = Uninstall("com.openharmony.nothisBundleName", &installParam, TestInstallerCallback);
650     sem_wait(&g_sem);
651 
652     bool isUninstallSuccess = (g_errCode == 0) ? true : false;
653     TEST_ASSERT_FALSE(isUninstallSuccess);
654     printf("uninstall nothisBundleName result is %d err %u\n", ret, g_errCode);
655 
656     printf("------end testUninstallErrBundleName------\n");
657 }
658 
659 /**
660  * @tc.number    : SUB_APPEXECFWK_0025
661  * @tc.name      : testUninstallLegal
662  * @tc.desc      : Uninstall parameter legal test
663  */
664 LITE_TEST_CASE(BundleMgrTestSuite, testUninstallLegal, Function | MediumTest | Level0)
665 {
666     printf("------start testUninstallLegal------\n");
667 
668     InstallParam installParam = {
669         .installLocation = 1,
670         .keepData = false
671     };
672     sem_init(&g_sem, 0, 0);
673     bool ret = Install(INSTALL_APP_BIN_NAME, &installParam, TestInstallerCallback);
674     sem_wait(&g_sem);
675 
676     bool isInstallSuccess = (g_errCode == 0) ? true : false;
677     TEST_ASSERT_TRUE(isInstallSuccess);
678     printf("install testdemo2 result is %d err %u\n", ret, g_errCode);
679 
680     sleep(1);
681     sem_init(&g_sem, 0, 0);
682     ret = Uninstall(INSTALL_APP_BUNDLE_NAME, &installParam, TestInstallerCallback);
683     sem_wait(&g_sem);
684 
685     bool isUninstallSuccess = (g_errCode == 0) ? true : false;
686     TEST_ASSERT_TRUE(isUninstallSuccess);
687     printf("uninstall testdemo2 result is %d err %u\n", ret, g_errCode);
688 
689     printf("------end testUninstallLegal------\n");
690 }
691 
692 RUN_TEST_SUITE(BundleMgrTestSuite);
693