1/*
2 * Copyright (c) 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 "functionalext.h"
17
18/**
19 * @tc.name      : execlp_0100
20 * @tc.desc      : Each parameter is valid, and the specified file can be executed.
21 * @tc.level     : Level 0
22 */
23void execlp_0100(void)
24{
25    pid_t fpid;
26    fpid = fork();
27    if (fpid == 0) {
28        int ret = execlp("touch", "touch", "execlptest.txt", NULL);
29        EXPECT_NE("execlp_0100", ret, -1);
30    }
31    sleep(1);
32
33    int isExist = access("execlptest.txt", F_OK);
34    EXPECT_EQ("execlp_0100", isExist, 0);
35    remove("execlptest.txt");
36}
37
38/**
39 * @tc.name      : execlp_0200
40 * @tc.desc      : The content pointed to by the file parameter is empty, and the specified file cannot be executed.
41 * @tc.level     : Level 2
42 */
43void execlp_0200(void)
44{
45    int ret = execlp(" ", "touch", "execlptest.txt", NULL);
46    EXPECT_EQ("execlp_0200", ret, -1);
47}
48
49/**
50 * @tc.name      : execlp_0300
51 * @tc.desc      : The length of file exceeds NAME_MAX, and the specified file cannot be executed.
52 * @tc.level     : Level 2
53 */
54void execlp_0300(void)
55{
56    char buff[300];
57    for (int i = 0; i < 300; i++) {
58        buff[i] = 'a';
59    }
60    int ret = execlp(buff, "touch", "execlptest.txt", NULL);
61    EXPECT_EQ("execlp_0300", ret, -1);
62}
63
64int main(int argc, char *argv[])
65{
66    execlp_0100();
67    execlp_0200();
68    execlp_0300();
69    return t_status;
70}