• 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 char *path = "/data/freadable.txt";
20 
21 /**
22  * @tc.name      : __freadable_0100
23  * @tc.desc      : The parameters are valid, and the file can be judged to be readable.
24  * @tc.level     : Level 0
25  */
__freadable_0100(void)26 void __freadable_0100(void)
27 {
28     char buf[100];
29     FILE *fp = fopen(path, "w");
30     EXPECT_PTRNE("__freadable_0100", fp, NULL);
31     fclose(fp);
32     FILE *ffp = fopen(path, "r");
33     EXPECT_PTRNE("__freadable_0100", ffp, NULL);
34 
35     size_t ret = __freadable(ffp);
36     EXPECT_NE("__freadable_0100", ret, 0);
37 
38     fclose(ffp);
39     remove(path);
40 }
41 
42 /**
43  * @tc.name      : __freadable_0200
44  * @tc.desc      : The parameters are valid, and the file can be judged to be unreadable.
45  * @tc.level     : Level 1
46  */
__freadable_0200(void)47 void __freadable_0200(void)
48 {
49     FILE *fp = fopen(path, "wb");
50     EXPECT_PTRNE("__freadable_0200", fp, NULL);
51 
52     size_t ret = __freadable(fp);
53     EXPECT_EQ("__freadable_0200", ret, 0);
54 
55     fclose(fp);
56     remove(path);
57 }
58 
main(int argc,char * argv[])59 int main(int argc, char *argv[])
60 {
61     __freadable_0100();
62     __freadable_0200();
63     return t_status;
64 }