AbilityMgrTest.cpp 33.8 KB
Newer Older
W
wenjun 已提交
1
/**
C
chengxingzhen 已提交
2
 * Copyright (c) 2022 Huawei Device Co., Ltd.
W
wenjun 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 * 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>
M
mamingshuai 已提交
18 19 20
#include <stdio.h>
#include <stdlib.h>
#include <string>
W
wenjun 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

#include "gtest/gtest.h"
#include "securec.h"

#include "ability.h"
#include "ability_connection.h"
#include "ability_env.h"
#include "ability_event_handler.h"
#include "ability_manager.h"
#include "ability_slice.h"
#include "abilityms_client.h"
#include "bundle_manager.h"
#include "want.h"

using namespace std;
using namespace testing::ext;
using namespace OHOS;
static int32_t g_errorCode = -1;
static sem_t g_sem;
static const int32_t WAIT_TIMEOUT = 30;
static bool g_installState = false;
M
mamingshuai 已提交
42
static string g_testPath;
W
wenjun 已提交
43 44 45 46 47 48 49 50 51 52

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

/* install 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 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
    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 已提交
68
    } else {
M
mamingshuai 已提交
69 70 71
        printf("Current Dir: %s\r\n", buffer);
        filePath = buffer;
        free(buffer);
W
wenjun 已提交
72
    }
M
mamingshuai 已提交
73
    return filePath + "/";
W
wenjun 已提交
74 75
}

M
mamingshuai 已提交
76
/* connectAbility callback */
W
wenjun 已提交
77 78 79 80 81 82 83 84 85 86 87
static void OnAbilityConnectDone(ElementName *elementName, SvcIdentity *serviceSid, int resultCode, void *storeData)
{
    printf("OnAbilityConnectDone, serviceSid is %p \n", serviceSid);
    printf("elementName is %s, %s \n", elementName->bundleName, elementName->abilityName);
    ClearElement(elementName);
    if (serviceSid == nullptr) {
        return;
    }
    printf("ipc callback success \n");
    // push data
    IpcIo request;
L
liubb_0516 已提交
88 89
    char data[MAX_IO_SIZE];
    IpcIoInit(&request, data, MAX_IO_SIZE, 0);
W
wenjun 已提交
90 91
    int32_t data1 = 10;
    int32_t data2 = 6;
L
liubb_0516 已提交
92 93
    WriteInt32(&request, data1);
    WriteInt32(&request, data2);
W
wenjun 已提交
94 95 96
    // send and getReply
    IpcIo reply = {nullptr};
    uintptr_t ptr = 0;
L
liubb_0516 已提交
97 98 99 100
    MessageOption option;
    MessageOptionInit(&option);
    SendRequest(*serviceSid, 0, &request, &reply, option, &ptr);
    ReadInt32(&reply, &g_errorCode);
M
mamingshuai 已提交
101 102
    if (g_errorCode != 0) {
        printf("execute add method, result is %d\n", g_errorCode);
W
wenjun 已提交
103 104
    }
    if (ptr != 0) {
L
liubb_0516 已提交
105
        FreeBuffer(reinterpret_cast<void *>(ptr));
W
wenjun 已提交
106 107 108 109
    }
    sem_post(&g_sem);
}

110
static void OnAbilityDisconnectDone(ElementName *elementName, int resultCode, void *storeData)
W
wenjun 已提交
111 112 113 114 115 116 117 118 119 120
{
    printf("OnAbilityDisconnectDone\n");
}


static IAbilityConnection g_conn = {
    .OnAbilityConnectDone = OnAbilityConnectDone,
    .OnAbilityDisconnectDone = OnAbilityDisconnectDone
};

M
mamingshuai 已提交
121
class AbilityMgrTest : public testing::Test {
W
wenjun 已提交
122 123 124 125 126 127 128 129
protected:
    static void SetUpTestCase(void)
    {
        printf("----------test case with AbilityMgrTest start-------------\n");
        HOS_SystemInit();
        AbilityMsClient::GetInstance().Initialize();
        sem_init(&g_sem, 0, 0);
        bool installResult = false;
M
mamingshuai 已提交
130 131 132 133 134 135 136 137
        InstallParam installParam = { .installLocation = 1, .keepData = false };
        g_testPath = GetCurDir();
#ifdef __LINUX__
        string hapPath = g_testPath + "testnative_hispark_taurus_linux.hap";
#else
        string hapPath = g_testPath + "testnative_hispark_taurus_liteos.hap";
#endif
        installResult = Install(hapPath.c_str(), &installParam, TestBundleStateCallback);
W
wenjun 已提交
138 139 140 141 142 143 144 145 146 147 148 149
        struct timespec ts = {};
        clock_gettime(CLOCK_REALTIME, &ts);
        ts.tv_sec += WAIT_TIMEOUT;
        sem_timedwait(&g_sem, &ts);
        if (installResult) {
            printf("sem exit \n");
        }
    }
    static void TearDownTestCase(void)
    {
        bool uninstallResult = false;
        sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
150
        InstallParam installParam = { .installLocation = 1, .keepData = false };
J
jiyong 已提交
151
        uninstallResult = Uninstall("com.openharmony.testnative", &installParam, TestBundleStateCallback);
W
wenjun 已提交
152 153 154 155 156 157 158 159 160
        sem_wait(&g_sem);
        if (uninstallResult) {
            printf("sem exit \n");
        }
        printf("----------test case with AbilityMgrTest end-------------\n");
    }
};

