libutil

C Utility Library
git clone http://git.omkov.net/libutil
Log | Tree | Refs | README | LICENCE | Download

libutil/src/test/test_strtou.c (353 lines, 7.2 KiB) -rw-r--r-- file download

9b704eb Jamozed 2021-02-22 11:39:52
0
// test_strtou.c
98e5939 Jamozed 2021-11-27 17:53:46
1
// String conversion unit test for libutil
4b7a448 Jamozed 2021-02-21 23:23:53
2
// Copyright (C) 2021, Jakob Wakeling
7f427d9 Jamozed 2022-03-06 12:55:13
3
// MIT Licence
4b7a448 Jamozed 2021-02-21 23:23:53
4
4b7a448 Jamozed 2021-02-21 23:23:53
5
#include "../strconv.h"
4b7a448 Jamozed 2021-02-21 23:23:53
6
#include "unit.h"
4b7a448 Jamozed 2021-02-21 23:23:53
7
4b7a448 Jamozed 2021-02-21 23:23:53
8
#include <stdint.h>
4b7a448 Jamozed 2021-02-21 23:23:53
9
#include <stdio.h>
4b7a448 Jamozed 2021-02-21 23:23:53
10
#include <errno.h>
4b7a448 Jamozed 2021-02-21 23:23:53
11
4b7a448 Jamozed 2021-02-21 23:23:53
12
int main(void) {
4b7a448 Jamozed 2021-02-21 23:23:53
13
	/* STRTOU8 */
4b7a448 Jamozed 2021-02-21 23:23:53
14
	{
4b7a448 Jamozed 2021-02-21 23:23:53
15
		char i[] = "0";
4b7a448 Jamozed 2021-02-21 23:23:53
16
		
4b7a448 Jamozed 2021-02-21 23:23:53
17
		ASSERT("T000 STRTOU8 ZERO BASE 0",
4b7a448 Jamozed 2021-02-21 23:23:53
18
				strtou8(i, NULL, 0) == 0);
4b7a448 Jamozed 2021-02-21 23:23:53
19
		
4b7a448 Jamozed 2021-02-21 23:23:53
20
		ASSERT("T001 STRTOU8 ZERO BASE 8",
4b7a448 Jamozed 2021-02-21 23:23:53
21
				strtou8(i, NULL, 8) == 0);
4b7a448 Jamozed 2021-02-21 23:23:53
22
	}
4b7a448 Jamozed 2021-02-21 23:23:53
23
	
4b7a448 Jamozed 2021-02-21 23:23:53
24
	{
4b7a448 Jamozed 2021-02-21 23:23:53
25
		char i[] = "64";
4b7a448 Jamozed 2021-02-21 23:23:53
26
		
4b7a448 Jamozed 2021-02-21 23:23:53
27
		ASSERT("T002 STRTOU8 NORMAL BASE 0",
4b7a448 Jamozed 2021-02-21 23:23:53
28
				strtou8(i, NULL, 0) == 64);
4b7a448 Jamozed 2021-02-21 23:23:53
29
		
4b7a448 Jamozed 2021-02-21 23:23:53
30
		ASSERT("T003 STRTOU8 NORMAL BASE 8",
4b7a448 Jamozed 2021-02-21 23:23:53
31
				strtou8(i, NULL, 8) == 52);
4b7a448 Jamozed 2021-02-21 23:23:53
32
		
4b7a448 Jamozed 2021-02-21 23:23:53
33
		ASSERT("T004 STRTOU8 NORMAL BASE 10",
4b7a448 Jamozed 2021-02-21 23:23:53
34
				strtou8(i, NULL, 10) == 64);
4b7a448 Jamozed 2021-02-21 23:23:53
35
		
4b7a448 Jamozed 2021-02-21 23:23:53
36
		ASSERT("T005 STRTOU8 NORMAL BASE 16",
4b7a448 Jamozed 2021-02-21 23:23:53
37
				strtou8(i, NULL, 16) == 100);
4b7a448 Jamozed 2021-02-21 23:23:53
38
	}
4b7a448 Jamozed 2021-02-21 23:23:53
39
	
4b7a448 Jamozed 2021-02-21 23:23:53
40
	{
4b7a448 Jamozed 2021-02-21 23:23:53
41
		char i[] = "3M";
4b7a448 Jamozed 2021-02-21 23:23:53
42
		
4b7a448 Jamozed 2021-02-21 23:23:53
43
		ASSERT("T006 STRTOU8 NORMAL BASE 36",
4b7a448 Jamozed 2021-02-21 23:23:53
44
				strtou8(i, NULL, 36) == 130u);
4b7a448 Jamozed 2021-02-21 23:23:53
45
	}
4b7a448 Jamozed 2021-02-21 23:23:53
46
	
4b7a448 Jamozed 2021-02-21 23:23:53
47
	{
4b7a448 Jamozed 2021-02-21 23:23:53
48
		char i8[] = "0377";
4b7a448 Jamozed 2021-02-21 23:23:53
49
		char i10[] = "255";
4b7a448 Jamozed 2021-02-21 23:23:53
50
		char i16[] = "0xFF";
4b7a448 Jamozed 2021-02-21 23:23:53
51
		
4b7a448 Jamozed 2021-02-21 23:23:53
52
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
53
		ASSERT("T007 STRTOU8 MAX BASE 0",
4b7a448 Jamozed 2021-02-21 23:23:53
54
				strtou8(i8, NULL, 0) == UINT8_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
55
		
4b7a448 Jamozed 2021-02-21 23:23:53
56
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
57
		ASSERT("T008 STRTOU8 MAX BASE 8",
4b7a448 Jamozed 2021-02-21 23:23:53
58
				strtou8(i8, NULL, 8) == UINT8_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
59
		
4b7a448 Jamozed 2021-02-21 23:23:53
60
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
61
		ASSERT("T009 STRTOU8 MAX BASE 10",
4b7a448 Jamozed 2021-02-21 23:23:53
62
				strtou8(i10, NULL, 10) == UINT8_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
63
		
4b7a448 Jamozed 2021-02-21 23:23:53
64
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
65
		ASSERT("T010 STRTOU8 MAX BASE 16",
4b7a448 Jamozed 2021-02-21 23:23:53
66
				strtou8(i16, NULL, 16) == UINT8_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
67
	}
4b7a448 Jamozed 2021-02-21 23:23:53
68
	
4b7a448 Jamozed 2021-02-21 23:23:53
69
	{
4b7a448 Jamozed 2021-02-21 23:23:53
70
		char i[] = "-153";
4b7a448 Jamozed 2021-02-21 23:23:53
71
		
4b7a448 Jamozed 2021-02-21 23:23:53
72
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
73
		ASSERT("T011 STRTOU8 NEGATIVE",
4b7a448 Jamozed 2021-02-21 23:23:53
74
				!strtou8(i, NULL, 10) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
75
		
4b7a448 Jamozed 2021-02-21 23:23:53
76
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
77
		ASSERT("T012 STRTOU8 BASE 1",
4b7a448 Jamozed 2021-02-21 23:23:53
78
				!strtou8(i, NULL, 1) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
79
		
4b7a448 Jamozed 2021-02-21 23:23:53
80
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
81
		ASSERT("T013 STRTOU8 BASE -1",
4b7a448 Jamozed 2021-02-21 23:23:53
82
				!strtou8(i, NULL, -1) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
83
		
4b7a448 Jamozed 2021-02-21 23:23:53
84
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
85
		ASSERT("T014 STRTOU8 BASE 37",
4b7a448 Jamozed 2021-02-21 23:23:53
86
				!strtou8(i, NULL, 37) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
87
	}
4b7a448 Jamozed 2021-02-21 23:23:53
88
	
4b7a448 Jamozed 2021-02-21 23:23:53
89
	{
4b7a448 Jamozed 2021-02-21 23:23:53
90
		char i[] = "257";
4b7a448 Jamozed 2021-02-21 23:23:53
91
		
4b7a448 Jamozed 2021-02-21 23:23:53
92
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
93
		ASSERT("T015 STRTOU8 OVERFLOW",
4b7a448 Jamozed 2021-02-21 23:23:53
94
				strtou8(i, NULL, 10) == UINT8_MAX && errno == ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
95
	}
4b7a448 Jamozed 2021-02-21 23:23:53
96
	
4b7a448 Jamozed 2021-02-21 23:23:53
97
	/* STRTOU16 */
4b7a448 Jamozed 2021-02-21 23:23:53
98
	{
4b7a448 Jamozed 2021-02-21 23:23:53
99
		char i[] = "0";
4b7a448 Jamozed 2021-02-21 23:23:53
100
		
4b7a448 Jamozed 2021-02-21 23:23:53
101
		ASSERT("T100 STRTOU16 ZERO BASE 0",
4b7a448 Jamozed 2021-02-21 23:23:53
102
				strtou16(i, NULL, 0) == 0);
4b7a448 Jamozed 2021-02-21 23:23:53
103
		
4b7a448 Jamozed 2021-02-21 23:23:53
104
		ASSERT("T101 STRTOU16 ZERO BASE 8",
4b7a448 Jamozed 2021-02-21 23:23:53
105
				strtou16(i, NULL, 8) == 0);
4b7a448 Jamozed 2021-02-21 23:23:53
106
	}
4b7a448 Jamozed 2021-02-21 23:23:53
107
	
4b7a448 Jamozed 2021-02-21 23:23:53
108
	{
4b7a448 Jamozed 2021-02-21 23:23:53
109
		char i[] = "64";
4b7a448 Jamozed 2021-02-21 23:23:53
110
		
4b7a448 Jamozed 2021-02-21 23:23:53
111
		ASSERT("T102 STRTOU16 NORMAL BASE 0",
4b7a448 Jamozed 2021-02-21 23:23:53
112
				strtou16(i, NULL, 0) == 64);
4b7a448 Jamozed 2021-02-21 23:23:53
113
		
4b7a448 Jamozed 2021-02-21 23:23:53
114
		ASSERT("T103 STRTOU16 NORMAL BASE 8",
4b7a448 Jamozed 2021-02-21 23:23:53
115
				strtou16(i, NULL, 8) == 52);
4b7a448 Jamozed 2021-02-21 23:23:53
116
		
4b7a448 Jamozed 2021-02-21 23:23:53
117
		ASSERT("T104 STRTOU16 NORMAL BASE 10",
4b7a448 Jamozed 2021-02-21 23:23:53
118
				strtou16(i, NULL, 10) == 64);
4b7a448 Jamozed 2021-02-21 23:23:53
119
		
4b7a448 Jamozed 2021-02-21 23:23:53
120
		ASSERT("T105 STRTOU16 NORMAL BASE 16",
4b7a448 Jamozed 2021-02-21 23:23:53
121
				strtou16(i, NULL, 16) == 100);
4b7a448 Jamozed 2021-02-21 23:23:53
122
	}
4b7a448 Jamozed 2021-02-21 23:23:53
123
	
4b7a448 Jamozed 2021-02-21 23:23:53
124
	{
4b7a448 Jamozed 2021-02-21 23:23:53
125
		char i[] = "AZ1";
4b7a448 Jamozed 2021-02-21 23:23:53
126
		
4b7a448 Jamozed 2021-02-21 23:23:53
127
		ASSERT("T106 STRTOU16 NORMAL BASE 36",
4b7a448 Jamozed 2021-02-21 23:23:53
128
				strtou16(i, NULL, 36) == 14221u);
4b7a448 Jamozed 2021-02-21 23:23:53
129
	}
4b7a448 Jamozed 2021-02-21 23:23:53
130
	
4b7a448 Jamozed 2021-02-21 23:23:53
131
	{
4b7a448 Jamozed 2021-02-21 23:23:53
132
		char i8[] = "0177777";
4b7a448 Jamozed 2021-02-21 23:23:53
133
		char i10[] = "65535";
4b7a448 Jamozed 2021-02-21 23:23:53
134
		char i16[] = "0xFFFF";
4b7a448 Jamozed 2021-02-21 23:23:53
135
		
4b7a448 Jamozed 2021-02-21 23:23:53
136
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
137
		ASSERT("T107 STRTOU16 MAX BASE 0",
4b7a448 Jamozed 2021-02-21 23:23:53
138
				strtou16(i8, NULL, 0) == UINT16_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
139
		
4b7a448 Jamozed 2021-02-21 23:23:53
140
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
141
		ASSERT("T108 STRTOU16 MAX BASE 8",
4b7a448 Jamozed 2021-02-21 23:23:53
142
				strtou16(i8, NULL, 8) == UINT16_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
143
		
4b7a448 Jamozed 2021-02-21 23:23:53
144
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
145
		ASSERT("T109 STRTOU16 MAX BASE 10",
4b7a448 Jamozed 2021-02-21 23:23:53
146
				strtou16(i10, NULL, 10) == UINT16_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
147
		
4b7a448 Jamozed 2021-02-21 23:23:53
148
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
149
		ASSERT("T110 STRTOU16 MAX BASE 16",
4b7a448 Jamozed 2021-02-21 23:23:53
150
				strtou16(i16, NULL, 16) == UINT16_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
151
	}
4b7a448 Jamozed 2021-02-21 23:23:53
152
	
4b7a448 Jamozed 2021-02-21 23:23:53
153
	{
4b7a448 Jamozed 2021-02-21 23:23:53
154
		char i[] = "-153";
4b7a448 Jamozed 2021-02-21 23:23:53
155
		
4b7a448 Jamozed 2021-02-21 23:23:53
156
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
157
		ASSERT("T111 STRTOU16 NEGATIVE",
4b7a448 Jamozed 2021-02-21 23:23:53
158
				!strtou16(i, NULL, 10) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
159
		
4b7a448 Jamozed 2021-02-21 23:23:53
160
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
161
		ASSERT("T112 STRTOU16 BASE 1",
4b7a448 Jamozed 2021-02-21 23:23:53
162
				!strtou16(i, NULL, 1) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
163
		
4b7a448 Jamozed 2021-02-21 23:23:53
164
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
165
		ASSERT("T113 STRTOU16 BASE -1",
4b7a448 Jamozed 2021-02-21 23:23:53
166
				!strtou16(i, NULL, -1) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
167
		
4b7a448 Jamozed 2021-02-21 23:23:53
168
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
169
		ASSERT("T114 STRTOU16 BASE 37",
4b7a448 Jamozed 2021-02-21 23:23:53
170
				!strtou16(i, NULL, 37) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
171
	}
4b7a448 Jamozed 2021-02-21 23:23:53
172
	
4b7a448 Jamozed 2021-02-21 23:23:53
173
	{
4b7a448 Jamozed 2021-02-21 23:23:53
174
		char i[] = "65537";
4b7a448 Jamozed 2021-02-21 23:23:53
175
		
4b7a448 Jamozed 2021-02-21 23:23:53
176
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
177
		ASSERT("T115 STRTOU16 OVERFLOW",
4b7a448 Jamozed 2021-02-21 23:23:53
178
				strtou16(i, NULL, 10) == UINT16_MAX && errno == ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
179
	}
4b7a448 Jamozed 2021-02-21 23:23:53
180
	
4b7a448 Jamozed 2021-02-21 23:23:53
181
	/* STRTOU32 */
4b7a448 Jamozed 2021-02-21 23:23:53
182
	{
4b7a448 Jamozed 2021-02-21 23:23:53
183
		char i[] = "0";
4b7a448 Jamozed 2021-02-21 23:23:53
184
		
4b7a448 Jamozed 2021-02-21 23:23:53
185
		ASSERT("T200 STRTOU32 ZERO BASE 0",
4b7a448 Jamozed 2021-02-21 23:23:53
186
				strtou32(i, NULL, 0) == 0);
4b7a448 Jamozed 2021-02-21 23:23:53
187
		
4b7a448 Jamozed 2021-02-21 23:23:53
188
		ASSERT("T201 STRTOU32 ZERO BASE 8",
4b7a448 Jamozed 2021-02-21 23:23:53
189
				strtou32(i, NULL, 8) == 0);
4b7a448 Jamozed 2021-02-21 23:23:53
190
	}
4b7a448 Jamozed 2021-02-21 23:23:53
191
	
4b7a448 Jamozed 2021-02-21 23:23:53
192
	{
4b7a448 Jamozed 2021-02-21 23:23:53
193
		char i[] = "64";
4b7a448 Jamozed 2021-02-21 23:23:53
194
		
4b7a448 Jamozed 2021-02-21 23:23:53
195
		ASSERT("T202 STRTOU32 NORMAL BASE 0",
4b7a448 Jamozed 2021-02-21 23:23:53
196
				strtou32(i, NULL, 0) == 64);
4b7a448 Jamozed 2021-02-21 23:23:53
197
		
4b7a448 Jamozed 2021-02-21 23:23:53
198
		ASSERT("T203 STRTOU32 NORMAL BASE 8",
4b7a448 Jamozed 2021-02-21 23:23:53
199
				strtou32(i, NULL, 8) == 52);
4b7a448 Jamozed 2021-02-21 23:23:53
200
		
4b7a448 Jamozed 2021-02-21 23:23:53
201
		ASSERT("T204 STRTOU32 NORMAL BASE 10",
4b7a448 Jamozed 2021-02-21 23:23:53
202
				strtou32(i, NULL, 10) == 64);
4b7a448 Jamozed 2021-02-21 23:23:53
203
		
4b7a448 Jamozed 2021-02-21 23:23:53
204
		ASSERT("T205 STRTOU32 NORMAL BASE 16",
4b7a448 Jamozed 2021-02-21 23:23:53
205
				strtou32(i, NULL, 16) == 100);
4b7a448 Jamozed 2021-02-21 23:23:53
206
	}
4b7a448 Jamozed 2021-02-21 23:23:53
207
	
4b7a448 Jamozed 2021-02-21 23:23:53
208
	{
4b7a448 Jamozed 2021-02-21 23:23:53
209
		char i[] = "T7A7J";
4b7a448 Jamozed 2021-02-21 23:23:53
210
		
4b7a448 Jamozed 2021-02-21 23:23:53
211
		ASSERT("T206 STRTOU32 NORMAL BASE 36",
4b7a448 Jamozed 2021-02-21 23:23:53
212
				strtou32(i, NULL, 36) == 49048687u);
4b7a448 Jamozed 2021-02-21 23:23:53
213
	}
4b7a448 Jamozed 2021-02-21 23:23:53
214
	
4b7a448 Jamozed 2021-02-21 23:23:53
215
	{
4b7a448 Jamozed 2021-02-21 23:23:53
216
		char i8[] = "037777777777";
4b7a448 Jamozed 2021-02-21 23:23:53
217
		char i10[] = "4294967295";
4b7a448 Jamozed 2021-02-21 23:23:53
218
		char i16[] = "0xFFFFFFFF";
4b7a448 Jamozed 2021-02-21 23:23:53
219
		
4b7a448 Jamozed 2021-02-21 23:23:53
220
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
221
		ASSERT("T207 STRTOU32 MAX BASE 0",
4b7a448 Jamozed 2021-02-21 23:23:53
222
				strtou32(i8, NULL, 0) == UINT32_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
223
		
4b7a448 Jamozed 2021-02-21 23:23:53
224
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
225
		ASSERT("T208 STRTOU32 MAX BASE 8",
4b7a448 Jamozed 2021-02-21 23:23:53
226
				strtou32(i8, NULL, 8) == UINT32_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
227
		
4b7a448 Jamozed 2021-02-21 23:23:53
228
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
229
		ASSERT("T209 STRTOU32 MAX BASE 10",
4b7a448 Jamozed 2021-02-21 23:23:53
230
				strtou32(i10, NULL, 10) == UINT32_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
231
		
4b7a448 Jamozed 2021-02-21 23:23:53
232
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
233
		ASSERT("T210 STRTOU32 MAX BASE 16",
4b7a448 Jamozed 2021-02-21 23:23:53
234
				strtou32(i16, NULL, 16) == UINT32_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
235
	}
4b7a448 Jamozed 2021-02-21 23:23:53
236
	
4b7a448 Jamozed 2021-02-21 23:23:53
237
	{
4b7a448 Jamozed 2021-02-21 23:23:53
238
		char i[] = "-153";
4b7a448 Jamozed 2021-02-21 23:23:53
239
		
4b7a448 Jamozed 2021-02-21 23:23:53
240
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
241
		ASSERT("T211 STRTOU32 NEGATIVE",
4b7a448 Jamozed 2021-02-21 23:23:53
242
				!strtou32(i, NULL, 10) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
243
		
4b7a448 Jamozed 2021-02-21 23:23:53
244
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
245
		ASSERT("T212 STRTOU32 BASE 1",
4b7a448 Jamozed 2021-02-21 23:23:53
246
				!strtou32(i, NULL, 1) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
247
		
4b7a448 Jamozed 2021-02-21 23:23:53
248
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
249
		ASSERT("T213 STRTOU32 BASE -1",
4b7a448 Jamozed 2021-02-21 23:23:53
250
				!strtou32(i, NULL, -1) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
251
		
4b7a448 Jamozed 2021-02-21 23:23:53
252
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
253
		ASSERT("T214 STRTOU32 BASE 37",
4b7a448 Jamozed 2021-02-21 23:23:53
254
				!strtou32(i, NULL, 37) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
255
	}
4b7a448 Jamozed 2021-02-21 23:23:53
256
	
4b7a448 Jamozed 2021-02-21 23:23:53
257
	{
4b7a448 Jamozed 2021-02-21 23:23:53
258
		char i[] = "4294967297";
4b7a448 Jamozed 2021-02-21 23:23:53
259
		
4b7a448 Jamozed 2021-02-21 23:23:53
260
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
261
		ASSERT("T215 STRTOU32 OVERFLOW",
4b7a448 Jamozed 2021-02-21 23:23:53
262
				strtou32(i, NULL, 10) == UINT32_MAX && errno == ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
263
	}
4b7a448 Jamozed 2021-02-21 23:23:53
264
	
4b7a448 Jamozed 2021-02-21 23:23:53
265
	/* STRTOU64 */
4b7a448 Jamozed 2021-02-21 23:23:53
266
	{
4b7a448 Jamozed 2021-02-21 23:23:53
267
		char i[] = "0";
4b7a448 Jamozed 2021-02-21 23:23:53
268
		
4b7a448 Jamozed 2021-02-21 23:23:53
269
		ASSERT("T300 STRTOU64 ZERO BASE 0",
4b7a448 Jamozed 2021-02-21 23:23:53
270
				strtou64(i, NULL, 0) == 0);
4b7a448 Jamozed 2021-02-21 23:23:53
271
		
4b7a448 Jamozed 2021-02-21 23:23:53
272
		ASSERT("T301 STRTOU64 ZERO BASE 8",
4b7a448 Jamozed 2021-02-21 23:23:53
273
				strtou64(i, NULL, 8) == 0);
4b7a448 Jamozed 2021-02-21 23:23:53
274
	}
4b7a448 Jamozed 2021-02-21 23:23:53
275
	
4b7a448 Jamozed 2021-02-21 23:23:53
276
	{
4b7a448 Jamozed 2021-02-21 23:23:53
277
		char i[] = "64";
4b7a448 Jamozed 2021-02-21 23:23:53
278
		
4b7a448 Jamozed 2021-02-21 23:23:53
279
		ASSERT("T302 STRTOU64 NORMAL BASE 0",
4b7a448 Jamozed 2021-02-21 23:23:53
280
				strtou64(i, NULL, 0) == 64);
4b7a448 Jamozed 2021-02-21 23:23:53
281
		
4b7a448 Jamozed 2021-02-21 23:23:53
282
		ASSERT("T303 STRTOU64 NORMAL BASE 8",
4b7a448 Jamozed 2021-02-21 23:23:53
283
				strtou64(i, NULL, 8) == 52);
4b7a448 Jamozed 2021-02-21 23:23:53
284
		
4b7a448 Jamozed 2021-02-21 23:23:53
285
		ASSERT("T304 STRTOU64 NORMAL BASE 10",
4b7a448 Jamozed 2021-02-21 23:23:53
286
				strtou64(i, NULL, 10) == 64);
4b7a448 Jamozed 2021-02-21 23:23:53
287
		
4b7a448 Jamozed 2021-02-21 23:23:53
288
		ASSERT("T305 STRTOU64 NORMAL BASE 16",
4b7a448 Jamozed 2021-02-21 23:23:53
289
				strtou64(i, NULL, 16) == 100);
4b7a448 Jamozed 2021-02-21 23:23:53
290
	}
4b7a448 Jamozed 2021-02-21 23:23:53
291
	
4b7a448 Jamozed 2021-02-21 23:23:53
292
	{
4b7a448 Jamozed 2021-02-21 23:23:53
293
		char i[] = "3579ADGJMPSVZ";
4b7a448 Jamozed 2021-02-21 23:23:53
294
		
4b7a448 Jamozed 2021-02-21 23:23:53
295
		ASSERT("T306 STRTOU64 NORMAL BASE 36",
4b7a448 Jamozed 2021-02-21 23:23:53
296
				strtou64(i, NULL, 36) == 14899788948715380863u);
4b7a448 Jamozed 2021-02-21 23:23:53
297
	}
4b7a448 Jamozed 2021-02-21 23:23:53
298
	
4b7a448 Jamozed 2021-02-21 23:23:53
299
	{
4b7a448 Jamozed 2021-02-21 23:23:53
300
		char i8[] = "01777777777777777777777";
4b7a448 Jamozed 2021-02-21 23:23:53
301
		char i10[] = "18446744073709551615";
4b7a448 Jamozed 2021-02-21 23:23:53
302
		char i16[] = "0xFFFFFFFFFFFFFFFF";
4b7a448 Jamozed 2021-02-21 23:23:53
303
		
4b7a448 Jamozed 2021-02-21 23:23:53
304
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
305
		ASSERT("T307 STRTOU64 MAX BASE 0",
4b7a448 Jamozed 2021-02-21 23:23:53
306
				strtou64(i8, NULL, 0) == UINT64_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
307
		
4b7a448 Jamozed 2021-02-21 23:23:53
308
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
309
		ASSERT("T308 STRTOU64 MAX BASE 8",
4b7a448 Jamozed 2021-02-21 23:23:53
310
				strtou64(i8, NULL, 8) == UINT64_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
311
		
4b7a448 Jamozed 2021-02-21 23:23:53
312
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
313
		ASSERT("T309 STRTOU64 MAX BASE 10",
4b7a448 Jamozed 2021-02-21 23:23:53
314
				strtou64(i10, NULL, 10) == UINT64_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
315
		
4b7a448 Jamozed 2021-02-21 23:23:53
316
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
317
		ASSERT("T310 STRTOU64 MAX BASE 16",
4b7a448 Jamozed 2021-02-21 23:23:53
318
				strtou64(i16, NULL, 16) == UINT64_MAX && errno != ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
319
	}
4b7a448 Jamozed 2021-02-21 23:23:53
320
	
4b7a448 Jamozed 2021-02-21 23:23:53
321
	{
4b7a448 Jamozed 2021-02-21 23:23:53
322
		char i[] = "-153";
4b7a448 Jamozed 2021-02-21 23:23:53
323
		
4b7a448 Jamozed 2021-02-21 23:23:53
324
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
325
		ASSERT("T311 STRTOU64 NEGATIVE",
4b7a448 Jamozed 2021-02-21 23:23:53
326
				!strtou64(i, NULL, 10) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
327
		
4b7a448 Jamozed 2021-02-21 23:23:53
328
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
329
		ASSERT("T312 STRTOU64 BASE 1",
4b7a448 Jamozed 2021-02-21 23:23:53
330
				!strtou64(i, NULL, 1) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
331
		
4b7a448 Jamozed 2021-02-21 23:23:53
332
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
333
		ASSERT("T313 STRTOU64 BASE -1",
4b7a448 Jamozed 2021-02-21 23:23:53
334
				!strtou64(i, NULL, -1) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
335
		
4b7a448 Jamozed 2021-02-21 23:23:53
336
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
337
		ASSERT("T314 STRTOU64 BASE 37",
4b7a448 Jamozed 2021-02-21 23:23:53
338
				!strtou64(i, NULL, 37) && errno == EINVAL);
4b7a448 Jamozed 2021-02-21 23:23:53
339
	}
4b7a448 Jamozed 2021-02-21 23:23:53
340
	
4b7a448 Jamozed 2021-02-21 23:23:53
341
	{
4b7a448 Jamozed 2021-02-21 23:23:53
342
		char i[] = "18446744073709551616";
4b7a448 Jamozed 2021-02-21 23:23:53
343
		
4b7a448 Jamozed 2021-02-21 23:23:53
344
		errno = 0;
4b7a448 Jamozed 2021-02-21 23:23:53
345
		ASSERT("T315 STRTOU64 OVERFLOW",
4b7a448 Jamozed 2021-02-21 23:23:53
346
				strtou64(i, NULL, 10) == UINT64_MAX && errno == ERANGE);
4b7a448 Jamozed 2021-02-21 23:23:53
347
	}
4b7a448 Jamozed 2021-02-21 23:23:53
348
	
4b7a448 Jamozed 2021-02-21 23:23:53
349
	printf("%d of %d tests passed\n", testspassed, testsrun);
4b7a448 Jamozed 2021-02-21 23:23:53
350
	return testsfailed;
4b7a448 Jamozed 2021-02-21 23:23:53
351
}
352