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 /**
22 * @tc.name : fgetln_0100
23 * @tc.desc : Returns a pointer to the next line from the stream referenced by stream
24 * @tc.level : level 0
25 */
fgetln_0100(void)26 void fgetln_0100(void)
27 {
28 size_t plen;
29
30 FILE *f = fopen("/data/test.txt", "w+");
31 if (!f) {
32 t_error("%s fopen failed\n", __func__);
33 }
34
35 fputs("HelloWorld", f);
36 fseek(f, 0, SEEK_SET);
37 char *result = fgetln(f, &plen);
38 if (!result) {
39 t_error("%s fgetln failed\n", __func__);
40 }
41 if (strcmp(result, "HelloWorld")) {
42 t_error("%s result is %s, not HelloWorld\n", __func__, result);
43 }
44 if (plen != strlen(result)) {
45 t_error("%s failed, plen is %zu\n", __func__, plen);
46 }
47
48 fclose(f);
49 remove("/data/test.txt");
50 }
51
52 /**
53 * @tc.name : fgetln_0200
54 * @tc.desc :
55 * @tc.level : level 2
56 */
fgetln_0200(void)57 void fgetln_0200(void)
58 {
59 size_t plen;
60
61 FILE *f = fopen("/data/test.txt", "w+");
62 if (!f) {
63 t_error("%s fopen failed\n", __func__);
64 }
65
66 char *result = fgetln(f, &plen);
67 if (result) {
68 t_error("%s fgetln should be failed\n", __func__);
69 }
70
71 fclose(f);
72 remove("/data/test.txt");
73 }
74
main(int argc,char * argv[])75 int main(int argc, char *argv[])
76 {
77 fgetln_0100();
78 fgetln_0200();
79 return t_status;
80 }