1570af302Sopenharmony_ci/* 2570af302Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3570af302Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4570af302Sopenharmony_ci * you may not use this file except in compliance with the License. 5570af302Sopenharmony_ci * You may obtain a copy of the License at 6570af302Sopenharmony_ci * 7570af302Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8570af302Sopenharmony_ci * 9570af302Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10570af302Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11570af302Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12570af302Sopenharmony_ci * See the License for the specific language governing permissions and 13570af302Sopenharmony_ci * limitations under the License. 14570af302Sopenharmony_ci */ 15570af302Sopenharmony_ci 16570af302Sopenharmony_ci#include <stdio.h> 17570af302Sopenharmony_ci#include <string.h> 18570af302Sopenharmony_ci#include <wchar.h> 19570af302Sopenharmony_ci#include "test.h" 20570af302Sopenharmony_ci 21570af302Sopenharmony_ci#define N(s, sub) \ 22570af302Sopenharmony_ci { \ 23570af302Sopenharmony_ci wchar_t *p = s; \ 24570af302Sopenharmony_ci wchar_t *q = wcswcs(p, sub); \ 25570af302Sopenharmony_ci if (q) \ 26570af302Sopenharmony_ci t_error("wcswcs(%s,%s) returned str+%d, wanted 0\n", #s, #sub, q - p); \ 27570af302Sopenharmony_ci } 28570af302Sopenharmony_ci 29570af302Sopenharmony_ci#define T(s, sub, n) \ 30570af302Sopenharmony_ci { \ 31570af302Sopenharmony_ci wchar_t *p = s; \ 32570af302Sopenharmony_ci wchar_t *q = wcswcs(p, sub); \ 33570af302Sopenharmony_ci if (q == 0) \ 34570af302Sopenharmony_ci t_error("wcswcs(%s,%s) returned 0, wanted str+%d\n", #s, #sub, n); \ 35570af302Sopenharmony_ci else if (q - p != n) \ 36570af302Sopenharmony_ci t_error("wcswcs(%s,%s) returned str+%d, wanted str+%d\n", #s, #sub, q - p, n); \ 37570af302Sopenharmony_ci } 38570af302Sopenharmony_ci 39570af302Sopenharmony_ci/** 40570af302Sopenharmony_ci * @tc.name : wcswcs_0100 41570af302Sopenharmony_ci * @tc.desc : Test the wcswcs method to find the first occurrence of the second wide string from the first wide 42570af302Sopenharmony_ci * string 43570af302Sopenharmony_ci * @tc.level : Level 0 44570af302Sopenharmony_ci */ 45570af302Sopenharmony_civoid wcswcs_0100(void) 46570af302Sopenharmony_ci{ 47570af302Sopenharmony_ci T(L"", L"", 0) 48570af302Sopenharmony_ci T(L"abcd", L"", 0) 49570af302Sopenharmony_ci T(L"abcd", L"a", 0) 50570af302Sopenharmony_ci T(L"abcd", L"b", 1) 51570af302Sopenharmony_ci T(L"abcd", L"c", 2) 52570af302Sopenharmony_ci T(L"abcd", L"d", 3) 53570af302Sopenharmony_ci T(L"abcd", L"ab", 0) 54570af302Sopenharmony_ci T(L"abcd", L"bc", 1) 55570af302Sopenharmony_ci T(L"abcd", L"cd", 2) 56570af302Sopenharmony_ci T(L"ababa", L"baba", 1) 57570af302Sopenharmony_ci T(L"ababab", L"babab", 1) 58570af302Sopenharmony_ci T(L"abababa", L"bababa", 1) 59570af302Sopenharmony_ci T(L"abababab", L"bababab", 1) 60570af302Sopenharmony_ci T(L"ababababa", L"babababa", 1) 61570af302Sopenharmony_ci T(L"abbababab", L"bababa", 2) 62570af302Sopenharmony_ci T(L"abbababab", L"ababab", 3) 63570af302Sopenharmony_ci T(L"abacabcabcab", L"abcabcab", 4) 64570af302Sopenharmony_ci T(L"nanabanabanana", L"aba", 3) 65570af302Sopenharmony_ci T(L"nanabanabanana", L"ban", 4) 66570af302Sopenharmony_ci T(L"nanabanabanana", L"anab", 1) 67570af302Sopenharmony_ci T(L"nanabanabanana", L"banana", 8) 68570af302Sopenharmony_ci T(L"_ _\xff_ _", L"_\xff_", 2) 69570af302Sopenharmony_ci} 70570af302Sopenharmony_ci 71570af302Sopenharmony_ci/** 72570af302Sopenharmony_ci * @tc.name : wcswcs_0200 73570af302Sopenharmony_ci * @tc.desc : Test the result of the wcswcs method when the second substring cannot be found from the first 74570af302Sopenharmony_ci * substring 75570af302Sopenharmony_ci * @tc.level : Level 1 76570af302Sopenharmony_ci */ 77570af302Sopenharmony_civoid wcswcs_0200(void) 78570af302Sopenharmony_ci{ 79570af302Sopenharmony_ci N(L"", L"a") 80570af302Sopenharmony_ci N(L"a", L"aa") 81570af302Sopenharmony_ci N(L"a", L"b") 82570af302Sopenharmony_ci N(L"aa", L"ab") 83570af302Sopenharmony_ci N(L"aa", L"aaa") 84570af302Sopenharmony_ci N(L"abba", L"aba") 85570af302Sopenharmony_ci N(L"abc abc", L"abcd") 86570af302Sopenharmony_ci N(L"0-1-2-3-4-5-6-7-8-9", L"-3-4-56-7-8-") 87570af302Sopenharmony_ci N(L"0-1-2-3-4-5-6-7-8-9", L"-3-4-5+6-7-8-") 88570af302Sopenharmony_ci N(L"_ _ _\xff_ _ _", L"_\x7f_") 89570af302Sopenharmony_ci N(L"_ _ _\x7f_ _ _", L"_\xff_") 90570af302Sopenharmony_ci} 91570af302Sopenharmony_ci 92570af302Sopenharmony_ciint main(int argc, char *argv[]) 93570af302Sopenharmony_ci{ 94570af302Sopenharmony_ci wcswcs_0100(); 95570af302Sopenharmony_ci wcswcs_0200(); 96570af302Sopenharmony_ci return t_status; 97570af302Sopenharmony_ci}