• 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 <stdio.h>
18 #include <locale.h>
19 #include <string.h>
20 #include "test.h"
21 
22 /**
23  * @tc.name      : wcstok_0100
24  * @tc.desc      : Test wcstok to intercept the target string according to the incoming wide string
25  * @tc.level     : Level 0
26  */
wcstok_0100(void)27 void wcstok_0100(void)
28 {
29     wchar_t str[] = L"parrot,owl,sparrow,pigeon,crow";
30     wchar_t delim[] = L",";
31     wchar_t *ptr;
32     wchar_t *compare[5] = {L"parrot", L"owl", L"sparrow", L"pigeon", L"crow"};
33     wchar_t *result[5] = {0};
34     wchar_t *token = wcstok(str, delim, &ptr);
35     int i = 0;
36     while (token) {
37         result[i] = token;
38         i++;
39         token = wcstok(NULL, delim, &ptr);
40     }
41     for (i = 0; i < 5; i++) {
42         if (wcscmp(result[i], compare[i]) != 0) {
43             t_error("%s wcstok in %d get value is %s and %s\n", __func__, i, result[i], compare[i]);
44         }
45     }
46 }
47 
48 /**
49  * @tc.name      : wcstok_0200
50  * @tc.desc      : Test wcstok to intercept multiple targets according to incoming
51  * @tc.level     : Level 1
52  */
wcstok_0200(void)53 void wcstok_0200(void)
54 {
55     wchar_t str[] = L"parrot,owl.sparrow,pigeon,crow";
56     wchar_t delim[] = L",.";
57     wchar_t *ptr;
58     wchar_t *result = wcstok(str, delim, &ptr);
59     if (wcscmp(result, L"parrot") != 0) {
60         t_error("%s wcstok get result is %s are not parrot\n", __func__, result);
61     }
62     if (wcscmp(ptr, L"owl.sparrow,pigeon,crow") != 0) {
63         t_error("%s wcstok get ptr is %s are not parrot\n", __func__, ptr);
64     }
65 }
66 
main(int argc,char * argv[])67 int main(int argc, char *argv[])
68 {
69     setlocale(LC_ALL, "en_US.utf8");
70     wcstok_0100();
71     wcstok_0200();
72     return t_status;
73 }