BundleMgrTest.cpp 39.4 KB
Newer Older
W
wenjun 已提交
1
/**
M
mamingshuai 已提交
2
 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
W
wenjun 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <log.h>
#include <semaphore.h>
#include <string>

#include "gtest/gtest.h"
#include "securec.h"
#include "bundle_info.h"
#include "bundle_manager.h"
#include "want.h"

using namespace std;
using namespace testing::ext;
using namespace OHOS;
static bool g_installState = false;
static int g_errorCode = -1;
static sem_t g_sem;
static const int32_t WAIT_TIMEOUT = 60;
M
mamingshuai 已提交
33
static string g_testPath;
W
wenjun 已提交
34 35 36 37 38 39 40 41 42 43

extern "C" {
void __attribute__((weak)) HOS_SystemInit(void){};
}

/* callback */
static void TestBundleStateCallback(const uint8_t resultCode, const void *resultMessage)
{
    HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleStateCallback resultCode: %d", resultCode);
    HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleStateCallback resultMessage: %s", (char *) resultMessage);
M
mamingshuai 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    g_installState = (resultCode == 0);
    g_errorCode = resultCode;
    sem_post(&g_sem);
}

/* *
 * get current dir
 * @return  string current file path of the test suits
 */
static string GetCurDir()
{
    string filePath = "";
    char *buffer;
    if ((buffer = getcwd(NULL, 0)) == NULL) {
        perror("get file path error");
W
wenjun 已提交
59
    } else {
M
mamingshuai 已提交
60 61 62
        printf("Current Dir: %s\r\n", buffer);
        filePath = buffer;
        free(buffer);
W
wenjun 已提交
63
    }
M
mamingshuai 已提交
64
    return filePath + "/";
W
wenjun 已提交
65 66 67 68 69 70 71 72 73
}

class BundleMgrTest : public testing::Test {
protected:
    static void SetUpTestCase(void)
    {
        printf("----------test case with BundleMgrTest start-------------\n");
        HOS_SystemInit();
        sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
74 75 76 77
        InstallParam installParam = { .installLocation = 1, .keepData = false };
        g_testPath = GetCurDir();
        string hapPath = g_testPath + "testjsdemo.hap";
        Install(hapPath.c_str(), &installParam, TestBundleStateCallback);
W
wenjun 已提交
78
        sem_wait(&g_sem);
M
mamingshuai 已提交
79 80
        printf("callback installresult is %d \n", g_errorCode);
        EXPECT_EQ(g_errorCode, 0);
W
wenjun 已提交
81 82 83 84
    }
    static void TearDownTestCase(void)
    {
        sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
85 86
        InstallParam installParam = { .installLocation = 1, .keepData = false };
        Uninstall("com.huawei.testjsdemo", &installParam, TestBundleStateCallback);
W
wenjun 已提交
87
        sem_wait(&g_sem);
M
mamingshuai 已提交
88 89
        printf("callback uninstallresult is %d \n", g_errorCode);
        EXPECT_EQ(g_errorCode, 0);
W
wenjun 已提交
90 91 92 93 94 95
        printf("----------test case with BundleMgrTest end-------------\n");
    }
};


/**
M
mamingshuai 已提交
96
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0044
W
wenjun 已提交
97 98 99
 * @tc.name      : ClearAbilityInfo parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
100
HWTEST_F(BundleMgrTest, testClearAbilityInfoIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113
{
    printf("------start testClearAbilityInfoIllegal------\n");
    // abilityInfo is nullptr
    AbilityInfo abilityInfo;
    memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo));
    abilityInfo.bundleName = (char*)"com.huawei.testjsdemo";
    printf("abilityInfo.bundleName is %s \n", abilityInfo.bundleName);
    ClearAbilityInfo(nullptr);
    EXPECT_STREQ(abilityInfo.bundleName, "com.huawei.testjsdemo");
    printf("------end testClearAbilityInfoIllegal------\n");
}

/**
M
mamingshuai 已提交
114 115
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0045
 * @tc.name      : ClearAbilityInfo parameter legal test with bundle name
W
wenjun 已提交
116 117
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
118
HWTEST_F(BundleMgrTest, testClearBundleInfoIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
119 120 121 122 123 124 125 126 127 128 129 130 131
{
    printf("------start testClearBundleInfoIllegal------\n");
    BundleInfo bundleInfo;
    memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo));
    bundleInfo.bundleName = (char*)"com.huawei.testjsdemo";
    printf("abilityInfo.bundleName is %s \n", bundleInfo.bundleName);
    ClearBundleInfo(nullptr);
    printf("abilityInfo.bundleName afterclear is %s \n", bundleInfo.bundleName);
    EXPECT_STREQ(bundleInfo.bundleName, "com.huawei.testjsdemo");
    printf("------end testClearBundleInfoIllegal------\n");
}

/**
M
mamingshuai 已提交
132 133
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0046
 * @tc.name      : ClearAbilityInfo parameter legal test with module info
W
wenjun 已提交
134 135
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
136
HWTEST_F(BundleMgrTest, testClearModuleInfoIllegal, Function | MediumTest | Level1)
W
wenjun 已提交
137 138 139 140 141 142 143 144 145 146 147 148 149
{
    printf("------start testClearModuleInfoIllegal------\n");
    ModuleInfo moduleInfo;
    memset_s(&moduleInfo, sizeof(moduleInfo), 0, sizeof(moduleInfo));
    moduleInfo.description = (char*)"test app";
    moduleInfo.moduleType = (char*)"entry";
    ClearModuleInfo(nullptr);
    EXPECT_STREQ(moduleInfo.description, "test app");
    EXPECT_STREQ(moduleInfo.moduleType, "entry");
    printf("------end testClearModuleInfoIllegal------\n");
}

/**
M
mamingshuai 已提交
150
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0009
W
wenjun 已提交
151 152 153
 * @tc.name      : testAbilityMgrSetWantElement parameter legal test
 * @tc.desc      : [C- SOFTWARE -0100]
 */
