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 <wchar.h>
17 #include "functionalext.h"
18 
19 const char *path = "/data/test.txt";
20 
21 /**
22  * @tc.name      : fwide_0100
23  * @tc.desc      : Verify that the set byte stream is a wide character stream (valid, mode > 0)
24  * @tc.level     : Level 0
25  */
fwide_0100(void)26 void fwide_0100(void)
27 {
28     FILE *fp = fopen(path, "w+");
29     EXPECT_PTRNE("fwide_0100", fp, NULL);
30 
31     int result = fwide(fp, 5);
32     EXPECT_TRUE("fwide_0100", result > 0);
33 
34     fclose(fp);
35     remove(path);
36 }
37 
38 /**
39  * @tc.name      : fwide_0200
40  * @tc.desc      : Verify that the set byte stream remains as it is (all parameters are valid, mode equals 0)
41  * @tc.level     : Level 0
42  */
fwide_0200(void)43 void fwide_0200(void)
44 {
45     FILE *fp = fopen(path, "w+");
46     EXPECT_PTRNE("fwide_0100", fp, NULL);
47 
48     int result = fwide(fp, 0);
49     EXPECT_EQ("fwide_0200", result, 0);
50 
51     fclose(fp);
52     remove(path);
53 }
54 
55 /**
56  * @tc.name      : fwide_0300
57  * @tc.desc      : Verify that the set byte stream is a multi-byte character stream (valid with mode less than 0)
58  * @tc.level     : Level 0
59  */
fwide_0300(void)60 void fwide_0300(void)
61 {
62     FILE *fp = fopen(path, "w+");
63     EXPECT_PTRNE("fwide_0100", fp, NULL);
64 
65     int result = fwide(fp, -5);
66     EXPECT_TRUE("fwide_0300", result < 0);
67 
68     fclose(fp);
69     remove(path);
70 }
71 
main(int argc, char *argv[])72 int main(int argc, char *argv[])
73 {
74 
75     fwide_0100();
76     fwide_0200();
77     fwide_0300();
78     return t_status;
79 }