1 /* 2 * Copyright (c) 2021 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 <strings.h> 17 #include <wctype.h> 18 #include <wchar.h> 19 20 #include "gtest/gtest.h" 21 #include "log.h" 22 #include "utils.h" 23 24 using namespace testing::ext; 25 26 class ActsUtilStringOperApiTest : public testing::Test { 27 public: 28 locale_t g_ausoaLocale; 29 protected: 30 // SetUpTestCase: Testsuit setup, run before 1st testcase SetUpTestCase(void)31 static void SetUpTestCase(void) 32 { 33 } 34 // TearDownTestCase: Testsuit teardown, run after last testcase TearDownTestCase(void)35 static void TearDownTestCase(void) 36 { 37 } 38 // Testcase setup SetUp()39 virtual void SetUp() 40 { 41 g_ausoaLocale = newlocale(LC_ALL_MASK, "", (locale_t)0); 42 } 43 // Testcase teardown TearDown()44 virtual void TearDown() 45 { 46 freelocale(g_ausoaLocale); 47 } 48 }; 49 50 /** 51 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFS_0100 52 * @tc.name test fss api with digit 1 53 * @tc.desc [C- SOFTWARE -0200] 54 */ 55 HWTEST_F(ActsUtilStringOperApiTest, testFss0100, Function | MediumTest | Level1) { 56 int paraValue; 57 int returnVal; 58 59 paraValue = 1; 60 returnVal = ffs(paraValue); 61 LOGD(" ffs returnVal:='%d'\n", returnVal); 62 ASSERT_TRUE(1 == returnVal) << "ErrInfo: ffs returnVal:='" << returnVal << "'"; 63 } 64 65 /** 66 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFS_0200 67 * @tc.name test fss api with digit 0 68 * @tc.desc [C- SOFTWARE -0200] 69 */ 70 HWTEST_F(ActsUtilStringOperApiTest, testFss0200, Function | MediumTest | Level1) { 71 int paraValue; 72 int returnVal; 73 74 paraValue = 0; 75 returnVal = ffs(paraValue); 76 LOGD(" ffs returnVal:='%d'\n", returnVal); 77 ASSERT_TRUE(0 == returnVal) << "ErrInfo: ffs returnVal:='" << returnVal << "'"; 78 } 79 80 /** 81 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFS_0300 82 * @tc.name test fss api with xdigit 83 * @tc.desc [C- SOFTWARE -0200] 84 */ 85 HWTEST_F(ActsUtilStringOperApiTest, testFss0300, Function | MediumTest | Level1) { 86 int paraValue; 87 int returnVal; 88 89 paraValue = 0x8000; 90 returnVal = ffs(paraValue); 91 LOGD(" ffs returnVal:='%d'\n", returnVal); 92 ASSERT_TRUE(16 == returnVal) << "ErrInfo: ffs returnVal:='" << returnVal << "'"; 93 } 94 95 /** 96 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFSL_0400 97 * @tc.name test fssl api with digit 1 98 * @tc.desc [C- SOFTWARE -0200] 99 */ 100 HWTEST_F(ActsUtilStringOperApiTest, testFssl0400, Function | MediumTest | Level1) { 101 long int paraValue; 102 int returnVal; 103 104 paraValue = 1; 105 returnVal = ffsl(paraValue); 106 LOGD(" ffsl returnVal:='%d'\n", returnVal); 107 ASSERT_TRUE(1 == returnVal) << "ErrInfo: ffsl returnVal:='" << returnVal << "'"; 108 } 109 110 /** 111 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFSL_0500 112 * @tc.name test fssl api with digit 0 113 * @tc.desc [C- SOFTWARE -0200] 114 */ 115 HWTEST_F(ActsUtilStringOperApiTest, testFssl0500, Function | MediumTest | Level1) { 116 long int paraValue; 117 int returnVal; 118 119 paraValue = 0; 120 returnVal = ffsl(paraValue); 121 LOGD(" ffsl returnVal:='%d'\n", returnVal); 122 ASSERT_TRUE(0 == returnVal) << "ErrInfo: ffsl returnVal:='" << returnVal << "'"; 123 } 124 125 /** 126 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFSL_0600 127 * @tc.name test fssl api with xdigit 128 * @tc.desc [C- SOFTWARE -0200] 129 */ 130 HWTEST_F(ActsUtilStringOperApiTest, testFssl0600, Function | MediumTest | Level1) { 131 long int paraValue; 132 int returnVal; 133 134 paraValue = 0x8000; 135 returnVal = ffsl(paraValue); 136 LOGD(" ffsl returnVal:='%d'\n", returnVal); 137 ASSERT_TRUE(16 == returnVal) << "ErrInfo: ffsl returnVal:='" << returnVal << "'"; 138 } 139 140 /** 141 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFSLL_0700 142 * @tc.name test fssll api with digit 1 143 * @tc.desc [C- SOFTWARE -0200] 144 */ 145 HWTEST_F(ActsUtilStringOperApiTest, testFssll0700, Function | MediumTest | Level1) { 146 long long int paraValue; 147 int returnVal; 148 149 paraValue = 1; 150 returnVal = ffsll(paraValue); 151 LOGD(" ffsll returnVal:='%d'\n", returnVal); 152 ASSERT_TRUE(1 == returnVal) << "ErrInfo: ffsll returnVal:='" << returnVal << "'"; 153 } 154 155 /** 156 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFSLL_0800 157 * @tc.name test fssll api with digit 0 158 * @tc.desc [C- SOFTWARE -0200] 159 */ 160 HWTEST_F(ActsUtilStringOperApiTest, testFssll0800, Function | MediumTest | Level1) { 161 long long int paraValue; 162 int returnVal; 163 164 paraValue = 0; 165 returnVal = ffsll(paraValue); 166 LOGD(" ffsll returnVal:='%d'\n", returnVal); 167 ASSERT_TRUE(0 == returnVal) << "ErrInfo: ffsll returnVal:='" << returnVal << "'"; 168 } 169 170 /** 171 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_FFSLL_0900 172 * @tc.name test fssll api with xdigit 173 * @tc.desc [C- SOFTWARE -0200] 174 */ 175 HWTEST_F(ActsUtilStringOperApiTest, testFssll0900, Function | MediumTest | Level1) { 176 long long int paraValue; 177 int returnVal; 178 179 paraValue = 0x800000000000; 180 returnVal = ffsll(paraValue); 181 LOGD(" ffsll returnVal:='%d'\n", returnVal); 182 ASSERT_TRUE(48 == returnVal) << "ErrInfo: ffsll returnVal:='" << returnVal << "'"; 183 } 184 185 /** 186 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCWIDTH_1000 187 * @tc.name test wcwidth api with null wide character 188 * @tc.desc [C- SOFTWARE -0200] 189 */ 190 HWTEST_F(ActsUtilStringOperApiTest, testWcwidth1000, Function | MediumTest | Level1) { 191 wchar_t wideChar; 192 int returnVal; 193 194 wideChar = '\0'; 195 returnVal = wcwidth(wideChar); 196 LOGD(" wcwidth returnVal:='%d'\n", returnVal); 197 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcwidth returnVal:='" << returnVal << "'"; 198 } 199 200 /** 201 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCWIDTH_1100 202 * @tc.name test wcwidth api with upper alpha 203 * @tc.desc [C- SOFTWARE -0200] 204 */ 205 HWTEST_F(ActsUtilStringOperApiTest, testWcwidth1100, Function | MediumTest | Level1) { 206 wchar_t wideChar; 207 int returnVal; 208 209 wideChar = 'A'; 210 returnVal = wcwidth(wideChar); 211 LOGD(" wcwidth returnVal:='%d'\n", returnVal); 212 ASSERT_TRUE(1 == returnVal) << "ErrInfo: wcwidth returnVal:='" << returnVal << "'"; 213 } 214 215 /** 216 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCTYPE_1200 217 * @tc.name test wctype api with alnum 218 * @tc.desc [C- SOFTWARE -0200] 219 */ 220 HWTEST_F(ActsUtilStringOperApiTest, testWctype1200, Function | MediumTest | Level1) { 221 const char *paraVal = "alnum"; 222 wctype_t returnVal; 223 224 returnVal = wctype(paraVal); 225 LOGD(" wcwidth returnVal:='%d'\n", returnVal); 226 ASSERT_TRUE(returnVal != 0) << "ErrInfo: wcwidth returnVal:='" << returnVal << "'"; 227 } 228 229 /** 230 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCTYPE_1300 231 * @tc.name test wctype api with alnumalpha 232 * @tc.desc [C- SOFTWARE -0200] 233 */ 234 HWTEST_F(ActsUtilStringOperApiTest, testWctype1300, Function | MediumTest | Level1) { 235 const char *paraVal = "alnumalpha"; 236 wctype_t returnVal; 237 238 returnVal = wctype(paraVal); 239 LOGD(" wcwidth returnVal:='%d'\n", returnVal); 240 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcwidth returnVal:='" << returnVal << "'"; 241 } 242 243 /** 244 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCTYPE_L_1400 245 * @tc.name test wctype_l api with alnum 246 * @tc.desc [C- SOFTWARE -0200] 247 */ 248 HWTEST_F(ActsUtilStringOperApiTest, testWctypeL1400, Function | MediumTest | Level1) { 249 const char *paraVal = "alnum"; 250 wctype_t returnVal; 251 252 returnVal = wctype_l(paraVal, g_ausoaLocale); 253 LOGD(" wctype_l returnVal:='%d'\n", returnVal); 254 ASSERT_TRUE(returnVal != 0) << "ErrInfo: wctype_l returnVal:='" << returnVal << "'"; 255 } 256 257 /** 258 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCTYPE_L_1500 259 * @tc.name test wctype_l api with alnumalpha 260 * @tc.desc [C- SOFTWARE -0200] 261 */ 262 HWTEST_F(ActsUtilStringOperApiTest, testWctypeL1500, Function | MediumTest | Level1) { 263 const char *paraVal = "alnumalpha"; 264 wctype_t returnVal; 265 266 returnVal = wctype_l(paraVal, g_ausoaLocale); 267 LOGD(" wctype_l returnVal:='%d'\n", returnVal); 268 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wctype_l returnVal:='" << returnVal << "'"; 269 } 270 271 /** 272 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_MBLEN_1600 273 * @tc.name test mblen api 274 * @tc.desc [C- SOFTWARE -0200] 275 */ 276 HWTEST_F(ActsUtilStringOperApiTest, testMblen1600, Function | MediumTest | Level1) { 277 const char *paraVal = nullptr; 278 size_t sizeVal; 279 int returnVal; 280 281 paraVal = "a"; 282 sizeVal = 1; 283 returnVal = mblen(paraVal, sizeVal); 284 LOGD(" mblen returnVal:='%d'\n", returnVal); 285 ASSERT_TRUE(1 == returnVal) << "ErrInfo: mblen returnVal:='" << returnVal << "'"; 286 } 287 288 /** 289 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_MBLEN_1700 290 * @tc.name test mbrlen api 291 * @tc.desc [C- SOFTWARE -0200] 292 */ 293 HWTEST_F(ActsUtilStringOperApiTest, testMbrlen1700, Function | MediumTest | Level1) { 294 const char *paraVal = nullptr; 295 size_t sizeVal; 296 mbstate_t *psVal = nullptr; 297 size_t returnVal; 298 299 paraVal = "a"; 300 sizeVal = 1; 301 returnVal = mbrlen(paraVal, sizeVal, psVal); 302 LOGD(" mbrlen returnVal:='%d'\n", returnVal); 303 ASSERT_TRUE(1 == returnVal) << "ErrInfo: mbrlen returnVal:='" << returnVal << "'"; 304 } 305 306 /** 307 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCPCPY_1800 308 * @tc.name test wcpcpy api 309 * @tc.desc [C- SOFTWARE -0200] 310 */ 311 HWTEST_F(ActsUtilStringOperApiTest, testWcpcpy1800, Function | MediumTest | Level1) { 312 wchar_t paraDest[10]; 313 const wchar_t *paraSrc = L"abcde"; 314 wchar_t *returnVal = nullptr; 315 316 returnVal = wcpcpy(paraDest, paraSrc); 317 LOGD(" wcpcpy returnVal:='%x'\n", returnVal); 318 ASSERT_TRUE(0 == wcscmp(paraDest, paraSrc) && L'\0' == *returnVal) 319 << "ErrInfo: wcpcpy returnVal:='" << returnVal << "'"; 320 } 321 322 /** 323 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCPNCPY_1900 324 * @tc.name test wcpncpy api 325 * @tc.desc [C- SOFTWARE -0200] 326 */ 327 HWTEST_F(ActsUtilStringOperApiTest, testWcpncpy1900, Function | MediumTest | Level1) { 328 wchar_t paraDest[10]; 329 const wchar_t *paraSrc = L"abcde"; 330 size_t lenVal; 331 wchar_t *returnVal = nullptr; 332 333 lenVal = wcslen(paraSrc); 334 returnVal = wcpncpy(paraDest, paraSrc, lenVal + 1); 335 LOGD(" wcpncpy returnVal:='%x'\n", returnVal); 336 ASSERT_TRUE(0 == wcsncmp(paraDest, paraSrc, lenVal) && L'\0' == *returnVal) 337 << "ErrInfo: wcpncpy returnVal:='" << returnVal << "'"; 338 } 339 340 /** 341 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCASECMP_2000 342 * @tc.name test wcscasecmp api with para1 is lower case of para2 343 * @tc.desc [C- SOFTWARE -0200] 344 */ 345 HWTEST_F(ActsUtilStringOperApiTest, testWcscasecmp2000, Function | MediumTest | Level1) { 346 const wchar_t *strVal1 = L"abcde"; 347 const wchar_t *strVal2 = L"ABCDE"; 348 int returnVal; 349 350 returnVal = wcscasecmp(strVal1, strVal2); 351 LOGD(" wcscasecmp returnVal:='%d'\n", returnVal); 352 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcscasecmp returnVal:='" << returnVal << "'"; 353 } 354 355 /** 356 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCASECMP_2100 357 * @tc.name test wcscasecmp api with same string 358 * @tc.desc [C- SOFTWARE -0200] 359 */ 360 HWTEST_F(ActsUtilStringOperApiTest, testWcscasecmp2100, Function | MediumTest | Level1) { 361 const wchar_t *strVal1 = L"abcde"; 362 const wchar_t *strVal2 = L"abcde"; 363 int returnVal; 364 365 returnVal = wcscasecmp(strVal1, strVal2); 366 LOGD(" wcscasecmp returnVal:='%d'\n", returnVal); 367 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcscasecmp returnVal:='" << returnVal << "'"; 368 } 369 370 /** 371 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCASECMP_L_2000 372 * @tc.name test wcscasecmp_l api with para1 is lower case of para2 373 * @tc.desc [C- SOFTWARE -0200] 374 */ 375 HWTEST_F(ActsUtilStringOperApiTest, testWcscasecmpL2200, Function | MediumTest | Level1) { 376 const wchar_t *strVal1 = L"abcde"; 377 const wchar_t *strVal2 = L"ABCDE"; 378 int returnVal; 379 380 returnVal = wcscasecmp_l(strVal1, strVal2, g_ausoaLocale); 381 LOGD(" wcscasecmp_l returnVal:='%d'\n", returnVal); 382 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcscasecmp_l returnVal:='" << returnVal << "'"; 383 } 384 385 /** 386 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCASECMP_L_2100 387 * @tc.name test wcscasecmp_l api with same string 388 * @tc.desc [C- SOFTWARE -0200] 389 */ 390 HWTEST_F(ActsUtilStringOperApiTest, testWcscasecmpL2300, Function | MediumTest | Level1) { 391 const wchar_t *strVal1 = L"abcde"; 392 const wchar_t *strVal2 = L"abcde"; 393 int returnVal; 394 395 returnVal = wcscasecmp_l(strVal1, strVal2, g_ausoaLocale); 396 LOGD(" wcscasecmp_l returnVal:='%d'\n", returnVal); 397 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcscasecmp_l returnVal:='" << returnVal << "'"; 398 } 399 400 /** 401 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSNCASECMP_2400 402 * @tc.name test wcsncasecmp api with para1 is lower case of para2 403 * @tc.desc [C- SOFTWARE -0200] 404 */ 405 HWTEST_F(ActsUtilStringOperApiTest, testWcsncasecmp2400, Function | MediumTest | Level1) { 406 const wchar_t *strVal1 = L"abcde"; 407 const wchar_t *strVal2 = L"ABCDE"; 408 size_t lenVal; 409 int returnVal; 410 411 lenVal = 3; 412 returnVal = wcsncasecmp(strVal1, strVal2, lenVal); 413 LOGD(" wcsncasecmp returnVal:='%d'\n", returnVal); 414 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcsncasecmp returnVal:='" << returnVal << "'"; 415 } 416 417 /** 418 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSNCASECMP_2500 419 * @tc.name test wcsncasecmp api with same string 420 * @tc.desc [C- SOFTWARE -0200] 421 */ 422 HWTEST_F(ActsUtilStringOperApiTest, testWcsncasecmp2500, Function | MediumTest | Level1) { 423 const wchar_t *strVal1 = L"abcde"; 424 const wchar_t *strVal2 = L"abcde"; 425 size_t lenVal; 426 int returnVal; 427 428 lenVal = 5; 429 returnVal = wcsncasecmp(strVal1, strVal2, lenVal); 430 LOGD(" wcsncasecmp returnVal:='%d'\n", returnVal); 431 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcsncasecmp returnVal:='" << returnVal << "'"; 432 } 433 434 /** 435 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSNCASECMP_L_2600 436 * @tc.name test wcsncasecmp_l api with para1 is lower case of para2 437 * @tc.desc [C- SOFTWARE -0200] 438 */ 439 HWTEST_F(ActsUtilStringOperApiTest, testWcsncasecmpL2600, Function | MediumTest | Level1) { 440 const wchar_t *strVal1 = L"abcde"; 441 const wchar_t *strVal2 = L"ABCDE"; 442 size_t lenVal; 443 int returnVal; 444 445 lenVal = 3; 446 returnVal = wcsncasecmp_l(strVal1, strVal2, lenVal, g_ausoaLocale); 447 LOGD(" wcsncasecmp_l returnVal:='%d'\n", returnVal); 448 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcsncasecmp_l returnVal:='" << returnVal << "'"; 449 } 450 451 /** 452 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSNCASECMP_L_2700 453 * @tc.name test wcsncasecmp_l api with same string 454 * @tc.desc [C- SOFTWARE -0200] 455 */ 456 HWTEST_F(ActsUtilStringOperApiTest, testWcsncasecmpL2700, Function | MediumTest | Level1) { 457 const wchar_t *strVal1 = L"abcde"; 458 const wchar_t *strVal2 = L"abcde"; 459 size_t lenVal; 460 int returnVal; 461 462 lenVal = 5; 463 returnVal = wcsncasecmp_l(strVal1, strVal2, lenVal, g_ausoaLocale); 464 LOGD(" wcsncasecmp_l returnVal:='%d'\n", returnVal); 465 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcsncasecmp_l returnVal:='" << returnVal << "'"; 466 } 467 468 /** 469 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSNLEN_2800 470 * @tc.name test wcsnlen api 471 * @tc.desc [C- SOFTWARE -0200] 472 */ 473 HWTEST_F(ActsUtilStringOperApiTest, testWcsnlen2800, Function | MediumTest | Level1) { 474 const wchar_t *paraVal = L"abcde"; 475 size_t maxLen; 476 size_t returnVal; 477 478 maxLen = wcslen(paraVal); 479 returnVal = wcsnlen(paraVal, maxLen); 480 LOGD(" wcsnlen returnVal:='%d'\n", returnVal); 481 ASSERT_TRUE(5 == returnVal) << "ErrInfo: wcsnlen returnVal:='" << returnVal << "'"; 482 } 483 484 /** 485 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSWIDTH_2900 486 * @tc.name test wcswidth api 487 * @tc.desc [C- SOFTWARE -0200] 488 */ 489 HWTEST_F(ActsUtilStringOperApiTest, testWcswidth2900, Function | MediumTest | Level1) { 490 const wchar_t *paraVal = L"abcde"; 491 size_t lenVal; 492 int returnVal; 493 494 lenVal = wcslen(paraVal); 495 returnVal = wcswidth(paraVal, lenVal); 496 LOGD(" wcswidth returnVal:='%d'\n", returnVal); 497 ASSERT_TRUE(5 == returnVal) << "ErrInfo: wcswidth returnVal:='" << returnVal << "'"; 498 } 499 500 /** 501 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCAT_3000 502 * @tc.name test wcscat api 503 * @tc.desc [C- SOFTWARE -0200] 504 */ 505 HWTEST_F(ActsUtilStringOperApiTest, testWcscat3000, Function | MediumTest | Level1) { 506 wchar_t paraDest[10]; 507 wchar_t paraSrc[5]; 508 wchar_t *returnVal = nullptr; 509 510 wcscpy(paraDest, L"abc"); 511 wcscpy(paraSrc, L"def"); 512 returnVal = wcscat(paraDest, paraSrc); 513 LOGD(" wcscat returnVal:='%s'\n", returnVal); 514 ASSERT_TRUE(0 == wcscmp(returnVal, L"abcdef")) << "ErrInfo: wcscat returnVal:='" << returnVal << "'"; 515 } 516 517 /** 518 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSNCAT_3100 519 * @tc.name test wcsncat api 520 * @tc.desc [C- SOFTWARE -0200] 521 */ 522 HWTEST_F(ActsUtilStringOperApiTest, testWcsncat3100, Function | MediumTest | Level1) { 523 wchar_t paraDest[10]; 524 wchar_t paraSrc[5]; 525 wchar_t *returnVal = nullptr; 526 527 wcsncpy(paraDest, L"abc", wcslen(L"abc") + 1); 528 wcsncpy(paraSrc, L"def", wcslen(L"def") + 1); 529 returnVal = wcsncat(paraDest, paraSrc, wcslen(L"def")); 530 LOGD(" wcscat returnVal:='%x'\n", returnVal); 531 ASSERT_TRUE(0 == wcscmp(returnVal, L"abcdef")) << "ErrInfo: wcscat returnVal:='" << returnVal << "'"; 532 } 533 534 /** 535 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCHR_3200 536 * @tc.name test wcschr api with wc in wcs 537 * @tc.desc [C- SOFTWARE -0200] 538 */ 539 HWTEST_F(ActsUtilStringOperApiTest, testWcschr3200, Function | MediumTest | Level1) { 540 const wchar_t *paraWcs; 541 wchar_t paraWc; 542 wchar_t *returnVal; 543 544 paraWcs = L"abcdefa"; 545 paraWc = 'a'; 546 returnVal = wcschr((wchar_t *)paraWcs, paraWc); 547 LOGD(" wcschr returnVal:='%x'\n", returnVal); 548 ASSERT_TRUE(paraWcs == returnVal) << "ErrInfo: wcschr *returnVal:='" << *returnVal << "'"; 549 } 550 551 /** 552 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCHR_3300 553 * @tc.name test wcschr api with wc not in wcs 554 * @tc.desc [C- SOFTWARE -0200] 555 */ 556 HWTEST_F(ActsUtilStringOperApiTest, testWcschr3300, Function | MediumTest | Level1) { 557 const wchar_t *paraWcs; 558 wchar_t paraWc; 559 wchar_t *returnVal; 560 561 paraWcs = L"abcdef"; 562 paraWc = 'g'; 563 returnVal = wcschr((wchar_t *)paraWcs, paraWc); 564 LOGD(" wcschr returnVal:='%x'\n", returnVal); 565 ASSERT_TRUE(nullptr == returnVal) << "ErrInfo: wcschr returnVal:='" << returnVal << "'"; 566 } 567 568 /** 569 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSRCHR_3400 570 * @tc.name test wcsrchr api with wc in wcs 571 * @tc.desc [C- SOFTWARE -0200] 572 */ 573 HWTEST_F(ActsUtilStringOperApiTest, testWcsrchr3400, Function | MediumTest | Level1) { 574 const wchar_t *paraWcs; 575 wchar_t paraWc; 576 wchar_t *returnVal; 577 578 paraWcs = L"abcdefa"; 579 paraWc = 'a'; 580 returnVal = wcsrchr((wchar_t *)paraWcs, paraWc); 581 LOGD(" wcsrchr returnVal:='%x %x %x'\n", paraWcs, returnVal, (paraWcs + wcslen(L"abcdef"))); 582 ASSERT_TRUE((paraWcs + wcslen(L"abcdef")) == returnVal) << "ErrInfo: wcsrchr *returnVal:='" << *returnVal << "'"; 583 } 584 585 /** 586 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCHR_3500 587 * @tc.name test wcsrchr api with wc not in wcs 588 * @tc.desc [C- SOFTWARE -0200] 589 */ 590 HWTEST_F(ActsUtilStringOperApiTest, testWcsrchr3500, Function | MediumTest | Level1) { 591 const wchar_t *paraWcs; 592 wchar_t paraWc; 593 wchar_t *returnVal; 594 595 paraWcs = L"abcdef"; 596 paraWc = 'g'; 597 returnVal = wcsrchr((wchar_t *)paraWcs, paraWc); 598 LOGD(" wcsrchr returnVal:='%x'\n", returnVal); 599 ASSERT_TRUE(nullptr == returnVal) << "ErrInfo: wcsrchr returnVal:='" << returnVal << "'"; 600 } 601 602 /** 603 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSDUP_3600 604 * @tc.name test wcsdup api 605 * @tc.desc [C- SOFTWARE -0200] 606 */ 607 HWTEST_F(ActsUtilStringOperApiTest, testWcsdup3600, Function | MediumTest | Level1) { 608 const wchar_t *paraWcs; 609 wchar_t *returnVal; 610 611 paraWcs = L"abcdef"; 612 returnVal = wcsdup(paraWcs); 613 LOGD(" wcsdup returnVal:='%x'\n", returnVal); 614 ASSERT_TRUE(0 == wcscmp(returnVal, paraWcs)) << "ErrInfo: wcsdup returnVal:='" << returnVal << "'"; 615 free(returnVal); 616 } 617 618 /** 619 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCOLL_3700 620 * @tc.name test wcscoll api with para1 is equal to para2 621 * @tc.desc [C- SOFTWARE -0200] 622 */ 623 HWTEST_F(ActsUtilStringOperApiTest, testWcscoll3700, Function | MediumTest | Level1) { 624 const wchar_t *paraWcs1; 625 const wchar_t *paraWcs2; 626 int returnVal; 627 628 paraWcs1 = L"abcdef"; 629 paraWcs2 = L"abcdef"; 630 returnVal = wcscoll(paraWcs1, paraWcs2); 631 LOGD(" wcscoll returnVal:='%d'\n", returnVal); 632 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcscoll returnVal:='" << returnVal << "'"; 633 } 634 635 /** 636 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCOLL_3800 637 * @tc.name test wcscoll api with para1 is greater than para2 638 * @tc.desc [C- SOFTWARE -0200] 639 */ 640 HWTEST_F(ActsUtilStringOperApiTest, testWcscoll3800, Function | MediumTest | Level1) { 641 const wchar_t *paraWcs1; 642 const wchar_t *paraWcs2; 643 int returnVal; 644 645 paraWcs1 = L"abcdefg"; 646 paraWcs2 = L"abcdef"; 647 returnVal = wcscoll(paraWcs1, paraWcs2); 648 LOGD(" wcscoll returnVal:='%d'\n", returnVal); 649 ASSERT_TRUE(returnVal > 0) << "ErrInfo: wcscoll returnVal:='" << returnVal << "'"; 650 } 651 652 /** 653 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCOLL_3900 654 * @tc.name test wcscoll api with para1 is less than para2 655 * @tc.desc [C- SOFTWARE -0200] 656 */ 657 HWTEST_F(ActsUtilStringOperApiTest, testWcscoll3900, Function | MediumTest | Level1) { 658 const wchar_t *paraWcs1; 659 const wchar_t *paraWcs2; 660 int returnVal; 661 662 paraWcs1 = L"abcde"; 663 paraWcs2 = L"abcdef"; 664 returnVal = wcscoll(paraWcs1, paraWcs2); 665 LOGD(" wcscoll returnVal:='%d'\n", returnVal); 666 ASSERT_TRUE(returnVal < 0) << "ErrInfo: wcscoll returnVal:='" << returnVal << "'"; 667 } 668 669 /** 670 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCOLL_L_4000 671 * @tc.name test wcscoll_l api with para1 is equal to para2 672 * @tc.desc [C- SOFTWARE -0200] 673 */ 674 HWTEST_F(ActsUtilStringOperApiTest, testWcscollL4000, Function | MediumTest | Level1) { 675 const wchar_t *paraWcs1; 676 const wchar_t *paraWcs2; 677 int returnVal; 678 679 paraWcs1 = L"abcdef"; 680 paraWcs2 = L"abcdef"; 681 returnVal = wcscoll_l(paraWcs1, paraWcs2, g_ausoaLocale); 682 LOGD(" wcscoll_l returnVal:='%d'\n", returnVal); 683 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcscoll_l returnVal:='" << returnVal << "'"; 684 } 685 686 /** 687 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCOLL_L_4100 688 * @tc.name test wcscoll_l api with para1 is greater than para2 689 * @tc.desc [C- SOFTWARE -0200] 690 */ 691 HWTEST_F(ActsUtilStringOperApiTest, testWcscollL4100, Function | MediumTest | Level1) { 692 const wchar_t *paraWcs1; 693 const wchar_t *paraWcs2; 694 int returnVal; 695 696 paraWcs1 = L"abcdefg"; 697 paraWcs2 = L"abcdef"; 698 returnVal = wcscoll_l(paraWcs1, paraWcs2, g_ausoaLocale); 699 LOGD(" wcscoll_l returnVal:='%d'\n", returnVal); 700 ASSERT_TRUE(returnVal > 0) << "ErrInfo: wcscoll_l returnVal:='" << returnVal << "'"; 701 } 702 703 /** 704 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCOLL_L_4200 705 * @tc.name test wcscoll_l api with para1 is less than para2 706 * @tc.desc [C- SOFTWARE -0200] 707 */ 708 HWTEST_F(ActsUtilStringOperApiTest, testWcscollL4200, Function | MediumTest | Level1) { 709 const wchar_t *paraWcs1; 710 const wchar_t *paraWcs2; 711 int returnVal; 712 713 paraWcs1 = L"abcde"; 714 paraWcs2 = L"abcdef"; 715 returnVal = wcscoll_l(paraWcs1, paraWcs2, g_ausoaLocale); 716 LOGD(" wcscoll_l returnVal:='%d'\n", returnVal); 717 ASSERT_TRUE(returnVal < 0) << "ErrInfo: wcscoll_l returnVal:='" << returnVal << "'"; 718 } 719 720 /** 721 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCSPN_4300 722 * @tc.name test wcscspn api with para2 is included in para1 723 * @tc.desc [C- SOFTWARE -0200] 724 */ 725 HWTEST_F(ActsUtilStringOperApiTest, testWcscspn4300, Function | MediumTest | Level1) { 726 const wchar_t *paraWcs; 727 const wchar_t *paraRjct; 728 size_t returnVal; 729 730 paraWcs = L"abcdef"; 731 paraRjct = L"def"; 732 returnVal = wcscspn(paraWcs, paraRjct); 733 LOGD(" wcscspn returnVal:='%d'\n", returnVal); 734 ASSERT_TRUE(3 == returnVal) << "ErrInfo: wcscspn returnVal:='" << returnVal << "'"; 735 } 736 737 /** 738 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSCSPN_4400 739 * @tc.name test wcscspn api with para2 is not included in para1 740 * @tc.desc [C- SOFTWARE -0200] 741 */ 742 HWTEST_F(ActsUtilStringOperApiTest, testWcscspn4400, Function | MediumTest | Level1) { 743 const wchar_t *paraWcs; 744 const wchar_t *paraRjct; 745 size_t returnVal; 746 747 paraWcs = L"abcdef"; 748 paraRjct = L"ghi"; 749 returnVal = wcscspn(paraWcs, paraRjct); 750 LOGD(" wcscspn returnVal:='%d'\n", returnVal); 751 ASSERT_TRUE(6 == returnVal) << "ErrInfo: wcscspn returnVal:='" << returnVal << "'"; 752 } 753 754 /** 755 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSSPN_4500 756 * @tc.name test wcsspn api with para2 is included in para1 757 * @tc.desc [C- SOFTWARE -0200] 758 */ 759 HWTEST_F(ActsUtilStringOperApiTest, testWcsspn4500, Function | MediumTest | Level1) { 760 const wchar_t *paraWcs; 761 const wchar_t *paraAcpt; 762 size_t returnVal; 763 764 paraWcs = L"abcdef"; 765 paraAcpt = L"def"; 766 returnVal = wcsspn(paraWcs, paraAcpt); 767 LOGD(" wcsspn returnVal:='%d'\n", returnVal); 768 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcsspn returnVal:='" << returnVal << "'"; 769 } 770 771 /** 772 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSSPN_4600 773 * @tc.name test wcscspn api with para2 is not included in para1 774 * @tc.desc [C- SOFTWARE -0200] 775 */ 776 HWTEST_F(ActsUtilStringOperApiTest, testWcsspn4600, Function | MediumTest | Level1) { 777 const wchar_t *paraWcs; 778 const wchar_t *paraAcpt; 779 size_t returnVal; 780 781 paraWcs = L"abcdef"; 782 paraAcpt = L"ghi"; 783 returnVal = wcsspn(paraWcs, paraAcpt); 784 LOGD(" wcsspn returnVal:='%d'\n", returnVal); 785 ASSERT_TRUE(0 == returnVal) << "ErrInfo: wcsspn returnVal:='" << returnVal << "'"; 786 } 787 788 /** 789 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSPBRK_4700 790 * @tc.name test wcspbrk api with para2 is included in para1 791 * @tc.desc [C- SOFTWARE -0200] 792 */ 793 HWTEST_F(ActsUtilStringOperApiTest, testWcspbrk4700, Function | MediumTest | Level1) { 794 const wchar_t *paraWcs; 795 const wchar_t *paraAcpt; 796 wchar_t *returnVal; 797 798 paraWcs = L"abcdef"; 799 paraAcpt = L"def"; 800 returnVal = wcspbrk((wchar_t *)paraWcs, paraAcpt); 801 LOGD(" wcspbrk returnVal:='%x'\n", returnVal); 802 ASSERT_TRUE((paraWcs + wcslen(L"abc")) == returnVal) << "ErrInfo: wcspbrk returnVal:='" << returnVal << "'"; 803 } 804 805 /** 806 * @tc.number SUB_KERNEL_UTIL_STRINGOPER_WCSPBRK_4800 807 * @tc.name test wcspbrk api with para2 is not included in para1 808 * @tc.desc [C- SOFTWARE -0200] 809 */ 810 HWTEST_F(ActsUtilStringOperApiTest, testWcspbrk4800, Function | MediumTest | Level1) { 811 const wchar_t *paraWcs; 812 const wchar_t *paraAcpt; 813 wchar_t *returnVal; 814 815 paraWcs = L"abcdef"; 816 paraAcpt = L"ghi"; 817 returnVal = wcspbrk((wchar_t *)paraWcs, paraAcpt); 818 LOGD(" wcspbrk returnVal:='%x'\n", returnVal); 819 ASSERT_TRUE(nullptr == returnVal) << "ErrInfo: wcspbrk returnVal:='" << returnVal << "'"; 820 } 821