/**
M
mamingshuai 已提交
161
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0013
W
wenjun 已提交
162 163 164
 * @tc.name      : testClearElement parameter legal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
165
HWTEST_F(AbilityMgrTest, testClearElement, Function | MediumTest | Level0)
W
wenjun 已提交
166 167 168
{
    printf("------start testClearElement------\n");
    ElementName element = { nullptr };
M
mamingshuai 已提交
169 170
    bool setResult = SetElementAbilityName(&element, "SecondAbility");
    if (setResult) {
W
wenjun 已提交
171 172
        char aName[] = "SecondAbility";
        EXPECT_STREQ(element.abilityName, aName);
M
mamingshuai 已提交
173
        printf("abilityName is %s \n", element.abilityName);
W
wenjun 已提交
174 175 176 177 178 179 180
        ClearElement(&element);
        EXPECT_STREQ(element.abilityName, nullptr);
    }
    printf("------end testClearElement------\n");
}

/**
M
mamingshuai 已提交
181
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0014
W
wenjun 已提交
182 183 184
 * @tc.name      : testClearElement parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
185
HWTEST_F(AbilityMgrTest, testClearElementIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
186 187 188
{
    printf("------start testClearElementIllegal------\n");
    ElementName element = { nullptr };
M
mamingshuai 已提交
189 190
    bool setResult = SetElementAbilityName(&element, "SecondAbility");
    if (setResult) {
W
wenjun 已提交
191 192
        char aName[] = "SecondAbility";
        EXPECT_STREQ(element.abilityName, aName);
M
mamingshuai 已提交
193
        printf("abilityName is %s \n", element.abilityName);
W
wenjun 已提交
194 195
        ClearElement(nullptr);
        EXPECT_STREQ(element.abilityName, aName);
M
mamingshuai 已提交
196
        printf("AbilityName of element is %s \n", element.abilityName);
W
wenjun 已提交
197 198 199 200 201
    }
    printf("------end testClearElementIllegal------\n");
}

/**
M
mamingshuai 已提交
202
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0015
W
wenjun 已提交
203 204 205
 * @tc.name      : testSetWantElement parameter legal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
206
HWTEST_F(AbilityMgrTest, testSetWantElement, Function | MediumTest | Level0)
W
wenjun 已提交
207 208 209 210 211
{
    printf("------start testSetWantElement------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
    SetElementDeviceID(&element, "0001000");
J
jiyong 已提交
212
    SetElementBundleName(&element, "com.openharmony.testnative");
W
wenjun 已提交
213
    SetElementAbilityName(&element, "SecondAbility");
M
mamingshuai 已提交
214 215 216
    if (element.abilityName != nullptr) {
        bool setResult = SetWantElement(&want, element);
        if (setResult) {
W
wenjun 已提交
217 218
            EXPECT_STREQ(want.element->deviceId, "0001000");
            EXPECT_STREQ(want.element->abilityName, "SecondAbility");
J
jiyong 已提交
219
            EXPECT_STREQ(want.element->bundleName, "com.openharmony.testnative");
W
wenjun 已提交
220 221 222 223 224 225 226 227
        }
    }
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testSetWantElement------\n");
}

/**
M
mamingshuai 已提交
228
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0016
W
wenjun 已提交
229 230 231
 * @tc.name      : testSetWantElement parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
232
HWTEST_F(AbilityMgrTest, testSetWantElementIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
233 234 235 236
{
    printf("------start testSetWantElementIllegal------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
M
mamingshuai 已提交
237 238
    bool setResult = SetWantElement(&want, element);
    if (setResult) {
W
wenjun 已提交
239 240 241 242 243 244 245 246 247 248
        EXPECT_STREQ(want.element->deviceId, nullptr);
        EXPECT_STREQ(want.element->abilityName, nullptr);
        EXPECT_STREQ(want.element->bundleName, nullptr);
    }
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testSetWantElementIllegal------\n");
}

/**
M
mamingshuai 已提交
249
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0022
W
wenjun 已提交
250 251 252
 * @tc.name      : testClearWant parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
253
HWTEST_F(AbilityMgrTest, testClearWantIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
254 255 256 257
{
    printf("------start testClearWantIllegal------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
M
mamingshuai 已提交
258 259 260 261
    bool setResult = SetElementAbilityName(&element, "SecondAbility");
    if (setResult) {
        setResult = SetWantElement(&want, element);
        if (setResult) {
W
wenjun 已提交
262 263
            char aName[] = "SecondAbility";
            EXPECT_STREQ(want.element->abilityName, aName);
M
mamingshuai 已提交
264
            printf("abilityName is %s \n", want.element->abilityName);
W
wenjun 已提交
265 266 267 268 269 270 271 272 273 274
            ClearWant(nullptr);
            EXPECT_STREQ(want.element->abilityName, aName);
        }
    }
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testClearWantIllegal------\n");
}

/**
M
mamingshuai 已提交
275
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0025
W
wenjun 已提交
276 277 278
 * @tc.name      : testWantToUri parameter legal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
279
HWTEST_F(AbilityMgrTest, testWantToUri, Function | MediumTest | Level0)
W
wenjun 已提交
280 281 282 283 284
{
    printf("------start testWantToUri------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
    SetElementDeviceID(&element, "0001000");
J
jiyong 已提交
285
    SetElementBundleName(&element, "com.openharmony.testnative");
W
wenjun 已提交
286 287
    SetElementAbilityName(&element, "SecondAbility");
    if (element.abilityName !=nullptr) {
M
mamingshuai 已提交
288 289
        bool setResult = SetWantElement(&want, element);
        if (setResult) {
W
wenjun 已提交
290 291
            const char *uri = WantToUri(want);
            printf("uri is %s \n", uri);
J
jiyong 已提交
292
            const char *expectResult = "#Want;device=0001000;bundle=com.openharmony.testnative;ability=SecondAbility;end";
W
wenjun 已提交
293 294 295 296 297 298 299 300 301 302
            EXPECT_STREQ(uri, expectResult);
            free((void*)uri);
        }
    }
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testWantToUri------\n");
}

/**
M
mamingshuai 已提交
303
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0026
W
wenjun 已提交
304 305 306
 * @tc.name      : testWantToUri parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
307
HWTEST_F(AbilityMgrTest, testWantToUriIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
308 309 310 311 312 313 314 315 316 317 318 319 320 321
{
    printf("------start testWantToUriIllegal------\n");
    Want want = { nullptr };
    const char *uri = WantToUri(want);
    printf("uri is %s \n", uri);
    const char *expectResult = "#Want;device=;bundle=;ability=;end";
    EXPECT_STREQ(uri, expectResult);
    if (uri != nullptr) {
        free((void*)uri);
    }
    printf("------end testWantToUriIllegal------\n");
}

/**
M
mamingshuai 已提交
322
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0017
W
wenjun 已提交
323 324 325
 * @tc.name      : testSetWantDate parameter legal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
326
HWTEST_F(AbilityMgrTest, testSetWantDate, Function | MediumTest | Level0)
W
wenjun 已提交
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
{
    printf("------start testSetWantDate------\n");
    Want want = { nullptr };
    SetWantData(&want, "test", 5);
    if (want.data != nullptr) {
        printf("data is %s \n", (char*)(want.data));
        printf("dataLength is %d \n", want.dataLength);
        EXPECT_STREQ((char*)(want.data), "test");
        EXPECT_TRUE(want.dataLength == 5);
    }
    ClearWant(&want);
    printf("------end testSetWantDate------\n");
}

/**
M
mamingshuai 已提交
342
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0018
W
wenjun 已提交
343 344 345
 * @tc.name      : testSetWantDate parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
346
HWTEST_F(AbilityMgrTest, testSetWantDateIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
{
    printf("------start testSetWantDateIllegal------\n");
    Want want = { nullptr };
    SetWantData(&want, "test", -1);
    printf("dataLength is %d \n", want.dataLength);
    EXPECT_STREQ((char*)(want.data), nullptr);
    EXPECT_TRUE(want.dataLength == 0);
    SetWantData(&want, nullptr, 0);
    printf("dataLength is %d \n", want.dataLength);
    EXPECT_STREQ((char*)(want.data), nullptr);
    EXPECT_TRUE(want.dataLength == 0);
    printf("------end testSetWantDateIllegal------\n");
}

/**
M
mamingshuai 已提交
362
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0023
W
wenjun 已提交
363 364 365
 * @tc.name      : testWantParseUri parameter legal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
366
HWTEST_F(AbilityMgrTest, testWantParseUri, Function | MediumTest | Level0)
W
wenjun 已提交
367 368 369 370 371
{
    printf("------start testWantParseUri------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
    SetElementDeviceID(&element, "0001000");
J
jiyong 已提交
372
    SetElementBundleName(&element, "com.openharmony.testnative");
W
wenjun 已提交
373 374
    SetElementAbilityName(&element, "SecondAbility");
    if (element.abilityName != nullptr) {
M
mamingshuai 已提交
375 376
        bool setResult = SetWantElement(&want, element);
        if (setResult) {
W
wenjun 已提交
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
            const char *uri = WantToUri(want);
            Want *want2 = WantParseUri(uri);
            printf("uri is %s \n", uri);
            if (uri != nullptr) {
                free((void*)uri);
            }
            EXPECT_STREQ(want2->element->deviceId, want.element->deviceId);
            EXPECT_STREQ(want2->element->abilityName, want.element->abilityName);
            EXPECT_STREQ(want2->element->bundleName, want.element->bundleName);
            free(want2);
        }
    }
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testWantParseUri------\n");
}

/**
M
mamingshuai 已提交
395
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0024
W
wenjun 已提交
396 397 398
 * @tc.name      : testWantParseUri parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
399
HWTEST_F(AbilityMgrTest, testWantParseUriIllegal, Function | MediumTest | Level2)
W
wenjun 已提交
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
{
    printf("------start testWantParseUriIllegal------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
    SetElementBundleName(&element, nullptr);
    SetWantElement(&want, element);
    const char *uri = WantToUri(want);
    // empty
    printf("uri is %s \n", uri);
    Want *want2 = WantParseUri(uri);
    if (uri != nullptr) {
        free((void*)uri);
    }
    if (want2 != nullptr) {
        printf("want is %s \n", want2->element->bundleName);
        EXPECT_STREQ(want2->element->deviceId, "");
        EXPECT_STREQ(want2->element->abilityName, "");
        EXPECT_STREQ(want2->element->bundleName, "");
        free(want2);
M
mamingshuai 已提交
419
    }
W
wenjun 已提交
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
    // nullptr
    Want *want4 = WantParseUri(nullptr);
    printf("want4 is %p \n", want4);
    EXPECT_TRUE(want4 == nullptr);
    const char *str = "test";
    // error format
    Want *want1 = WantParseUri(str);
    printf("want is %p \n", want1);
    EXPECT_TRUE(want1 == nullptr);
    Want *want3 = WantParseUri("");
    printf("want is %p \n", want3);
    EXPECT_TRUE(want3 == nullptr);
    free(want1);
    free(want3);
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testWantParseUriIllegal------\n");
}

/**
M
mamingshuai 已提交
440
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0030
W
wenjun 已提交
441 442 443
 * @tc.name      : testGetBundleNameIllegal parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
444
HWTEST_F(AbilityMgrTest, testGetBundleNameIllegal, Function | MediumTest | Level1)
W
wenjun 已提交
445 446 447
{
    printf("------start testGetBundleNameIllegal------\n");
    Want want;
C
chengxingzhen 已提交
448
    (void)memset_s(&want, sizeof(Want), 0, sizeof(Want));
W
wenjun 已提交
449
    ElementName element;
C
chengxingzhen 已提交
450
    (void)memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName));
J
jiyong 已提交
451
    SetElementBundleName(&element, "com.openharmony.testnative");
M
mamingshuai 已提交
452
    SetElementAbilityName(&element, "SecondAbility");
W
wenjun 已提交
453 454 455 456 457
    SetWantElement(&want, element);
    int result = StartAbility(&want);
    sleep(2);
    printf("ret is %d \n", result);
    const char * bundleName1 = GetBundleName();
M
mamingshuai 已提交
458
    printf("result of GetBundleName is %s \n", bundleName1);
W
wenjun 已提交
459 460 461 462 463
    EXPECT_STREQ(bundleName1, "");
    printf("------end testGetBundleNameIllegal------\n");
}

/**
M
mamingshuai 已提交
464
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0031
W
wenjun 已提交
465 466 467
 * @tc.name      : testGetSrcPathIllegal parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
468
HWTEST_F(AbilityMgrTest, testGetSrcPathIllegal, Function | MediumTest | Level1)
W
wenjun 已提交
469 470 471 472
{
    printf("------start testGetSrcPathIllegal------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
J
jiyong 已提交
473
    SetElementBundleName(&element, "com.openharmony.testnative");
M
mamingshuai 已提交
474
    SetElementAbilityName(&element, "SecondAbility");
W
wenjun 已提交
475 476 477 478 479 480 481 482 483 484
    SetWantElement(&want, element);
    int result = StartAbility(&want);
    sleep(2);
    printf("ret is %d \n", result);
    const char * srcPath = GetSrcPath();
    EXPECT_STREQ(srcPath, "");
    printf("------end testGetSrcPathIllegal------\n");
}

/**
M
mamingshuai 已提交
485
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0032
W
wenjun 已提交
486 487 488
 * @tc.name      : testGetDataPath parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
489
HWTEST_F(AbilityMgrTest, testGetDataPathIllegal, Function | MediumTest | Level1)
W
wenjun 已提交
490 491 492 493
{
    printf("------start testGetDataPathIllegal------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
J
jiyong 已提交
494
    SetElementBundleName(&element, "com.openharmony.testnative");
M
mamingshuai 已提交
495
    SetElementAbilityName(&element, "SecondAbility");
W
wenjun 已提交
496 497 498 499 500
    SetWantElement(&want, element);
    int result = StartAbility(&want);
    sleep(2);
    printf("ret is %d \n", result);
    const char * dataPath = GetDataPath();
M
mamingshuai 已提交
501
    printf("result of GetDataPath is %s \n", dataPath);
W
wenjun 已提交
502 503 504 505 506
    EXPECT_STREQ(dataPath, "");
    printf("------end testGetDataPathIllegal------\n");
}

/**
M
mamingshuai 已提交
507
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0019
W
wenjun 已提交
508 509 510
 * @tc.name      : testDump parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
511
HWTEST_F(AbilityMgrTest, testDumpIllegal, Function | MediumTest | Level1)
W
wenjun 已提交
512 513 514
{
    printf("------start testDump------\n");
    Want want;
C
chengxingzhen 已提交
515
    (void)memset_s(&want, sizeof(Want), 0, sizeof(Want));
W
wenjun 已提交
516
    ElementName element;
C
chengxingzhen 已提交
517
    (void)memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName));
J
jiyong 已提交
518
    SetElementBundleName(&element, "com.openharmony.testnative");
M
mamingshuai 已提交
519
    SetElementAbilityName(&element, "SecondAbility");
W
wenjun 已提交
520 521 522
    SetWantElement(&want, element);
    Ability *ability = new Ability();
    int result = ability->StartAbility(want);
M
mamingshuai 已提交
523
    sleep(2);
W
wenjun 已提交
524 525 526 527 528 529 530 531
    printf("ret is %d \n", result);
    EXPECT_EQ(result, 0);
    char *extra = (char*)"test";
    ability->Dump(extra);
    printf("------end testDump------\n");
}

/**
M
mamingshuai 已提交
532 533
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0033
 * @tc.name      : testStartAbility parameter legal test
W
wenjun 已提交
534 535
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
536
HWTEST_F(AbilityMgrTest, testStartAbility, Function | MediumTest | Level1)
W
wenjun 已提交
537
{
M
mamingshuai 已提交
538
    printf("------start testStartAbility------\n");
W
wenjun 已提交
539 540
    Want want = { nullptr };
    ElementName element = { nullptr };
J
jiyong 已提交
541
    SetElementBundleName(&element, "com.openharmony.testnative");
M
mamingshuai 已提交
542
    SetElementAbilityName(&element, "MainAbility");
W
wenjun 已提交
543
    SetWantElement(&want, element);
M
mamingshuai 已提交
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560
    int result = StartAbility(&want);
    sleep(2);
    printf("ret is %d \n", result);
    EXPECT_EQ(result, 0);
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testStartAbility------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0005
 * @tc.name      : testStartAbilityIllegal parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(AbilityMgrTest, testStartAbilityIllegal, Function | MediumTest | Level2)
{
    printf("------start testStartAbilityIllegal------\n");
W
wenjun 已提交
561 562 563 564 565 566 567 568
    int result = StartAbility(nullptr);
    printf("ret is %d \n", result);
    int expect = -1;
    EXPECT_EQ(result, expect);
    printf("------end testStartAbilityIllegal------\n");
}

/**
M
mamingshuai 已提交
569 570
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0006
 * @tc.name      : testStopAbility parameter legal test
W
wenjun 已提交
571 572
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
573
HWTEST_F(AbilityMgrTest, testStopAbility, Function | MediumTest | Level0)
W
wenjun 已提交
574
{
M
mamingshuai 已提交
575
    printf("------start testStopAbility------\n");
W
wenjun 已提交
576 577
    Want want = { nullptr };
    ElementName element = { nullptr };
J
jiyong 已提交
578
    SetElementBundleName(&element, "com.openharmony.testnative");
W
wenjun 已提交
579 580 581
    SetElementAbilityName(&element, "ServiceAbility");
    SetWantElement(&want, element);
    g_errorCode = StartAbility(&want);
M
mamingshuai 已提交
582
    sleep(2);
W
wenjun 已提交
583 584
    printf("ret is %d \n", g_errorCode);
    EXPECT_EQ(g_errorCode, 0);
M
mamingshuai 已提交
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601
    g_errorCode = StopAbility(&want);
    sleep(2);
    printf("ret of stop is %d \n", g_errorCode);
    EXPECT_EQ(g_errorCode, 0);
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testStopAbility------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0007
 * @tc.name      : testStopAbilityIllegal parameter illegal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(AbilityMgrTest, testStopAbilityIllegal, Function | MediumTest | Level2)
{
    printf("------start testStopAbilityIllegal------\n");
W
wenjun 已提交
602 603 604 605 606 607 608
    g_errorCode = StopAbility(nullptr);
    printf("ret of stop is %d \n", g_errorCode);
    EXPECT_EQ(g_errorCode, -1);
    printf("------end testStopAbilityIllegal------\n");
}

/**
M
mamingshuai 已提交
609 610
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0008
 * @tc.name      : testConnectAbility parameter legal test
W
wenjun 已提交
611 612
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
613
HWTEST_F(AbilityMgrTest, testConnectAbility, Function | MediumTest | Level1)
W
wenjun 已提交
614
{
M
mamingshuai 已提交
615
    printf("------start testConnectAbility------\n");
W
wenjun 已提交
616 617
    Want want = { nullptr };
    ElementName element = { nullptr };
J
jiyong 已提交
618
    SetElementBundleName(&element, "com.openharmony.testnative");
W
wenjun 已提交
619 620 621
    SetElementAbilityName(&element, "ServiceAbility");
    SetWantElement(&want, element);
    sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
622
    int result = ConnectAbility(&want, &g_conn, this);
W
wenjun 已提交
623 624 625 626 627
    struct timespec ts = {};
    clock_gettime(CLOCK_REALTIME, &ts);
    ts.tv_sec += WAIT_TIMEOUT;
    sem_timedwait(&g_sem, &ts);
    printf("sem exit \n");
M
mamingshuai 已提交
628 629 630 631
    printf("ret is %d \n ", result);
    EXPECT_EQ(result, 0);
    DisconnectAbility(&g_conn);
    sleep(1);
W
wenjun 已提交
632 633
    ClearElement(&element);
    ClearWant(&want);
M
mamingshuai 已提交
634
    printf("------end testConnectAbility------\n");
W
wenjun 已提交
635 636 637
}

/**
M
mamingshuai 已提交
638 639 640
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0010
 * @tc.name      : testWantMathBundle
 * @tc.desc      : [C- SOFTWARE -0100]
J
jiyong 已提交
641
 * @tc.author    : lijiashan
M
mamingshuai 已提交
642 643 644 645 646 647
 */
