• 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 <fcntl.h>
17 #include <wchar.h>
18 #include "functionalext.h"
19 
20 /**
21  * @tc.name      : fgetws_0100
22  * @tc.desc      : Verify that a string of wide characters can be read from the specified file
23  * @tc.level     : Level 0
24  */
fgetws_0100()25 void fgetws_0100()
26 {
27     wchar_t mystring[100];
28     char str[] = "test";
29 
30     FILE *fp = fopen("/data/test.txt", "w+");
31     EXPECT_PTRNE("fgetws_0100", fp, NULL);
32 
33     size_t fw = fwrite(str, sizeof(char), sizeof(str), fp);
34     EXPECT_TRUE("fgetws_0100", fw > 0);
35     fseek(fp, 0, SEEK_SET);
36 
37     wchar_t *ret = fgetws(mystring, 100, fp);
38     EXPECT_PTRNE("fgetws_0100", ret, NULL);
39 
40     if (wcscmp(mystring, L"test")) {
41         t_error("%s str invalid\n", __func__);
42     }
43     fclose(fp);
44 }
45 
46 /**
47  * @tc.name      : fgetws_0200
48  * @tc.desc      : Verify that a string of wide characters cannot be read from the specified file
49  * @tc.level     : Level 2
50  */
fgetws_0200()51 void fgetws_0200()
52 {
53     wchar_t wrstring[100];
54     wchar_t line[] = L"hello";
55     const char *ptr = "/data/test.txt";
56 
57     FILE *fptr = fopen(ptr, "w+");
58     EXPECT_PTRNE("fgetws_0100", fptr, NULL);
59 
60     fwrite(line, sizeof(line) / sizeof(wchar_t), sizeof(*line), fptr);
61     fflush(fptr);
62 
63     wchar_t *ch = fgetws(wrstring, EINVAL, fptr);
64     EXPECT_PTREQ("fgetws_0200", ch, NULL);
65 
66     fclose(fptr);
67     remove(ptr);
68 }
69 
main(int argc,char * argv[])70 int main(int argc, char *argv[])
71 {
72     fgetws_0100();
73     fgetws_0200();
74     return t_status;
75 }