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 <fcntl.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include "test.h"
20 
21 const char *wrstring = "This is a test sample!";
22 const char *path = "test.txt";
23 
24 /**
25  * @tc.name      : getc_0100
26  * @tc.desc      : Verify that the characters in the file can be get
27  * @tc.level     : Level 0
28  */
getc_0100(void)29 void getc_0100(void)
30 {
31     FILE *fptr = fopen(path, "w+");
32     if (!fptr) {
33         t_error("%s fopen failed\n", __func__);
34     }
35 
36     size_t ret = fwrite(wrstring, sizeof(char), strlen(wrstring), fptr);
37     if (ret < 0) {
38         t_error("%s fwrite failed\n", __func__);
39     }
40 
41     int fret = fseek(fptr, 0, SEEK_SET);
42     if (fret != 0) {
43         t_error("%s fseek failed\n", __func__);
44     }
45     char ch = getc(fptr);
46     if (ch != 'T') {
47         t_error("%s getc failed\n", __func__);
48     }
49 
50     fclose(fptr);
51     remove(path);
52 }
53 
main(int argc, char *argv[])54 int main(int argc, char *argv[])
55 {
56     getc_0100();
57     return t_status;
58 }