• 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 <stdio_ext.h>
17 #include "functionalext.h"
18 
19 const int32_t NUM_ZERO = 0;
20 
21 /**
22  * @tc.name      : __fwritable_0100
23  * @tc.desc      : Verify that the file is writable (parameters are valid)
24  * @tc.level     : Level 0
25  */
__fwritable_0100(void)26 void __fwritable_0100(void)
27 {
28     const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt";
29     FILE *fptr = fopen(ptr, "w+");
30     if (!fptr) {
31         t_error("%s fopen failed\n", __func__);
32     }
33     int result = __fwritable(fptr);
34     EXPECT_NE("__fwritable_0100", result, NUM_ZERO);
35     fclose(fptr);
36 }
37 
38 /**
39  * @tc.name      : __fwritable_0200
40  * @tc.desc      : Verify file is not writable (parameter invalid)
41  * @tc.level     : Level 1
42  */
__fwritable_0200(void)43 void __fwritable_0200(void)
44 {
45     const char *ptr = "/data/tests/libc-test/src/functionalext/supplement/stdio/Freadtest.txt";
46     FILE *fptr = fopen(ptr, "r");
47     if (!fptr) {
48         t_error("%s fopen failed\n", __func__);
49     }
50     int result = __fwritable(fptr);
51     EXPECT_EQ("__fwritable_0200", result, NUM_ZERO);
52     fclose(fptr);
53     remove(ptr);
54 }
55 
main(int argc,char * argv[])56 int main(int argc, char *argv[])
57 {
58     __fwritable_0100();
59     __fwritable_0200();
60     return t_status;
61 }