• 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 <stdio.h>
17 #include <string.h>
18 #include <stdlib.h>
19 #include <stdarg.h>
20 #include <locale.h>
21 #include <wchar.h>
22 #include "test.h"
23 
get_str_value(const wchar_t * buffer,const wchar_t * format,...)24 int get_str_value(const wchar_t *buffer, const wchar_t *format, ...)
25 {
26     int result = 0;
27     va_list args;
28     va_start(args, format);
29     vswscanf(buffer, format, args);
30     va_end(args);
31     return result;
32 }
33 
34 /**
35  * @tc.name      : vswscanf_0100
36  * @tc.desc      : Test the vswscanf function to read data from the wide character buffer and store it in the
37  *                 corresponding variable
38  * @tc.level     : Level 0
39  */
vswscanf_0100(void)40 void vswscanf_0100(void)
41 {
42     wchar_t symbol[] = L"\u0fd7\u00c6\u20b9\u2127\u17d8";
43     wchar_t str[20];
44     int result = get_str_value(symbol, L"%ls", str);
45     if (result != 0) {
46         t_error("%s vswscanf get result is %d are not want 0\n", __func__, result);
47     }
48     if (wcscmp(symbol, str) != 0) {
49         t_error("%s vswscanf error %ls are not eq %ls\n", __func__, symbol, str);
50     }
51 }
52 
53 /**
54  * @tc.name      : vswscanf_0200
55  * @tc.desc      : Test the result of wswscanf when fetching multiple variables from a wide character buffer
56  * @tc.level     : Level 1
57  */
vswscanf_0200(void)58 void vswscanf_0200(void)
59 {
60     wchar_t symbol[] = L"ABC DEF";
61     wchar_t str[20];
62     wchar_t strs[20];
63     int result = get_str_value(symbol, L"%ls %ls", str, strs);
64     if (result != 0) {
65         t_error("%s vswscanf get result is %d are not want 0\n", __func__, result);
66     }
67     if (wcscmp(str, L"ABC") != 0) {
68         t_error("%s vswscanf error %ls are not eq ABC\n", __func__, str);
69     }
70     if (wcscmp(strs, L"DEF") != 0) {
71         t_error("%s vswscanf error %ls are not eq DEF\n", __func__, strs);
72     }
73 }
74 
main(int argc,char * argv[])75 int main(int argc, char *argv[])
76 {
77     setlocale(LC_ALL, "en_US.UTF-8");
78     vswscanf_0100();
79     vswscanf_0200();
80     return t_status;
81 }