ati-vga: Fix indexed access to video memory
[qemu/ar7.git] / tests / test-cutils.c
blob1aa8351520ae33201a3f7fb0b67841498aefad06
1 /*
2 * cutils.c unit-tests
4 * Copyright (C) 2013 Red Hat Inc.
6 * Authors:
7 * Eduardo Habkost <ehabkost@redhat.com>
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:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
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.
28 #include "qemu/osdep.h"
29 #include "qemu/units.h"
30 #include "qemu/cutils.h"
31 #include "qemu/units.h"
33 static void test_parse_uint_null(void)
35 unsigned long long i = 999;
36 char f = 'X';
37 char *endptr = &f;
38 int r;
40 r = parse_uint(NULL, &i, &endptr, 0);
42 g_assert_cmpint(r, ==, -EINVAL);
43 g_assert_cmpint(i, ==, 0);
44 g_assert(endptr == NULL);
47 static void test_parse_uint_empty(void)
49 unsigned long long i = 999;
50 char f = 'X';
51 char *endptr = &f;
52 const char *str = "";
53 int r;
55 r = parse_uint(str, &i, &endptr, 0);
57 g_assert_cmpint(r, ==, -EINVAL);
58 g_assert_cmpint(i, ==, 0);
59 g_assert(endptr == str);
62 static void test_parse_uint_whitespace(void)
64 unsigned long long i = 999;
65 char f = 'X';
66 char *endptr = &f;
67 const char *str = " \t ";
68 int r;
70 r = parse_uint(str, &i, &endptr, 0);
72 g_assert_cmpint(r, ==, -EINVAL);
73 g_assert_cmpint(i, ==, 0);
74 g_assert(endptr == str);
78 static void test_parse_uint_invalid(void)
80 unsigned long long i = 999;
81 char f = 'X';
82 char *endptr = &f;
83 const char *str = " \t xxx";
84 int r;
86 r = parse_uint(str, &i, &endptr, 0);
88 g_assert_cmpint(r, ==, -EINVAL);
89 g_assert_cmpint(i, ==, 0);
90 g_assert(endptr == str);
94 static void test_parse_uint_trailing(void)
96 unsigned long long i = 999;
97 char f = 'X';
98 char *endptr = &f;
99 const char *str = "123xxx";
100 int r;
102 r = parse_uint(str, &i, &endptr, 0);
104 g_assert_cmpint(r, ==, 0);
105 g_assert_cmpint(i, ==, 123);
106 g_assert(endptr == str + 3);
109 static void test_parse_uint_correct(void)
111 unsigned long long i = 999;
112 char f = 'X';
113 char *endptr = &f;
114 const char *str = "123";
115 int r;
117 r = parse_uint(str, &i, &endptr, 0);
119 g_assert_cmpint(r, ==, 0);
120 g_assert_cmpint(i, ==, 123);
121 g_assert(endptr == str + strlen(str));
124 static void test_parse_uint_octal(void)
126 unsigned long long i = 999;
127 char f = 'X';
128 char *endptr = &f;
129 const char *str = "0123";
130 int r;
132 r = parse_uint(str, &i, &endptr, 0);
134 g_assert_cmpint(r, ==, 0);
135 g_assert_cmpint(i, ==, 0123);
136 g_assert(endptr == str + strlen(str));
139 static void test_parse_uint_decimal(void)
141 unsigned long long i = 999;
142 char f = 'X';
143 char *endptr = &f;
144 const char *str = "0123";
145 int r;
147 r = parse_uint(str, &i, &endptr, 10);
149 g_assert_cmpint(r, ==, 0);
150 g_assert_cmpint(i, ==, 123);
151 g_assert(endptr == str + strlen(str));
155 static void test_parse_uint_llong_max(void)
157 unsigned long long i = 999;
158 char f = 'X';
159 char *endptr = &f;
160 char *str = g_strdup_printf("%llu", (unsigned long long)LLONG_MAX + 1);
161 int r;
163 r = parse_uint(str, &i, &endptr, 0);
165 g_assert_cmpint(r, ==, 0);
166 g_assert_cmpint(i, ==, (unsigned long long)LLONG_MAX + 1);
167 g_assert(endptr == str + strlen(str));
169 g_free(str);
172 static void test_parse_uint_overflow(void)
174 unsigned long long i = 999;
175 char f = 'X';
176 char *endptr = &f;
177 const char *str = "99999999999999999999999999999999999999";
178 int r;
180 r = parse_uint(str, &i, &endptr, 0);
182 g_assert_cmpint(r, ==, -ERANGE);
183 g_assert_cmpint(i, ==, ULLONG_MAX);
184 g_assert(endptr == str + strlen(str));
187 static void test_parse_uint_negative(void)
189 unsigned long long i = 999;
190 char f = 'X';
191 char *endptr = &f;
192 const char *str = " \t -321";
193 int r;
195 r = parse_uint(str, &i, &endptr, 0);
197 g_assert_cmpint(r, ==, -ERANGE);
198 g_assert_cmpint(i, ==, 0);
199 g_assert(endptr == str + strlen(str));
203 static void test_parse_uint_full_trailing(void)
205 unsigned long long i = 999;
206 const char *str = "123xxx";
207 int r;
209 r = parse_uint_full(str, &i, 0);
211 g_assert_cmpint(r, ==, -EINVAL);
212 g_assert_cmpint(i, ==, 0);
215 static void test_parse_uint_full_correct(void)
217 unsigned long long i = 999;
218 const char *str = "123";
219 int r;
221 r = parse_uint_full(str, &i, 0);
223 g_assert_cmpint(r, ==, 0);
224 g_assert_cmpint(i, ==, 123);
227 static void test_qemu_strtoi_correct(void)
229 const char *str = "12345 foo";
230 char f = 'X';
231 const char *endptr = &f;
232 int res = 999;
233 int err;
235 err = qemu_strtoi(str, &endptr, 0, &res);
237 g_assert_cmpint(err, ==, 0);
238 g_assert_cmpint(res, ==, 12345);
239 g_assert(endptr == str + 5);
242 static void test_qemu_strtoi_null(void)
244 char f = 'X';
245 const char *endptr = &f;
246 int res = 999;
247 int err;
249 err = qemu_strtoi(NULL, &endptr, 0, &res);
251 g_assert_cmpint(err, ==, -EINVAL);
252 g_assert(endptr == NULL);
255 static void test_qemu_strtoi_empty(void)
257 const char *str = "";
258 char f = 'X';
259 const char *endptr = &f;
260 int res = 999;
261 int err;
263 err = qemu_strtoi(str, &endptr, 0, &res);
265 g_assert_cmpint(err, ==, -EINVAL);
266 g_assert(endptr == str);
269 static void test_qemu_strtoi_whitespace(void)
271 const char *str = " \t ";
272 char f = 'X';
273 const char *endptr = &f;
274 int res = 999;
275 int err;
277 err = qemu_strtoi(str, &endptr, 0, &res);
279 g_assert_cmpint(err, ==, -EINVAL);
280 g_assert(endptr == str);
283 static void test_qemu_strtoi_invalid(void)
285 const char *str = " xxxx \t abc";
286 char f = 'X';
287 const char *endptr = &f;
288 int res = 999;
289 int err;
291 err = qemu_strtoi(str, &endptr, 0, &res);
293 g_assert_cmpint(err, ==, -EINVAL);
294 g_assert(endptr == str);
297 static void test_qemu_strtoi_trailing(void)
299 const char *str = "123xxx";
300 char f = 'X';
301 const char *endptr = &f;
302 int res = 999;
303 int err;
305 err = qemu_strtoi(str, &endptr, 0, &res);
307 g_assert_cmpint(err, ==, 0);
308 g_assert_cmpint(res, ==, 123);
309 g_assert(endptr == str + 3);
312 static void test_qemu_strtoi_octal(void)
314 const char *str = "0123";
315 char f = 'X';
316 const char *endptr = &f;
317 int res = 999;
318 int err;
320 err = qemu_strtoi(str, &endptr, 8, &res);
322 g_assert_cmpint(err, ==, 0);
323 g_assert_cmpint(res, ==, 0123);
324 g_assert(endptr == str + strlen(str));
326 res = 999;
327 endptr = &f;
328 err = qemu_strtoi(str, &endptr, 0, &res);
330 g_assert_cmpint(err, ==, 0);
331 g_assert_cmpint(res, ==, 0123);
332 g_assert(endptr == str + strlen(str));
335 static void test_qemu_strtoi_decimal(void)
337 const char *str = "0123";
338 char f = 'X';
339 const char *endptr = &f;
340 int res = 999;
341 int err;
343 err = qemu_strtoi(str, &endptr, 10, &res);
345 g_assert_cmpint(err, ==, 0);
346 g_assert_cmpint(res, ==, 123);
347 g_assert(endptr == str + strlen(str));
349 str = "123";
350 res = 999;
351 endptr = &f;
352 err = qemu_strtoi(str, &endptr, 0, &res);
354 g_assert_cmpint(err, ==, 0);
355 g_assert_cmpint(res, ==, 123);
356 g_assert(endptr == str + strlen(str));
359 static void test_qemu_strtoi_hex(void)
361 const char *str = "0123";
362 char f = 'X';
363 const char *endptr = &f;
364 int res = 999;
365 int err;
367 err = qemu_strtoi(str, &endptr, 16, &res);
369 g_assert_cmpint(err, ==, 0);
370 g_assert_cmpint(res, ==, 0x123);
371 g_assert(endptr == str + strlen(str));
373 str = "0x123";
374 res = 999;
375 endptr = &f;
376 err = qemu_strtoi(str, &endptr, 0, &res);
378 g_assert_cmpint(err, ==, 0);
379 g_assert_cmpint(res, ==, 0x123);
380 g_assert(endptr == str + strlen(str));
383 static void test_qemu_strtoi_max(void)
385 char *str = g_strdup_printf("%d", INT_MAX);
386 char f = 'X';
387 const char *endptr = &f;
388 int res = 999;
389 int err;
391 err = qemu_strtoi(str, &endptr, 0, &res);
393 g_assert_cmpint(err, ==, 0);
394 g_assert_cmpint(res, ==, INT_MAX);
395 g_assert(endptr == str + strlen(str));
396 g_free(str);
399 static void test_qemu_strtoi_overflow(void)
401 char *str = g_strdup_printf("%lld", (long long)INT_MAX + 1ll);
402 char f = 'X';
403 const char *endptr = &f;
404 int res = 999;
405 int err;
407 err = qemu_strtoi(str, &endptr, 0, &res);
409 g_assert_cmpint(err, ==, -ERANGE);
410 g_assert_cmpint(res, ==, INT_MAX);
411 g_assert(endptr == str + strlen(str));
412 g_free(str);
415 static void test_qemu_strtoi_underflow(void)
417 char *str = g_strdup_printf("%lld", (long long)INT_MIN - 1ll);
418 char f = 'X';
419 const char *endptr = &f;
420 int res = 999;
421 int err;
423 err = qemu_strtoi(str, &endptr, 0, &res);
425 g_assert_cmpint(err, ==, -ERANGE);
426 g_assert_cmpint(res, ==, INT_MIN);
427 g_assert(endptr == str + strlen(str));
428 g_free(str);
431 static void test_qemu_strtoi_negative(void)
433 const char *str = " \t -321";
434 char f = 'X';
435 const char *endptr = &f;
436 int res = 999;
437 int err;
439 err = qemu_strtoi(str, &endptr, 0, &res);
441 g_assert_cmpint(err, ==, 0);
442 g_assert_cmpint(res, ==, -321);
443 g_assert(endptr == str + strlen(str));
446 static void test_qemu_strtoi_full_correct(void)
448 const char *str = "123";
449 int res = 999;
450 int err;
452 err = qemu_strtoi(str, NULL, 0, &res);
454 g_assert_cmpint(err, ==, 0);
455 g_assert_cmpint(res, ==, 123);
458 static void test_qemu_strtoi_full_null(void)
460 char f = 'X';
461 const char *endptr = &f;
462 int res = 999;
463 int err;
465 err = qemu_strtoi(NULL, &endptr, 0, &res);
467 g_assert_cmpint(err, ==, -EINVAL);
468 g_assert(endptr == NULL);
471 static void test_qemu_strtoi_full_empty(void)
473 const char *str = "";
474 int res = 999L;
475 int err;
477 err = qemu_strtoi(str, NULL, 0, &res);
479 g_assert_cmpint(err, ==, -EINVAL);
482 static void test_qemu_strtoi_full_negative(void)
484 const char *str = " \t -321";
485 int res = 999;
486 int err;
488 err = qemu_strtoi(str, NULL, 0, &res);
490 g_assert_cmpint(err, ==, 0);
491 g_assert_cmpint(res, ==, -321);
494 static void test_qemu_strtoi_full_trailing(void)
496 const char *str = "123xxx";
497 int res;
498 int err;
500 err = qemu_strtoi(str, NULL, 0, &res);
502 g_assert_cmpint(err, ==, -EINVAL);
505 static void test_qemu_strtoi_full_max(void)
507 char *str = g_strdup_printf("%d", INT_MAX);
508 int res;
509 int err;
511 err = qemu_strtoi(str, NULL, 0, &res);
513 g_assert_cmpint(err, ==, 0);
514 g_assert_cmpint(res, ==, INT_MAX);
515 g_free(str);
518 static void test_qemu_strtoui_correct(void)
520 const char *str = "12345 foo";
521 char f = 'X';
522 const char *endptr = &f;
523 unsigned int res = 999;
524 int err;
526 err = qemu_strtoui(str, &endptr, 0, &res);
528 g_assert_cmpint(err, ==, 0);
529 g_assert_cmpuint(res, ==, 12345);
530 g_assert(endptr == str + 5);
533 static void test_qemu_strtoui_null(void)
535 char f = 'X';
536 const char *endptr = &f;
537 unsigned int res = 999;
538 int err;
540 err = qemu_strtoui(NULL, &endptr, 0, &res);
542 g_assert_cmpint(err, ==, -EINVAL);
543 g_assert(endptr == NULL);
546 static void test_qemu_strtoui_empty(void)
548 const char *str = "";
549 char f = 'X';
550 const char *endptr = &f;
551 unsigned int res = 999;
552 int err;
554 err = qemu_strtoui(str, &endptr, 0, &res);
556 g_assert_cmpint(err, ==, -EINVAL);
557 g_assert(endptr == str);
560 static void test_qemu_strtoui_whitespace(void)
562 const char *str = " \t ";
563 char f = 'X';
564 const char *endptr = &f;
565 unsigned int res = 999;
566 int err;
568 err = qemu_strtoui(str, &endptr, 0, &res);
570 g_assert_cmpint(err, ==, -EINVAL);
571 g_assert(endptr == str);
574 static void test_qemu_strtoui_invalid(void)
576 const char *str = " xxxx \t abc";
577 char f = 'X';
578 const char *endptr = &f;
579 unsigned int res = 999;
580 int err;
582 err = qemu_strtoui(str, &endptr, 0, &res);
584 g_assert_cmpint(err, ==, -EINVAL);
585 g_assert(endptr == str);
588 static void test_qemu_strtoui_trailing(void)
590 const char *str = "123xxx";
591 char f = 'X';
592 const char *endptr = &f;
593 unsigned int res = 999;
594 int err;
596 err = qemu_strtoui(str, &endptr, 0, &res);
598 g_assert_cmpint(err, ==, 0);
599 g_assert_cmpuint(res, ==, 123);
600 g_assert(endptr == str + 3);
603 static void test_qemu_strtoui_octal(void)
605 const char *str = "0123";
606 char f = 'X';
607 const char *endptr = &f;
608 unsigned int res = 999;
609 int err;
611 err = qemu_strtoui(str, &endptr, 8, &res);
613 g_assert_cmpint(err, ==, 0);
614 g_assert_cmpuint(res, ==, 0123);
615 g_assert(endptr == str + strlen(str));
617 res = 999;
618 endptr = &f;
619 err = qemu_strtoui(str, &endptr, 0, &res);
621 g_assert_cmpint(err, ==, 0);
622 g_assert_cmpuint(res, ==, 0123);
623 g_assert(endptr == str + strlen(str));
626 static void test_qemu_strtoui_decimal(void)
628 const char *str = "0123";
629 char f = 'X';
630 const char *endptr = &f;
631 unsigned int res = 999;
632 int err;
634 err = qemu_strtoui(str, &endptr, 10, &res);
636 g_assert_cmpint(err, ==, 0);
637 g_assert_cmpuint(res, ==, 123);
638 g_assert(endptr == str + strlen(str));
640 str = "123";
641 res = 999;
642 endptr = &f;
643 err = qemu_strtoui(str, &endptr, 0, &res);
645 g_assert_cmpint(err, ==, 0);
646 g_assert_cmpuint(res, ==, 123);
647 g_assert(endptr == str + strlen(str));
650 static void test_qemu_strtoui_hex(void)
652 const char *str = "0123";
653 char f = 'X';
654 const char *endptr = &f;
655 unsigned int res = 999;
656 int err;
658 err = qemu_strtoui(str, &endptr, 16, &res);
660 g_assert_cmpint(err, ==, 0);
661 g_assert_cmphex(res, ==, 0x123);
662 g_assert(endptr == str + strlen(str));
664 str = "0x123";
665 res = 999;
666 endptr = &f;
667 err = qemu_strtoui(str, &endptr, 0, &res);
669 g_assert_cmpint(err, ==, 0);
670 g_assert_cmphex(res, ==, 0x123);
671 g_assert(endptr == str + strlen(str));
674 static void test_qemu_strtoui_max(void)
676 char *str = g_strdup_printf("%u", UINT_MAX);
677 char f = 'X';
678 const char *endptr = &f;
679 unsigned int res = 999;
680 int err;
682 err = qemu_strtoui(str, &endptr, 0, &res);
684 g_assert_cmpint(err, ==, 0);
685 g_assert_cmphex(res, ==, UINT_MAX);
686 g_assert(endptr == str + strlen(str));
687 g_free(str);
690 static void test_qemu_strtoui_overflow(void)
692 char *str = g_strdup_printf("%lld", (long long)UINT_MAX + 1ll);
693 char f = 'X';
694 const char *endptr = &f;
695 unsigned int res = 999;
696 int err;
698 err = qemu_strtoui(str, &endptr, 0, &res);
700 g_assert_cmpint(err, ==, -ERANGE);
701 g_assert_cmphex(res, ==, UINT_MAX);
702 g_assert(endptr == str + strlen(str));
703 g_free(str);
706 static void test_qemu_strtoui_underflow(void)
708 char *str = g_strdup_printf("%lld", (long long)INT_MIN - 1ll);
709 char f = 'X';
710 const char *endptr = &f;
711 unsigned int res = 999;
712 int err;
714 err = qemu_strtoui(str, &endptr, 0, &res);
716 g_assert_cmpint(err, ==, -ERANGE);
717 g_assert_cmpuint(res, ==, (unsigned int)-1);
718 g_assert(endptr == str + strlen(str));
719 g_free(str);
722 static void test_qemu_strtoui_negative(void)
724 const char *str = " \t -321";
725 char f = 'X';
726 const char *endptr = &f;
727 unsigned int res = 999;
728 int err;
730 err = qemu_strtoui(str, &endptr, 0, &res);
732 g_assert_cmpint(err, ==, 0);
733 g_assert_cmpuint(res, ==, (unsigned int)-321);
734 g_assert(endptr == str + strlen(str));
737 static void test_qemu_strtoui_full_correct(void)
739 const char *str = "123";
740 unsigned int res = 999;
741 int err;
743 err = qemu_strtoui(str, NULL, 0, &res);
745 g_assert_cmpint(err, ==, 0);
746 g_assert_cmpuint(res, ==, 123);
749 static void test_qemu_strtoui_full_null(void)
751 unsigned int res = 999;
752 int err;
754 err = qemu_strtoui(NULL, NULL, 0, &res);
756 g_assert_cmpint(err, ==, -EINVAL);
759 static void test_qemu_strtoui_full_empty(void)
761 const char *str = "";
762 unsigned int res = 999;
763 int err;
765 err = qemu_strtoui(str, NULL, 0, &res);
767 g_assert_cmpint(err, ==, -EINVAL);
769 static void test_qemu_strtoui_full_negative(void)
771 const char *str = " \t -321";
772 unsigned int res = 999;
773 int err;
775 err = qemu_strtoui(str, NULL, 0, &res);
776 g_assert_cmpint(err, ==, 0);
777 g_assert_cmpuint(res, ==, (unsigned int)-321);
780 static void test_qemu_strtoui_full_trailing(void)
782 const char *str = "123xxx";
783 unsigned int res;
784 int err;
786 err = qemu_strtoui(str, NULL, 0, &res);
788 g_assert_cmpint(err, ==, -EINVAL);
791 static void test_qemu_strtoui_full_max(void)
793 char *str = g_strdup_printf("%u", UINT_MAX);
794 unsigned int res = 999;
795 int err;
797 err = qemu_strtoui(str, NULL, 0, &res);
799 g_assert_cmpint(err, ==, 0);
800 g_assert_cmphex(res, ==, UINT_MAX);
801 g_free(str);
804 static void test_qemu_strtol_correct(void)
806 const char *str = "12345 foo";
807 char f = 'X';
808 const char *endptr = &f;
809 long res = 999;
810 int err;
812 err = qemu_strtol(str, &endptr, 0, &res);
814 g_assert_cmpint(err, ==, 0);
815 g_assert_cmpint(res, ==, 12345);
816 g_assert(endptr == str + 5);
819 static void test_qemu_strtol_null(void)
821 char f = 'X';
822 const char *endptr = &f;
823 long res = 999;
824 int err;
826 err = qemu_strtol(NULL, &endptr, 0, &res);
828 g_assert_cmpint(err, ==, -EINVAL);
829 g_assert(endptr == NULL);
832 static void test_qemu_strtol_empty(void)
834 const char *str = "";
835 char f = 'X';
836 const char *endptr = &f;
837 long res = 999;
838 int err;
840 err = qemu_strtol(str, &endptr, 0, &res);
842 g_assert_cmpint(err, ==, -EINVAL);
843 g_assert(endptr == str);
846 static void test_qemu_strtol_whitespace(void)
848 const char *str = " \t ";
849 char f = 'X';
850 const char *endptr = &f;
851 long res = 999;
852 int err;
854 err = qemu_strtol(str, &endptr, 0, &res);
856 g_assert_cmpint(err, ==, -EINVAL);
857 g_assert(endptr == str);
860 static void test_qemu_strtol_invalid(void)
862 const char *str = " xxxx \t abc";
863 char f = 'X';
864 const char *endptr = &f;
865 long res = 999;
866 int err;
868 err = qemu_strtol(str, &endptr, 0, &res);
870 g_assert_cmpint(err, ==, -EINVAL);
871 g_assert(endptr == str);
874 static void test_qemu_strtol_trailing(void)
876 const char *str = "123xxx";
877 char f = 'X';
878 const char *endptr = &f;
879 long res = 999;
880 int err;
882 err = qemu_strtol(str, &endptr, 0, &res);
884 g_assert_cmpint(err, ==, 0);
885 g_assert_cmpint(res, ==, 123);
886 g_assert(endptr == str + 3);
889 static void test_qemu_strtol_octal(void)
891 const char *str = "0123";
892 char f = 'X';
893 const char *endptr = &f;
894 long res = 999;
895 int err;
897 err = qemu_strtol(str, &endptr, 8, &res);
899 g_assert_cmpint(err, ==, 0);
900 g_assert_cmpint(res, ==, 0123);
901 g_assert(endptr == str + strlen(str));
903 res = 999;
904 endptr = &f;
905 err = qemu_strtol(str, &endptr, 0, &res);
907 g_assert_cmpint(err, ==, 0);
908 g_assert_cmpint(res, ==, 0123);
909 g_assert(endptr == str + strlen(str));
912 static void test_qemu_strtol_decimal(void)
914 const char *str = "0123";
915 char f = 'X';
916 const char *endptr = &f;
917 long res = 999;
918 int err;
920 err = qemu_strtol(str, &endptr, 10, &res);
922 g_assert_cmpint(err, ==, 0);
923 g_assert_cmpint(res, ==, 123);
924 g_assert(endptr == str + strlen(str));
926 str = "123";
927 res = 999;
928 endptr = &f;
929 err = qemu_strtol(str, &endptr, 0, &res);
931 g_assert_cmpint(err, ==, 0);
932 g_assert_cmpint(res, ==, 123);
933 g_assert(endptr == str + strlen(str));
936 static void test_qemu_strtol_hex(void)
938 const char *str = "0123";
939 char f = 'X';
940 const char *endptr = &f;
941 long res = 999;
942 int err;
944 err = qemu_strtol(str, &endptr, 16, &res);
946 g_assert_cmpint(err, ==, 0);
947 g_assert_cmpint(res, ==, 0x123);
948 g_assert(endptr == str + strlen(str));
950 str = "0x123";
951 res = 999;
952 endptr = &f;
953 err = qemu_strtol(str, &endptr, 0, &res);
955 g_assert_cmpint(err, ==, 0);
956 g_assert_cmpint(res, ==, 0x123);
957 g_assert(endptr == str + strlen(str));
960 static void test_qemu_strtol_max(void)
962 char *str = g_strdup_printf("%ld", LONG_MAX);
963 char f = 'X';
964 const char *endptr = &f;
965 long res = 999;
966 int err;
968 err = qemu_strtol(str, &endptr, 0, &res);
970 g_assert_cmpint(err, ==, 0);
971 g_assert_cmpint(res, ==, LONG_MAX);
972 g_assert(endptr == str + strlen(str));
973 g_free(str);
976 static void test_qemu_strtol_overflow(void)
978 const char *str = "99999999999999999999999999999999999999999999";
979 char f = 'X';
980 const char *endptr = &f;
981 long res = 999;
982 int err;
984 err = qemu_strtol(str, &endptr, 0, &res);
986 g_assert_cmpint(err, ==, -ERANGE);
987 g_assert_cmpint(res, ==, LONG_MAX);
988 g_assert(endptr == str + strlen(str));
991 static void test_qemu_strtol_underflow(void)
993 const char *str = "-99999999999999999999999999999999999999999999";
994 char f = 'X';
995 const char *endptr = &f;
996 long res = 999;
997 int err;
999 err = qemu_strtol(str, &endptr, 0, &res);
1001 g_assert_cmpint(err, ==, -ERANGE);
1002 g_assert_cmpint(res, ==, LONG_MIN);
1003 g_assert(endptr == str + strlen(str));
1006 static void test_qemu_strtol_negative(void)
1008 const char *str = " \t -321";
1009 char f = 'X';
1010 const char *endptr = &f;
1011 long res = 999;
1012 int err;
1014 err = qemu_strtol(str, &endptr, 0, &res);
1016 g_assert_cmpint(err, ==, 0);
1017 g_assert_cmpint(res, ==, -321);
1018 g_assert(endptr == str + strlen(str));
1021 static void test_qemu_strtol_full_correct(void)
1023 const char *str = "123";
1024 long res = 999;
1025 int err;
1027 err = qemu_strtol(str, NULL, 0, &res);
1029 g_assert_cmpint(err, ==, 0);
1030 g_assert_cmpint(res, ==, 123);
1033 static void test_qemu_strtol_full_null(void)
1035 char f = 'X';
1036 const char *endptr = &f;
1037 long res = 999;
1038 int err;
1040 err = qemu_strtol(NULL, &endptr, 0, &res);
1042 g_assert_cmpint(err, ==, -EINVAL);
1043 g_assert(endptr == NULL);
1046 static void test_qemu_strtol_full_empty(void)
1048 const char *str = "";
1049 long res = 999L;
1050 int err;
1052 err = qemu_strtol(str, NULL, 0, &res);
1054 g_assert_cmpint(err, ==, -EINVAL);
1057 static void test_qemu_strtol_full_negative(void)
1059 const char *str = " \t -321";
1060 long res = 999;
1061 int err;
1063 err = qemu_strtol(str, NULL, 0, &res);
1065 g_assert_cmpint(err, ==, 0);
1066 g_assert_cmpint(res, ==, -321);
1069 static void test_qemu_strtol_full_trailing(void)
1071 const char *str = "123xxx";
1072 long res;
1073 int err;
1075 err = qemu_strtol(str, NULL, 0, &res);
1077 g_assert_cmpint(err, ==, -EINVAL);
1080 static void test_qemu_strtol_full_max(void)
1082 char *str = g_strdup_printf("%ld", LONG_MAX);
1083 long res;
1084 int err;
1086 err = qemu_strtol(str, NULL, 0, &res);
1088 g_assert_cmpint(err, ==, 0);
1089 g_assert_cmpint(res, ==, LONG_MAX);
1090 g_free(str);
1093 static void test_qemu_strtoul_correct(void)
1095 const char *str = "12345 foo";
1096 char f = 'X';
1097 const char *endptr = &f;
1098 unsigned long res = 999;
1099 int err;
1101 err = qemu_strtoul(str, &endptr, 0, &res);
1103 g_assert_cmpint(err, ==, 0);
1104 g_assert_cmpuint(res, ==, 12345);
1105 g_assert(endptr == str + 5);
1108 static void test_qemu_strtoul_null(void)
1110 char f = 'X';
1111 const char *endptr = &f;
1112 unsigned long res = 999;
1113 int err;
1115 err = qemu_strtoul(NULL, &endptr, 0, &res);
1117 g_assert_cmpint(err, ==, -EINVAL);
1118 g_assert(endptr == NULL);
1121 static void test_qemu_strtoul_empty(void)
1123 const char *str = "";
1124 char f = 'X';
1125 const char *endptr = &f;
1126 unsigned long res = 999;
1127 int err;
1129 err = qemu_strtoul(str, &endptr, 0, &res);
1131 g_assert_cmpint(err, ==, -EINVAL);
1132 g_assert(endptr == str);
1135 static void test_qemu_strtoul_whitespace(void)
1137 const char *str = " \t ";
1138 char f = 'X';
1139 const char *endptr = &f;
1140 unsigned long res = 999;
1141 int err;
1143 err = qemu_strtoul(str, &endptr, 0, &res);
1145 g_assert_cmpint(err, ==, -EINVAL);
1146 g_assert(endptr == str);
1149 static void test_qemu_strtoul_invalid(void)
1151 const char *str = " xxxx \t abc";
1152 char f = 'X';
1153 const char *endptr = &f;
1154 unsigned long res = 999;
1155 int err;
1157 err = qemu_strtoul(str, &endptr, 0, &res);
1159 g_assert_cmpint(err, ==, -EINVAL);
1160 g_assert(endptr == str);
1163 static void test_qemu_strtoul_trailing(void)
1165 const char *str = "123xxx";
1166 char f = 'X';
1167 const char *endptr = &f;
1168 unsigned long res = 999;
1169 int err;
1171 err = qemu_strtoul(str, &endptr, 0, &res);
1173 g_assert_cmpint(err, ==, 0);
1174 g_assert_cmpuint(res, ==, 123);
1175 g_assert(endptr == str + 3);
1178 static void test_qemu_strtoul_octal(void)
1180 const char *str = "0123";
1181 char f = 'X';
1182 const char *endptr = &f;
1183 unsigned long res = 999;
1184 int err;
1186 err = qemu_strtoul(str, &endptr, 8, &res);
1188 g_assert_cmpint(err, ==, 0);
1189 g_assert_cmpuint(res, ==, 0123);
1190 g_assert(endptr == str + strlen(str));
1192 res = 999;
1193 endptr = &f;
1194 err = qemu_strtoul(str, &endptr, 0, &res);
1196 g_assert_cmpint(err, ==, 0);
1197 g_assert_cmpuint(res, ==, 0123);
1198 g_assert(endptr == str + strlen(str));
1201 static void test_qemu_strtoul_decimal(void)
1203 const char *str = "0123";
1204 char f = 'X';
1205 const char *endptr = &f;
1206 unsigned long res = 999;
1207 int err;
1209 err = qemu_strtoul(str, &endptr, 10, &res);
1211 g_assert_cmpint(err, ==, 0);
1212 g_assert_cmpuint(res, ==, 123);
1213 g_assert(endptr == str + strlen(str));
1215 str = "123";
1216 res = 999;
1217 endptr = &f;
1218 err = qemu_strtoul(str, &endptr, 0, &res);
1220 g_assert_cmpint(err, ==, 0);
1221 g_assert_cmpuint(res, ==, 123);
1222 g_assert(endptr == str + strlen(str));
1225 static void test_qemu_strtoul_hex(void)
1227 const char *str = "0123";
1228 char f = 'X';
1229 const char *endptr = &f;
1230 unsigned long res = 999;
1231 int err;
1233 err = qemu_strtoul(str, &endptr, 16, &res);
1235 g_assert_cmpint(err, ==, 0);
1236 g_assert_cmphex(res, ==, 0x123);
1237 g_assert(endptr == str + strlen(str));
1239 str = "0x123";
1240 res = 999;
1241 endptr = &f;
1242 err = qemu_strtoul(str, &endptr, 0, &res);
1244 g_assert_cmpint(err, ==, 0);
1245 g_assert_cmphex(res, ==, 0x123);
1246 g_assert(endptr == str + strlen(str));
1249 static void test_qemu_strtoul_max(void)
1251 char *str = g_strdup_printf("%lu", ULONG_MAX);
1252 char f = 'X';
1253 const char *endptr = &f;
1254 unsigned long res = 999;
1255 int err;
1257 err = qemu_strtoul(str, &endptr, 0, &res);
1259 g_assert_cmpint(err, ==, 0);
1260 g_assert_cmphex(res, ==, ULONG_MAX);
1261 g_assert(endptr == str + strlen(str));
1262 g_free(str);
1265 static void test_qemu_strtoul_overflow(void)
1267 const char *str = "99999999999999999999999999999999999999999999";
1268 char f = 'X';
1269 const char *endptr = &f;
1270 unsigned long res = 999;
1271 int err;
1273 err = qemu_strtoul(str, &endptr, 0, &res);
1275 g_assert_cmpint(err, ==, -ERANGE);
1276 g_assert_cmphex(res, ==, ULONG_MAX);
1277 g_assert(endptr == str + strlen(str));
1280 static void test_qemu_strtoul_underflow(void)
1282 const char *str = "-99999999999999999999999999999999999999999999";
1283 char f = 'X';
1284 const char *endptr = &f;
1285 unsigned long res = 999;
1286 int err;
1288 err = qemu_strtoul(str, &endptr, 0, &res);
1290 g_assert_cmpint(err, ==, -ERANGE);
1291 g_assert_cmpuint(res, ==, -1ul);
1292 g_assert(endptr == str + strlen(str));
1295 static void test_qemu_strtoul_negative(void)
1297 const char *str = " \t -321";
1298 char f = 'X';
1299 const char *endptr = &f;
1300 unsigned long res = 999;
1301 int err;
1303 err = qemu_strtoul(str, &endptr, 0, &res);
1305 g_assert_cmpint(err, ==, 0);
1306 g_assert_cmpuint(res, ==, -321ul);
1307 g_assert(endptr == str + strlen(str));
1310 static void test_qemu_strtoul_full_correct(void)
1312 const char *str = "123";
1313 unsigned long res = 999;
1314 int err;
1316 err = qemu_strtoul(str, NULL, 0, &res);
1318 g_assert_cmpint(err, ==, 0);
1319 g_assert_cmpuint(res, ==, 123);
1322 static void test_qemu_strtoul_full_null(void)
1324 unsigned long res = 999;
1325 int err;
1327 err = qemu_strtoul(NULL, NULL, 0, &res);
1329 g_assert_cmpint(err, ==, -EINVAL);
1332 static void test_qemu_strtoul_full_empty(void)
1334 const char *str = "";
1335 unsigned long res = 999;
1336 int err;
1338 err = qemu_strtoul(str, NULL, 0, &res);
1340 g_assert_cmpint(err, ==, -EINVAL);
1342 static void test_qemu_strtoul_full_negative(void)
1344 const char *str = " \t -321";
1345 unsigned long res = 999;
1346 int err;
1348 err = qemu_strtoul(str, NULL, 0, &res);
1349 g_assert_cmpint(err, ==, 0);
1350 g_assert_cmpuint(res, ==, -321ul);
1353 static void test_qemu_strtoul_full_trailing(void)
1355 const char *str = "123xxx";
1356 unsigned long res;
1357 int err;
1359 err = qemu_strtoul(str, NULL, 0, &res);
1361 g_assert_cmpint(err, ==, -EINVAL);
1364 static void test_qemu_strtoul_full_max(void)
1366 char *str = g_strdup_printf("%lu", ULONG_MAX);
1367 unsigned long res = 999;
1368 int err;
1370 err = qemu_strtoul(str, NULL, 0, &res);
1372 g_assert_cmpint(err, ==, 0);
1373 g_assert_cmphex(res, ==, ULONG_MAX);
1374 g_free(str);
1377 static void test_qemu_strtoi64_correct(void)
1379 const char *str = "12345 foo";
1380 char f = 'X';
1381 const char *endptr = &f;
1382 int64_t res = 999;
1383 int err;
1385 err = qemu_strtoi64(str, &endptr, 0, &res);
1387 g_assert_cmpint(err, ==, 0);
1388 g_assert_cmpint(res, ==, 12345);
1389 g_assert(endptr == str + 5);
1392 static void test_qemu_strtoi64_null(void)
1394 char f = 'X';
1395 const char *endptr = &f;
1396 int64_t res = 999;
1397 int err;
1399 err = qemu_strtoi64(NULL, &endptr, 0, &res);
1401 g_assert_cmpint(err, ==, -EINVAL);
1402 g_assert(endptr == NULL);
1405 static void test_qemu_strtoi64_empty(void)
1407 const char *str = "";
1408 char f = 'X';
1409 const char *endptr = &f;
1410 int64_t res = 999;
1411 int err;
1413 err = qemu_strtoi64(str, &endptr, 0, &res);
1415 g_assert_cmpint(err, ==, -EINVAL);
1416 g_assert(endptr == str);
1419 static void test_qemu_strtoi64_whitespace(void)
1421 const char *str = " \t ";
1422 char f = 'X';
1423 const char *endptr = &f;
1424 int64_t res = 999;
1425 int err;
1427 err = qemu_strtoi64(str, &endptr, 0, &res);
1429 g_assert_cmpint(err, ==, -EINVAL);
1430 g_assert(endptr == str);
1433 static void test_qemu_strtoi64_invalid(void)
1435 const char *str = " xxxx \t abc";
1436 char f = 'X';
1437 const char *endptr = &f;
1438 int64_t res = 999;
1439 int err;
1441 err = qemu_strtoi64(str, &endptr, 0, &res);
1443 g_assert_cmpint(err, ==, -EINVAL);
1444 g_assert(endptr == str);
1447 static void test_qemu_strtoi64_trailing(void)
1449 const char *str = "123xxx";
1450 char f = 'X';
1451 const char *endptr = &f;
1452 int64_t res = 999;
1453 int err;
1455 err = qemu_strtoi64(str, &endptr, 0, &res);
1457 g_assert_cmpint(err, ==, 0);
1458 g_assert_cmpint(res, ==, 123);
1459 g_assert(endptr == str + 3);
1462 static void test_qemu_strtoi64_octal(void)
1464 const char *str = "0123";
1465 char f = 'X';
1466 const char *endptr = &f;
1467 int64_t res = 999;
1468 int err;
1470 err = qemu_strtoi64(str, &endptr, 8, &res);
1472 g_assert_cmpint(err, ==, 0);
1473 g_assert_cmpint(res, ==, 0123);
1474 g_assert(endptr == str + strlen(str));
1476 endptr = &f;
1477 res = 999;
1478 err = qemu_strtoi64(str, &endptr, 0, &res);
1480 g_assert_cmpint(err, ==, 0);
1481 g_assert_cmpint(res, ==, 0123);
1482 g_assert(endptr == str + strlen(str));
1485 static void test_qemu_strtoi64_decimal(void)
1487 const char *str = "0123";
1488 char f = 'X';
1489 const char *endptr = &f;
1490 int64_t res = 999;
1491 int err;
1493 err = qemu_strtoi64(str, &endptr, 10, &res);
1495 g_assert_cmpint(err, ==, 0);
1496 g_assert_cmpint(res, ==, 123);
1497 g_assert(endptr == str + strlen(str));
1499 str = "123";
1500 endptr = &f;
1501 res = 999;
1502 err = qemu_strtoi64(str, &endptr, 0, &res);
1504 g_assert_cmpint(err, ==, 0);
1505 g_assert_cmpint(res, ==, 123);
1506 g_assert(endptr == str + strlen(str));
1509 static void test_qemu_strtoi64_hex(void)
1511 const char *str = "0123";
1512 char f = 'X';
1513 const char *endptr = &f;
1514 int64_t res = 999;
1515 int err;
1517 err = qemu_strtoi64(str, &endptr, 16, &res);
1519 g_assert_cmpint(err, ==, 0);
1520 g_assert_cmpint(res, ==, 0x123);
1521 g_assert(endptr == str + strlen(str));
1523 str = "0x123";
1524 endptr = &f;
1525 res = 999;
1526 err = qemu_strtoi64(str, &endptr, 0, &res);
1528 g_assert_cmpint(err, ==, 0);
1529 g_assert_cmpint(res, ==, 0x123);
1530 g_assert(endptr == str + strlen(str));
1533 static void test_qemu_strtoi64_max(void)
1535 char *str = g_strdup_printf("%lld", LLONG_MAX);
1536 char f = 'X';
1537 const char *endptr = &f;
1538 int64_t res = 999;
1539 int err;
1541 err = qemu_strtoi64(str, &endptr, 0, &res);
1543 g_assert_cmpint(err, ==, 0);
1544 g_assert_cmpint(res, ==, LLONG_MAX);
1545 g_assert(endptr == str + strlen(str));
1546 g_free(str);
1549 static void test_qemu_strtoi64_overflow(void)
1551 const char *str = "99999999999999999999999999999999999999999999";
1552 char f = 'X';
1553 const char *endptr = &f;
1554 int64_t res = 999;
1555 int err;
1557 err = qemu_strtoi64(str, &endptr, 0, &res);
1559 g_assert_cmpint(err, ==, -ERANGE);
1560 g_assert_cmpint(res, ==, LLONG_MAX);
1561 g_assert(endptr == str + strlen(str));
1564 static void test_qemu_strtoi64_underflow(void)
1566 const char *str = "-99999999999999999999999999999999999999999999";
1567 char f = 'X';
1568 const char *endptr = &f;
1569 int64_t res = 999;
1570 int err;
1572 err = qemu_strtoi64(str, &endptr, 0, &res);
1574 g_assert_cmpint(err, ==, -ERANGE);
1575 g_assert_cmpint(res, ==, LLONG_MIN);
1576 g_assert(endptr == str + strlen(str));
1579 static void test_qemu_strtoi64_negative(void)
1581 const char *str = " \t -321";
1582 char f = 'X';
1583 const char *endptr = &f;
1584 int64_t res = 999;
1585 int err;
1587 err = qemu_strtoi64(str, &endptr, 0, &res);
1589 g_assert_cmpint(err, ==, 0);
1590 g_assert_cmpint(res, ==, -321);
1591 g_assert(endptr == str + strlen(str));
1594 static void test_qemu_strtoi64_full_correct(void)
1596 const char *str = "123";
1597 int64_t res = 999;
1598 int err;
1600 err = qemu_strtoi64(str, NULL, 0, &res);
1602 g_assert_cmpint(err, ==, 0);
1603 g_assert_cmpint(res, ==, 123);
1606 static void test_qemu_strtoi64_full_null(void)
1608 int64_t res = 999;
1609 int err;
1611 err = qemu_strtoi64(NULL, NULL, 0, &res);
1613 g_assert_cmpint(err, ==, -EINVAL);
1616 static void test_qemu_strtoi64_full_empty(void)
1618 const char *str = "";
1619 int64_t res = 999;
1620 int err;
1622 err = qemu_strtoi64(str, NULL, 0, &res);
1624 g_assert_cmpint(err, ==, -EINVAL);
1627 static void test_qemu_strtoi64_full_negative(void)
1629 const char *str = " \t -321";
1630 int64_t res = 999;
1631 int err;
1633 err = qemu_strtoi64(str, NULL, 0, &res);
1635 g_assert_cmpint(err, ==, 0);
1636 g_assert_cmpint(res, ==, -321);
1639 static void test_qemu_strtoi64_full_trailing(void)
1641 const char *str = "123xxx";
1642 int64_t res = 999;
1643 int err;
1645 err = qemu_strtoi64(str, NULL, 0, &res);
1647 g_assert_cmpint(err, ==, -EINVAL);
1650 static void test_qemu_strtoi64_full_max(void)
1653 char *str = g_strdup_printf("%lld", LLONG_MAX);
1654 int64_t res;
1655 int err;
1657 err = qemu_strtoi64(str, NULL, 0, &res);
1659 g_assert_cmpint(err, ==, 0);
1660 g_assert_cmpint(res, ==, LLONG_MAX);
1661 g_free(str);
1664 static void test_qemu_strtou64_correct(void)
1666 const char *str = "12345 foo";
1667 char f = 'X';
1668 const char *endptr = &f;
1669 uint64_t res = 999;
1670 int err;
1672 err = qemu_strtou64(str, &endptr, 0, &res);
1674 g_assert_cmpint(err, ==, 0);
1675 g_assert_cmpuint(res, ==, 12345);
1676 g_assert(endptr == str + 5);
1679 static void test_qemu_strtou64_null(void)
1681 char f = 'X';
1682 const char *endptr = &f;
1683 uint64_t res = 999;
1684 int err;
1686 err = qemu_strtou64(NULL, &endptr, 0, &res);
1688 g_assert_cmpint(err, ==, -EINVAL);
1689 g_assert(endptr == NULL);
1692 static void test_qemu_strtou64_empty(void)
1694 const char *str = "";
1695 char f = 'X';
1696 const char *endptr = &f;
1697 uint64_t res = 999;
1698 int err;
1700 err = qemu_strtou64(str, &endptr, 0, &res);
1702 g_assert_cmpint(err, ==, -EINVAL);
1703 g_assert(endptr == str);
1706 static void test_qemu_strtou64_whitespace(void)
1708 const char *str = " \t ";
1709 char f = 'X';
1710 const char *endptr = &f;
1711 uint64_t res = 999;
1712 int err;
1714 err = qemu_strtou64(str, &endptr, 0, &res);
1716 g_assert_cmpint(err, ==, -EINVAL);
1717 g_assert(endptr == str);
1720 static void test_qemu_strtou64_invalid(void)
1722 const char *str = " xxxx \t abc";
1723 char f = 'X';
1724 const char *endptr = &f;
1725 uint64_t res = 999;
1726 int err;
1728 err = qemu_strtou64(str, &endptr, 0, &res);
1730 g_assert_cmpint(err, ==, -EINVAL);
1731 g_assert(endptr == str);
1734 static void test_qemu_strtou64_trailing(void)
1736 const char *str = "123xxx";
1737 char f = 'X';
1738 const char *endptr = &f;
1739 uint64_t res = 999;
1740 int err;
1742 err = qemu_strtou64(str, &endptr, 0, &res);
1744 g_assert_cmpint(err, ==, 0);
1745 g_assert_cmpuint(res, ==, 123);
1746 g_assert(endptr == str + 3);
1749 static void test_qemu_strtou64_octal(void)
1751 const char *str = "0123";
1752 char f = 'X';
1753 const char *endptr = &f;
1754 uint64_t res = 999;
1755 int err;
1757 err = qemu_strtou64(str, &endptr, 8, &res);
1759 g_assert_cmpint(err, ==, 0);
1760 g_assert_cmpuint(res, ==, 0123);
1761 g_assert(endptr == str + strlen(str));
1763 endptr = &f;
1764 res = 999;
1765 err = qemu_strtou64(str, &endptr, 0, &res);
1767 g_assert_cmpint(err, ==, 0);
1768 g_assert_cmpuint(res, ==, 0123);
1769 g_assert(endptr == str + strlen(str));
1772 static void test_qemu_strtou64_decimal(void)
1774 const char *str = "0123";
1775 char f = 'X';
1776 const char *endptr = &f;
1777 uint64_t res = 999;
1778 int err;
1780 err = qemu_strtou64(str, &endptr, 10, &res);
1782 g_assert_cmpint(err, ==, 0);
1783 g_assert_cmpuint(res, ==, 123);
1784 g_assert(endptr == str + strlen(str));
1786 str = "123";
1787 endptr = &f;
1788 res = 999;
1789 err = qemu_strtou64(str, &endptr, 0, &res);
1791 g_assert_cmpint(err, ==, 0);
1792 g_assert_cmpuint(res, ==, 123);
1793 g_assert(endptr == str + strlen(str));
1796 static void test_qemu_strtou64_hex(void)
1798 const char *str = "0123";
1799 char f = 'X';
1800 const char *endptr = &f;
1801 uint64_t res = 999;
1802 int err;
1804 err = qemu_strtou64(str, &endptr, 16, &res);
1806 g_assert_cmpint(err, ==, 0);
1807 g_assert_cmphex(res, ==, 0x123);
1808 g_assert(endptr == str + strlen(str));
1810 str = "0x123";
1811 endptr = &f;
1812 res = 999;
1813 err = qemu_strtou64(str, &endptr, 0, &res);
1815 g_assert_cmpint(err, ==, 0);
1816 g_assert_cmphex(res, ==, 0x123);
1817 g_assert(endptr == str + strlen(str));
1820 static void test_qemu_strtou64_max(void)
1822 char *str = g_strdup_printf("%llu", ULLONG_MAX);
1823 char f = 'X';
1824 const char *endptr = &f;
1825 uint64_t res = 999;
1826 int err;
1828 err = qemu_strtou64(str, &endptr, 0, &res);
1830 g_assert_cmpint(err, ==, 0);
1831 g_assert_cmphex(res, ==, ULLONG_MAX);
1832 g_assert(endptr == str + strlen(str));
1833 g_free(str);
1836 static void test_qemu_strtou64_overflow(void)
1838 const char *str = "99999999999999999999999999999999999999999999";
1839 char f = 'X';
1840 const char *endptr = &f;
1841 uint64_t res = 999;
1842 int err;
1844 err = qemu_strtou64(str, &endptr, 0, &res);
1846 g_assert_cmpint(err, ==, -ERANGE);
1847 g_assert_cmphex(res, ==, ULLONG_MAX);
1848 g_assert(endptr == str + strlen(str));
1851 static void test_qemu_strtou64_underflow(void)
1853 const char *str = "-99999999999999999999999999999999999999999999";
1854 char f = 'X';
1855 const char *endptr = &f;
1856 uint64_t res = 999;
1857 int err;
1859 err = qemu_strtou64(str, &endptr, 0, &res);
1861 g_assert_cmpint(err, ==, -ERANGE);
1862 g_assert_cmphex(res, ==, -1ull);
1863 g_assert(endptr == str + strlen(str));
1866 static void test_qemu_strtou64_negative(void)
1868 const char *str = " \t -321";
1869 char f = 'X';
1870 const char *endptr = &f;
1871 uint64_t res = 999;
1872 int err;
1874 err = qemu_strtou64(str, &endptr, 0, &res);
1876 g_assert_cmpint(err, ==, 0);
1877 g_assert_cmpuint(res, ==, -321ull);
1878 g_assert(endptr == str + strlen(str));
1881 static void test_qemu_strtou64_full_correct(void)
1883 const char *str = "18446744073709551614";
1884 uint64_t res = 999;
1885 int err;
1887 err = qemu_strtou64(str, NULL, 0, &res);
1889 g_assert_cmpint(err, ==, 0);
1890 g_assert_cmpuint(res, ==, 18446744073709551614ull);
1893 static void test_qemu_strtou64_full_null(void)
1895 uint64_t res = 999;
1896 int err;
1898 err = qemu_strtou64(NULL, NULL, 0, &res);
1900 g_assert_cmpint(err, ==, -EINVAL);
1903 static void test_qemu_strtou64_full_empty(void)
1905 const char *str = "";
1906 uint64_t res = 999;
1907 int err;
1909 err = qemu_strtou64(str, NULL, 0, &res);
1911 g_assert_cmpint(err, ==, -EINVAL);
1914 static void test_qemu_strtou64_full_negative(void)
1916 const char *str = " \t -321";
1917 uint64_t res = 999;
1918 int err;
1920 err = qemu_strtou64(str, NULL, 0, &res);
1922 g_assert_cmpint(err, ==, 0);
1923 g_assert_cmpuint(res, ==, -321ull);
1926 static void test_qemu_strtou64_full_trailing(void)
1928 const char *str = "18446744073709551614xxxxxx";
1929 uint64_t res = 999;
1930 int err;
1932 err = qemu_strtou64(str, NULL, 0, &res);
1934 g_assert_cmpint(err, ==, -EINVAL);
1937 static void test_qemu_strtou64_full_max(void)
1939 char *str = g_strdup_printf("%lld", ULLONG_MAX);
1940 uint64_t res = 999;
1941 int err;
1943 err = qemu_strtou64(str, NULL, 0, &res);
1945 g_assert_cmpint(err, ==, 0);
1946 g_assert_cmphex(res, ==, ULLONG_MAX);
1947 g_free(str);
1950 static void test_qemu_strtosz_simple(void)
1952 const char *str;
1953 const char *endptr;
1954 int err;
1955 uint64_t res = 0xbaadf00d;
1957 str = "0";
1958 err = qemu_strtosz(str, &endptr, &res);
1959 g_assert_cmpint(err, ==, 0);
1960 g_assert_cmpint(res, ==, 0);
1961 g_assert(endptr == str + 1);
1963 str = "12345";
1964 err = qemu_strtosz(str, &endptr, &res);
1965 g_assert_cmpint(err, ==, 0);
1966 g_assert_cmpint(res, ==, 12345);
1967 g_assert(endptr == str + 5);
1969 err = qemu_strtosz(str, NULL, &res);
1970 g_assert_cmpint(err, ==, 0);
1971 g_assert_cmpint(res, ==, 12345);
1973 /* Note: precision is 53 bits since we're parsing with strtod() */
1975 str = "9007199254740991"; /* 2^53-1 */
1976 err = qemu_strtosz(str, &endptr, &res);
1977 g_assert_cmpint(err, ==, 0);
1978 g_assert_cmpint(res, ==, 0x1fffffffffffff);
1979 g_assert(endptr == str + 16);
1981 str = "9007199254740992"; /* 2^53 */
1982 err = qemu_strtosz(str, &endptr, &res);
1983 g_assert_cmpint(err, ==, 0);
1984 g_assert_cmpint(res, ==, 0x20000000000000);
1985 g_assert(endptr == str + 16);
1987 str = "9007199254740993"; /* 2^53+1 */
1988 err = qemu_strtosz(str, &endptr, &res);
1989 g_assert_cmpint(err, ==, 0);
1990 g_assert_cmpint(res, ==, 0x20000000000000); /* rounded to 53 bits */
1991 g_assert(endptr == str + 16);
1993 str = "18446744073709549568"; /* 0xfffffffffffff800 (53 msbs set) */
1994 err = qemu_strtosz(str, &endptr, &res);
1995 g_assert_cmpint(err, ==, 0);
1996 g_assert_cmpint(res, ==, 0xfffffffffffff800);
1997 g_assert(endptr == str + 20);
1999 str = "18446744073709550591"; /* 0xfffffffffffffbff */
2000 err = qemu_strtosz(str, &endptr, &res);
2001 g_assert_cmpint(err, ==, 0);
2002 g_assert_cmpint(res, ==, 0xfffffffffffff800); /* rounded to 53 bits */
2003 g_assert(endptr == str + 20);
2005 /* 0x7ffffffffffffe00..0x7fffffffffffffff get rounded to
2006 * 0x8000000000000000, thus -ERANGE; see test_qemu_strtosz_erange() */
2009 static void test_qemu_strtosz_units(void)
2011 const char *none = "1";
2012 const char *b = "1B";
2013 const char *k = "1K";
2014 const char *m = "1M";
2015 const char *g = "1G";
2016 const char *t = "1T";
2017 const char *p = "1P";
2018 const char *e = "1E";
2019 int err;
2020 const char *endptr;
2021 uint64_t res = 0xbaadf00d;
2023 /* default is M */
2024 err = qemu_strtosz_MiB(none, &endptr, &res);
2025 g_assert_cmpint(err, ==, 0);
2026 g_assert_cmpint(res, ==, MiB);
2027 g_assert(endptr == none + 1);
2029 err = qemu_strtosz(b, &endptr, &res);
2030 g_assert_cmpint(err, ==, 0);
2031 g_assert_cmpint(res, ==, 1);
2032 g_assert(endptr == b + 2);
2034 err = qemu_strtosz(k, &endptr, &res);
2035 g_assert_cmpint(err, ==, 0);
2036 g_assert_cmpint(res, ==, KiB);
2037 g_assert(endptr == k + 2);
2039 err = qemu_strtosz(m, &endptr, &res);
2040 g_assert_cmpint(err, ==, 0);
2041 g_assert_cmpint(res, ==, MiB);
2042 g_assert(endptr == m + 2);
2044 err = qemu_strtosz(g, &endptr, &res);
2045 g_assert_cmpint(err, ==, 0);
2046 g_assert_cmpint(res, ==, GiB);
2047 g_assert(endptr == g + 2);
2049 err = qemu_strtosz(t, &endptr, &res);
2050 g_assert_cmpint(err, ==, 0);
2051 g_assert_cmpint(res, ==, TiB);
2052 g_assert(endptr == t + 2);
2054 err = qemu_strtosz(p, &endptr, &res);
2055 g_assert_cmpint(err, ==, 0);
2056 g_assert_cmpint(res, ==, PiB);
2057 g_assert(endptr == p + 2);
2059 err = qemu_strtosz(e, &endptr, &res);
2060 g_assert_cmpint(err, ==, 0);
2061 g_assert_cmpint(res, ==, EiB);
2062 g_assert(endptr == e + 2);
2065 static void test_qemu_strtosz_float(void)
2067 const char *str = "12.345M";
2068 int err;
2069 const char *endptr;
2070 uint64_t res = 0xbaadf00d;
2072 err = qemu_strtosz(str, &endptr, &res);
2073 g_assert_cmpint(err, ==, 0);
2074 g_assert_cmpint(res, ==, 12.345 * MiB);
2075 g_assert(endptr == str + 7);
2078 static void test_qemu_strtosz_invalid(void)
2080 const char *str;
2081 const char *endptr;
2082 int err;
2083 uint64_t res = 0xbaadf00d;
2085 str = "";
2086 err = qemu_strtosz(str, &endptr, &res);
2087 g_assert_cmpint(err, ==, -EINVAL);
2088 g_assert(endptr == str);
2090 str = " \t ";
2091 err = qemu_strtosz(str, &endptr, &res);
2092 g_assert_cmpint(err, ==, -EINVAL);
2093 g_assert(endptr == str);
2095 str = "crap";
2096 err = qemu_strtosz(str, &endptr, &res);
2097 g_assert_cmpint(err, ==, -EINVAL);
2098 g_assert(endptr == str);
2100 str = "inf";
2101 err = qemu_strtosz(str, &endptr, &res);
2102 g_assert_cmpint(err, ==, -EINVAL);
2103 g_assert(endptr == str);
2105 str = "NaN";
2106 err = qemu_strtosz(str, &endptr, &res);
2107 g_assert_cmpint(err, ==, -EINVAL);
2108 g_assert(endptr == str);
2111 static void test_qemu_strtosz_trailing(void)
2113 const char *str;
2114 const char *endptr;
2115 int err;
2116 uint64_t res = 0xbaadf00d;
2118 str = "123xxx";
2119 err = qemu_strtosz_MiB(str, &endptr, &res);
2120 g_assert_cmpint(res, ==, 123 * MiB);
2121 g_assert(endptr == str + 3);
2123 err = qemu_strtosz(str, NULL, &res);
2124 g_assert_cmpint(err, ==, -EINVAL);
2126 str = "1kiB";
2127 err = qemu_strtosz(str, &endptr, &res);
2128 g_assert_cmpint(err, ==, 0);
2129 g_assert_cmpint(res, ==, 1024);
2130 g_assert(endptr == str + 2);
2132 err = qemu_strtosz(str, NULL, &res);
2133 g_assert_cmpint(err, ==, -EINVAL);
2136 static void test_qemu_strtosz_erange(void)
2138 const char *str;
2139 const char *endptr;
2140 int err;
2141 uint64_t res = 0xbaadf00d;
2143 str = "-1";
2144 err = qemu_strtosz(str, &endptr, &res);
2145 g_assert_cmpint(err, ==, -ERANGE);
2146 g_assert(endptr == str + 2);
2148 str = "18446744073709550592"; /* 0xfffffffffffffc00 */
2149 err = qemu_strtosz(str, &endptr, &res);
2150 g_assert_cmpint(err, ==, -ERANGE);
2151 g_assert(endptr == str + 20);
2153 str = "18446744073709551615"; /* 2^64-1 */
2154 err = qemu_strtosz(str, &endptr, &res);
2155 g_assert_cmpint(err, ==, -ERANGE);
2156 g_assert(endptr == str + 20);
2158 str = "18446744073709551616"; /* 2^64 */
2159 err = qemu_strtosz(str, &endptr, &res);
2160 g_assert_cmpint(err, ==, -ERANGE);
2161 g_assert(endptr == str + 20);
2163 str = "20E";
2164 err = qemu_strtosz(str, &endptr, &res);
2165 g_assert_cmpint(err, ==, -ERANGE);
2166 g_assert(endptr == str + 3);
2169 static void test_qemu_strtosz_metric(void)
2171 const char *str = "12345k";
2172 int err;
2173 const char *endptr;
2174 uint64_t res = 0xbaadf00d;
2176 err = qemu_strtosz_metric(str, &endptr, &res);
2177 g_assert_cmpint(err, ==, 0);
2178 g_assert_cmpint(res, ==, 12345000);
2179 g_assert(endptr == str + 6);
2182 int main(int argc, char **argv)
2184 g_test_init(&argc, &argv, NULL);
2186 g_test_add_func("/cutils/parse_uint/null", test_parse_uint_null);
2187 g_test_add_func("/cutils/parse_uint/empty", test_parse_uint_empty);
2188 g_test_add_func("/cutils/parse_uint/whitespace",
2189 test_parse_uint_whitespace);
2190 g_test_add_func("/cutils/parse_uint/invalid", test_parse_uint_invalid);
2191 g_test_add_func("/cutils/parse_uint/trailing", test_parse_uint_trailing);
2192 g_test_add_func("/cutils/parse_uint/correct", test_parse_uint_correct);
2193 g_test_add_func("/cutils/parse_uint/octal", test_parse_uint_octal);
2194 g_test_add_func("/cutils/parse_uint/decimal", test_parse_uint_decimal);
2195 g_test_add_func("/cutils/parse_uint/llong_max", test_parse_uint_llong_max);
2196 g_test_add_func("/cutils/parse_uint/overflow", test_parse_uint_overflow);
2197 g_test_add_func("/cutils/parse_uint/negative", test_parse_uint_negative);
2198 g_test_add_func("/cutils/parse_uint_full/trailing",
2199 test_parse_uint_full_trailing);
2200 g_test_add_func("/cutils/parse_uint_full/correct",
2201 test_parse_uint_full_correct);
2203 /* qemu_strtoi() tests */
2204 g_test_add_func("/cutils/qemu_strtoi/correct",
2205 test_qemu_strtoi_correct);
2206 g_test_add_func("/cutils/qemu_strtoi/null",
2207 test_qemu_strtoi_null);
2208 g_test_add_func("/cutils/qemu_strtoi/empty",
2209 test_qemu_strtoi_empty);
2210 g_test_add_func("/cutils/qemu_strtoi/whitespace",
2211 test_qemu_strtoi_whitespace);
2212 g_test_add_func("/cutils/qemu_strtoi/invalid",
2213 test_qemu_strtoi_invalid);
2214 g_test_add_func("/cutils/qemu_strtoi/trailing",
2215 test_qemu_strtoi_trailing);
2216 g_test_add_func("/cutils/qemu_strtoi/octal",
2217 test_qemu_strtoi_octal);
2218 g_test_add_func("/cutils/qemu_strtoi/decimal",
2219 test_qemu_strtoi_decimal);
2220 g_test_add_func("/cutils/qemu_strtoi/hex",
2221 test_qemu_strtoi_hex);
2222 g_test_add_func("/cutils/qemu_strtoi/max",
2223 test_qemu_strtoi_max);
2224 g_test_add_func("/cutils/qemu_strtoi/overflow",
2225 test_qemu_strtoi_overflow);
2226 g_test_add_func("/cutils/qemu_strtoi/underflow",
2227 test_qemu_strtoi_underflow);
2228 g_test_add_func("/cutils/qemu_strtoi/negative",
2229 test_qemu_strtoi_negative);
2230 g_test_add_func("/cutils/qemu_strtoi_full/correct",
2231 test_qemu_strtoi_full_correct);
2232 g_test_add_func("/cutils/qemu_strtoi_full/null",
2233 test_qemu_strtoi_full_null);
2234 g_test_add_func("/cutils/qemu_strtoi_full/empty",
2235 test_qemu_strtoi_full_empty);
2236 g_test_add_func("/cutils/qemu_strtoi_full/negative",
2237 test_qemu_strtoi_full_negative);
2238 g_test_add_func("/cutils/qemu_strtoi_full/trailing",
2239 test_qemu_strtoi_full_trailing);
2240 g_test_add_func("/cutils/qemu_strtoi_full/max",
2241 test_qemu_strtoi_full_max);
2243 /* qemu_strtoui() tests */
2244 g_test_add_func("/cutils/qemu_strtoui/correct",
2245 test_qemu_strtoui_correct);
2246 g_test_add_func("/cutils/qemu_strtoui/null",
2247 test_qemu_strtoui_null);
2248 g_test_add_func("/cutils/qemu_strtoui/empty",
2249 test_qemu_strtoui_empty);
2250 g_test_add_func("/cutils/qemu_strtoui/whitespace",
2251 test_qemu_strtoui_whitespace);
2252 g_test_add_func("/cutils/qemu_strtoui/invalid",
2253 test_qemu_strtoui_invalid);
2254 g_test_add_func("/cutils/qemu_strtoui/trailing",
2255 test_qemu_strtoui_trailing);
2256 g_test_add_func("/cutils/qemu_strtoui/octal",
2257 test_qemu_strtoui_octal);
2258 g_test_add_func("/cutils/qemu_strtoui/decimal",
2259 test_qemu_strtoui_decimal);
2260 g_test_add_func("/cutils/qemu_strtoui/hex",
2261 test_qemu_strtoui_hex);
2262 g_test_add_func("/cutils/qemu_strtoui/max",
2263 test_qemu_strtoui_max);
2264 g_test_add_func("/cutils/qemu_strtoui/overflow",
2265 test_qemu_strtoui_overflow);
2266 g_test_add_func("/cutils/qemu_strtoui/underflow",
2267 test_qemu_strtoui_underflow);
2268 g_test_add_func("/cutils/qemu_strtoui/negative",
2269 test_qemu_strtoui_negative);
2270 g_test_add_func("/cutils/qemu_strtoui_full/correct",
2271 test_qemu_strtoui_full_correct);
2272 g_test_add_func("/cutils/qemu_strtoui_full/null",
2273 test_qemu_strtoui_full_null);
2274 g_test_add_func("/cutils/qemu_strtoui_full/empty",
2275 test_qemu_strtoui_full_empty);
2276 g_test_add_func("/cutils/qemu_strtoui_full/negative",
2277 test_qemu_strtoui_full_negative);
2278 g_test_add_func("/cutils/qemu_strtoui_full/trailing",
2279 test_qemu_strtoui_full_trailing);
2280 g_test_add_func("/cutils/qemu_strtoui_full/max",
2281 test_qemu_strtoui_full_max);
2283 /* qemu_strtol() tests */
2284 g_test_add_func("/cutils/qemu_strtol/correct",
2285 test_qemu_strtol_correct);
2286 g_test_add_func("/cutils/qemu_strtol/null",
2287 test_qemu_strtol_null);
2288 g_test_add_func("/cutils/qemu_strtol/empty",
2289 test_qemu_strtol_empty);
2290 g_test_add_func("/cutils/qemu_strtol/whitespace",
2291 test_qemu_strtol_whitespace);
2292 g_test_add_func("/cutils/qemu_strtol/invalid",
2293 test_qemu_strtol_invalid);
2294 g_test_add_func("/cutils/qemu_strtol/trailing",
2295 test_qemu_strtol_trailing);
2296 g_test_add_func("/cutils/qemu_strtol/octal",
2297 test_qemu_strtol_octal);
2298 g_test_add_func("/cutils/qemu_strtol/decimal",
2299 test_qemu_strtol_decimal);
2300 g_test_add_func("/cutils/qemu_strtol/hex",
2301 test_qemu_strtol_hex);
2302 g_test_add_func("/cutils/qemu_strtol/max",
2303 test_qemu_strtol_max);
2304 g_test_add_func("/cutils/qemu_strtol/overflow",
2305 test_qemu_strtol_overflow);
2306 g_test_add_func("/cutils/qemu_strtol/underflow",
2307 test_qemu_strtol_underflow);
2308 g_test_add_func("/cutils/qemu_strtol/negative",
2309 test_qemu_strtol_negative);
2310 g_test_add_func("/cutils/qemu_strtol_full/correct",
2311 test_qemu_strtol_full_correct);
2312 g_test_add_func("/cutils/qemu_strtol_full/null",
2313 test_qemu_strtol_full_null);
2314 g_test_add_func("/cutils/qemu_strtol_full/empty",
2315 test_qemu_strtol_full_empty);
2316 g_test_add_func("/cutils/qemu_strtol_full/negative",
2317 test_qemu_strtol_full_negative);
2318 g_test_add_func("/cutils/qemu_strtol_full/trailing",
2319 test_qemu_strtol_full_trailing);
2320 g_test_add_func("/cutils/qemu_strtol_full/max",
2321 test_qemu_strtol_full_max);
2323 /* qemu_strtoul() tests */
2324 g_test_add_func("/cutils/qemu_strtoul/correct",
2325 test_qemu_strtoul_correct);
2326 g_test_add_func("/cutils/qemu_strtoul/null",
2327 test_qemu_strtoul_null);
2328 g_test_add_func("/cutils/qemu_strtoul/empty",
2329 test_qemu_strtoul_empty);
2330 g_test_add_func("/cutils/qemu_strtoul/whitespace",
2331 test_qemu_strtoul_whitespace);
2332 g_test_add_func("/cutils/qemu_strtoul/invalid",
2333 test_qemu_strtoul_invalid);
2334 g_test_add_func("/cutils/qemu_strtoul/trailing",
2335 test_qemu_strtoul_trailing);
2336 g_test_add_func("/cutils/qemu_strtoul/octal",
2337 test_qemu_strtoul_octal);
2338 g_test_add_func("/cutils/qemu_strtoul/decimal",
2339 test_qemu_strtoul_decimal);
2340 g_test_add_func("/cutils/qemu_strtoul/hex",
2341 test_qemu_strtoul_hex);
2342 g_test_add_func("/cutils/qemu_strtoul/max",
2343 test_qemu_strtoul_max);
2344 g_test_add_func("/cutils/qemu_strtoul/overflow",
2345 test_qemu_strtoul_overflow);
2346 g_test_add_func("/cutils/qemu_strtoul/underflow",
2347 test_qemu_strtoul_underflow);
2348 g_test_add_func("/cutils/qemu_strtoul/negative",
2349 test_qemu_strtoul_negative);
2350 g_test_add_func("/cutils/qemu_strtoul_full/correct",
2351 test_qemu_strtoul_full_correct);
2352 g_test_add_func("/cutils/qemu_strtoul_full/null",
2353 test_qemu_strtoul_full_null);
2354 g_test_add_func("/cutils/qemu_strtoul_full/empty",
2355 test_qemu_strtoul_full_empty);
2356 g_test_add_func("/cutils/qemu_strtoul_full/negative",
2357 test_qemu_strtoul_full_negative);
2358 g_test_add_func("/cutils/qemu_strtoul_full/trailing",
2359 test_qemu_strtoul_full_trailing);
2360 g_test_add_func("/cutils/qemu_strtoul_full/max",
2361 test_qemu_strtoul_full_max);
2363 /* qemu_strtoi64() tests */
2364 g_test_add_func("/cutils/qemu_strtoi64/correct",
2365 test_qemu_strtoi64_correct);
2366 g_test_add_func("/cutils/qemu_strtoi64/null",
2367 test_qemu_strtoi64_null);
2368 g_test_add_func("/cutils/qemu_strtoi64/empty",
2369 test_qemu_strtoi64_empty);
2370 g_test_add_func("/cutils/qemu_strtoi64/whitespace",
2371 test_qemu_strtoi64_whitespace);
2372 g_test_add_func("/cutils/qemu_strtoi64/invalid"
2374 test_qemu_strtoi64_invalid);
2375 g_test_add_func("/cutils/qemu_strtoi64/trailing",
2376 test_qemu_strtoi64_trailing);
2377 g_test_add_func("/cutils/qemu_strtoi64/octal",
2378 test_qemu_strtoi64_octal);
2379 g_test_add_func("/cutils/qemu_strtoi64/decimal",
2380 test_qemu_strtoi64_decimal);
2381 g_test_add_func("/cutils/qemu_strtoi64/hex",
2382 test_qemu_strtoi64_hex);
2383 g_test_add_func("/cutils/qemu_strtoi64/max",
2384 test_qemu_strtoi64_max);
2385 g_test_add_func("/cutils/qemu_strtoi64/overflow",
2386 test_qemu_strtoi64_overflow);
2387 g_test_add_func("/cutils/qemu_strtoi64/underflow",
2388 test_qemu_strtoi64_underflow);
2389 g_test_add_func("/cutils/qemu_strtoi64/negative",
2390 test_qemu_strtoi64_negative);
2391 g_test_add_func("/cutils/qemu_strtoi64_full/correct",
2392 test_qemu_strtoi64_full_correct);
2393 g_test_add_func("/cutils/qemu_strtoi64_full/null",
2394 test_qemu_strtoi64_full_null);
2395 g_test_add_func("/cutils/qemu_strtoi64_full/empty",
2396 test_qemu_strtoi64_full_empty);
2397 g_test_add_func("/cutils/qemu_strtoi64_full/negative",
2398 test_qemu_strtoi64_full_negative);
2399 g_test_add_func("/cutils/qemu_strtoi64_full/trailing",
2400 test_qemu_strtoi64_full_trailing);
2401 g_test_add_func("/cutils/qemu_strtoi64_full/max",
2402 test_qemu_strtoi64_full_max);
2404 /* qemu_strtou64() tests */
2405 g_test_add_func("/cutils/qemu_strtou64/correct",
2406 test_qemu_strtou64_correct);
2407 g_test_add_func("/cutils/qemu_strtou64/null",
2408 test_qemu_strtou64_null);
2409 g_test_add_func("/cutils/qemu_strtou64/empty",
2410 test_qemu_strtou64_empty);
2411 g_test_add_func("/cutils/qemu_strtou64/whitespace",
2412 test_qemu_strtou64_whitespace);
2413 g_test_add_func("/cutils/qemu_strtou64/invalid",
2414 test_qemu_strtou64_invalid);
2415 g_test_add_func("/cutils/qemu_strtou64/trailing",
2416 test_qemu_strtou64_trailing);
2417 g_test_add_func("/cutils/qemu_strtou64/octal",
2418 test_qemu_strtou64_octal);
2419 g_test_add_func("/cutils/qemu_strtou64/decimal",
2420 test_qemu_strtou64_decimal);
2421 g_test_add_func("/cutils/qemu_strtou64/hex",
2422 test_qemu_strtou64_hex);
2423 g_test_add_func("/cutils/qemu_strtou64/max",
2424 test_qemu_strtou64_max);
2425 g_test_add_func("/cutils/qemu_strtou64/overflow",
2426 test_qemu_strtou64_overflow);
2427 g_test_add_func("/cutils/qemu_strtou64/underflow",
2428 test_qemu_strtou64_underflow);
2429 g_test_add_func("/cutils/qemu_strtou64/negative",
2430 test_qemu_strtou64_negative);
2431 g_test_add_func("/cutils/qemu_strtou64_full/correct",
2432 test_qemu_strtou64_full_correct);
2433 g_test_add_func("/cutils/qemu_strtou64_full/null",
2434 test_qemu_strtou64_full_null);
2435 g_test_add_func("/cutils/qemu_strtou64_full/empty",
2436 test_qemu_strtou64_full_empty);
2437 g_test_add_func("/cutils/qemu_strtou64_full/negative",
2438 test_qemu_strtou64_full_negative);
2439 g_test_add_func("/cutils/qemu_strtou64_full/trailing",
2440 test_qemu_strtou64_full_trailing);
2441 g_test_add_func("/cutils/qemu_strtou64_full/max",
2442 test_qemu_strtou64_full_max);
2444 g_test_add_func("/cutils/strtosz/simple",
2445 test_qemu_strtosz_simple);
2446 g_test_add_func("/cutils/strtosz/units",
2447 test_qemu_strtosz_units);
2448 g_test_add_func("/cutils/strtosz/float",
2449 test_qemu_strtosz_float);
2450 g_test_add_func("/cutils/strtosz/invalid",
2451 test_qemu_strtosz_invalid);
2452 g_test_add_func("/cutils/strtosz/trailing",
2453 test_qemu_strtosz_trailing);
2454 g_test_add_func("/cutils/strtosz/erange",
2455 test_qemu_strtosz_erange);
2456 g_test_add_func("/cutils/strtosz/metric",
2457 test_qemu_strtosz_metric);
2459 return g_test_run();