• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <stdlib.h>
17 #include "functionalext.h"
18 #include "filepath_util.h"
19 
20 /*
21  * @tc.name      : exit_0100
22  * @tc.desc      : Verify that the file content of the auxiliary application output information is viewed
23  *                 by calling the exit(0) function.
24  * @tc.level     : Level 0
25  */
exit_0100(void)26 void exit_0100(void)
27 {
28     char path[PATH_MAX] = {0};
29     FILE_ABSOLUTE_DIR(path);
30     char cmd[PATH_MAX] = {0};
31     snprintf(cmd, sizeof(cmd), "cd %s; ./exittest01", path);
32     system(cmd);
33 
34     char str[100] = {0};
35     const char *ptr = "/data/Exittest01.txt";
36     FILE *fp = fopen(ptr, "r");
37     if (!fp) {
38         t_error("%s fopen failed\n", __func__);
39     }
40     int ret = fseek(fp, 0, SEEK_SET);
41     if (ret != 0) {
42         t_error("%s fseek failed\n", __func__);
43     }
44 
45     size_t rsize = fread(str, sizeof(str), 1, fp);
46     if (strcmp(str, "exit before")) {
47         t_error("%s exit failed\n", __func__);
48     }
49 
50     fclose(fp);
51     remove(ptr);
52 }
53 
54 /*
55  * @tc.name      : exit_0200
56  * @tc.desc      : Verify that the file content of the auxiliary application output information
57  *                 is viewed by calling the exit(1) function.
58  * @tc.level     : Level 0
59  */
exit_0200(void)60 void exit_0200(void)
61 {
62     char path[PATH_MAX] = {0};
63     FILE_ABSOLUTE_DIR(path);
64     char cmd[PATH_MAX] = {0};
65     snprintf(cmd, sizeof(cmd), "cd %s; ./exittest02", path);
66     system(cmd);
67 
68     char abc[100] = {0};
69     const char *ptr = "/data/Exittest02.txt";
70     FILE *fp = fopen(ptr, "r");
71     if (!fp) {
72         t_error("%s fopen failed\n", __func__);
73     }
74     int ret = fseek(fp, 0, SEEK_SET);
75     if (ret != 0) {
76         t_error("%s fseek failed\n", __func__);
77     }
78     char *content = fgets(abc, 27, fp);
79     if (strcmp(content, "exit before")) {
80         t_error("%s exit failed\n", __func__);
81     }
82 
83     fclose(fp);
84     remove(ptr);
85 }
86 
main(int argc,char * argv[])87 int main(int argc, char *argv[])
88 {
89     exit_0100();
90     exit_0200();
91     return t_status;
92 }