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