HWTEST_F(AbilityMgrTest, testDisConnectAbility, Function | MediumTest | Level1)
{
    printf("------start testDisConnectAbility------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
J
jiyong 已提交
648
    SetElementBundleName(&element, "com.openharmony.testnative");
M
mamingshuai 已提交
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
    SetElementAbilityName(&element, "ServiceAbility");
    SetWantElement(&want, element);
    sem_init(&g_sem, 0, 0);
    int result = ConnectAbility(&want, &g_conn, this);
    struct timespec ts = {};
    clock_gettime(CLOCK_REALTIME, &ts);
    ts.tv_sec += WAIT_TIMEOUT;
    sem_timedwait(&g_sem, &ts);
    printf("sem exit \n");
    printf("ret of connect is %d \n ", result);
    if (g_errorCode == 16) {
        result = DisconnectAbility(&g_conn);
        sleep(2);
        EXPECT_EQ(result, 0);
        printf("ret of disconnect is %d \n ", result);
    }
    ClearElement(&element);
    ClearWant(&want);
    printf("------end testDisConnectAbility------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0009
 * @tc.name      : testConnectAbilityIllegal parameter illegal test
W
wenjun 已提交
673 674
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
675
HWTEST_F(AbilityMgrTest, testConnectAbilityIllegal, Function | MediumTest | Level1)
W
wenjun 已提交
676
{
M
mamingshuai 已提交
677
    printf("------start testConnectAbilityIllegal------\n");
W
wenjun 已提交
678 679
    Want want = { nullptr };
    ElementName element = { nullptr };
J
jiyong 已提交
680
    SetElementBundleName(&element, "com.openharmony.testnative");
W
wenjun 已提交
681 682 683 684 685 686 687 688 689 690
    SetElementAbilityName(&element, "ServiceAbility");
    SetWantElement(&want, element);
    g_errorCode = ConnectAbility(nullptr, &g_conn, this);
    printf("ret1 is %d \n ", g_errorCode);
    EXPECT_EQ(g_errorCode, -1);
    g_errorCode = ConnectAbility(&want, nullptr, this);
    printf("ret2 is %d \n ", g_errorCode);
    EXPECT_EQ(g_errorCode, -1);
    ClearElement(&element);
    ClearWant(&want);
M
mamingshuai 已提交
691
    printf("------end testConnectAbilityIllegal------\n");
W
wenjun 已提交
692 693 694
}

/**
M
mamingshuai 已提交
695 696
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0011
 * @tc.name      : testDisConnectAbilityIllegal parameter illegal test
W
wenjun 已提交
697 698
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
699
HWTEST_F(AbilityMgrTest, testDisConnectAbilityIllegal, Function | MediumTest | Level1)
W
wenjun 已提交
700
{
M
mamingshuai 已提交
701
    printf("------start testDisConnectAbilityIllegal------\n");
W
wenjun 已提交
702 703
    Want want = { nullptr };
    ElementName element = { nullptr };
J
jiyong 已提交
704
    SetElementBundleName(&element, "com.openharmony.testnative");
W
wenjun 已提交
705 706 707
    SetElementAbilityName(&element, "ServiceAbility");
    SetWantElement(&want, element);
    sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
708
    int result = ConnectAbility(&want, &g_conn, this);
W
wenjun 已提交
709 710 711 712 713
    struct timespec ts = {};
    clock_gettime(CLOCK_REALTIME, &ts);
    ts.tv_sec += WAIT_TIMEOUT;
    sem_timedwait(&g_sem, &ts);
    printf("sem exit \n");
L
liubb_0516 已提交
714
    printf("ret of connect is %d \n ", result);
M
mamingshuai 已提交
715
    EXPECT_EQ(result, 0);
W
wenjun 已提交
716
    g_errorCode = DisconnectAbility(nullptr);
L
liubb_0516 已提交
717
    int expect = -2;
W
wenjun 已提交
718 719 720 721
    EXPECT_EQ(g_errorCode, expect);
    printf("ret of disconnect is %d \n ", g_errorCode);
    ClearElement(&element);
    ClearWant(&want);
M
mamingshuai 已提交
722
    printf("------end testDisConnectAbilityIllegal------\n");
W
wenjun 已提交
723 724 725
}

/**
M
mamingshuai 已提交
726
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0012
W
wenjun 已提交
727 728 729
 * @tc.name      : testTerminateAbility parameter legal test
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
730
HWTEST_F(AbilityMgrTest, testTerminateAbility, Function | MediumTest | Level1)
W
wenjun 已提交
731 732 733 734
{
    printf("------start testTerminateAbility------\n");
    Want want = { nullptr };
    ElementName element = { nullptr };
J
jiyong 已提交
735
    SetElementBundleName(&element, "com.openharmony.testnative");
W
wenjun 已提交
736 737 738
    SetElementAbilityName(&element, "SecondAbility");
    SetWantElement(&want, element);
    int result1 = StartAbility(&want);
M
mamingshuai 已提交
739
    sleep(2);
W
wenjun 已提交
740 741 742 743
    printf("result1 of startAbility is %d \n", result1);
    EXPECT_EQ(result1, 0);
    Ability *ability = new Ability();
    int result2 = ability->TerminateAbility();
M
mamingshuai 已提交
744
    sleep(2);
W
wenjun 已提交
745 746 747 748 749 750 751 752 753
    printf("result2 of TerminateAbility is %d \n", result2);
    EXPECT_EQ(result2, 0);
    ClearElement(&element);
    ClearWant(&want);
    delete ability;
    printf("------end testTerminateAbility------\n");
}

/**
M
mamingshuai 已提交
754 755 756 757 758 759 760 761
 * @tc.number    : SUB_APPEXECFWK_AMS_WANT_0001
 * @tc.name      : test Want Match BundleInfo
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(AbilityMgrTest, testWantMatchBundle, Function | MediumTest | Level1)
{
    printf("------start testWantMathBundle------\n");
    Want want;
C
chengxingzhen 已提交
762
    (void)memset_s(&want, sizeof(Want), 0, sizeof(Want));
M
mamingshuai 已提交
763
    ElementName element;
C
chengxingzhen 已提交
764
    (void)memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName));
M
mamingshuai 已提交
765
    SetElementAbilityName(&element, "MainAbility");
J
jiyong 已提交
766
    SetElementBundleName(&element, "com.openharmony.testnative");
M
mamingshuai 已提交
767 768 769
    SetElementDeviceID(&element, "");
    SetWantElement(&want, element);
    AbilityInfo abilityInfo;
C
chengxingzhen 已提交
770
    (void)memset_s(&abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo));
M
mamingshuai 已提交
771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
    g_errorCode = QueryAbilityInfo(&want, &abilityInfo);
    printf("ret of query is %d \n", g_errorCode);
    EXPECT_EQ(g_errorCode, 0);
    if (g_errorCode == 0) {
        printf("abilityInfo.name is %s \n", abilityInfo.name);
    }
    int result = StartAbility(&want);
    sleep(2);
    printf("result of startAbility is %d \n", result);
    EXPECT_EQ(result, 0);
    printf("element is %s \n", want.element->bundleName);
    printf("element is %s \n", want.element->abilityName);
    StopAbility(&want);
    sleep(1);
    printf("------end testWantMathBundle------\n");
}

/**
 * @tc.number    : SUB_APPEXECFWK_AMS_WANT_0004
W
wenjun 已提交
790 791 792
 * @tc.name      : test Want Not Match BundleInfo
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
793
HWTEST_F(AbilityMgrTest, testWantNotMathBundle, Function | MediumTest | Level2)
W
wenjun 已提交
794 795 796
{
    printf("------start testWantNotMathBundle------\n");
    Want want;
C
chengxingzhen 已提交
797
    (void)memset_s(&want, sizeof(Want), 0, sizeof(Want));
W
wenjun 已提交
798
    ElementName element;
M
mamingshuai 已提交
799
    std::string aName = "NoThisAbility";
C
chengxingzhen 已提交
800
    (void)memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName));
M
mamingshuai 已提交
801
    SetElementAbilityName(&element, aName.c_str());
J
jiyong 已提交
802
    SetElementBundleName(&element, "com.openharmony.nothishap");
W
wenjun 已提交
803 804
    SetWantElement(&want, element);
    AbilityInfo abilityInfo;
C
chengxingzhen 已提交
805
    (void)memset_s(&abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo));
W
wenjun 已提交
806 807 808 809 810 811 812 813 814 815 816 817
    g_errorCode = QueryAbilityInfo(&want, &abilityInfo);
    printf("ret is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode != 0);
    int result = StartAbility(&want);
    sleep(2);
    printf("result of startAbility is %d \n", result);
    EXPECT_TRUE(result == 0);
    printf("element is %s \n", want.element->bundleName);
    printf("------end testWantNotMathBundle------\n");
}

/**
M
mamingshuai 已提交
818
 * @tc.number    : SUB_APPEXECFWK_AMS_WANT_0002
W
wenjun 已提交
819 820 821
 * @tc.name      : testWantOnlyMathBundle
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
822
HWTEST_F(AbilityMgrTest, testWantOnlyMathBundleName, Function | MediumTest | Level1)
W
wenjun 已提交
823 824 825
{
    printf("------start testWantOnlyMathBundleName------\n");
    Want want;
C
chengxingzhen 已提交
826
    (void)memset_s(&want, sizeof(Want), 0, sizeof(Want));
W
wenjun 已提交
827
    ElementName element;
M
mamingshuai 已提交
828
    std::string aName = "Ability";
C
chengxingzhen 已提交
829
    (void)memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName));
M
mamingshuai 已提交
830
    SetElementAbilityName(&element, aName.c_str());
J
jiyong 已提交
831
    SetElementBundleName(&element, "com.openharmony.testnative");
W
wenjun 已提交
832 833
    SetWantElement(&want, element);
    AbilityInfo abilityInfo;
C
chengxingzhen 已提交
834
    (void)memset_s(&abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo));
W
wenjun 已提交
835 836 837 838 839 840 841 842 843 844 845 846
    g_errorCode = QueryAbilityInfo(&want, &abilityInfo);
    printf("ret is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode != 0);
    int result = StartAbility(&want);
    sleep(2);
    printf("result of startAbility is %d \n", result);
    EXPECT_TRUE(result == 0);
    printf("element is %s \n", want.element->bundleName);
    printf("------end testWantOnlyMathBundleName------\n");
}

/**
M
mamingshuai 已提交
847
 * @tc.number    : SUB_APPEXECFWK_AMS_WANT_0003
W
wenjun 已提交
848 849 850
 * @tc.name      : testWantOnlyMathAbility
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
851
HWTEST_F(AbilityMgrTest, testWantOnlyMathAbility, Function | MediumTest | Level1)
W
wenjun 已提交
852 853 854
{
    printf("------start testWantOnlyMathAbility------\n");
    Want want;
C
chengxingzhen 已提交
855
    (void)memset_s(&want, sizeof(Want), 0, sizeof(Want));
W
wenjun 已提交
856
    ElementName element;
M
mamingshuai 已提交
857
    std::string aName = "MainAbility";
C
chengxingzhen 已提交
858
    (void)memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName));
M
mamingshuai 已提交
859
    SetElementAbilityName(&element, aName.c_str());
J
jiyong 已提交
860
    SetElementBundleName(&element, "com.openharmony.test");
W
wenjun 已提交
861 862
    SetWantElement(&want, element);
    AbilityInfo abilityInfo;
C
chengxingzhen 已提交
863
    (void)memset_s(&abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo));
W
wenjun 已提交
864 865 866 867 868 869 870 871 872 873 874 875
    g_errorCode = QueryAbilityInfo(&want, &abilityInfo);
    printf("ret is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode != 0);
    int result = StartAbility(&want);
    sleep(2);
    printf("result of startAbility is %d \n", result);
    EXPECT_TRUE(result == 0);
    printf("element is %s \n", want.element->abilityName);
    printf("------end testWantOnlyMathAbility------\n");
}

/**
M
mamingshuai 已提交
876 877 878 879 880 881 882 883
 * @tc.number    : SUB_APPEXECFWK_AMS_WANT_0005
 * @tc.name      : test WantData Match DataLength
 * @tc.desc      : [C- SOFTWARE -0200]
 */
HWTEST_F(AbilityMgrTest, testWantDataMatchLength, Function | MediumTest | Level1)
{
    printf("------start testWantDataMatchLength------\n");
    Want want;
C
chengxingzhen 已提交
884
    (void)memset_s(&want, sizeof(Want), 0, sizeof(Want));
M
mamingshuai 已提交
885
    ElementName element;
C
chengxingzhen 已提交
886
    (void)memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName));
M
mamingshuai 已提交
887
    SetElementAbilityName(&element, "MainAbility");
J
jiyong 已提交
888
    SetElementBundleName(&element, "com.openharmony.testnative");
M
mamingshuai 已提交
889 890 891
    SetWantElement(&want, element);
    SetWantData(&want, "test", 5);
    AbilityInfo abilityInfo;
C
chengxingzhen 已提交
892
    (void)memset_s(&abilityInfo, sizeof(AbilityInfo), 0, sizeof(AbilityInfo));
M
mamingshuai 已提交
893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909
    g_errorCode = QueryAbilityInfo(&want, &abilityInfo);
    printf("ret is %d \n", g_errorCode);
    EXPECT_TRUE(g_errorCode == 0);
    int result = StartAbility(&want);
    sleep(2);
    printf("result of startAbility is %d \n", result);
    EXPECT_TRUE(result == 0);
    EXPECT_STREQ((char*)(want.data), "test");
    EXPECT_EQ(want.dataLength, 5);
    StopAbility(&want);
    sleep(1);
    printf("------end testWantDataMatchLength------\n");
}


/**
 * @tc.number    : SUB_APPEXECFWK_AMS_WANT_0006
W
wenjun 已提交
910 911 912
 * @tc.name      : test WantData Not Match DataLength
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
913
HWTEST_F(AbilityMgrTest, testWantDataNotMatchLength, Function | MediumTest | Level2)
W
wenjun 已提交
914 915 916
{
    printf("------start testWantDataNotMatchLength------\n");
    Want want;
C
chengxingzhen 已提交
917
    (void)memset_s(&want, sizeof(Want), 0, sizeof(Want));
W
wenjun 已提交
918
    ElementName element;
C
chengxingzhen 已提交
919
    (void)memset_s(&element, sizeof(ElementName), 0, sizeof(ElementName));
W
wenjun 已提交
920
    SetElementAbilityName(&element, "SecondAbility");
J
jiyong 已提交
921
    SetElementBundleName(&element, "com.openharmony.testnative");
W
wenjun 已提交
922 923 924 925 926 927 928 929 930 931 932
    SetWantElement(&want, element);
    SetWantData(&want, "test", 3);
    int result = StartAbility(&want);
    sleep(2);
    printf("result of startAbility is %d \n", result);
    EXPECT_TRUE(result == 0);
    EXPECT_EQ(want.dataLength, 3);
    printf("------end testWantDataNotMatchLength------\n");
}

/**
M
mamingshuai 已提交
933
 * @tc.number    : SUB_APPEXECFWK_AMS_API_0040
W
wenjun 已提交
934 935 936
 * @tc.name      : PostTask parameter illegal test that callback is null
 * @tc.desc      : [C- SOFTWARE -0200]
 */
M
mamingshuai 已提交
937
HWTEST_F(AbilityMgrTest, testPostTask, Function | MediumTest | Level1)
W
wenjun 已提交
938 939
{
    printf("------start testPostTask------\n");
M
mamingshuai 已提交
940 941 942 943 944
#ifdef __LINUX__
    string hapPath = g_testPath + "testnative_hispark_taurus_linux.hap";
#else
    string hapPath = g_testPath + "testnative_hispark_taurus_liteos.hap";
#endif
W
wenjun 已提交
945
    AbilityEventHandler eventHandler1;
946
    auto task = [hapPath]{
W
wenjun 已提交
947
        sem_init(&g_sem, 0, 0);
M
mamingshuai 已提交
948 949
        InstallParam installParam = { .installLocation = 1, .keepData = false };
        bool installResult = Install(hapPath.c_str(), &installParam, TestBundleStateCallback);
W
wenjun 已提交
950 951 952 953 954 955 956 957 958 959 960
        sem_wait(&g_sem);
        printf("installResult is %d \n", installResult);
        EXPECT_TRUE(installResult);

        AbilityEventHandler *eventHandler2 = AbilityEventHandler::GetCurrentHandler();
        eventHandler2->PostQuit();
    };
    eventHandler1.PostTask(task);
    eventHandler1.Run();
    printf("------end testPostTask------\n");
}