M
mamingshuai 已提交
154
HWTEST_F(BundleMgrTest, testSetElementAbilityName, Function | MediumTest | Level0)
W
wenjun 已提交
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
{
    printf("------start testSetElementAbilityName------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
    SetElementAbilityName(&element, "SecondAbility");
    SetWantElement(&want, element);
    printf("element is %s \n", want.element->abilityName);
    char aName[] = "SecondAbility";
    printf("aName is %s \n", aName);
    EXPECT_STREQ(want.element->abilityName, aName);
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testSetElementAbilityName------\n");
}

/**
M
mamingshuai 已提交
171
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0010
W
wenjun 已提交
172 173 174
 * @tc.name      : testSetElementAbilityName parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0100]
 */
M
mamingshuai 已提交
175
HWTEST_F(BundleMgrTest, testSetElementAbilityNameIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
{
    printf("------start testSetElementAbilityNameIllegal------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
    SetElementAbilityName(&element, nullptr);
    SetWantElement(&want, element);
    printf("AbilityName1 is %s \n", want.element->abilityName);
    EXPECT_STREQ(want.element->abilityName, nullptr);
    char aName[] = "";
    SetElementAbilityName(&element, aName);
    SetWantElement(&want, element);
    printf("AbilityName2 is %s \n", want.element->abilityName);
    EXPECT_STREQ(want.element->abilityName, "");
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testSetElementAbilityNameIllegal------\n");
}

/**
M
mamingshuai 已提交
195
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0007
W
wenjun 已提交
196 197 198
 * @tc.name      : testSetElementBundleName parameter legal test
 * @tc.desc      : [C- SOFTWARE -0100]
 */
M
mamingshuai 已提交
199
HWTEST_F(BundleMgrTest, testSetElementBundleName, Function | MediumTest | Level0)
W
wenjun 已提交
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
{
    printf("------start testSetElementBundleName------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
    SetElementBundleName(&element, "com.huawei.testjsdemo");
    SetWantElement(&want, element);
    printf("element is %s \n", want.element->bundleName);
    char bName[] = "com.huawei.testjsdemo";
    EXPECT_STREQ(want.element->bundleName, bName);
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testSetElementBundleName------\n");
}

/**
M
mamingshuai 已提交
215
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0008
W
wenjun 已提交
216 217 218
 * @tc.name      : testAbilityMgrSetWantElement parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0100]
 */
M
mamingshuai 已提交
219
HWTEST_F(BundleMgrTest, testSetElementBundleNameIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
{
    printf("------start testSetElementBundleNameIllegal------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
    SetElementBundleName(&element, "");
    SetWantElement(&want, element);
    printf("BundleName1 is %s \n", want.element->bundleName);
    char bName[] = "";
    EXPECT_STREQ(want.element->bundleName, bName);
    SetElementBundleName(&element, nullptr);
    SetWantElement(&want, element);
    printf("BundleName2 is %s \n", want.element->bundleName);
    EXPECT_STREQ(want.element->bundleName, nullptr);
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testSetElementBundleNameIllegal------\n");
}

/**
M
mamingshuai 已提交
239
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0005
W
wenjun 已提交
240 241 242
 * @tc.name      : testSetElementDeviceID parameter legal test
 * @tc.desc      : [C- SOFTWARE -0100]
 */
M
mamingshuai 已提交
243
HWTEST_F(BundleMgrTest, testSetElementDeviceID, Function | MediumTest | Level0)
W
wenjun 已提交
244 245 246 247 248 249 250 251 252 253 254 255 256 257
{
    printf("------start testSetElementDeviceID------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
    SetElementDeviceID(&element, "0001000");
    SetWantElement(&want, element);
    char dID[] = "0001000";
    EXPECT_STREQ(want.element->deviceId, dID);
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testSetElementDeviceID------\n");
}

/**
M
mamingshuai 已提交
258
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0006
W
wenjun 已提交
259 260 261
 * @tc.name      : testSetElementDeviceID parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0100]
 */
M
mamingshuai 已提交
262
HWTEST_F(BundleMgrTest, testSetElementDeviceIDIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
{
    printf("------start testSetElementDeviceIDIllegal------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
    SetElementDeviceID(&element, "");
    SetWantElement(&want, element);
    char dID[] = "";
    EXPECT_STREQ(want.element->deviceId, dID);
    SetElementDeviceID(&element, nullptr);
    SetWantElement(&want, element);
    EXPECT_STREQ(want.element->deviceId, nullptr);
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testSetElementDeviceIDIllegal------\n");
}

/**
M
mamingshuai 已提交
280
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0007
W
wenjun 已提交
281 282 283
 * @tc.name      : Install parameter illegal test that callback is null
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
284
HWTEST_F(BundleMgrTest, testInstallWithNullptr, Function | MediumTest | Level2)
W
wenjun 已提交
285 286
{
    printf("------start testInstallWithNullptr------\n");
M
mamingshuai 已提交
287 288 289
    string hapPath = g_testPath + "testnative.hap";
    InstallParam installParam = { .installLocation = 1, .keepData = false };
    bool isInstallSuccess = Install(hapPath.c_str(), &installParam, nullptr);
W
wenjun 已提交
290 291 292 293 294 295
    EXPECT_FALSE(isInstallSuccess);
    printf("install result is %d \n", isInstallSuccess);
    printf("------end testInstallWithNullptr------\n");
}

/**
M
mamingshuai 已提交
296
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0004
W
wenjun 已提交
297 298 299
 * @tc.name      : Install parameter illegal test that path is null
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
300
HWTEST_F(BundleMgrTest, testInstallWithNullPath, Function | MediumTest | Level2)
W
wenjun 已提交
301 302
{
    printf("------start testInstallWithNullPath------\n");
M
mamingshuai 已提交
303 304
    InstallParam installParam = { .installLocation = 1, .keepData = false };
    bool isInstallSuccess = Install(nullptr, &installParam, TestBundleStateCallback);
W
wenjun 已提交
305 306 307 308 309 310
    EXPECT_FALSE(isInstallSuccess);
    printf("install result is %d \n", isInstallSuccess);
    printf("------end testInstallWithNullPath------\n");
}

/**
M
mamingshuai 已提交
311
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0002
W
wenjun 已提交
312 313 314
 * @tc.name      : Install parameter illegal test that ErrorPath is wrong
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
315
HWTEST_F(BundleMgrTest, testInstallWithErrorPath, Function | MediumTest | Level2)
W
wenjun 已提交
316 317
{
    printf("------start testBundleMgrInstallWithErrorPath------\n");
M
mamingshuai 已提交
318
    string hapPath = "appexecfwk/nothishap.hap";
W
wenjun 已提交
319 320
    bool isInstallSuccess = false;
    sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
321 322
    InstallParam installParam = { .installLocation = 1, .keepData = false };
    bool installResult = Install(hapPath.c_str(), &installParam, TestBundleStateCallback);
W
wenjun 已提交
323 324 325 326 327 328 329 330 331 332 333 334 335
    sem_wait(&g_sem);
    if (g_errorCode == 0) {
        isInstallSuccess = true;
    }else if (g_errorCode > 0) {
        isInstallSuccess = false;
        HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrInstall failed,g_errorCode is: %d", g_errorCode);
    }
    EXPECT_FALSE(isInstallSuccess);
    printf("install result is %d", installResult);
    printf("------end testBundleMgrInstallWithErrorPath------\n");
}

/**
M
mamingshuai 已提交
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0001
 * @tc.name      : Install parameter legal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testBundleMgrInstallright, Function | MediumTest | Level0)
{
    printf("------start testBundleMgrInstallright------\n");
    string hapPath = g_testPath + "testnative.hap";
    bool isInstallSuccess = false;
    sem_init(&g_sem, 0, 0);
    InstallParam installParam = { .installLocation = 1, .keepData = false };
    bool installResult = Install(hapPath.c_str(), &installParam, TestBundleStateCallback);
    sem_wait(&g_sem);
    if (g_errorCode == 0) {
        isInstallSuccess = true;
    }else if (g_errorCode > 0) {
        isInstallSuccess = false;
        HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrInstall failed,g_errorCode is: %d", g_errorCode);
    }
    EXPECT_TRUE(isInstallSuccess);
    printf("install result is %d \n", installResult);
    printf("------end testBundleMgrInstallright------\n");
}
/**
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0003
W
wenjun 已提交
361 362 363
 * @tc.name      : Install parameter illegal test that Path is empty
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
364
HWTEST_F(BundleMgrTest, testBundleMgrInstallEmpty, Function | MediumTest | Level2)
W
wenjun 已提交
365 366 367 368 369
{
    printf("------start testBundleMgrInstallEmpty------\n");
    string hapPath = "";
    bool isInstallSuccess = false;
    sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
370 371
    InstallParam installParam = { .installLocation = 1, .keepData = false };
    bool installResult = Install(hapPath.c_str(), &installParam, TestBundleStateCallback);
W
wenjun 已提交
372 373 374 375 376 377 378 379 380 381 382 383 384
    sem_wait(&g_sem);
    if (g_errorCode == 0) {
        isInstallSuccess = true;
    }else if (g_errorCode > 0) {
        isInstallSuccess = false;
        HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrInstall failed,g_errorCode is: %d", g_errorCode);
    }
    EXPECT_FALSE(isInstallSuccess);
    printf("install result is %d", installResult);
    printf("------end testBundleMgrInstallEmpty------\n");
}

/**
M
mamingshuai 已提交
385 386
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0009
 * @tc.name      : Install parameter illegal test that file is bin
W
wenjun 已提交
387 388
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
389
HWTEST_F(BundleMgrTest, testBundleMgrInstallBin, Function | MediumTest | Level1)
W
wenjun 已提交
390 391
{
    printf("------start testBundleMgrInstallBin------\n");
M
mamingshuai 已提交
392
    string hapPath = g_testPath + "testdemo.bin";
W
wenjun 已提交
393 394
    bool isInstallSuccess = false;
    sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
395 396
    InstallParam installParam = { .installLocation = 1, .keepData = false };
    bool installResult = Install(hapPath.c_str(), &installParam, TestBundleStateCallback);
W
wenjun 已提交
397 398 399 400 401 402 403 404 405 406 407 408 409
    sem_wait(&g_sem);
    if (g_errorCode == 0) {
        isInstallSuccess = true;
    }else if (g_errorCode > 0) {
        isInstallSuccess = false;
        HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrInstall failed,g_errorCode is: %d", g_errorCode);
    }
    EXPECT_FALSE(isInstallSuccess);
    printf("install result is %d", installResult);
    printf("------end testBundleMgrInstallBin------\n");
}

/**
M
mamingshuai 已提交
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0008
 * @tc.name      : Install parameter illegal test that hap is destroyed
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testBundleMgrInstallBadfile, Function | MediumTest | Level2)
{
    printf("------start testBundleMgrInstallBadfile------\n");
    string hapPath = g_testPath + "errpinjie.hap";
    bool isInstallSuccess = false;
    sem_init(&g_sem, 0, 0);
    InstallParam installParam = { .installLocation = 1, .keepData = false };
    bool installResult = Install(hapPath.c_str(), &installParam, TestBundleStateCallback);
    sem_wait(&g_sem);
    if (g_errorCode == 0) {
        isInstallSuccess = true;
    }else if (g_errorCode > 0) {
        isInstallSuccess = false;
        HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrInstall failed,g_errorCode is: %d", g_errorCode);
    }
    EXPECT_FALSE(isInstallSuccess);
    printf("install result is %d", installResult);
    printf("------start testBundleMgrInstallBadfile------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0014
W
wenjun 已提交
436 437 438
 * @tc.name      : Uninstall parameter illegal test that callback is null
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
439
HWTEST_F(BundleMgrTest, testUninstallNullCallback, Function | MediumTest | Level2)
W
wenjun 已提交
440 441 442
{
    printf("------start testUninstallNullCallback------\n");
    const char *bundleName = (char*)"com.huawei.testdemo";
M
mamingshuai 已提交
443 444
    InstallParam installParam = { .installLocation = 1, .keepData = false };
    bool isUninstallSuccess = Uninstall(bundleName, &installParam, nullptr);
W
wenjun 已提交
445 446 447 448 449 450
    EXPECT_FALSE(isUninstallSuccess);
    printf("uninstall result is %d", isUninstallSuccess);
    printf("------end testUninstallNullCallback------\n");
}

/**
M
mamingshuai 已提交
451
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0013
W
wenjun 已提交
452 453 454
 * @tc.name      : Uninstall parameter illegal test that bundleName is null
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
455
HWTEST_F(BundleMgrTest, testUninstallnullBundleName, Function | MediumTest | Level2)
W
wenjun 已提交
456 457
{
    printf("------start testUninstallnullBundleName------\n");
M
mamingshuai 已提交
458 459
    InstallParam installParam = { .installLocation = 1, .keepData = false };
    bool isUninstallSuccess = Uninstall(nullptr, &installParam, TestBundleStateCallback);
W
wenjun 已提交
460 461 462 463 464 465
    EXPECT_FALSE(isUninstallSuccess);
    printf("uninstall result is %d", isUninstallSuccess);
    printf("------end testUninstallnullBundleName------\n");
}

/**
M
mamingshuai 已提交
466
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0010
W
wenjun 已提交
467 468 469
 * @tc.name      : Uninstall parameter legal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
470
HWTEST_F(BundleMgrTest, testUninstallright, Function | MediumTest | Level0)
W
wenjun 已提交
471 472
{
    printf("------start testUninstallright------\n");
M
mamingshuai 已提交
473
    string hapPath = g_testPath + "testnative.hap";
W
wenjun 已提交
474
    sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
475 476
    InstallParam installParam = { .installLocation = 1, .keepData = false };
    bool installResult = Install(hapPath.c_str(), &installParam, TestBundleStateCallback);
W
wenjun 已提交
477 478 479 480 481 482
    sem_wait(&g_sem);
    EXPECT_TRUE(installResult);
    sleep(1);
    const char *bundleName = (char*)"com.huawei.testnative";
    bool isUninstallSuccess = false;
    sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
483
    bool uninstallState = Uninstall(bundleName, &installParam, TestBundleStateCallback);
W
wenjun 已提交
484 485 486 487 488 489 490 491 492 493 494 495 496 497
    sem_wait(&g_sem);
    printf("uninstall result is %d", uninstallState);
    if (g_installState) {
        isUninstallSuccess = true;
    }else if (g_errorCode > 0) {
        isUninstallSuccess = false;
        HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrUninstall failed,g_errorCode is: %d", g_errorCode);
    }
    EXPECT_TRUE(uninstallState);
    printf("uninstall result is %d", isUninstallSuccess);
    printf("------end testUninstallright------\n");
}

/**
M
mamingshuai 已提交
498
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0011
W
wenjun 已提交
499 500 501
 * @tc.name      : Uninstall parameter illegal test that bundleName is wrong
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
502
HWTEST_F(BundleMgrTest, testUninstallErrorName, Function | MediumTest | Level2)
W
wenjun 已提交
503 504 505 506 507
{
    printf("------start testUninstallErrorName------\n");
    const char *bundleName = (char*)"com.huawei.nothisBundleName";
    bool isUninstallSuccess = false;
    sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
508 509
    InstallParam installParam = { .installLocation = 1, .keepData = false };
    bool uninstallState = Uninstall(bundleName, &installParam, TestBundleStateCallback);
W
wenjun 已提交
510
    sem_wait(&g_sem);
M
mamingshuai 已提交
511
    printf("uninstall result is %d", uninstallState);
W
wenjun 已提交
512 513 514 515 516 517 518 519 520 521 522 523
    if (g_installState) {
        isUninstallSuccess = true;
    }else if (g_errorCode > 0) {
        isUninstallSuccess = false;
        HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrUninstall failed,g_errorCode is: %d", g_errorCode);
    }
    EXPECT_FALSE(isUninstallSuccess);
    printf("uninstall result is %d", isUninstallSuccess);
    printf("------end testUninstallErrorName------\n");
}

/**
M
mamingshuai 已提交
524
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0012
W
wenjun 已提交
525 526 527
 * @tc.name      : Uninstall parameter illegal test that bundleName is empty
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
528
HWTEST_F(BundleMgrTest, testUninstallEmptyName, Function | MediumTest | Level2)
W
wenjun 已提交
529 530 531 532 533
{
    printf("------start testUninstallEmptyName------\n");
    const char *bundleName = (char*)"";
    bool isUninstallSuccess = false;
    sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
534 535
    InstallParam installParam = { .installLocation = 1, .keepData = false };
    bool uninstallState = Uninstall(bundleName, &installParam, TestBundleStateCallback);
W
wenjun 已提交
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
    sem_wait(&g_sem);
    printf("uninstall resute is %d", uninstallState);
    if (g_installState) {
        isUninstallSuccess = true;
    }else if (g_errorCode > 0) {
        isUninstallSuccess = false;
        HILOG_DEBUG(HILOG_MODULE_APP, "TestBundleMgrUninstall failed,g_errorCode is: %d", g_errorCode);
    }
    EXPECT_FALSE(isUninstallSuccess);
    printf("uninstall result is %d", isUninstallSuccess);
    printf("------end testUninstallEmptyName------\n");
}


/**
M
mamingshuai 已提交
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0040
 * @tc.name      : QueryAbilityInfo parameter legal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testQueryAbilityInfoRight, Function | MediumTest | Level1)
{
    printf("------start testQueryAbilityInfoRight------\n");
    Want want;
    memset_s(&want, sizeof(Want), 0, sizeof(Want));
    ElementName element;
    memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName));
    SetElementAbilityName(&element, "MainAbility");
    SetElementBundleName(&element, "com.huawei.testjsdemo");
    SetWantElement(&want, element);
    SetWantData(&want, "test", 4);
    AbilityInfo abilityInfo;
    memset_s(&abilityInfo, sizeof(abilityInfo), 0, sizeof(abilityInfo));
    printf("element.elementname is %s \n",  want.element->bundleName);
    printf("AbilityName2 is %s \n", want.element->abilityName);
    g_errorCode = QueryAbilityInfo(&want, &abilityInfo);
    printf("abilityInfo.bundleName is %s \n", abilityInfo.bundleName);
    printf("abilityInfo.label is %s \n", abilityInfo.label);
    printf("abilityInfo.iconPath is %s \n", abilityInfo.iconPath);
    printf("ret is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode == 0);
    printf("------end testQueryAbilityInfoRight------\n");
}
/**
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0041
W
wenjun 已提交
580 581 582
 * @tc.name      : QueryAbilityInfo parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
583
HWTEST_F(BundleMgrTest, testQueryAbilityInfoIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
{
    printf("------start testQueryAbilityInfoIllegal------\n");
    AbilityInfo abilityInfo;
    memset_s(&abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo));
    // want is nullptr
    g_errorCode = QueryAbilityInfo(nullptr, &abilityInfo);
    printf("ret is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode == 4);
    // abilityInfo is nullptr
    Want want;
    memset_s(&want, sizeof(Want), 0, sizeof(Want));
    ElementName element;
    memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName));
    SetElementAbilityName(&element, "MainAbility");
    SetElementBundleName(&element, "com.huawei.testjsdemo");
    SetWantElement(&want, element);
    SetWantData(&want, "test", 4);
    g_errorCode = QueryAbilityInfo(&want, nullptr);
    printf("ret is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode == 4);
    // content of want is ""
    Want want1 = { nullptr };
    ElementName element1 = { nullptr };
    SetElementBundleName(&element1, "");
    SetElementAbilityName(&element1, "");
    SetWantElement(&want1, element1);
    AbilityInfo abilityInfo1;
    g_errorCode = QueryAbilityInfo(&want1, &abilityInfo1);
    printf("abilityInfo is null \n");
    printf("ret is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode == 2);
    printf("------end testQueryAbilityInfoIllegal------\n");
}

/**
M
mamingshuai 已提交
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0029
 * @tc.name      : GetBundleInfo parameter legal test.
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testGetBundleInfoRight, Function | MediumTest | Level1)
{
    printf("------start testGetBundleInfoRight------\n");
    BundleInfo bundleInfo;
    memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo));
    const char *bundleName = (char*)"com.huawei.testjsdemo";
    int32_t flags = 0;
    printf("bundleName is %s \n", bundleName);
    sleep(2);
    g_errorCode = GetBundleInfo(bundleName, flags, &bundleInfo);
    printf("getBundleInfo result is %d \n", g_errorCode);
    EXPECT_STREQ(bundleInfo.bundleName, bundleName);
    EXPECT_EQ(bundleInfo.numOfAbility, 0);
    EXPECT_EQ(g_errorCode, 0);
    flags = 1;
    printf("bundleName is %s \n", bundleName);
    g_errorCode = GetBundleInfo(bundleName, flags, &bundleInfo);
    sleep(2);
    printf("getBundleInfo result is %d \n", g_errorCode);
    EXPECT_EQ(g_errorCode, 0);
    EXPECT_STREQ(bundleInfo.bundleName, bundleName);
    EXPECT_EQ(bundleInfo.numOfAbility, 3);
    ClearBundleInfo(&bundleInfo);
    printf("------end testGetBundleInfoRight------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0030
W
wenjun 已提交
651 652 653
 * @tc.name      : GetBundleInfo parameter illegal test.
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
654
HWTEST_F(BundleMgrTest, testGetBundleInfoIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
{
    printf("------start testGetBundleInfoIllegal------\n");
    BundleInfo bundleInfo;
    memset_s(&bundleInfo, sizeof(bundleInfo), 0, sizeof(bundleInfo));
    const char *bundleName = (char*)"com.huawei.nothishap";
    int32_t flags = 0;
    // error bundleName
    g_errorCode = GetBundleInfo(bundleName, flags, &bundleInfo);
    printf("bundleInfo1.bundleName is %s \n", bundleInfo.bundleName);
    printf("bundleInfo1.versionCode is %d \n", bundleInfo.versionCode);
    printf("bundleInfo1.codePath is %s \n", bundleInfo.codePath);
    EXPECT_EQ(g_errorCode, 2);
    // bundleName = nullptr
    g_errorCode = GetBundleInfo(nullptr, flags, &bundleInfo);
    printf("abilityInfo2 is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode == 4);
    printf("bundleInfo2.bundleName is %s \n", bundleInfo.bundleName);
    printf("bundleInfo2.versionCode is %d \n", bundleInfo.versionCode);
    printf("bundleInfo2.codePath is %s \n", bundleInfo.codePath);
    // bunldeName = ""
    g_errorCode = GetBundleInfo("", flags, &bundleInfo);
    printf("bundleInfo3.bundleName is %s \n", bundleInfo.bundleName);
    printf("bundleInfo3.versionCode is %d \n", bundleInfo.versionCode);
    printf("bundleInfo3.codePath is %s \n", bundleInfo.codePath);
    EXPECT_TRUE(g_errorCode == 2);
    // flags not exit
    g_errorCode = GetBundleInfo("com.huawei.testjsdemo", 2, &bundleInfo);
    sleep(2);
    printf("bundleInfo3.bundleName is %s \n", bundleInfo.bundleName);
    printf("bundleInfo3.versionCode is %d \n", bundleInfo.versionCode);
    printf("bundleInfo3.codePath is %s \n", bundleInfo.codePath);
    EXPECT_EQ(g_errorCode, 1);
    printf("------end testGetBundleInfoIllegal------\n");
}

/**
M
mamingshuai 已提交
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0042
 * @tc.name      : GetBundleInfos parameter legal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testGetBundleInfosRight, Function | MediumTest | Level1)
{
    printf("------start testGetBundleInfosRight------\n");
    BundleInfo *bundleInfos = nullptr;
    int32_t flags = 0;
    int32_t length = 0;
    g_errorCode = GetBundleInfos(flags, &bundleInfos, &length);
    sleep(2);
    printf("getBundleInfo result is %d \n", g_errorCode);
    EXPECT_EQ(g_errorCode, 0);
    if (g_errorCode == 0){
        printf("bundleInfos.codePath is %s \n", bundleInfos[0].codePath);
        printf("bundleInfos.bundleName is %s \n", bundleInfos[0].bundleName);
        printf("bundleInfos.versionCode is %d \n", bundleInfos[0].versionCode);
    }
    flags = 1;
    g_errorCode = GetBundleInfos(flags, &bundleInfos, &length);
    printf("getBundleInfo result is %d \n", g_errorCode);
    sleep(2);
    EXPECT_EQ(g_errorCode, 0);
        if (g_errorCode == 0){
        printf("bundleInfos.codePath is %s \n", bundleInfos[0].codePath);
        printf("bundleInfos.bundleName is %s \n", bundleInfos[0].bundleName);
        printf("bundleInfos.versionCode is %d \n", bundleInfos[0].versionCode);
    }
    free(bundleInfos);
    printf("------end testGetBundleInfosRight------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0043
W
wenjun 已提交
726 727 728
 * @tc.name      : GetBundleInfos parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
729
HWTEST_F(BundleMgrTest, testGetBundleInfosIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
{
    printf("------start testGetBundleInfosIllegal------\n");
    BundleInfo *bundleInfos = {nullptr};
    int32_t *length = nullptr;
    int32_t flags = 0;
    g_errorCode = GetBundleInfos(flags, nullptr, length);
    EXPECT_EQ(g_errorCode, 4);
    g_errorCode = GetBundleInfos(flags, &bundleInfos, nullptr);
    printf("g_errorCode is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode == 4);
    g_errorCode = GetBundleInfos(2, &bundleInfos, length);
    printf("g_errorCode is %d \n", g_errorCode);
    EXPECT_EQ(g_errorCode, 4);
    printf("------end testGetBundleInfosIllegal------\n");
}

/**
M
mamingshuai 已提交
747
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0039
W
wenjun 已提交
748 749 750
 * @tc.name      : GetBundleInfosByMetaData parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
751
HWTEST_F(BundleMgrTest, testGetBundleInfosByMetaDataIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777
{
    printf("------start testGetBundleInfosByMetaDataIllegal------\n");
    BundleInfo *bundleInfos = {nullptr};
    int32_t length = 0;
    const char *metaDataKey = "appId";
    g_errorCode = GetBundleInfosByMetaData(nullptr, &bundleInfos, &length);
    EXPECT_EQ(g_errorCode, 4);
    g_errorCode = GetBundleInfosByMetaData(metaDataKey, &bundleInfos, nullptr);
    printf("g_errorCode is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode == 4);
    g_errorCode = GetBundleInfosByMetaData(metaDataKey, nullptr, &length);
    printf("g_errorCode is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode == 4);
    const char *metaDataKey1 = "noThisKey";
    printf("metaDataKey is %s \n", metaDataKey1);
    g_errorCode = GetBundleInfosByMetaData(metaDataKey1, &bundleInfos, &length);
    printf("GetBundleInfosByMetaData result is %d \n", g_errorCode);
    EXPECT_EQ(g_errorCode, 2);
    const char *metaDataKey2 = "";
    g_errorCode = GetBundleInfosByMetaData(metaDataKey2, &bundleInfos, &length);
    printf("GetBundleInfosByMetaData result is %d \n", g_errorCode);
    EXPECT_EQ(g_errorCode, 2);
    printf("------end testGetBundleInfosByMetaDataIllegal------\n");
}

/**
M
mamingshuai 已提交
778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0038
 * @tc.name      : GetBundleInfosByMetaData parameter legal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testGetBundleInfosByMetaDataRight, Function | MediumTest | Level1)
{
    printf("------start testGetBundleInfosByMetaDataRight------\n");
    BundleInfo *bundleInfos = nullptr;
    const char *metaDataKey = "appId";
    int32_t length = 0;
    printf("metaDataKey is %s \n", metaDataKey);
    g_errorCode = GetBundleInfosByMetaData(metaDataKey, &bundleInfos, &length);
    sleep(2);
    printf("GetBundleInfosByMetaData result is %d \n", g_errorCode);
    EXPECT_EQ(g_errorCode, 0);
    if (g_errorCode == 0){
        printf("bundleInfos.bundleName is %s \n", bundleInfos[0].bundleName);
    }
    printf("------end testGetBundleInfosByMetaDataRight------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0037
W
wenjun 已提交
801 802 803
 * @tc.name      : QueryKeepAliveBundleInfos parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
804
HWTEST_F(BundleMgrTest, testQueryKeepAliveBundleInfosIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
805 806 807 808 809 810 811 812 813 814 815 816 817 818
{
    printf("------start testQueryKeepAliveBundleInfosIllegal------\n");
    BundleInfo *bundleInfos = {nullptr};
    int32_t length = 0;
    g_errorCode = QueryKeepAliveBundleInfos(nullptr, &length);
    printf("g_errorCode1 is %d \n", g_errorCode);
    EXPECT_EQ(g_errorCode, 4);
    g_errorCode = QueryKeepAliveBundleInfos(&bundleInfos, nullptr);
    printf("g_errorCode2 is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode == 4);
    printf("------end testQueryKeepAliveBundleInfosIllegal------\n");
}

/**
M
mamingshuai 已提交
819
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0034
W
wenjun 已提交
820 821 822
 * @tc.name      : GetBundleNameForUid parameter nullptr test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
823
HWTEST_F(BundleMgrTest, testGetBundleNameForUidWithNullptr, Function | MediumTest | Level2)
W
wenjun 已提交
824 825 826 827 828 829 830
{
    printf("------start testGetBundleNameForUidWithNullptr------\n");
    int32_t resultCode = GetBundleNameForUid(0, nullptr);
    EXPECT_EQ(resultCode, 4);
    printf("GetBundleNameForUid result is %d \n", resultCode);
    printf("------end testGetBundleNameForUidWithNullptr------\n");
}
M
mamingshuai 已提交
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_API_0035
 * @tc.name      : GetBundleNameForUid parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testGetBundleNameForUidWithIllegal, Function | MediumTest | Level2)
{
    printf("------start testGetBundleNameForUidWithIllegal------\n");
    char *bundleName = nullptr;
    int32_t resultCode = GetBundleNameForUid(0, &bundleName);
    EXPECT_EQ(resultCode, 114);
    printf("GetBundleNameForUid result is %d \n", resultCode);
    if (bundleName != nullptr) {
        free(bundleName);
    }
    printf("------end testGetBundleNameForUidWithIllegal------\n");
}
J
jiyong 已提交
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_SIZE_0001
 * @tc.name      : Test the GetBundleSize of the thirld hap can be obtained normally
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testGetBundleSizeWithLegal_0001, Function | MediumTest | Level1)
{
    printf("------start testGetBundleSizeWithLegal_0001------\n");
    char *bundleName = (char*)"com.huawei.testjsdemo";
    uint32_t resultCode = GetBundleSize(bundleName);
    EXPECT_GT(resultCode, 0);
    printf("------end testGetBundleSizeWithLegal_0001------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_SIZE_0002
 * @tc.name      : Test the GetBundleSize of the system hap can be obtained normally
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testGetBundleSizeWithLegal_0002, Function | MediumTest | Level1)
{
    printf("------start testGetBundleSizeWithLegal_0002------\n");
    char *bundleName = (char*)"com.huawei.launcher";
    uint32_t resultCode = GetBundleSize(bundleName);
    EXPECT_GT(resultCode, 0);
    printf("------end testGetBundleSizeWithLegal_0002------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_SIZE_0003
J
jiyong 已提交
880
 * @tc.name      : GetBundleSize parameter legal and bundleName length equal to 127 test
J
jiyong 已提交
881 882 883 884 885 886 887 888
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testGetBundleSizeWithLegal_0003, Function | MediumTest | Level1)
{
    printf("------start testGetBundleSizeWithLegal_0003------\n");
    char *bundleName = (char*)"com.huawei.testjsdemoBundleNameLengt" \
"hEqualTo127testjsdemoBundleNameLengthEqualTo127testjsdemoBundleNameLengthEqualTo127testjsde";
    sem_init(&g_sem, 0, 0);
J
jiyong 已提交
889
    InstallParam installParam = {.installLocation = 1,.keepData = false };
J
jiyong 已提交
890 891 892 893 894 895
    string hapPath = g_testPath + "testGetBundleNameWithLegal127.hap";
    Install(hapPath.c_str(), &installParam, TestBundleStateCallback);
    sem_wait(&g_sem);
    uint32_t resultCode = GetBundleSize(bundleName);
    EXPECT_EQ(strlen(bundleName), 127);
    EXPECT_GT(resultCode, 0);
J
jiyong 已提交
896
    // uninstall
J
jiyong 已提交
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
    sem_init(&g_sem, 0, 0);
    Uninstall(bundleName, &installParam, TestBundleStateCallback);
    sem_wait(&g_sem);
    printf("------end testGetBundleSizeWithLegal_0003------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_SIZE_0004
 * @tc.name      : GetBundleSize parameter illegal and bundleName length equal to 128 test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testGetBundleSizeWithIllegal_0001, Function | MediumTest | Level2)
{
    printf("------start testGetBundleSizeWithIllegal_0001------\n");
    char *bundleName = (char*)"com.huawei.testjsdemoBundleNameLength128test" \
"jsdemoBundleNameLength128testjsdemoBundleNameLength128testjsdemoBundleNameLength128T";
    EXPECT_EQ(strlen(bundleName), 128);
    uint32_t resultCode = GetBundleSize(bundleName);
    EXPECT_EQ(resultCode, 0);
    printf("------end testGetBundleSizeWithIllegal_0001------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_SIZE_0005
 * @tc.name      : GetBundleSize parameter illegal and bundleName nullptr test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testGetBundleSizeWithIllegal_0002, Function | MediumTest | Level2)
{
    printf("------start testGetBundleSizeWithIllegal_0002------\n");
    char *bundleName = nullptr;
J
jiyong 已提交
928
    // bundleName nullptr
J
jiyong 已提交
929 930 931 932 933 934 935 936 937 938 939 940 941 942
    uint32_t resultCode = GetBundleSize(bundleName);
    EXPECT_EQ(resultCode, 0);
    printf("------end testGetBundleSizeWithIllegal_0002------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_SIZE_0006
 * @tc.name      : GetBundleSize parameter illegal and bundleName error test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testGetBundleSizeWithIllegal_0003, Function | MediumTest | Level2)
{
    printf("------start testGetBundleSizeWithIllegal_0003------\n");
    char *bundleName = (char*)"com.huawei.nothishap";
J
jiyong 已提交
943
    // error bundleName
J
jiyong 已提交
944 945 946 947 948 949 950 951 952 953 954 955 956 957
    uint32_t resultCode = GetBundleSize(bundleName);
    EXPECT_EQ(resultCode, 0);
    printf("------end testGetBundleSizeWithIllegal_0003------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_SIZE_0007
 * @tc.name      : GetBundleSize parameter illegal and bundleName " " test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testGetBundleSizeWithIllegal_0004, Function | MediumTest | Level2)
{
    printf("------start testGetBundleSizeWithIllegal_0004------\n");
    char *bundleName = (char*)" ";
J
jiyong 已提交
958
    // bundleName " "
J
jiyong 已提交
959 960 961 962 963 964 965 966 967 968 969 970 971 972
    uint32_t resultCode = GetBundleSize(bundleName);
    EXPECT_EQ(resultCode, 0);
    printf("------end testGetBundleSizeWithIllegal_0004------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_SIZE_0008
 * @tc.name      : stress test of the same application
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testStressConfig_0001, Function | MediumTest | Level2)
{
    printf("------start testStressConfig_0001------\n");
    char *bundleName = (char*)"com.huawei.testjsdemo";
J
jiyong 已提交
973
    for (int i = 1; i <= 100; i++) {
J
jiyong 已提交
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
        uint32_t resultCode = GetBundleSize(bundleName);
        EXPECT_GT(resultCode, 0);
    }
    printf("------end testStressConfig_0001------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_BMS_SIZE_0009
 * @tc.name      : stress test of the difference application
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(BundleMgrTest, testStressConfig_0002, Function | MediumTest | Level2)
{
    printf("------start testStressConfig_0002------\n");
    char *bundleName = (char*)"com.huawei.testjsdemo";
    char *bundleName2 = (char*)"com.huawei.testjsdemoBtestjsdemoB";
    sem_init(&g_sem, 0, 0);
J
jiyong 已提交
991
    InstallParam installParam = {.installLocation = 1,.keepData = false };
J
jiyong 已提交
992
    string hapPath = g_testPath + "frequentlyStress.hap";
J
jiyong 已提交
993 994
    Install(hapPath.c_str(), &installParam, TestBundleStateCallback);
    sem_wait(&g_sem);
J
jiyong 已提交
995
    for (int i = 1; i <= 100; i++) {
J
jiyong 已提交
996 997 998 999 1000
        uint32_t resultCode = GetBundleSize(bundleName);
        EXPECT_GT(resultCode, 0);
        resultCode = GetBundleSize(bundleName2);
        EXPECT_GT(resultCode, 0);
    }
J
jiyong 已提交
1001
    // uninstall
J
jiyong 已提交
1002 1003 1004 1005 1006
    sem_init(&g_sem, 0, 0);
    Uninstall(bundleName2, &installParam, TestBundleStateCallback);
    sem_wait(&g_sem);
    printf("------end testStressConfig_0002------\n");
}