• 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 <ctype.h>
17 #include <stdlib.h>
18 #include <unistd.h>
19 #include <wchar.h>
20 #include "functionalext.h"
21 
22 const int SUCCESS = 0;
23 const int FAILED = -1;
24 const int STRING_EQUAL = 0;
25 
26 /**
27  * @tc.name      : fputwc_0100
28  * @tc.desc      : Each parameter is valid, a single call can output wide characters to the file stream
29  * @tc.level     : Level 0
30  */
fputwc_0100()31 void fputwc_0100()
32 {
33     wchar_t str[] = L"T";
34     wchar_t buf[100];
35     wint_t wc;
36     int ri = 0;
37     int j = 0;
38     FILE *fp = fopen("file.txt", "w+");
39     if (fp) {
40         for (unsigned int i = 0; i < wcslen(str); i++) {
41             wc = fputwc(str[i], fp);
42             if (wc != str[i]) {
43                 ri++;
44             }
45         }
46     } else {
47         t_error("%s File opening failed", __func__);
48     }
49 
50     fclose(fp);
51     FILE *ffp = fopen("file.txt", "r");
52     EXPECT_PTRNE("fputwc_0100", ffp, NULL);
53     fgetws(buf, wcslen(str) + 1, ffp);
54     EXPECT_EQ("fputwc_0100", ri, 0);
55     EXPECT_EQ("fputwc_0100", wcscoll(buf, str), STRING_EQUAL);
56 
57     fclose(ffp);
58     remove("file.txt");
59 }
60 
61 /**
62  * @tc.name      : fputwc_0200
63  * @tc.desc      : Each parameter is valid, called multiple times, and can output wide characters to the file stream
64  * @tc.level     : Level 1
65  */
fputwc_0200()66 void fputwc_0200()
67 {
68     wchar_t str[] = L"This is a test";
69     wchar_t buf[100];
70     wint_t wc;
71     int ri = 0;
72     int j = 0;
73     FILE *fp = fopen("file.txt", "w+");
74     if (fp) {
75         for (unsigned int i = 0; i < wcslen(str); i++) {
76             wc = fputwc(str[i], fp);
77             if (wc != str[i]) {
78                 ri++;
79             }
80         }
81     } else {
82         t_error("%s File opening failed", __func__);
83     }
84     fclose(fp);
85     FILE *ffp = fopen("file.txt", "r");
86     EXPECT_PTRNE("fputwc_0200", ffp, NULL);
87     fgetws(buf, wcslen(str) + 1, ffp);
88     EXPECT_EQ("fputwc_0200", ri, 0);
89     EXPECT_EQ("fputwc_0200", wcscoll(buf, str), STRING_EQUAL);
90     fclose(ffp);
91     remove("file.txt");
92 }
93 
main(int argc,char * argv[])94 int main(int argc, char *argv[])
95 {
96     fputwc_0100();
97     fputwc_0200();
98     return t_status;
99 }