exit.c 2.5 KB
Newer Older
G
ganlan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * 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"
18
#include "filepath_util.h"
G
ganlan 已提交
19 20 21

/*
 * @tc.name      : exit_0100
G
ganlan 已提交
22 23
 * @tc.desc      : Verify that the file content of the auxiliary application output information is viewed
 *                 by calling the exit(0) function.
G
ganlan 已提交
24 25 26 27
 * @tc.level     : Level 0
 */
void exit_0100(void)
{
28 29 30
    char path[PATH_MAX] = {0};
    FILE_ABSOLUTE_DIR(path);
    char cmd[PATH_MAX] = {0};
D
dhy308 已提交
31 32
    snprintf(cmd, sizeof(cmd), "cd %s; ./exittest01", path);
    system(cmd);
G
ganlan 已提交
33 34

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

    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 已提交
51 52 53 54 55 56 57 58 59 60 61
    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)
{
62 63 64
    char path[PATH_MAX] = {0};
    FILE_ABSOLUTE_DIR(path);
    char cmd[PATH_MAX] = {0};
D
dhy308 已提交
65 66
    snprintf(cmd, sizeof(cmd), "cd %s; ./exittest02", path);
    system(cmd);
G
ganlan 已提交
67

G
ganlan 已提交
68 69
    char abc[100] = {0};
    const char *ptr = "/data/Exittest02.txt";
G
ganlan 已提交
70 71 72 73 74 75 76
    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 已提交
77
    }
G
ganlan 已提交
78 79 80
    char *content = fgets(abc, 27, fp);
    if (strcmp(content, "exit before")) {
        t_error("%s exit failed\n", __func__);
G
ganlan 已提交
81
    }
G
ganlan 已提交
82 83

    fclose(fp);
G
ganlan 已提交
84 85 86
    remove(ptr);
}

G
ganlan 已提交
87
int main(int argc, char *argv[])
G
ganlan 已提交
88
{
G
ganlan 已提交
89 90
    exit_0100();
    exit_0200();
G
ganlan 已提交
91 92
    return t_status;
}