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 <fcntl.h>
17 #include <unistd.h>
18 #include "functionalext.h"
19
20 typedef void (*TEST_FUN)();
21
22 /**
23 * @tc.name : isatty_0100
24 * @tc.desc : Verify that the file is a terminal (parameters are valid)
25 * @tc.level : Level 0
26 */
isatty_0100()27 void isatty_0100()
28 {
29 int result = isatty(fileno(stdout));
30 EXPECT_EQ("isatty_0100", result, 1);
31 }
32
33 /**
34 * @tc.name : isatty_0200
35 * @tc.desc : Verify that the file is not a terminal (parameter invalid)
36 * @tc.level : Level 2
37 */
isatty_0200()38 void isatty_0200()
39 {
40 int fd = open("/data/readtest.txt", O_RDWR | O_CREAT, TEST_MODE);
41 int result = isatty(fd);
42 EXPECT_EQ("isatty_0200", result, 0);
43 close(fd);
44 remove("/data/readtest.txt");
45 }
46
47 TEST_FUN G_Fun_Array[] = {
48 isatty_0100,
49 isatty_0200,
50 };
51
main(int argc,char * argv[])52 int main(int argc, char *argv[])
53 {
54 int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
55 for (int pos = 0; pos < num; ++pos) {
56 G_Fun_Array[pos]();
57 }
58
59 return t_status;
60 }