exit.c 2.3 KB
Newer Older
G
ganlan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * 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 <stdlib.h>
#include "functionalext.h"

/*
 * @tc.name      : exit_0100
G
ganlan 已提交
21 22
 * @tc.desc      : Verify that the file content of the auxiliary application output information is viewed
 *                 by calling the exit(0) function.
G
ganlan 已提交
23 24 25 26 27
 * @tc.level     : Level 0
 */
void exit_0100(void)
{
    system("cd /data/tests/libc-test/src/functionalext/supplement/unistd/; ./exittest01");
G
ganlan 已提交
28 29

    char str[100] = {0};
G
ganlan 已提交
30
    const char *ptr = "/data/Exittest01.txt";
G
ganlan 已提交
31 32 33
    FILE *fp = fopen(ptr, "r");
    if (!fp) {
        t_error("%s fopen failed\n", __func__);
G
ganlan 已提交
34
    }
G
ganlan 已提交
35 36 37
    int ret = fseek(fp, 0, SEEK_SET);
    if (ret != 0) {
        t_error("%s fseek failed\n", __func__);
G
ganlan 已提交
38
    }
G
ganlan 已提交
39 40 41 42 43 44 45

    size_t rsize = fread(str, sizeof(str), 1, fp);
    if (strcmp(str, "exit before")) {
        t_error("%s exit failed\n", __func__);
    }

    fclose(fp);
G
ganlan 已提交
46 47 48 49 50 51 52 53 54 55 56 57
    remove(ptr);
}

/*
 * @tc.name      : exit_0200
 * @tc.desc      : Verify that the file content of the auxiliary application output information
 *                 is viewed by calling the exit(1) function.
 * @tc.level     : Level 0
 */
void exit_0200(void)
{
    system("cd /data/tests/libc-test/src/functionalext/supplement/unistd/; ./exittest02");
G
ganlan 已提交
58

G
ganlan 已提交
59 60
    char abc[100] = {0};
    const char *ptr = "/data/Exittest02.txt";
G
ganlan 已提交
61 62 63 64 65 66 67
    FILE *fp = fopen(ptr, "r");
    if (!fp) {
        t_error("%s fopen failed\n", __func__);
    }
    int ret = fseek(fp, 0, SEEK_SET);
    if (ret != 0) {
        t_error("%s fseek failed\n", __func__);
G
ganlan 已提交
68
    }
G
ganlan 已提交
69 70 71
    char *content = fgets(abc, 27, fp);
    if (strcmp(content, "exit before")) {
        t_error("%s exit failed\n", __func__);
G
ganlan 已提交
72
    }
G
ganlan 已提交
73 74

    fclose(fp);
G
ganlan 已提交
75 76 77
    remove(ptr);
}

G
ganlan 已提交
78
int main(int argc, char *argv[])
G
ganlan 已提交
79
{
G
ganlan 已提交
80 81
    exit_0100();
    exit_0200();
G
ganlan 已提交
82 83
    return t_status;
}