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 <stdio.h>
17 #include <stdio_ext.h>
18 #include <stdlib.h>
19 #include <stdint.h>
20 #include <stddef.h>
21 #include "functionalext.h"
22
23 const int32_t NUM_ZERO = 0;
24
25 /**
26 * @tc.name : __fwriting_0100
27 * @tc.desc : Verify that the file stream is write-only
28 * @tc.level : Level 0
29 */
__fwriting_0100(void)30 void __fwriting_0100(void)
31 {
32 const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt";
33 FILE *fptr = fopen(ptr, "w");
34 int result = __fwriting(fptr);
35 EXPECT_NE("__fwriting_0100", result, NUM_ZERO);
36 fclose(fptr);
37 remove(ptr);
38 }
39
40 /**
41 * @tc.name : __fwriting_0200
42 * @tc.desc : The last operation on the stream was a write operation
43 * @tc.level : Level 0
44 */
__fwriting_0200(void)45 void __fwriting_0200(void)
46 {
47 const char *wrstring = "helloworld";
48 const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt";
49 FILE *fptr = fopen(ptr, "w+");
50 fwrite(wrstring, sizeof(char), strlen(wrstring), fptr);
51 int result = __fwriting(fptr);
52 EXPECT_NE("__fwriting_0200", result, NUM_ZERO);
53 fclose(fptr);
54 remove(ptr);
55 }
56
57 /**
58 * @tc.name : __fwriting_0300
59 * @tc.desc : The last operation on the stream was not a write operation
60 * @tc.level : Level 2
61 */
__fwriting_0300(void)62 void __fwriting_0300(void)
63 {
64 char abc[100] = {0};
65 const char *wrstring = "helloworld";
66 const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt";
67 FILE *fptr = fopen(ptr, "w+");
68 fwrite(wrstring, sizeof(char), strlen(wrstring), fptr);
69 fseek(fptr, 0, SEEK_SET);
70 int32_t rsize = fread(abc, 1, 10, fptr);
71 int result = __fwriting(fptr);
72 EXPECT_EQ("__fwriting_0300", result, NUM_ZERO);
73 fclose(fptr);
74 remove(ptr);
75 }
76
main(int argc,char * argv[])77 int main(int argc, char *argv[])
78 {
79 __fwriting_0100();
80 __fwriting_0200();
81 __fwriting_0300();
82 return t_status;
83 }