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 <stdlib.h> 17570af302Sopenharmony_ci#include "functionalext.h" 18570af302Sopenharmony_ci 19570af302Sopenharmony_citypedef void (*TEST_FUN)(); 20570af302Sopenharmony_ciconst int32_t ZERO = 0; 21570af302Sopenharmony_ciconst int32_t NUMBER = 123456; 22570af302Sopenharmony_ciconst int32_t NUM = 123; 23570af302Sopenharmony_ciconst int32_t NUMB = 1234; 24570af302Sopenharmony_ciconst int32_t NU = 12; 25570af302Sopenharmony_ciconst int32_t BURDENNUM = -2147483648; 26570af302Sopenharmony_ci 27570af302Sopenharmony_ci/** 28570af302Sopenharmony_ci * @tc.name : atoi_0100 29570af302Sopenharmony_ci * @tc.desc : Verify that there are and only numbers (starting with non-zero digits) strings are 30570af302Sopenharmony_ci * converted to integers 31570af302Sopenharmony_ci * @tc.level : Level 0 32570af302Sopenharmony_ci */ 33570af302Sopenharmony_civoid atoi_0100(void) 34570af302Sopenharmony_ci{ 35570af302Sopenharmony_ci char str[] = "123456"; 36570af302Sopenharmony_ci int32_t fptr = atoi(str); 37570af302Sopenharmony_ci EXPECT_EQ("atoi_0100", fptr, NUMBER); 38570af302Sopenharmony_ci} 39570af302Sopenharmony_ci 40570af302Sopenharmony_ci/** 41570af302Sopenharmony_ci * @tc.name : atoi_0200 42570af302Sopenharmony_ci * @tc.desc : Verify that there are and only numbers (starting with a 0) string is converted to an integer 43570af302Sopenharmony_ci * @tc.level : Level 0 44570af302Sopenharmony_ci */ 45570af302Sopenharmony_civoid atoi_0200(void) 46570af302Sopenharmony_ci{ 47570af302Sopenharmony_ci char str[] = "000123456"; 48570af302Sopenharmony_ci int32_t fptr = atoi(str); 49570af302Sopenharmony_ci EXPECT_EQ("atoi_0200", fptr, NUMBER); 50570af302Sopenharmony_ci} 51570af302Sopenharmony_ci 52570af302Sopenharmony_ci/** 53570af302Sopenharmony_ci * @tc.name : atoi_0300 54570af302Sopenharmony_ci * @tc.desc : Verify that spaces are at the beginning of the string string is converted to an integer 55570af302Sopenharmony_ci * @tc.level : Level 1 56570af302Sopenharmony_ci */ 57570af302Sopenharmony_civoid atoi_0300(void) 58570af302Sopenharmony_ci{ 59570af302Sopenharmony_ci char str[] = " 123456"; 60570af302Sopenharmony_ci int32_t fptr = atoi(str); 61570af302Sopenharmony_ci EXPECT_EQ("atoi_0300", fptr, NUMBER); 62570af302Sopenharmony_ci} 63570af302Sopenharmony_ci 64570af302Sopenharmony_ci/** 65570af302Sopenharmony_ci * @tc.name : atoi_0400 66570af302Sopenharmony_ci * @tc.desc : Verify that spaces are in the middle of the string and convert the string to an integer 67570af302Sopenharmony_ci * @tc.level : Level 1 68570af302Sopenharmony_ci */ 69570af302Sopenharmony_civoid atoi_0400(void) 70570af302Sopenharmony_ci{ 71570af302Sopenharmony_ci char str[] = "123 456"; 72570af302Sopenharmony_ci int32_t fptr = atoi(str); 73570af302Sopenharmony_ci EXPECT_EQ("atoi_0400", fptr, NUM); 74570af302Sopenharmony_ci} 75570af302Sopenharmony_ci 76570af302Sopenharmony_ci/** 77570af302Sopenharmony_ci * @tc.name : atoi_0500 78570af302Sopenharmony_ci * @tc.desc : Verify that string conversion to integer (- at the beginning of the number) 79570af302Sopenharmony_ci * @tc.level : Level 1 80570af302Sopenharmony_ci */ 81570af302Sopenharmony_civoid atoi_0500(void) 82570af302Sopenharmony_ci{ 83570af302Sopenharmony_ci char str[] = "-123456"; 84570af302Sopenharmony_ci int32_t fptr = atoi(str); 85570af302Sopenharmony_ci EXPECT_EQ("atoi_0500", fptr, -NUMBER); 86570af302Sopenharmony_ci} 87570af302Sopenharmony_ci 88570af302Sopenharmony_ci/** 89570af302Sopenharmony_ci * @tc.name : atoi_0600 90570af302Sopenharmony_ci * @tc.desc : Verify that string conversion to integer (- in the middle of the number) 91570af302Sopenharmony_ci * @tc.level : Level 1 92570af302Sopenharmony_ci */ 93570af302Sopenharmony_civoid atoi_0600(void) 94570af302Sopenharmony_ci{ 95570af302Sopenharmony_ci char str[] = "1234-56"; 96570af302Sopenharmony_ci int32_t fptr = atoi(str); 97570af302Sopenharmony_ci EXPECT_EQ("atoi_0600", fptr, NUMB); 98570af302Sopenharmony_ci} 99570af302Sopenharmony_ci 100570af302Sopenharmony_ci/** 101570af302Sopenharmony_ci * @tc.name : atoi_0700 102570af302Sopenharmony_ci * @tc.desc : Verify that string conversion to integer (+ at the beginning of the number) 103570af302Sopenharmony_ci * @tc.level : Level 1 104570af302Sopenharmony_ci */ 105570af302Sopenharmony_civoid atoi_0700(void) 106570af302Sopenharmony_ci{ 107570af302Sopenharmony_ci char str[] = "+123456"; 108570af302Sopenharmony_ci int32_t fptr = atoi(str); 109570af302Sopenharmony_ci EXPECT_EQ("atoi_0700", fptr, NUMBER); 110570af302Sopenharmony_ci} 111570af302Sopenharmony_ci 112570af302Sopenharmony_ci/** 113570af302Sopenharmony_ci * @tc.name : atoi_0800 114570af302Sopenharmony_ci * @tc.desc : Verify that string conversion to integer (+ in the middle of the number) 115570af302Sopenharmony_ci * @tc.level : Level 1 116570af302Sopenharmony_ci */ 117570af302Sopenharmony_civoid atoi_0800(void) 118570af302Sopenharmony_ci{ 119570af302Sopenharmony_ci char str[] = "1234+56"; 120570af302Sopenharmony_ci int32_t fptr = atoi(str); 121570af302Sopenharmony_ci EXPECT_EQ("atoi_0800", fptr, NUMB); 122570af302Sopenharmony_ci} 123570af302Sopenharmony_ci 124570af302Sopenharmony_ci/** 125570af302Sopenharmony_ci * @tc.name : atoi_0900 126570af302Sopenharmony_ci * @tc.desc : Verify that string conversion to integer (English characters are at the beginning) 127570af302Sopenharmony_ci * @tc.level : Level 2 128570af302Sopenharmony_ci */ 129570af302Sopenharmony_civoid atoi_0900(void) 130570af302Sopenharmony_ci{ 131570af302Sopenharmony_ci char str[] = "a123456"; 132570af302Sopenharmony_ci int32_t fptr = atoi(str); 133570af302Sopenharmony_ci EXPECT_EQ("atoi_0900", fptr, ZERO); 134570af302Sopenharmony_ci} 135570af302Sopenharmony_ci 136570af302Sopenharmony_ci/** 137570af302Sopenharmony_ci * @tc.name : atoi_1000 138570af302Sopenharmony_ci * @tc.desc : Verify that string conversion to integer (English characters are in the middle) 139570af302Sopenharmony_ci * @tc.level : Level 2 140570af302Sopenharmony_ci */ 141570af302Sopenharmony_civoid atoi_1000(void) 142570af302Sopenharmony_ci{ 143570af302Sopenharmony_ci char str[] = "12b3456"; 144570af302Sopenharmony_ci int32_t fptr = atoi(str); 145570af302Sopenharmony_ci EXPECT_EQ("atoi_1000", fptr, NU); 146570af302Sopenharmony_ci} 147570af302Sopenharmony_ci 148570af302Sopenharmony_ci/** 149570af302Sopenharmony_ci * @tc.name : atoi_1100 150570af302Sopenharmony_ci * @tc.desc : Verify that string conversion to integer (parameter invalid NULL) 151570af302Sopenharmony_ci * @tc.level : Level 2 152570af302Sopenharmony_ci */ 153570af302Sopenharmony_civoid atoi_1100(void) 154570af302Sopenharmony_ci{ 155570af302Sopenharmony_ci char str[] = "NULL"; 156570af302Sopenharmony_ci int32_t fptr = atoi(str); 157570af302Sopenharmony_ci EXPECT_EQ("atoi_1100", fptr, ZERO); 158570af302Sopenharmony_ci} 159570af302Sopenharmony_ci 160570af302Sopenharmony_ci/** 161570af302Sopenharmony_ci * @tc.name : atoi_1200 162570af302Sopenharmony_ci * @tc.desc : Verify that string conversion to integer (parameter invalid "") 163570af302Sopenharmony_ci * @tc.level : Level 2 164570af302Sopenharmony_ci */ 165570af302Sopenharmony_civoid atoi_1200(void) 166570af302Sopenharmony_ci{ 167570af302Sopenharmony_ci char str[] = ""; 168570af302Sopenharmony_ci int32_t fptr = atoi(str); 169570af302Sopenharmony_ci EXPECT_EQ("atoi_1200", fptr, ZERO); 170570af302Sopenharmony_ci} 171570af302Sopenharmony_ci 172570af302Sopenharmony_ci/** 173570af302Sopenharmony_ci * @tc.name : atoi_1300 174570af302Sopenharmony_ci * @tc.desc : Verify that string conversion to integer (parameter exceeds max value) 175570af302Sopenharmony_ci * @tc.level : Level 2 176570af302Sopenharmony_ci */ 177570af302Sopenharmony_civoid atoi_1300(void) 178570af302Sopenharmony_ci{ 179570af302Sopenharmony_ci char str[] = "2147483648"; 180570af302Sopenharmony_ci int32_t fptr = atoi(str); 181570af302Sopenharmony_ci EXPECT_EQ("atoi_1300", fptr, BURDENNUM); 182570af302Sopenharmony_ci} 183570af302Sopenharmony_ci 184570af302Sopenharmony_ci/** 185570af302Sopenharmony_ci * @tc.name : atoi_1400 186570af302Sopenharmony_ci * @tc.desc : erify that string conversion to integer (parameter less than minimum value) 187570af302Sopenharmony_ci * @tc.level : Level 2 188570af302Sopenharmony_ci */ 189570af302Sopenharmony_civoid atoi_1400(void) 190570af302Sopenharmony_ci{ 191570af302Sopenharmony_ci char str[] = "-2147483648"; 192570af302Sopenharmony_ci int32_t fptr = atoi(str); 193570af302Sopenharmony_ci EXPECT_EQ("atoi_1400", fptr, BURDENNUM); 194570af302Sopenharmony_ci} 195570af302Sopenharmony_ci 196570af302Sopenharmony_ciTEST_FUN G_Fun_Array[] = { 197570af302Sopenharmony_ci atoi_0100, 198570af302Sopenharmony_ci atoi_0200, 199570af302Sopenharmony_ci atoi_0300, 200570af302Sopenharmony_ci atoi_0400, 201570af302Sopenharmony_ci atoi_0500, 202570af302Sopenharmony_ci atoi_0600, 203570af302Sopenharmony_ci atoi_0700, 204570af302Sopenharmony_ci atoi_0800, 205570af302Sopenharmony_ci atoi_0900, 206570af302Sopenharmony_ci atoi_1000, 207570af302Sopenharmony_ci atoi_1100, 208570af302Sopenharmony_ci atoi_1200, 209570af302Sopenharmony_ci atoi_1300, 210570af302Sopenharmony_ci atoi_1400, 211570af302Sopenharmony_ci}; 212570af302Sopenharmony_ci 213570af302Sopenharmony_ciint main(int argc, char *argv[]) 214570af302Sopenharmony_ci{ 215570af302Sopenharmony_ci int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); 216570af302Sopenharmony_ci for (int pos = 0; pos < num; ++pos) { 217570af302Sopenharmony_ci G_Fun_Array[pos](); 218570af302Sopenharmony_ci } 219570af302Sopenharmony_ci 220570af302Sopenharmony_ci return t_status; 221570af302Sopenharmony_ci}