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 <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <inttypes.h>
20 #include "test.h"
21
22 /**
23 * @tc.name : strtoimax_0100
24 * @tc.desc : Test that strtoimax interprets string contents as base 10 integers
25 * @tc.level : Level 0
26 */
strtoimax_0100(void)27 void strtoimax_0100(void)
28 {
29 char *p = {0};
30 intmax_t want = -18737357;
31 intmax_t result = strtoimax("-18737357foobar12", &p, 10);
32 if (result != want) {
33 t_error("%s strtoimax get result is %zu are not -18737357\n", __func__, result);
34 }
35 if (strcmp(p, "foobar12") != 0) {
36 t_error("%s strtoimax get is '%s' are not 'foobar12'\n", __func__, p);
37 }
38 }
39
40 /**
41 * @tc.name : strtoimax_0200
42 * @tc.desc : Test that strtoimax interprets string contents as base 16 integers
43 * @tc.level : Level 1
44 */
strtoimax_0200(void)45 void strtoimax_0200(void)
46 {
47 char *p = {0};
48 intmax_t want = -0x18737357f;
49 intmax_t result = strtoimax("-18737357foobar12", &p, 16);
50 if (result != want) {
51 t_error("%s strtoimax get result is %zu are not -0x18737357f\n", __func__, result);
52 }
53 if (strcmp(p, "oobar12") != 0) {
54 t_error("%s strtoimax get is '%s' are not 'oobar12'\n", __func__, p);
55 }
56 }
57
main(int argc,char * argv[])58 int main(int argc, char *argv[])
59 {
60 strtoimax_0100();
61 strtoimax_0200();
62 return t_status;
63 }