• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <errno.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <wchar.h>
20 #include "test.h"
21 
22 #define TEST(r, f, x, m) (errno = 0, msg = #f, ((r) = (f)) == (x) || (t_error("%s failed (" m ")\n", #f, r, x), 0))
23 
24 #define TEST2(r, f, x, m) (((r) = (f)) == (x) || (t_error("%s failed (" m ")\n", msg, r, x), 0))
25 
26 /**
27  * @tc.name      : wcstoll_0100
28  * @tc.desc      : Convert wide string "2147483647" to long long type
29  * @tc.level     : Level 0
30  */
wcstoll_0100(void)31 void wcstoll_0100(void)
32 {
33     long long ll;
34     char *msg = "";
35     TEST(ll, wcstoll(L"2147483647", 0, 0), 2147483647LL, "expect signed %lld != %lld");
36 }
37 
38 /**
39  * @tc.name      : wcstoll_0200
40  * @tc.desc      : Convert wide string "10" to long long type
41  * @tc.level     : Level 0
42  */
wcstoll_0200(void)43 void wcstoll_0200(void)
44 {
45     long long ll;
46     char *msg = "";
47     TEST(ll, wcstoll(L"10", 0, 0), 10LL, "expect signed %lld != %lld");
48 }
49 
50 /**
51  * @tc.name      : wcstoll_0300
52  * @tc.desc      : Convert wide string "z" to long long type
53  * @tc.level     : Level 1
54  */
wcstoll_0300(void)55 void wcstoll_0300(void)
56 {
57     long long ll;
58     char *msg = "";
59     TEST(ll, wcstoll(L"z", 0, 36), 35LL, "%lld != %lld");
60 }
61 
62 /**
63  * @tc.name      : wcstoll_0400
64  * @tc.desc      : Convert wide string "00010010001101000101011001111000" to long long type
65  * @tc.level     : Level 1
66  */
wcstoll_0400(void)67 void wcstoll_0400(void)
68 {
69     long long ll;
70     char *msg = "";
71     TEST(ll, wcstoll(L"00010010001101000101011001111000", 0, 2), 0x12345678, "%lld != %lld");
72 }
73 
74 /**
75  * @tc.name      : wcstoll_0500
76  * @tc.desc      : Convert wide string "0xz" to long long type
77  * @tc.level     : Level 1
78  */
wcstoll_0500(void)79 void wcstoll_0500(void)
80 {
81     int i;
82     long long ll;
83     char *msg = "";
84     wchar_t *s, *c;
85     TEST(ll, wcstoll(s = L"0xz", &c, 16), 0, "%lld != %lld");
86     TEST2(i, c - s, 1, "wrong final position %lld != %lld");
87 }
88 
89 /**
90  * @tc.name      : wcstoll_0600
91  * @tc.desc      : Convert wide string "0x1234" to long long type
92  * @tc.level     : Level 1
93  */
wcstoll_0600(void)94 void wcstoll_0600(void)
95 {
96     int i;
97     long long ll;
98     char *msg = "";
99     wchar_t *s, *c;
100     TEST(ll, wcstoll(s = L"0x1234", &c, 16), 0x1234, "%lld != %ld");
101     TEST2(i, c - s, 6, "wrong final position %lld != %lld");
102 }
103 
104 /**
105  * @tc.name      : wcstoll_0700
106  * @tc.desc      : Convert wide string "9223372036854775808" to long long type exceeds the maximum value of the type
107  * @tc.level     : Level 2
108  */
wcstoll_0700(void)109 void wcstoll_0700(void)
110 {
111     int i;
112     long long ll;
113     char *msg = "";
114     wchar_t *s, *c;
115     TEST(ll, wcstoll(s = L"9223372036854775808", &c, 0), 9223372036854775807LL, "uncaught overflow %lld != %lld");
116     TEST2(i, c - s, 19, "wrong final position %d != %d");
117     TEST2(i, errno, ERANGE, "missing errno %d != %d");
118 }
119 
120 /**
121  * @tc.name      : wcstoll_0800
122  * @tc.desc      : Convert wide string "-9223372036854775809" to long long type exceeds the maximum value of the type
123  * @tc.level     : Level 2
124  */
wcstoll_0800(void)125 void wcstoll_0800(void)
126 {
127     int i;
128     long long ll;
129     char *msg = "";
130     wchar_t *s, *c;
131     TEST(ll, wcstoll(s = L"-9223372036854775809", &c, 0), -9223372036854775807LL - 1, "overflow %lld != %lld");
132     TEST2(i, c - s, 20, "wrong final position %d != %d");
133     TEST2(i, errno, ERANGE, "missing errno %d != %d");
134 }
135 
main(int argc,char * argv[])136 int main(int argc, char *argv[])
137 {
138     wcstoll_0100();
139     wcstoll_0200();
140     wcstoll_0300();
141     wcstoll_0400();
142     wcstoll_0500();
143     wcstoll_0600();
144     wcstoll_0700();
145     wcstoll_0800();
146     return t_status;
147 }