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 #include "filepath_util.h"
18
19 /**
20 * @tc.name : setvbuf_0100
21 * @tc.desc : Authentication is successful (call the setvbuf function to see the return value)
22 * @tc.level : Level 0
23 */
setvbuf_0100(void)24 void setvbuf_0100(void)
25 {
26 char buff[1024] = {0};
27 char path[PATH_MAX] = {0};
28 FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
29 FILE *fptr = fopen(path, "w+");
30 EXPECT_PTRNE("setvbuf_0100", fptr, NULL);
31
32 int result = setvbuf(fptr, buff, _IOFBF, 1024);
33 EXPECT_EQ("setvbuf_0100", result, 0);
34
35 fclose(fptr);
36 remove(path);
37 }
38
39 /**
40 * @tc.name : setvbuf_0200
41 * @tc.desc : Authentication is fails (call the setvbuf function to see the return value)
42 * @tc.level : Level 2
43 */
setvbuf_0200(void)44 void setvbuf_0200(void)
45 {
46 char buff[1024] = {0};
47 char path[PATH_MAX] = {0};
48 FILE_ABSOLUTE_PATH(STR_FILE_TXT, path);
49 FILE *fptr = fopen(path, "w+");
50 EXPECT_PTRNE("setvbuf_0100", fptr, NULL);
51
52 int result = setvbuf(fptr, buff, -1, 1024);
53 EXPECT_EQ("setvbuf_0200", result, -1);
54
55 fclose(fptr);
56 remove(path);
57 }
58
main(int argc,char * argv[])59 int main(int argc, char *argv[])
60 {
61 setvbuf_0100();
62 setvbuf_0200();
63 return t_status;
64 }