• 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 "functionalext.h"
18 
19 /**
20  * @tc.name      : fwprintf_0100
21  * @tc.desc      : Verify the number of wide characters returned by the function (if the file parameter is stdout)
22  * @tc.level     : Level 0
23  */
fwprintf_0100(void)24 void fwprintf_0100(void)
25 {
26     int result = fwprintf(stdout, L"This is a test!!QAZ@WSX12");
27     printf("\n");
28     int ret = strlen("This is a test!!QAZ@WSX12");
29     EXPECT_EQ("fwprintf_0100", result, ret);
30 }
31 
32 /**
33  * @tc.name      : fwprintf_0200
34  * @tc.desc      : Verify the number of wide characters returned by the function (if the file parameter is stderr)
35  * @tc.level     : Level 0
36  */
fwprintf_0200(void)37 void fwprintf_0200(void)
38 {
39     int result = fwprintf(stderr, L"This is a test!");
40     printf("\n");
41     int ret = strlen("This is a test!");
42     EXPECT_EQ("fwprintf_0200", result, ret);
43 }
44 
45 /**
46  * @tc.name      : fwprintf_0300
47  * @tc.desc      : Verifies the number of wide characters returned by the function
48                    (if the file is successfully opened in W mode and its return value is used as the file parameter)
49  * @tc.level     : Level 0
50  */
fwprintf_0300(void)51 void fwprintf_0300(void)
52 {
53     FILE *fptr = fopen("/data/test.txt", "w");
54     EXPECT_PTRNE("fwprintf_0300", fptr, NULL);
55 
56     int result = fwprintf(fptr, L"This is a test!");
57     int ret = strlen("This is a test!");
58     EXPECT_EQ("fwprintf_0300", result, ret);
59 
60     fclose(fptr);
61     remove("/data/test.txt");
62 }
63 
64 /**
65  * @tc.name      : fwprintf_0400
66  * @tc.desc      : Verifies the number of wide characters returned by the function
67                   (if the file is successfully opened in R mode and its return value is used as a file parameter)
68  * @tc.level     : Level 2
69  */
fwprintf_0400(void)70 void fwprintf_0400(void)
71 {
72     const char *path = "/data/test.txt";
73 
74     FILE *fptr1 = fopen(path, "w");
75     EXPECT_PTRNE("fwprintf_0400", fptr1, NULL);
76     fclose(fptr1);
77 
78     FILE *fptr2 = fopen(path, "r");
79     int result = fwprintf(fptr2, L"This is a test!");
80     EXPECT_EQ("fwprintf_0400", result, -1);
81 
82     fclose(fptr2);
83     remove(path);
84 }
85 
main(int argc,char * argv[])86 int main(int argc, char *argv[])
87 {
88     fwprintf_0100();
89     fwprintf_0200();
90     fwprintf_0300();
91     fwprintf_0400();
92     return t_status;
93 }