• 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 <stdlib.h>
17 #include <stdint.h>
18 #include "functionalext.h"
19 
20 typedef void (*TEST_FUN)();
21 
22 const int32_t NUN_ELEVEN = 11;
23 
24 /**
25  * @tc.name      : fgetpos_0100
26  * @tc.desc      : File pointer at the end of a file, the position to which the current file pointer points
27  * @tc.level     : Level 0
28  */
fgetpos_0100()29 void fgetpos_0100()
30 {
31     fpos_t pos;
32     char buff[] = "hello world";
33     const char *path = "/data/test.txt";
34 
35     FILE *fp = fopen(path, "w+");
36     EXPECT_PTRNE("fgetpos_0100", fp, NULL);
37 
38     fputs(buff, fp);
39     fseek(fp, 0, SEEK_END);
40 
41     int result = fgetpos(fp, &pos);
42     EXPECT_EQ("fgetpos_0100", result, 0);
43 
44     fclose(fp);
45     remove(path);
46 }
47 
48 /**
49  * @tc.name      : fgetpos_0200
50  * @tc.desc      : File pointer at the beginning of a file, the location to which the current file pointer points
51  * @tc.level     : Level 0
52  */
fgetpos_0200()53 void fgetpos_0200()
54 {
55     fpos_t pos;
56     char buff[] = "hello world";
57     const char *path = "/data/test.txt";
58 
59     FILE *fptr = fopen(path, "w+");
60     EXPECT_PTRNE("fgetpos_0100", fptr, NULL);
61 
62     fputs(buff, fptr);
63     fseek(fptr, 0, SEEK_SET);
64     int result = fgetpos(fptr, &pos);
65     EXPECT_EQ("fgetpos_0200", result, 0);
66 
67     fclose(fptr);
68     remove(path);
69 }
70 
71 TEST_FUN G_Fun_Array[] = {
72     fgetpos_0100,
73     fgetpos_0200,
74 };
75 
main(int argc,char * argv[])76 int main(int argc, char *argv[])
77 {
78     int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
79     for (int pos = 0; pos < num; ++pos) {
80         G_Fun_Array[pos]();
81     }
82 
83     return t_status;
84 }