]> git.proxmox.com Git - mirror_qemu.git/blame - tests/test-cutils.c
util/cutils: Rename qemu_strtoll(), qemu_strtoull()
[mirror_qemu.git] / tests / test-cutils.c
CommitLineData
e3f9fe2d
EH
1/*
2 * cutils.c unit-tests
3 *
4 * Copyright (C) 2013 Red Hat Inc.
5 *
6 * Authors:
7 * Eduardo Habkost <ehabkost@redhat.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
26 */
27
681c28a3 28#include "qemu/osdep.h"
e3f9fe2d 29
f348b6d1 30#include "qemu/cutils.h"
e3f9fe2d
EH
31
32static void test_parse_uint_null(void)
33{
34 unsigned long long i = 999;
35 char f = 'X';
36 char *endptr = &f;
37 int r;
38
39 r = parse_uint(NULL, &i, &endptr, 0);
40
41 g_assert_cmpint(r, ==, -EINVAL);
42 g_assert_cmpint(i, ==, 0);
43 g_assert(endptr == NULL);
44}
45
46static void test_parse_uint_empty(void)
47{
48 unsigned long long i = 999;
49 char f = 'X';
50 char *endptr = &f;
51 const char *str = "";
52 int r;
53
54 r = parse_uint(str, &i, &endptr, 0);
55
56 g_assert_cmpint(r, ==, -EINVAL);
57 g_assert_cmpint(i, ==, 0);
58 g_assert(endptr == str);
59}
60
61static void test_parse_uint_whitespace(void)
62{
63 unsigned long long i = 999;
64 char f = 'X';
65 char *endptr = &f;
66 const char *str = " \t ";
67 int r;
68
69 r = parse_uint(str, &i, &endptr, 0);
70
71 g_assert_cmpint(r, ==, -EINVAL);
72 g_assert_cmpint(i, ==, 0);
73 g_assert(endptr == str);
74}
75
76
77static void test_parse_uint_invalid(void)
78{
79 unsigned long long i = 999;
80 char f = 'X';
81 char *endptr = &f;
82 const char *str = " \t xxx";
83 int r;
84
85 r = parse_uint(str, &i, &endptr, 0);
86
87 g_assert_cmpint(r, ==, -EINVAL);
88 g_assert_cmpint(i, ==, 0);
89 g_assert(endptr == str);
90}
91
92
93static void test_parse_uint_trailing(void)
94{
95 unsigned long long i = 999;
96 char f = 'X';
97 char *endptr = &f;
98 const char *str = "123xxx";
99 int r;
100
101 r = parse_uint(str, &i, &endptr, 0);
102
103 g_assert_cmpint(r, ==, 0);
104 g_assert_cmpint(i, ==, 123);
105 g_assert(endptr == str + 3);
106}
107
108static void test_parse_uint_correct(void)
109{
110 unsigned long long i = 999;
111 char f = 'X';
112 char *endptr = &f;
113 const char *str = "123";
114 int r;
115
116 r = parse_uint(str, &i, &endptr, 0);
117
118 g_assert_cmpint(r, ==, 0);
119 g_assert_cmpint(i, ==, 123);
120 g_assert(endptr == str + strlen(str));
121}
122
123static void test_parse_uint_octal(void)
124{
125 unsigned long long i = 999;
126 char f = 'X';
127 char *endptr = &f;
128 const char *str = "0123";
129 int r;
130
131 r = parse_uint(str, &i, &endptr, 0);
132
133 g_assert_cmpint(r, ==, 0);
134 g_assert_cmpint(i, ==, 0123);
135 g_assert(endptr == str + strlen(str));
136}
137
138static void test_parse_uint_decimal(void)
139{
140 unsigned long long i = 999;
141 char f = 'X';
142 char *endptr = &f;
143 const char *str = "0123";
144 int r;
145
146 r = parse_uint(str, &i, &endptr, 10);
147
148 g_assert_cmpint(r, ==, 0);
149 g_assert_cmpint(i, ==, 123);
150 g_assert(endptr == str + strlen(str));
151}
152
153
154static void test_parse_uint_llong_max(void)
155{
156 unsigned long long i = 999;
157 char f = 'X';
158 char *endptr = &f;
159 char *str = g_strdup_printf("%llu", (unsigned long long)LLONG_MAX + 1);
160 int r;
161
162 r = parse_uint(str, &i, &endptr, 0);
163
164 g_assert_cmpint(r, ==, 0);
165 g_assert_cmpint(i, ==, (unsigned long long)LLONG_MAX + 1);
166 g_assert(endptr == str + strlen(str));
167
168 g_free(str);
169}
170
171static void test_parse_uint_overflow(void)
172{
173 unsigned long long i = 999;
174 char f = 'X';
175 char *endptr = &f;
176 const char *str = "99999999999999999999999999999999999999";
177 int r;
178
179 r = parse_uint(str, &i, &endptr, 0);
180
181 g_assert_cmpint(r, ==, -ERANGE);
182 g_assert_cmpint(i, ==, ULLONG_MAX);
183 g_assert(endptr == str + strlen(str));
184}
185
186static void test_parse_uint_negative(void)
187{
188 unsigned long long i = 999;
189 char f = 'X';
190 char *endptr = &f;
191 const char *str = " \t -321";
192 int r;
193
194 r = parse_uint(str, &i, &endptr, 0);
195
196 g_assert_cmpint(r, ==, -ERANGE);
197 g_assert_cmpint(i, ==, 0);
198 g_assert(endptr == str + strlen(str));
199}
200
201
202static void test_parse_uint_full_trailing(void)
203{
204 unsigned long long i = 999;
205 const char *str = "123xxx";
206 int r;
207
208 r = parse_uint_full(str, &i, 0);
209
210 g_assert_cmpint(r, ==, -EINVAL);
211 g_assert_cmpint(i, ==, 0);
212}
213
214static void test_parse_uint_full_correct(void)
215{
216 unsigned long long i = 999;
217 const char *str = "123";
218 int r;
219
220 r = parse_uint_full(str, &i, 0);
221
222 g_assert_cmpint(r, ==, 0);
223 g_assert_cmpint(i, ==, 123);
224}
225
764e0fa4
CT
226static void test_qemu_strtol_correct(void)
227{
228 const char *str = "12345 foo";
229 char f = 'X';
230 const char *endptr = &f;
231 long res = 999;
232 int err;
233
234 err = qemu_strtol(str, &endptr, 0, &res);
235
236 g_assert_cmpint(err, ==, 0);
237 g_assert_cmpint(res, ==, 12345);
238 g_assert(endptr == str + 5);
239}
240
241static void test_qemu_strtol_null(void)
242{
243 char f = 'X';
244 const char *endptr = &f;
245 long res = 999;
246 int err;
247
248 err = qemu_strtol(NULL, &endptr, 0, &res);
249
250 g_assert_cmpint(err, ==, -EINVAL);
251 g_assert(endptr == NULL);
252}
253
254static void test_qemu_strtol_empty(void)
255{
256 const char *str = "";
257 char f = 'X';
258 const char *endptr = &f;
259 long res = 999;
260 int err;
261
262 err = qemu_strtol(str, &endptr, 0, &res);
263
47d4be12 264 g_assert_cmpint(err, ==, -EINVAL);
73245450 265 g_assert(endptr == str);
764e0fa4
CT
266}
267
268static void test_qemu_strtol_whitespace(void)
269{
270 const char *str = " \t ";
271 char f = 'X';
272 const char *endptr = &f;
273 long res = 999;
274 int err;
275
276 err = qemu_strtol(str, &endptr, 0, &res);
277
47d4be12 278 g_assert_cmpint(err, ==, -EINVAL);
73245450 279 g_assert(endptr == str);
764e0fa4
CT
280}
281
282static void test_qemu_strtol_invalid(void)
283{
284 const char *str = " xxxx \t abc";
285 char f = 'X';
286 const char *endptr = &f;
287 long res = 999;
288 int err;
289
290 err = qemu_strtol(str, &endptr, 0, &res);
291
47d4be12 292 g_assert_cmpint(err, ==, -EINVAL);
73245450 293 g_assert(endptr == str);
764e0fa4
CT
294}
295
296static void test_qemu_strtol_trailing(void)
297{
298 const char *str = "123xxx";
299 char f = 'X';
300 const char *endptr = &f;
301 long res = 999;
302 int err;
303
304 err = qemu_strtol(str, &endptr, 0, &res);
305
306 g_assert_cmpint(err, ==, 0);
307 g_assert_cmpint(res, ==, 123);
308 g_assert(endptr == str + 3);
309}
310
311static void test_qemu_strtol_octal(void)
312{
313 const char *str = "0123";
314 char f = 'X';
315 const char *endptr = &f;
316 long res = 999;
317 int err;
318
319 err = qemu_strtol(str, &endptr, 8, &res);
320
321 g_assert_cmpint(err, ==, 0);
322 g_assert_cmpint(res, ==, 0123);
323 g_assert(endptr == str + strlen(str));
324
325 res = 999;
326 endptr = &f;
327 err = qemu_strtol(str, &endptr, 0, &res);
328
329 g_assert_cmpint(err, ==, 0);
330 g_assert_cmpint(res, ==, 0123);
331 g_assert(endptr == str + strlen(str));
332}
333
334static void test_qemu_strtol_decimal(void)
335{
336 const char *str = "0123";
337 char f = 'X';
338 const char *endptr = &f;
339 long res = 999;
340 int err;
341
342 err = qemu_strtol(str, &endptr, 10, &res);
343
344 g_assert_cmpint(err, ==, 0);
345 g_assert_cmpint(res, ==, 123);
346 g_assert(endptr == str + strlen(str));
347
348 str = "123";
349 res = 999;
350 endptr = &f;
351 err = qemu_strtol(str, &endptr, 0, &res);
352
353 g_assert_cmpint(err, ==, 0);
354 g_assert_cmpint(res, ==, 123);
355 g_assert(endptr == str + strlen(str));
356}
357
358static void test_qemu_strtol_hex(void)
359{
360 const char *str = "0123";
361 char f = 'X';
362 const char *endptr = &f;
363 long res = 999;
364 int err;
365
366 err = qemu_strtol(str, &endptr, 16, &res);
367
368 g_assert_cmpint(err, ==, 0);
369 g_assert_cmpint(res, ==, 0x123);
370 g_assert(endptr == str + strlen(str));
371
372 str = "0x123";
373 res = 999;
374 endptr = &f;
375 err = qemu_strtol(str, &endptr, 0, &res);
376
377 g_assert_cmpint(err, ==, 0);
378 g_assert_cmpint(res, ==, 0x123);
379 g_assert(endptr == str + strlen(str));
380}
381
382static void test_qemu_strtol_max(void)
383{
d6f723b5 384 char *str = g_strdup_printf("%ld", LONG_MAX);
764e0fa4
CT
385 char f = 'X';
386 const char *endptr = &f;
387 long res = 999;
388 int err;
389
390 err = qemu_strtol(str, &endptr, 0, &res);
391
392 g_assert_cmpint(err, ==, 0);
393 g_assert_cmpint(res, ==, LONG_MAX);
394 g_assert(endptr == str + strlen(str));
d6f723b5 395 g_free(str);
764e0fa4
CT
396}
397
398static void test_qemu_strtol_overflow(void)
399{
400 const char *str = "99999999999999999999999999999999999999999999";
401 char f = 'X';
402 const char *endptr = &f;
403 long res = 999;
404 int err;
405
406 err = qemu_strtol(str, &endptr, 0, &res);
407
408 g_assert_cmpint(err, ==, -ERANGE);
409 g_assert_cmpint(res, ==, LONG_MAX);
410 g_assert(endptr == str + strlen(str));
411}
412
413static void test_qemu_strtol_underflow(void)
414{
415 const char *str = "-99999999999999999999999999999999999999999999";
416 char f = 'X';
417 const char *endptr = &f;
418 long res = 999;
419 int err;
420
421 err = qemu_strtol(str, &endptr, 0, &res);
422
423 g_assert_cmpint(err, ==, -ERANGE);
424 g_assert_cmpint(res, ==, LONG_MIN);
425 g_assert(endptr == str + strlen(str));
426}
427
428static void test_qemu_strtol_negative(void)
429{
430 const char *str = " \t -321";
431 char f = 'X';
432 const char *endptr = &f;
433 long res = 999;
434 int err;
435
436 err = qemu_strtol(str, &endptr, 0, &res);
437
438 g_assert_cmpint(err, ==, 0);
439 g_assert_cmpint(res, ==, -321);
440 g_assert(endptr == str + strlen(str));
441}
442
443static void test_qemu_strtol_full_correct(void)
444{
445 const char *str = "123";
446 long res = 999;
447 int err;
448
449 err = qemu_strtol(str, NULL, 0, &res);
450
451 g_assert_cmpint(err, ==, 0);
452 g_assert_cmpint(res, ==, 123);
453}
454
455static void test_qemu_strtol_full_null(void)
456{
457 char f = 'X';
458 const char *endptr = &f;
459 long res = 999;
460 int err;
461
462 err = qemu_strtol(NULL, &endptr, 0, &res);
463
464 g_assert_cmpint(err, ==, -EINVAL);
465 g_assert(endptr == NULL);
466}
467
468static void test_qemu_strtol_full_empty(void)
469{
470 const char *str = "";
471 long res = 999L;
472 int err;
473
474 err = qemu_strtol(str, NULL, 0, &res);
475
47d4be12 476 g_assert_cmpint(err, ==, -EINVAL);
764e0fa4
CT
477}
478
479static void test_qemu_strtol_full_negative(void)
480{
481 const char *str = " \t -321";
482 long res = 999;
483 int err;
484
485 err = qemu_strtol(str, NULL, 0, &res);
486
487 g_assert_cmpint(err, ==, 0);
488 g_assert_cmpint(res, ==, -321);
489}
490
491static void test_qemu_strtol_full_trailing(void)
492{
493 const char *str = "123xxx";
494 long res;
495 int err;
496
497 err = qemu_strtol(str, NULL, 0, &res);
498
499 g_assert_cmpint(err, ==, -EINVAL);
500}
501
502static void test_qemu_strtol_full_max(void)
503{
d6f723b5 504 char *str = g_strdup_printf("%ld", LONG_MAX);
764e0fa4
CT
505 long res;
506 int err;
507
508 err = qemu_strtol(str, NULL, 0, &res);
509
510 g_assert_cmpint(err, ==, 0);
511 g_assert_cmpint(res, ==, LONG_MAX);
d6f723b5 512 g_free(str);
764e0fa4 513}
c817c015
CT
514
515static void test_qemu_strtoul_correct(void)
516{
517 const char *str = "12345 foo";
518 char f = 'X';
519 const char *endptr = &f;
520 unsigned long res = 999;
521 int err;
522
523 err = qemu_strtoul(str, &endptr, 0, &res);
524
525 g_assert_cmpint(err, ==, 0);
bc7c08a2 526 g_assert_cmpuint(res, ==, 12345);
c817c015
CT
527 g_assert(endptr == str + 5);
528}
529
530static void test_qemu_strtoul_null(void)
531{
532 char f = 'X';
533 const char *endptr = &f;
534 unsigned long res = 999;
535 int err;
536
537 err = qemu_strtoul(NULL, &endptr, 0, &res);
538
539 g_assert_cmpint(err, ==, -EINVAL);
540 g_assert(endptr == NULL);
541}
542
543static void test_qemu_strtoul_empty(void)
544{
545 const char *str = "";
546 char f = 'X';
547 const char *endptr = &f;
548 unsigned long res = 999;
549 int err;
550
551 err = qemu_strtoul(str, &endptr, 0, &res);
552
47d4be12 553 g_assert_cmpint(err, ==, -EINVAL);
73245450 554 g_assert(endptr == str);
c817c015
CT
555}
556
557static void test_qemu_strtoul_whitespace(void)
558{
559 const char *str = " \t ";
560 char f = 'X';
561 const char *endptr = &f;
562 unsigned long res = 999;
563 int err;
564
565 err = qemu_strtoul(str, &endptr, 0, &res);
566
47d4be12 567 g_assert_cmpint(err, ==, -EINVAL);
73245450 568 g_assert(endptr == str);
c817c015
CT
569}
570
571static void test_qemu_strtoul_invalid(void)
572{
573 const char *str = " xxxx \t abc";
574 char f = 'X';
575 const char *endptr = &f;
576 unsigned long res = 999;
577 int err;
578
579 err = qemu_strtoul(str, &endptr, 0, &res);
580
47d4be12 581 g_assert_cmpint(err, ==, -EINVAL);
73245450 582 g_assert(endptr == str);
c817c015
CT
583}
584
585static void test_qemu_strtoul_trailing(void)
586{
587 const char *str = "123xxx";
588 char f = 'X';
589 const char *endptr = &f;
590 unsigned long res = 999;
591 int err;
592
593 err = qemu_strtoul(str, &endptr, 0, &res);
594
595 g_assert_cmpint(err, ==, 0);
bc7c08a2 596 g_assert_cmpuint(res, ==, 123);
c817c015
CT
597 g_assert(endptr == str + 3);
598}
599
600static void test_qemu_strtoul_octal(void)
601{
602 const char *str = "0123";
603 char f = 'X';
604 const char *endptr = &f;
605 unsigned long res = 999;
606 int err;
607
608 err = qemu_strtoul(str, &endptr, 8, &res);
609
610 g_assert_cmpint(err, ==, 0);
bc7c08a2 611 g_assert_cmpuint(res, ==, 0123);
c817c015
CT
612 g_assert(endptr == str + strlen(str));
613
614 res = 999;
615 endptr = &f;
616 err = qemu_strtoul(str, &endptr, 0, &res);
617
618 g_assert_cmpint(err, ==, 0);
bc7c08a2 619 g_assert_cmpuint(res, ==, 0123);
c817c015
CT
620 g_assert(endptr == str + strlen(str));
621}
622
623static void test_qemu_strtoul_decimal(void)
624{
625 const char *str = "0123";
626 char f = 'X';
627 const char *endptr = &f;
628 unsigned long res = 999;
629 int err;
630
631 err = qemu_strtoul(str, &endptr, 10, &res);
632
633 g_assert_cmpint(err, ==, 0);
bc7c08a2 634 g_assert_cmpuint(res, ==, 123);
c817c015
CT
635 g_assert(endptr == str + strlen(str));
636
637 str = "123";
638 res = 999;
639 endptr = &f;
640 err = qemu_strtoul(str, &endptr, 0, &res);
641
642 g_assert_cmpint(err, ==, 0);
bc7c08a2 643 g_assert_cmpuint(res, ==, 123);
c817c015
CT
644 g_assert(endptr == str + strlen(str));
645}
646
647static void test_qemu_strtoul_hex(void)
648{
649 const char *str = "0123";
650 char f = 'X';
651 const char *endptr = &f;
652 unsigned long res = 999;
653 int err;
654
655 err = qemu_strtoul(str, &endptr, 16, &res);
656
657 g_assert_cmpint(err, ==, 0);
bc7c08a2 658 g_assert_cmphex(res, ==, 0x123);
c817c015
CT
659 g_assert(endptr == str + strlen(str));
660
661 str = "0x123";
662 res = 999;
663 endptr = &f;
664 err = qemu_strtoul(str, &endptr, 0, &res);
665
666 g_assert_cmpint(err, ==, 0);
bc7c08a2 667 g_assert_cmphex(res, ==, 0x123);
c817c015
CT
668 g_assert(endptr == str + strlen(str));
669}
670
671static void test_qemu_strtoul_max(void)
672{
d6f723b5 673 char *str = g_strdup_printf("%lu", ULONG_MAX);
c817c015
CT
674 char f = 'X';
675 const char *endptr = &f;
676 unsigned long res = 999;
677 int err;
678
679 err = qemu_strtoul(str, &endptr, 0, &res);
680
681 g_assert_cmpint(err, ==, 0);
bc7c08a2 682 g_assert_cmphex(res, ==, ULONG_MAX);
c817c015 683 g_assert(endptr == str + strlen(str));
d6f723b5 684 g_free(str);
c817c015
CT
685}
686
687static void test_qemu_strtoul_overflow(void)
688{
689 const char *str = "99999999999999999999999999999999999999999999";
690 char f = 'X';
691 const char *endptr = &f;
692 unsigned long res = 999;
693 int err;
694
695 err = qemu_strtoul(str, &endptr, 0, &res);
696
697 g_assert_cmpint(err, ==, -ERANGE);
bc7c08a2 698 g_assert_cmphex(res, ==, ULONG_MAX);
c817c015
CT
699 g_assert(endptr == str + strlen(str));
700}
701
702static void test_qemu_strtoul_underflow(void)
703{
704 const char *str = "-99999999999999999999999999999999999999999999";
705 char f = 'X';
706 const char *endptr = &f;
707 unsigned long res = 999;
708 int err;
709
710 err = qemu_strtoul(str, &endptr, 0, &res);
711
712 g_assert_cmpint(err, ==, -ERANGE);
bc7c08a2 713 g_assert_cmpuint(res, ==, -1ul);
c817c015
CT
714 g_assert(endptr == str + strlen(str));
715}
716
717static void test_qemu_strtoul_negative(void)
718{
719 const char *str = " \t -321";
720 char f = 'X';
721 const char *endptr = &f;
722 unsigned long res = 999;
723 int err;
724
725 err = qemu_strtoul(str, &endptr, 0, &res);
726
727 g_assert_cmpint(err, ==, 0);
bc7c08a2 728 g_assert_cmpuint(res, ==, -321ul);
c817c015
CT
729 g_assert(endptr == str + strlen(str));
730}
731
732static void test_qemu_strtoul_full_correct(void)
733{
734 const char *str = "123";
735 unsigned long res = 999;
736 int err;
737
738 err = qemu_strtoul(str, NULL, 0, &res);
739
740 g_assert_cmpint(err, ==, 0);
bc7c08a2 741 g_assert_cmpuint(res, ==, 123);
c817c015
CT
742}
743
744static void test_qemu_strtoul_full_null(void)
745{
746 unsigned long res = 999;
747 int err;
748
749 err = qemu_strtoul(NULL, NULL, 0, &res);
750
751 g_assert_cmpint(err, ==, -EINVAL);
752}
753
754static void test_qemu_strtoul_full_empty(void)
755{
756 const char *str = "";
757 unsigned long res = 999;
758 int err;
759
760 err = qemu_strtoul(str, NULL, 0, &res);
761
47d4be12 762 g_assert_cmpint(err, ==, -EINVAL);
c817c015
CT
763}
764static void test_qemu_strtoul_full_negative(void)
765{
766 const char *str = " \t -321";
767 unsigned long res = 999;
768 int err;
769
770 err = qemu_strtoul(str, NULL, 0, &res);
771 g_assert_cmpint(err, ==, 0);
bc7c08a2 772 g_assert_cmpuint(res, ==, -321ul);
c817c015
CT
773}
774
775static void test_qemu_strtoul_full_trailing(void)
776{
777 const char *str = "123xxx";
778 unsigned long res;
779 int err;
780
781 err = qemu_strtoul(str, NULL, 0, &res);
782
783 g_assert_cmpint(err, ==, -EINVAL);
784}
785
786static void test_qemu_strtoul_full_max(void)
787{
d6f723b5 788 char *str = g_strdup_printf("%lu", ULONG_MAX);
c817c015
CT
789 unsigned long res = 999;
790 int err;
791
792 err = qemu_strtoul(str, NULL, 0, &res);
793
794 g_assert_cmpint(err, ==, 0);
bc7c08a2 795 g_assert_cmphex(res, ==, ULONG_MAX);
d6f723b5 796 g_free(str);
c817c015
CT
797}
798
b30d1886 799static void test_qemu_strtoi64_correct(void)
8ac4df40
CT
800{
801 const char *str = "12345 foo";
802 char f = 'X';
803 const char *endptr = &f;
804 int64_t res = 999;
805 int err;
806
b30d1886 807 err = qemu_strtoi64(str, &endptr, 0, &res);
8ac4df40
CT
808
809 g_assert_cmpint(err, ==, 0);
810 g_assert_cmpint(res, ==, 12345);
811 g_assert(endptr == str + 5);
812}
813
b30d1886 814static void test_qemu_strtoi64_null(void)
8ac4df40
CT
815{
816 char f = 'X';
817 const char *endptr = &f;
818 int64_t res = 999;
819 int err;
820
b30d1886 821 err = qemu_strtoi64(NULL, &endptr, 0, &res);
8ac4df40
CT
822
823 g_assert_cmpint(err, ==, -EINVAL);
824 g_assert(endptr == NULL);
825}
826
b30d1886 827static void test_qemu_strtoi64_empty(void)
8ac4df40
CT
828{
829 const char *str = "";
830 char f = 'X';
831 const char *endptr = &f;
832 int64_t res = 999;
833 int err;
834
b30d1886 835 err = qemu_strtoi64(str, &endptr, 0, &res);
8ac4df40 836
47d4be12 837 g_assert_cmpint(err, ==, -EINVAL);
73245450 838 g_assert(endptr == str);
8ac4df40
CT
839}
840
b30d1886 841static void test_qemu_strtoi64_whitespace(void)
8ac4df40
CT
842{
843 const char *str = " \t ";
844 char f = 'X';
845 const char *endptr = &f;
846 int64_t res = 999;
847 int err;
848
b30d1886 849 err = qemu_strtoi64(str, &endptr, 0, &res);
8ac4df40 850
47d4be12 851 g_assert_cmpint(err, ==, -EINVAL);
73245450 852 g_assert(endptr == str);
8ac4df40
CT
853}
854
b30d1886 855static void test_qemu_strtoi64_invalid(void)
8ac4df40
CT
856{
857 const char *str = " xxxx \t abc";
858 char f = 'X';
859 const char *endptr = &f;
860 int64_t res = 999;
861 int err;
862
b30d1886 863 err = qemu_strtoi64(str, &endptr, 0, &res);
8ac4df40 864
47d4be12 865 g_assert_cmpint(err, ==, -EINVAL);
73245450 866 g_assert(endptr == str);
8ac4df40
CT
867}
868
b30d1886 869static void test_qemu_strtoi64_trailing(void)
8ac4df40
CT
870{
871 const char *str = "123xxx";
872 char f = 'X';
873 const char *endptr = &f;
874 int64_t res = 999;
875 int err;
876
b30d1886 877 err = qemu_strtoi64(str, &endptr, 0, &res);
8ac4df40
CT
878
879 g_assert_cmpint(err, ==, 0);
880 g_assert_cmpint(res, ==, 123);
881 g_assert(endptr == str + 3);
882}
883
b30d1886 884static void test_qemu_strtoi64_octal(void)
8ac4df40
CT
885{
886 const char *str = "0123";
887 char f = 'X';
888 const char *endptr = &f;
889 int64_t res = 999;
890 int err;
891
b30d1886 892 err = qemu_strtoi64(str, &endptr, 8, &res);
8ac4df40
CT
893
894 g_assert_cmpint(err, ==, 0);
895 g_assert_cmpint(res, ==, 0123);
896 g_assert(endptr == str + strlen(str));
897
898 endptr = &f;
899 res = 999;
b30d1886 900 err = qemu_strtoi64(str, &endptr, 0, &res);
8ac4df40
CT
901
902 g_assert_cmpint(err, ==, 0);
903 g_assert_cmpint(res, ==, 0123);
904 g_assert(endptr == str + strlen(str));
905}
906
b30d1886 907static void test_qemu_strtoi64_decimal(void)
8ac4df40
CT
908{
909 const char *str = "0123";
910 char f = 'X';
911 const char *endptr = &f;
912 int64_t res = 999;
913 int err;
914
b30d1886 915 err = qemu_strtoi64(str, &endptr, 10, &res);
8ac4df40
CT
916
917 g_assert_cmpint(err, ==, 0);
918 g_assert_cmpint(res, ==, 123);
919 g_assert(endptr == str + strlen(str));
920
921 str = "123";
922 endptr = &f;
923 res = 999;
b30d1886 924 err = qemu_strtoi64(str, &endptr, 0, &res);
8ac4df40
CT
925
926 g_assert_cmpint(err, ==, 0);
927 g_assert_cmpint(res, ==, 123);
928 g_assert(endptr == str + strlen(str));
929}
930
b30d1886 931static void test_qemu_strtoi64_hex(void)
8ac4df40
CT
932{
933 const char *str = "0123";
934 char f = 'X';
935 const char *endptr = &f;
936 int64_t res = 999;
937 int err;
938
b30d1886 939 err = qemu_strtoi64(str, &endptr, 16, &res);
8ac4df40
CT
940
941 g_assert_cmpint(err, ==, 0);
942 g_assert_cmpint(res, ==, 0x123);
943 g_assert(endptr == str + strlen(str));
944
945 str = "0x123";
946 endptr = &f;
947 res = 999;
b30d1886 948 err = qemu_strtoi64(str, &endptr, 0, &res);
8ac4df40
CT
949
950 g_assert_cmpint(err, ==, 0);
951 g_assert_cmpint(res, ==, 0x123);
952 g_assert(endptr == str + strlen(str));
953}
954
b30d1886 955static void test_qemu_strtoi64_max(void)
8ac4df40 956{
d6f723b5 957 char *str = g_strdup_printf("%lld", LLONG_MAX);
8ac4df40
CT
958 char f = 'X';
959 const char *endptr = &f;
960 int64_t res = 999;
961 int err;
962
b30d1886 963 err = qemu_strtoi64(str, &endptr, 0, &res);
8ac4df40
CT
964
965 g_assert_cmpint(err, ==, 0);
966 g_assert_cmpint(res, ==, LLONG_MAX);
967 g_assert(endptr == str + strlen(str));
d6f723b5 968 g_free(str);
8ac4df40
CT
969}
970
b30d1886 971static void test_qemu_strtoi64_overflow(void)
8ac4df40
CT
972{
973 const char *str = "99999999999999999999999999999999999999999999";
974 char f = 'X';
975 const char *endptr = &f;
976 int64_t res = 999;
977 int err;
978
b30d1886 979 err = qemu_strtoi64(str, &endptr, 0, &res);
8ac4df40
CT
980
981 g_assert_cmpint(err, ==, -ERANGE);
982 g_assert_cmpint(res, ==, LLONG_MAX);
983 g_assert(endptr == str + strlen(str));
984}
985
b30d1886 986static void test_qemu_strtoi64_underflow(void)
8ac4df40
CT
987{
988 const char *str = "-99999999999999999999999999999999999999999999";
989 char f = 'X';
990 const char *endptr = &f;
991 int64_t res = 999;
992 int err;
993
b30d1886 994 err = qemu_strtoi64(str, &endptr, 0, &res);
8ac4df40
CT
995
996 g_assert_cmpint(err, ==, -ERANGE);
997 g_assert_cmpint(res, ==, LLONG_MIN);
998 g_assert(endptr == str + strlen(str));
999}
1000
b30d1886 1001static void test_qemu_strtoi64_negative(void)
8ac4df40
CT
1002{
1003 const char *str = " \t -321";
1004 char f = 'X';
1005 const char *endptr = &f;
1006 int64_t res = 999;
1007 int err;
1008
b30d1886 1009 err = qemu_strtoi64(str, &endptr, 0, &res);
8ac4df40
CT
1010
1011 g_assert_cmpint(err, ==, 0);
1012 g_assert_cmpint(res, ==, -321);
1013 g_assert(endptr == str + strlen(str));
1014}
1015
b30d1886 1016static void test_qemu_strtoi64_full_correct(void)
8ac4df40
CT
1017{
1018 const char *str = "123";
1019 int64_t res = 999;
1020 int err;
1021
b30d1886 1022 err = qemu_strtoi64(str, NULL, 0, &res);
8ac4df40
CT
1023
1024 g_assert_cmpint(err, ==, 0);
1025 g_assert_cmpint(res, ==, 123);
1026}
1027
b30d1886 1028static void test_qemu_strtoi64_full_null(void)
8ac4df40
CT
1029{
1030 int64_t res = 999;
1031 int err;
1032
b30d1886 1033 err = qemu_strtoi64(NULL, NULL, 0, &res);
8ac4df40
CT
1034
1035 g_assert_cmpint(err, ==, -EINVAL);
1036}
1037
b30d1886 1038static void test_qemu_strtoi64_full_empty(void)
8ac4df40
CT
1039{
1040 const char *str = "";
1041 int64_t res = 999;
1042 int err;
1043
b30d1886 1044 err = qemu_strtoi64(str, NULL, 0, &res);
8ac4df40 1045
47d4be12 1046 g_assert_cmpint(err, ==, -EINVAL);
8ac4df40
CT
1047}
1048
b30d1886 1049static void test_qemu_strtoi64_full_negative(void)
8ac4df40
CT
1050{
1051 const char *str = " \t -321";
1052 int64_t res = 999;
1053 int err;
1054
b30d1886 1055 err = qemu_strtoi64(str, NULL, 0, &res);
8ac4df40
CT
1056
1057 g_assert_cmpint(err, ==, 0);
1058 g_assert_cmpint(res, ==, -321);
1059}
1060
b30d1886 1061static void test_qemu_strtoi64_full_trailing(void)
8ac4df40
CT
1062{
1063 const char *str = "123xxx";
1064 int64_t res = 999;
1065 int err;
1066
b30d1886 1067 err = qemu_strtoi64(str, NULL, 0, &res);
8ac4df40
CT
1068
1069 g_assert_cmpint(err, ==, -EINVAL);
1070}
1071
b30d1886 1072static void test_qemu_strtoi64_full_max(void)
8ac4df40
CT
1073{
1074
d6f723b5 1075 char *str = g_strdup_printf("%lld", LLONG_MAX);
8ac4df40
CT
1076 int64_t res;
1077 int err;
1078
b30d1886 1079 err = qemu_strtoi64(str, NULL, 0, &res);
8ac4df40
CT
1080
1081 g_assert_cmpint(err, ==, 0);
1082 g_assert_cmpint(res, ==, LLONG_MAX);
d6f723b5 1083 g_free(str);
8ac4df40
CT
1084}
1085
b30d1886 1086static void test_qemu_strtou64_correct(void)
3904e6bf
CT
1087{
1088 const char *str = "12345 foo";
1089 char f = 'X';
1090 const char *endptr = &f;
1091 uint64_t res = 999;
1092 int err;
1093
b30d1886 1094 err = qemu_strtou64(str, &endptr, 0, &res);
3904e6bf
CT
1095
1096 g_assert_cmpint(err, ==, 0);
bc7c08a2 1097 g_assert_cmpuint(res, ==, 12345);
3904e6bf
CT
1098 g_assert(endptr == str + 5);
1099}
1100
b30d1886 1101static void test_qemu_strtou64_null(void)
3904e6bf
CT
1102{
1103 char f = 'X';
1104 const char *endptr = &f;
1105 uint64_t res = 999;
1106 int err;
1107
b30d1886 1108 err = qemu_strtou64(NULL, &endptr, 0, &res);
3904e6bf
CT
1109
1110 g_assert_cmpint(err, ==, -EINVAL);
1111 g_assert(endptr == NULL);
1112}
1113
b30d1886 1114static void test_qemu_strtou64_empty(void)
3904e6bf
CT
1115{
1116 const char *str = "";
1117 char f = 'X';
1118 const char *endptr = &f;
1119 uint64_t res = 999;
1120 int err;
1121
b30d1886 1122 err = qemu_strtou64(str, &endptr, 0, &res);
3904e6bf 1123
47d4be12 1124 g_assert_cmpint(err, ==, -EINVAL);
73245450 1125 g_assert(endptr == str);
3904e6bf
CT
1126}
1127
b30d1886 1128static void test_qemu_strtou64_whitespace(void)
3904e6bf
CT
1129{
1130 const char *str = " \t ";
1131 char f = 'X';
1132 const char *endptr = &f;
1133 uint64_t res = 999;
1134 int err;
1135
b30d1886 1136 err = qemu_strtou64(str, &endptr, 0, &res);
3904e6bf 1137
47d4be12 1138 g_assert_cmpint(err, ==, -EINVAL);
73245450 1139 g_assert(endptr == str);
3904e6bf
CT
1140}
1141
b30d1886 1142static void test_qemu_strtou64_invalid(void)
3904e6bf
CT
1143{
1144 const char *str = " xxxx \t abc";
1145 char f = 'X';
1146 const char *endptr = &f;
1147 uint64_t res = 999;
1148 int err;
1149
b30d1886 1150 err = qemu_strtou64(str, &endptr, 0, &res);
3904e6bf 1151
47d4be12 1152 g_assert_cmpint(err, ==, -EINVAL);
73245450 1153 g_assert(endptr == str);
3904e6bf
CT
1154}
1155
b30d1886 1156static void test_qemu_strtou64_trailing(void)
3904e6bf
CT
1157{
1158 const char *str = "123xxx";
1159 char f = 'X';
1160 const char *endptr = &f;
1161 uint64_t res = 999;
1162 int err;
1163
b30d1886 1164 err = qemu_strtou64(str, &endptr, 0, &res);
3904e6bf
CT
1165
1166 g_assert_cmpint(err, ==, 0);
bc7c08a2 1167 g_assert_cmpuint(res, ==, 123);
3904e6bf
CT
1168 g_assert(endptr == str + 3);
1169}
1170
b30d1886 1171static void test_qemu_strtou64_octal(void)
3904e6bf
CT
1172{
1173 const char *str = "0123";
1174 char f = 'X';
1175 const char *endptr = &f;
1176 uint64_t res = 999;
1177 int err;
1178
b30d1886 1179 err = qemu_strtou64(str, &endptr, 8, &res);
3904e6bf
CT
1180
1181 g_assert_cmpint(err, ==, 0);
bc7c08a2 1182 g_assert_cmpuint(res, ==, 0123);
3904e6bf
CT
1183 g_assert(endptr == str + strlen(str));
1184
1185 endptr = &f;
1186 res = 999;
b30d1886 1187 err = qemu_strtou64(str, &endptr, 0, &res);
3904e6bf
CT
1188
1189 g_assert_cmpint(err, ==, 0);
bc7c08a2 1190 g_assert_cmpuint(res, ==, 0123);
3904e6bf
CT
1191 g_assert(endptr == str + strlen(str));
1192}
1193
b30d1886 1194static void test_qemu_strtou64_decimal(void)
3904e6bf
CT
1195{
1196 const char *str = "0123";
1197 char f = 'X';
1198 const char *endptr = &f;
1199 uint64_t res = 999;
1200 int err;
1201
b30d1886 1202 err = qemu_strtou64(str, &endptr, 10, &res);
3904e6bf
CT
1203
1204 g_assert_cmpint(err, ==, 0);
bc7c08a2 1205 g_assert_cmpuint(res, ==, 123);
3904e6bf
CT
1206 g_assert(endptr == str + strlen(str));
1207
1208 str = "123";
1209 endptr = &f;
1210 res = 999;
b30d1886 1211 err = qemu_strtou64(str, &endptr, 0, &res);
3904e6bf
CT
1212
1213 g_assert_cmpint(err, ==, 0);
bc7c08a2 1214 g_assert_cmpuint(res, ==, 123);
3904e6bf
CT
1215 g_assert(endptr == str + strlen(str));
1216}
1217
b30d1886 1218static void test_qemu_strtou64_hex(void)
3904e6bf
CT
1219{
1220 const char *str = "0123";
1221 char f = 'X';
1222 const char *endptr = &f;
1223 uint64_t res = 999;
1224 int err;
1225
b30d1886 1226 err = qemu_strtou64(str, &endptr, 16, &res);
3904e6bf
CT
1227
1228 g_assert_cmpint(err, ==, 0);
bc7c08a2 1229 g_assert_cmphex(res, ==, 0x123);
3904e6bf
CT
1230 g_assert(endptr == str + strlen(str));
1231
1232 str = "0x123";
1233 endptr = &f;
1234 res = 999;
b30d1886 1235 err = qemu_strtou64(str, &endptr, 0, &res);
3904e6bf
CT
1236
1237 g_assert_cmpint(err, ==, 0);
bc7c08a2 1238 g_assert_cmphex(res, ==, 0x123);
3904e6bf
CT
1239 g_assert(endptr == str + strlen(str));
1240}
1241
b30d1886 1242static void test_qemu_strtou64_max(void)
3904e6bf 1243{
d6f723b5 1244 char *str = g_strdup_printf("%llu", ULLONG_MAX);
3904e6bf
CT
1245 char f = 'X';
1246 const char *endptr = &f;
1247 uint64_t res = 999;
1248 int err;
1249
b30d1886 1250 err = qemu_strtou64(str, &endptr, 0, &res);
3904e6bf
CT
1251
1252 g_assert_cmpint(err, ==, 0);
bc7c08a2 1253 g_assert_cmphex(res, ==, ULLONG_MAX);
3904e6bf 1254 g_assert(endptr == str + strlen(str));
d6f723b5 1255 g_free(str);
3904e6bf
CT
1256}
1257
b30d1886 1258static void test_qemu_strtou64_overflow(void)
3904e6bf
CT
1259{
1260 const char *str = "99999999999999999999999999999999999999999999";
1261 char f = 'X';
1262 const char *endptr = &f;
1263 uint64_t res = 999;
1264 int err;
1265
b30d1886 1266 err = qemu_strtou64(str, &endptr, 0, &res);
3904e6bf
CT
1267
1268 g_assert_cmpint(err, ==, -ERANGE);
bc7c08a2 1269 g_assert_cmphex(res, ==, ULLONG_MAX);
3904e6bf
CT
1270 g_assert(endptr == str + strlen(str));
1271}
1272
b30d1886 1273static void test_qemu_strtou64_underflow(void)
3904e6bf
CT
1274{
1275 const char *str = "-99999999999999999999999999999999999999999999";
1276 char f = 'X';
1277 const char *endptr = &f;
1278 uint64_t res = 999;
1279 int err;
1280
b30d1886 1281 err = qemu_strtou64(str, &endptr, 0, &res);
3904e6bf
CT
1282
1283 g_assert_cmpint(err, ==, -ERANGE);
bc7c08a2 1284 g_assert_cmphex(res, ==, -1ull);
3904e6bf
CT
1285 g_assert(endptr == str + strlen(str));
1286}
1287
b30d1886 1288static void test_qemu_strtou64_negative(void)
3904e6bf
CT
1289{
1290 const char *str = " \t -321";
1291 char f = 'X';
1292 const char *endptr = &f;
1293 uint64_t res = 999;
1294 int err;
1295
b30d1886 1296 err = qemu_strtou64(str, &endptr, 0, &res);
3904e6bf
CT
1297
1298 g_assert_cmpint(err, ==, 0);
bc7c08a2 1299 g_assert_cmpuint(res, ==, -321ull);
3904e6bf
CT
1300 g_assert(endptr == str + strlen(str));
1301}
1302
b30d1886 1303static void test_qemu_strtou64_full_correct(void)
3904e6bf
CT
1304{
1305 const char *str = "18446744073709551614";
1306 uint64_t res = 999;
1307 int err;
1308
b30d1886 1309 err = qemu_strtou64(str, NULL, 0, &res);
3904e6bf
CT
1310
1311 g_assert_cmpint(err, ==, 0);
bc7c08a2 1312 g_assert_cmpuint(res, ==, 18446744073709551614ull);
3904e6bf
CT
1313}
1314
b30d1886 1315static void test_qemu_strtou64_full_null(void)
3904e6bf
CT
1316{
1317 uint64_t res = 999;
1318 int err;
1319
b30d1886 1320 err = qemu_strtou64(NULL, NULL, 0, &res);
3904e6bf
CT
1321
1322 g_assert_cmpint(err, ==, -EINVAL);
1323}
1324
b30d1886 1325static void test_qemu_strtou64_full_empty(void)
3904e6bf
CT
1326{
1327 const char *str = "";
1328 uint64_t res = 999;
1329 int err;
1330
b30d1886 1331 err = qemu_strtou64(str, NULL, 0, &res);
3904e6bf 1332
47d4be12 1333 g_assert_cmpint(err, ==, -EINVAL);
3904e6bf
CT
1334}
1335
b30d1886 1336static void test_qemu_strtou64_full_negative(void)
3904e6bf
CT
1337{
1338 const char *str = " \t -321";
1339 uint64_t res = 999;
1340 int err;
1341
b30d1886 1342 err = qemu_strtou64(str, NULL, 0, &res);
3904e6bf
CT
1343
1344 g_assert_cmpint(err, ==, 0);
bc7c08a2 1345 g_assert_cmpuint(res, ==, -321ull);
3904e6bf
CT
1346}
1347
b30d1886 1348static void test_qemu_strtou64_full_trailing(void)
3904e6bf
CT
1349{
1350 const char *str = "18446744073709551614xxxxxx";
1351 uint64_t res = 999;
1352 int err;
1353
b30d1886 1354 err = qemu_strtou64(str, NULL, 0, &res);
3904e6bf
CT
1355
1356 g_assert_cmpint(err, ==, -EINVAL);
1357}
1358
b30d1886 1359static void test_qemu_strtou64_full_max(void)
3904e6bf 1360{
d6f723b5 1361 char *str = g_strdup_printf("%lld", ULLONG_MAX);
3904e6bf
CT
1362 uint64_t res = 999;
1363 int err;
1364
b30d1886 1365 err = qemu_strtou64(str, NULL, 0, &res);
3904e6bf
CT
1366
1367 g_assert_cmpint(err, ==, 0);
bc7c08a2 1368 g_assert_cmphex(res, ==, ULLONG_MAX);
d6f723b5 1369 g_free(str);
3904e6bf
CT
1370}
1371
fe854538
MAL
1372static void test_qemu_strtosz_simple(void)
1373{
1374 const char *str = "12345M";
1375 char *endptr = NULL;
1376 int64_t res;
1377
1378 res = qemu_strtosz(str, &endptr);
1379 g_assert_cmpint(res, ==, 12345 * M_BYTE);
1380 g_assert(endptr == str + 6);
1381
1382 res = qemu_strtosz(str, NULL);
1383 g_assert_cmpint(res, ==, 12345 * M_BYTE);
1384}
1385
1386static void test_qemu_strtosz_units(void)
1387{
1388 const char *none = "1";
1389 const char *b = "1B";
1390 const char *k = "1K";
1391 const char *m = "1M";
1392 const char *g = "1G";
1393 const char *t = "1T";
1394 const char *p = "1P";
1395 const char *e = "1E";
1396 int64_t res;
1397
1398 /* default is M */
1399 res = qemu_strtosz(none, NULL);
1400 g_assert_cmpint(res, ==, M_BYTE);
1401
1402 res = qemu_strtosz(b, NULL);
1403 g_assert_cmpint(res, ==, 1);
1404
1405 res = qemu_strtosz(k, NULL);
1406 g_assert_cmpint(res, ==, K_BYTE);
1407
1408 res = qemu_strtosz(m, NULL);
1409 g_assert_cmpint(res, ==, M_BYTE);
1410
1411 res = qemu_strtosz(g, NULL);
1412 g_assert_cmpint(res, ==, G_BYTE);
1413
1414 res = qemu_strtosz(t, NULL);
1415 g_assert_cmpint(res, ==, T_BYTE);
1416
1417 res = qemu_strtosz(p, NULL);
1418 g_assert_cmpint(res, ==, P_BYTE);
1419
1420 res = qemu_strtosz(e, NULL);
1421 g_assert_cmpint(res, ==, E_BYTE);
1422}
1423
1424static void test_qemu_strtosz_float(void)
1425{
1426 const char *str = "12.345M";
1427 int64_t res;
1428
1429 res = qemu_strtosz(str, NULL);
1430 g_assert_cmpint(res, ==, 12.345 * M_BYTE);
1431}
1432
1433static void test_qemu_strtosz_erange(void)
1434{
1435 const char *str = "10E";
1436 int64_t res;
1437
1438 res = qemu_strtosz(str, NULL);
1439 g_assert_cmpint(res, ==, -ERANGE);
1440}
1441
1442static void test_qemu_strtosz_suffix_unit(void)
1443{
1444 const char *str = "12345";
1445 int64_t res;
1446
1447 res = qemu_strtosz_suffix_unit(str, NULL,
1448 QEMU_STRTOSZ_DEFSUFFIX_KB, 1000);
1449 g_assert_cmpint(res, ==, 12345000);
1450}
1451
e3f9fe2d
EH
1452int main(int argc, char **argv)
1453{
1454 g_test_init(&argc, &argv, NULL);
1455
1456 g_test_add_func("/cutils/parse_uint/null", test_parse_uint_null);
1457 g_test_add_func("/cutils/parse_uint/empty", test_parse_uint_empty);
1458 g_test_add_func("/cutils/parse_uint/whitespace",
1459 test_parse_uint_whitespace);
1460 g_test_add_func("/cutils/parse_uint/invalid", test_parse_uint_invalid);
1461 g_test_add_func("/cutils/parse_uint/trailing", test_parse_uint_trailing);
1462 g_test_add_func("/cutils/parse_uint/correct", test_parse_uint_correct);
1463 g_test_add_func("/cutils/parse_uint/octal", test_parse_uint_octal);
1464 g_test_add_func("/cutils/parse_uint/decimal", test_parse_uint_decimal);
1465 g_test_add_func("/cutils/parse_uint/llong_max", test_parse_uint_llong_max);
1466 g_test_add_func("/cutils/parse_uint/overflow", test_parse_uint_overflow);
1467 g_test_add_func("/cutils/parse_uint/negative", test_parse_uint_negative);
1468 g_test_add_func("/cutils/parse_uint_full/trailing",
1469 test_parse_uint_full_trailing);
1470 g_test_add_func("/cutils/parse_uint_full/correct",
1471 test_parse_uint_full_correct);
1472
764e0fa4 1473 /* qemu_strtol() tests */
b30d1886
MA
1474 g_test_add_func("/cutils/qemu_strtol/correct",
1475 test_qemu_strtol_correct);
1476 g_test_add_func("/cutils/qemu_strtol/null",
1477 test_qemu_strtol_null);
1478 g_test_add_func("/cutils/qemu_strtol/empty",
1479 test_qemu_strtol_empty);
764e0fa4
CT
1480 g_test_add_func("/cutils/qemu_strtol/whitespace",
1481 test_qemu_strtol_whitespace);
b30d1886
MA
1482 g_test_add_func("/cutils/qemu_strtol/invalid",
1483 test_qemu_strtol_invalid);
1484 g_test_add_func("/cutils/qemu_strtol/trailing",
1485 test_qemu_strtol_trailing);
1486 g_test_add_func("/cutils/qemu_strtol/octal",
1487 test_qemu_strtol_octal);
1488 g_test_add_func("/cutils/qemu_strtol/decimal",
1489 test_qemu_strtol_decimal);
1490 g_test_add_func("/cutils/qemu_strtol/hex",
1491 test_qemu_strtol_hex);
1492 g_test_add_func("/cutils/qemu_strtol/max",
1493 test_qemu_strtol_max);
1494 g_test_add_func("/cutils/qemu_strtol/overflow",
1495 test_qemu_strtol_overflow);
764e0fa4
CT
1496 g_test_add_func("/cutils/qemu_strtol/underflow",
1497 test_qemu_strtol_underflow);
b30d1886
MA
1498 g_test_add_func("/cutils/qemu_strtol/negative",
1499 test_qemu_strtol_negative);
764e0fa4
CT
1500 g_test_add_func("/cutils/qemu_strtol_full/correct",
1501 test_qemu_strtol_full_correct);
1502 g_test_add_func("/cutils/qemu_strtol_full/null",
1503 test_qemu_strtol_full_null);
1504 g_test_add_func("/cutils/qemu_strtol_full/empty",
1505 test_qemu_strtol_full_empty);
1506 g_test_add_func("/cutils/qemu_strtol_full/negative",
1507 test_qemu_strtol_full_negative);
1508 g_test_add_func("/cutils/qemu_strtol_full/trailing",
1509 test_qemu_strtol_full_trailing);
1510 g_test_add_func("/cutils/qemu_strtol_full/max",
1511 test_qemu_strtol_full_max);
1512
c817c015 1513 /* qemu_strtoul() tests */
b30d1886
MA
1514 g_test_add_func("/cutils/qemu_strtoul/correct",
1515 test_qemu_strtoul_correct);
1516 g_test_add_func("/cutils/qemu_strtoul/null",
1517 test_qemu_strtoul_null);
1518 g_test_add_func("/cutils/qemu_strtoul/empty",
1519 test_qemu_strtoul_empty);
c817c015
CT
1520 g_test_add_func("/cutils/qemu_strtoul/whitespace",
1521 test_qemu_strtoul_whitespace);
b30d1886
MA
1522 g_test_add_func("/cutils/qemu_strtoul/invalid",
1523 test_qemu_strtoul_invalid);
c817c015
CT
1524 g_test_add_func("/cutils/qemu_strtoul/trailing",
1525 test_qemu_strtoul_trailing);
b30d1886
MA
1526 g_test_add_func("/cutils/qemu_strtoul/octal",
1527 test_qemu_strtoul_octal);
1528 g_test_add_func("/cutils/qemu_strtoul/decimal",
1529 test_qemu_strtoul_decimal);
1530 g_test_add_func("/cutils/qemu_strtoul/hex",
1531 test_qemu_strtoul_hex);
1532 g_test_add_func("/cutils/qemu_strtoul/max",
1533 test_qemu_strtoul_max);
c817c015
CT
1534 g_test_add_func("/cutils/qemu_strtoul/overflow",
1535 test_qemu_strtoul_overflow);
1536 g_test_add_func("/cutils/qemu_strtoul/underflow",
1537 test_qemu_strtoul_underflow);
1538 g_test_add_func("/cutils/qemu_strtoul/negative",
1539 test_qemu_strtoul_negative);
1540 g_test_add_func("/cutils/qemu_strtoul_full/correct",
1541 test_qemu_strtoul_full_correct);
1542 g_test_add_func("/cutils/qemu_strtoul_full/null",
1543 test_qemu_strtoul_full_null);
1544 g_test_add_func("/cutils/qemu_strtoul_full/empty",
1545 test_qemu_strtoul_full_empty);
1546 g_test_add_func("/cutils/qemu_strtoul_full/negative",
1547 test_qemu_strtoul_full_negative);
1548 g_test_add_func("/cutils/qemu_strtoul_full/trailing",
1549 test_qemu_strtoul_full_trailing);
1550 g_test_add_func("/cutils/qemu_strtoul_full/max",
1551 test_qemu_strtoul_full_max);
1552
b30d1886
MA
1553 /* qemu_strtoi64() tests */
1554 g_test_add_func("/cutils/qemu_strtoi64/correct",
1555 test_qemu_strtoi64_correct);
1556 g_test_add_func("/cutils/qemu_strtoi64/null",
1557 test_qemu_strtoi64_null);
1558 g_test_add_func("/cutils/qemu_strtoi64/empty",
1559 test_qemu_strtoi64_empty);
1560 g_test_add_func("/cutils/qemu_strtoi64/whitespace",
1561 test_qemu_strtoi64_whitespace);
1562 g_test_add_func("/cutils/qemu_strtoi64/invalid"
1563 ,
1564 test_qemu_strtoi64_invalid);
1565 g_test_add_func("/cutils/qemu_strtoi64/trailing",
1566 test_qemu_strtoi64_trailing);
1567 g_test_add_func("/cutils/qemu_strtoi64/octal",
1568 test_qemu_strtoi64_octal);
1569 g_test_add_func("/cutils/qemu_strtoi64/decimal",
1570 test_qemu_strtoi64_decimal);
1571 g_test_add_func("/cutils/qemu_strtoi64/hex",
1572 test_qemu_strtoi64_hex);
1573 g_test_add_func("/cutils/qemu_strtoi64/max",
1574 test_qemu_strtoi64_max);
1575 g_test_add_func("/cutils/qemu_strtoi64/overflow",
1576 test_qemu_strtoi64_overflow);
1577 g_test_add_func("/cutils/qemu_strtoi64/underflow",
1578 test_qemu_strtoi64_underflow);
1579 g_test_add_func("/cutils/qemu_strtoi64/negative",
1580 test_qemu_strtoi64_negative);
1581 g_test_add_func("/cutils/qemu_strtoi64_full/correct",
1582 test_qemu_strtoi64_full_correct);
1583 g_test_add_func("/cutils/qemu_strtoi64_full/null",
1584 test_qemu_strtoi64_full_null);
1585 g_test_add_func("/cutils/qemu_strtoi64_full/empty",
1586 test_qemu_strtoi64_full_empty);
1587 g_test_add_func("/cutils/qemu_strtoi64_full/negative",
1588 test_qemu_strtoi64_full_negative);
1589 g_test_add_func("/cutils/qemu_strtoi64_full/trailing",
1590 test_qemu_strtoi64_full_trailing);
1591 g_test_add_func("/cutils/qemu_strtoi64_full/max",
1592 test_qemu_strtoi64_full_max);
1593
1594 /* qemu_strtou64() tests */
1595 g_test_add_func("/cutils/qemu_strtou64/correct",
1596 test_qemu_strtou64_correct);
1597 g_test_add_func("/cutils/qemu_strtou64/null",
1598 test_qemu_strtou64_null);
1599 g_test_add_func("/cutils/qemu_strtou64/empty",
1600 test_qemu_strtou64_empty);
1601 g_test_add_func("/cutils/qemu_strtou64/whitespace",
1602 test_qemu_strtou64_whitespace);
1603 g_test_add_func("/cutils/qemu_strtou64/invalid",
1604 test_qemu_strtou64_invalid);
1605 g_test_add_func("/cutils/qemu_strtou64/trailing",
1606 test_qemu_strtou64_trailing);
1607 g_test_add_func("/cutils/qemu_strtou64/octal",
1608 test_qemu_strtou64_octal);
1609 g_test_add_func("/cutils/qemu_strtou64/decimal",
1610 test_qemu_strtou64_decimal);
1611 g_test_add_func("/cutils/qemu_strtou64/hex",
1612 test_qemu_strtou64_hex);
1613 g_test_add_func("/cutils/qemu_strtou64/max",
1614 test_qemu_strtou64_max);
1615 g_test_add_func("/cutils/qemu_strtou64/overflow",
1616 test_qemu_strtou64_overflow);
1617 g_test_add_func("/cutils/qemu_strtou64/underflow",
1618 test_qemu_strtou64_underflow);
1619 g_test_add_func("/cutils/qemu_strtou64/negative",
1620 test_qemu_strtou64_negative);
1621 g_test_add_func("/cutils/qemu_strtou64_full/correct",
1622 test_qemu_strtou64_full_correct);
1623 g_test_add_func("/cutils/qemu_strtou64_full/null",
1624 test_qemu_strtou64_full_null);
1625 g_test_add_func("/cutils/qemu_strtou64_full/empty",
1626 test_qemu_strtou64_full_empty);
1627 g_test_add_func("/cutils/qemu_strtou64_full/negative",
1628 test_qemu_strtou64_full_negative);
1629 g_test_add_func("/cutils/qemu_strtou64_full/trailing",
1630 test_qemu_strtou64_full_trailing);
1631 g_test_add_func("/cutils/qemu_strtou64_full/max",
1632 test_qemu_strtou64_full_max);
3904e6bf 1633
fe854538
MAL
1634 g_test_add_func("/cutils/strtosz/simple",
1635 test_qemu_strtosz_simple);
1636 g_test_add_func("/cutils/strtosz/units",
1637 test_qemu_strtosz_units);
1638 g_test_add_func("/cutils/strtosz/float",
1639 test_qemu_strtosz_float);
1640 g_test_add_func("/cutils/strtosz/erange",
1641 test_qemu_strtosz_erange);
1642 g_test_add_func("/cutils/strtosz/suffix-unit",
1643 test_qemu_strtosz_suffix_unit);
1644
e3f9fe2d
EH
1645 return g_test_run();
1646}