• 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 <wchar.h>
17 #include <locale.h>
18 #include "functionalext.h"
19 
20 const int FAILED = -1;
21 
22 /**
23  * @tc.name      : fputws_0100
24  * @tc.desc      : Each parameter is valid and can output a wide character string to a file stream.
25  * @tc.level     : Level 0
26  */
fputws_0100(void)27 void fputws_0100(void)
28 {
29     char str[100] = {0};
30     const char *ptr = "fputwstest.txt";
31     FILE *fptr = fopen(ptr, "w+");
32     EXPECT_TRUE("fputws_0100", fptr != NULL);
33     setlocale(LC_ALL, "en_US.utf8");
34     int ret = fputws(L"this is the test", fptr);
35     EXPECT_TRUE("fputws_0100", ret >= 0);
36     fseek(fptr, 0, SEEK_SET);
37     int rsize = fread(str, sizeof(char), 100, fptr);
38     EXPECT_EQ("fputws_0100", rsize, ret);
39     fclose(fptr);
40     remove(ptr);
41     fptr = NULL;
42     ptr = NULL;
43 }
44 
45 /**
46  * @tc.name      : fputws_0200
47  * @tc.desc      : The f parameter is invalid, a wide string cannot be output to a file stream.
48  * @tc.level     : Level 2
49  */
fputws_0200(void)50 void fputws_0200(void)
51 {
52     const char *ptr = "fputwstest.txt";
53     FILE *fptr = fopen(ptr, "w+");
54     EXPECT_TRUE("fputws_0200", fptr != NULL);
55     fclose(fptr);
56     fptr = fopen(ptr, "r");
57     EXPECT_TRUE("fputws_0200", fptr != NULL);
58     int ret = fputws(L"this is the test", fptr);
59     EXPECT_EQ("fputws_0200", ret, FAILED);
60     fclose(fptr);
61     remove(ptr);
62     fptr = NULL;
63     ptr = NULL;
64 }
65 
main(int argc,char * argv[])66 int main(int argc, char *argv[])
67 {
68     fputws_0100();
69     fputws_0200();
70     return t_status;
71 }