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 "functionalext.h"
17 
18 const char *path = "/data/fputs.txt";
19 
20 /**
21  * @tc.name       : fputs_0100
22  * @tc.desc       : Writes the string s to stream
23  * @tc.level      : level 0.
24  */
fputs_0100(void)25 void fputs_0100(void)
26 {
27     FILE *fptr = fopen(path, "w+");
28     EXPECT_PTRNE("fputs_0100", fptr, NULL);
29 
30     int len = fputs("this is a test string", fptr);
31     EXPECT_TRUE("fputs_0100", len >= 0);
32     fclose(fptr);
33     remove(path);
34 }
35 
36 /**
37  * @tc.name       : fputs_0200
38  * @tc.desc       : An empty string is written in the specified file.
39  * @tc.level      : level 0.
40  */
fputs_0200(void)41 void fputs_0200(void)
42 {
43     FILE *fptr = fopen(path, "w+");
44     EXPECT_PTRNE("fputs_0200", fptr, NULL);
45 
46     int len = fputs("", fptr);
47     EXPECT_TRUE("fputs_0200", len >= 0);
48     fclose(fptr);
49     remove(path);
50 }
51 
52 /**
53  * @tc.name       : fputs_0300
54  * @tc.desc       : Verify that an empty string cannot be written to the specified file.
55  * @tc.level      : level 2.
56  */
fputs_0300(void)57 void fputs_0300(void)
58 {
59     FILE *p = fopen(path, "w");
60     fclose(p);
61     p = fopen(path, "r");
62     int len = fputs("this is a test string", p);
63     EXPECT_EQ("fputs_0300", len, EOF);
64     fclose(p);
65     remove(path);
66 }
67 
main(int argc, char *argv[])68 int main(int argc, char *argv[])
69 {
70     fputs_0100();
71     fputs_0200();
72     fputs_0300();
73     return t_status;
74 }
75