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 <sys/mman.h> 17#include <stdio.h> 18#include <wchar.h> 19 20#include "functionalext.h" 21 22/** 23 * @tc.name : mbrlen_0100 24 * @tc.desc : Verify that the obtained character length is 1 byte 25 * @tc.level : Level 0 26 */ 27void mbrlen_0100(void) 28{ 29 char test[] = {'m', 'u', 's', 'l'}; 30 const int num = sizeof(test) / sizeof(test[0]); 31 size_t limitsize = sizeof(test[0]); 32 for (unsigned int i = 0; i < num; i++) { 33 EXPECT_EQ("mbrlen_0100", mbrlen(test + i, limitsize, NULL), 1); 34 } 35} 36 37/** 38 * @tc.name : mbrlen_0200 39 * @tc.desc : Verify that the length return value of the incoming exception is not an illegal value 40 * @tc.level : Level 2 41 */ 42void mbrlen_0200(void) 43{ 44 char test[] = {'m', 'u', 's', 'l', '\0'}; 45 size_t index = 1; 46 size_t ret = 0; 47 const int num = sizeof(test) / sizeof(test[0]) - 1; 48 for (unsigned int i = 0; i < num; i++) { 49 ret = mbrlen(&test[i], 0, NULL); 50 EXPECT_NE("mbrlen_0200", ret, index); 51 } 52 if (test[num] == '\0') { 53 ret = mbrlen(&test[num], 1, NULL); 54 EXPECT_EQ("mbrlen_0200", ret, CMPFLAG); 55 } 56} 57 58int main(void) 59{ 60 mbrlen_0100(); 61 mbrlen_0200(); 62 63 return t_status; 64}