4 * Copyright (C) 2013 Red Hat Inc.
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
28 #include "qemu/osdep.h"
29 #include "qemu/cutils.h"
30 #include "qemu/units.h"
32 static void test_parse_uint_null(void)
34 unsigned long long i
= 999;
39 r
= parse_uint(NULL
, &i
, &endptr
, 0);
41 g_assert_cmpint(r
, ==, -EINVAL
);
42 g_assert_cmpint(i
, ==, 0);
43 g_assert(endptr
== NULL
);
46 static void test_parse_uint_empty(void)
48 unsigned long long i
= 999;
54 r
= parse_uint(str
, &i
, &endptr
, 0);
56 g_assert_cmpint(r
, ==, -EINVAL
);
57 g_assert_cmpint(i
, ==, 0);
58 g_assert(endptr
== str
);
61 static void test_parse_uint_whitespace(void)
63 unsigned long long i
= 999;
66 const char *str
= " \t ";
69 r
= parse_uint(str
, &i
, &endptr
, 0);
71 g_assert_cmpint(r
, ==, -EINVAL
);
72 g_assert_cmpint(i
, ==, 0);
73 g_assert(endptr
== str
);
77 static void test_parse_uint_invalid(void)
79 unsigned long long i
= 999;
82 const char *str
= " \t xxx";
85 r
= parse_uint(str
, &i
, &endptr
, 0);
87 g_assert_cmpint(r
, ==, -EINVAL
);
88 g_assert_cmpint(i
, ==, 0);
89 g_assert(endptr
== str
);
93 static void test_parse_uint_trailing(void)
95 unsigned long long i
= 999;
98 const char *str
= "123xxx";
101 r
= parse_uint(str
, &i
, &endptr
, 0);
103 g_assert_cmpint(r
, ==, 0);
104 g_assert_cmpint(i
, ==, 123);
105 g_assert(endptr
== str
+ 3);
108 static void test_parse_uint_correct(void)
110 unsigned long long i
= 999;
113 const char *str
= "123";
116 r
= parse_uint(str
, &i
, &endptr
, 0);
118 g_assert_cmpint(r
, ==, 0);
119 g_assert_cmpint(i
, ==, 123);
120 g_assert(endptr
== str
+ strlen(str
));
123 static void test_parse_uint_octal(void)
125 unsigned long long i
= 999;
128 const char *str
= "0123";
131 r
= parse_uint(str
, &i
, &endptr
, 0);
133 g_assert_cmpint(r
, ==, 0);
134 g_assert_cmpint(i
, ==, 0123);
135 g_assert(endptr
== str
+ strlen(str
));
138 static void test_parse_uint_decimal(void)
140 unsigned long long i
= 999;
143 const char *str
= "0123";
146 r
= parse_uint(str
, &i
, &endptr
, 10);
148 g_assert_cmpint(r
, ==, 0);
149 g_assert_cmpint(i
, ==, 123);
150 g_assert(endptr
== str
+ strlen(str
));
154 static void test_parse_uint_llong_max(void)
156 unsigned long long i
= 999;
159 char *str
= g_strdup_printf("%llu", (unsigned long long)LLONG_MAX
+ 1);
162 r
= parse_uint(str
, &i
, &endptr
, 0);
164 g_assert_cmpint(r
, ==, 0);
165 g_assert_cmpint(i
, ==, (unsigned long long)LLONG_MAX
+ 1);
166 g_assert(endptr
== str
+ strlen(str
));
171 static void test_parse_uint_overflow(void)
173 unsigned long long i
= 999;
176 const char *str
= "99999999999999999999999999999999999999";
179 r
= parse_uint(str
, &i
, &endptr
, 0);
181 g_assert_cmpint(r
, ==, -ERANGE
);
182 g_assert_cmpint(i
, ==, ULLONG_MAX
);
183 g_assert(endptr
== str
+ strlen(str
));
186 static void test_parse_uint_negative(void)
188 unsigned long long i
= 999;
191 const char *str
= " \t -321";
194 r
= parse_uint(str
, &i
, &endptr
, 0);
196 g_assert_cmpint(r
, ==, -ERANGE
);
197 g_assert_cmpint(i
, ==, 0);
198 g_assert(endptr
== str
+ strlen(str
));
202 static void test_parse_uint_full_trailing(void)
204 unsigned long long i
= 999;
205 const char *str
= "123xxx";
208 r
= parse_uint_full(str
, &i
, 0);
210 g_assert_cmpint(r
, ==, -EINVAL
);
211 g_assert_cmpint(i
, ==, 0);
214 static void test_parse_uint_full_correct(void)
216 unsigned long long i
= 999;
217 const char *str
= "123";
220 r
= parse_uint_full(str
, &i
, 0);
222 g_assert_cmpint(r
, ==, 0);
223 g_assert_cmpint(i
, ==, 123);
226 static void test_qemu_strtoi_correct(void)
228 const char *str
= "12345 foo";
230 const char *endptr
= &f
;
234 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
236 g_assert_cmpint(err
, ==, 0);
237 g_assert_cmpint(res
, ==, 12345);
238 g_assert(endptr
== str
+ 5);
241 static void test_qemu_strtoi_null(void)
244 const char *endptr
= &f
;
248 err
= qemu_strtoi(NULL
, &endptr
, 0, &res
);
250 g_assert_cmpint(err
, ==, -EINVAL
);
251 g_assert(endptr
== NULL
);
254 static void test_qemu_strtoi_empty(void)
256 const char *str
= "";
258 const char *endptr
= &f
;
262 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
264 g_assert_cmpint(err
, ==, -EINVAL
);
265 g_assert(endptr
== str
);
268 static void test_qemu_strtoi_whitespace(void)
270 const char *str
= " \t ";
272 const char *endptr
= &f
;
276 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
278 g_assert_cmpint(err
, ==, -EINVAL
);
279 g_assert(endptr
== str
);
282 static void test_qemu_strtoi_invalid(void)
284 const char *str
= " xxxx \t abc";
286 const char *endptr
= &f
;
290 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
292 g_assert_cmpint(err
, ==, -EINVAL
);
293 g_assert(endptr
== str
);
296 static void test_qemu_strtoi_trailing(void)
298 const char *str
= "123xxx";
300 const char *endptr
= &f
;
304 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
306 g_assert_cmpint(err
, ==, 0);
307 g_assert_cmpint(res
, ==, 123);
308 g_assert(endptr
== str
+ 3);
311 static void test_qemu_strtoi_octal(void)
313 const char *str
= "0123";
315 const char *endptr
= &f
;
319 err
= qemu_strtoi(str
, &endptr
, 8, &res
);
321 g_assert_cmpint(err
, ==, 0);
322 g_assert_cmpint(res
, ==, 0123);
323 g_assert(endptr
== str
+ strlen(str
));
327 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
329 g_assert_cmpint(err
, ==, 0);
330 g_assert_cmpint(res
, ==, 0123);
331 g_assert(endptr
== str
+ strlen(str
));
334 static void test_qemu_strtoi_decimal(void)
336 const char *str
= "0123";
338 const char *endptr
= &f
;
342 err
= qemu_strtoi(str
, &endptr
, 10, &res
);
344 g_assert_cmpint(err
, ==, 0);
345 g_assert_cmpint(res
, ==, 123);
346 g_assert(endptr
== str
+ strlen(str
));
351 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
353 g_assert_cmpint(err
, ==, 0);
354 g_assert_cmpint(res
, ==, 123);
355 g_assert(endptr
== str
+ strlen(str
));
358 static void test_qemu_strtoi_hex(void)
360 const char *str
= "0123";
362 const char *endptr
= &f
;
366 err
= qemu_strtoi(str
, &endptr
, 16, &res
);
368 g_assert_cmpint(err
, ==, 0);
369 g_assert_cmpint(res
, ==, 0x123);
370 g_assert(endptr
== str
+ strlen(str
));
375 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
377 g_assert_cmpint(err
, ==, 0);
378 g_assert_cmpint(res
, ==, 0x123);
379 g_assert(endptr
== str
+ strlen(str
));
384 err
= qemu_strtoi(str
, &endptr
, 16, &res
);
386 g_assert_cmpint(err
, ==, 0);
387 g_assert_cmpint(res
, ==, 0);
388 g_assert(endptr
== str
+ 1);
391 static void test_qemu_strtoi_max(void)
393 char *str
= g_strdup_printf("%d", INT_MAX
);
395 const char *endptr
= &f
;
399 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
401 g_assert_cmpint(err
, ==, 0);
402 g_assert_cmpint(res
, ==, INT_MAX
);
403 g_assert(endptr
== str
+ strlen(str
));
407 static void test_qemu_strtoi_overflow(void)
409 char *str
= g_strdup_printf("%lld", (long long)INT_MAX
+ 1ll);
411 const char *endptr
= &f
;
415 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
417 g_assert_cmpint(err
, ==, -ERANGE
);
418 g_assert_cmpint(res
, ==, INT_MAX
);
419 g_assert(endptr
== str
+ strlen(str
));
423 static void test_qemu_strtoi_underflow(void)
425 char *str
= g_strdup_printf("%lld", (long long)INT_MIN
- 1ll);
427 const char *endptr
= &f
;
431 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
433 g_assert_cmpint(err
, ==, -ERANGE
);
434 g_assert_cmpint(res
, ==, INT_MIN
);
435 g_assert(endptr
== str
+ strlen(str
));
439 static void test_qemu_strtoi_negative(void)
441 const char *str
= " \t -321";
443 const char *endptr
= &f
;
447 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
449 g_assert_cmpint(err
, ==, 0);
450 g_assert_cmpint(res
, ==, -321);
451 g_assert(endptr
== str
+ strlen(str
));
454 static void test_qemu_strtoi_full_correct(void)
456 const char *str
= "123";
460 err
= qemu_strtoi(str
, NULL
, 0, &res
);
462 g_assert_cmpint(err
, ==, 0);
463 g_assert_cmpint(res
, ==, 123);
466 static void test_qemu_strtoi_full_null(void)
469 const char *endptr
= &f
;
473 err
= qemu_strtoi(NULL
, &endptr
, 0, &res
);
475 g_assert_cmpint(err
, ==, -EINVAL
);
476 g_assert(endptr
== NULL
);
479 static void test_qemu_strtoi_full_empty(void)
481 const char *str
= "";
485 err
= qemu_strtoi(str
, NULL
, 0, &res
);
487 g_assert_cmpint(err
, ==, -EINVAL
);
490 static void test_qemu_strtoi_full_negative(void)
492 const char *str
= " \t -321";
496 err
= qemu_strtoi(str
, NULL
, 0, &res
);
498 g_assert_cmpint(err
, ==, 0);
499 g_assert_cmpint(res
, ==, -321);
502 static void test_qemu_strtoi_full_trailing(void)
504 const char *str
= "123xxx";
508 err
= qemu_strtoi(str
, NULL
, 0, &res
);
510 g_assert_cmpint(err
, ==, -EINVAL
);
513 static void test_qemu_strtoi_full_max(void)
515 char *str
= g_strdup_printf("%d", INT_MAX
);
519 err
= qemu_strtoi(str
, NULL
, 0, &res
);
521 g_assert_cmpint(err
, ==, 0);
522 g_assert_cmpint(res
, ==, INT_MAX
);
526 static void test_qemu_strtoui_correct(void)
528 const char *str
= "12345 foo";
530 const char *endptr
= &f
;
531 unsigned int res
= 999;
534 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
536 g_assert_cmpint(err
, ==, 0);
537 g_assert_cmpuint(res
, ==, 12345);
538 g_assert(endptr
== str
+ 5);
541 static void test_qemu_strtoui_null(void)
544 const char *endptr
= &f
;
545 unsigned int res
= 999;
548 err
= qemu_strtoui(NULL
, &endptr
, 0, &res
);
550 g_assert_cmpint(err
, ==, -EINVAL
);
551 g_assert(endptr
== NULL
);
554 static void test_qemu_strtoui_empty(void)
556 const char *str
= "";
558 const char *endptr
= &f
;
559 unsigned int res
= 999;
562 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
564 g_assert_cmpint(err
, ==, -EINVAL
);
565 g_assert(endptr
== str
);
568 static void test_qemu_strtoui_whitespace(void)
570 const char *str
= " \t ";
572 const char *endptr
= &f
;
573 unsigned int res
= 999;
576 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
578 g_assert_cmpint(err
, ==, -EINVAL
);
579 g_assert(endptr
== str
);
582 static void test_qemu_strtoui_invalid(void)
584 const char *str
= " xxxx \t abc";
586 const char *endptr
= &f
;
587 unsigned int res
= 999;
590 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
592 g_assert_cmpint(err
, ==, -EINVAL
);
593 g_assert(endptr
== str
);
596 static void test_qemu_strtoui_trailing(void)
598 const char *str
= "123xxx";
600 const char *endptr
= &f
;
601 unsigned int res
= 999;
604 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
606 g_assert_cmpint(err
, ==, 0);
607 g_assert_cmpuint(res
, ==, 123);
608 g_assert(endptr
== str
+ 3);
611 static void test_qemu_strtoui_octal(void)
613 const char *str
= "0123";
615 const char *endptr
= &f
;
616 unsigned int res
= 999;
619 err
= qemu_strtoui(str
, &endptr
, 8, &res
);
621 g_assert_cmpint(err
, ==, 0);
622 g_assert_cmpuint(res
, ==, 0123);
623 g_assert(endptr
== str
+ strlen(str
));
627 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
629 g_assert_cmpint(err
, ==, 0);
630 g_assert_cmpuint(res
, ==, 0123);
631 g_assert(endptr
== str
+ strlen(str
));
634 static void test_qemu_strtoui_decimal(void)
636 const char *str
= "0123";
638 const char *endptr
= &f
;
639 unsigned int res
= 999;
642 err
= qemu_strtoui(str
, &endptr
, 10, &res
);
644 g_assert_cmpint(err
, ==, 0);
645 g_assert_cmpuint(res
, ==, 123);
646 g_assert(endptr
== str
+ strlen(str
));
651 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
653 g_assert_cmpint(err
, ==, 0);
654 g_assert_cmpuint(res
, ==, 123);
655 g_assert(endptr
== str
+ strlen(str
));
658 static void test_qemu_strtoui_hex(void)
660 const char *str
= "0123";
662 const char *endptr
= &f
;
663 unsigned int res
= 999;
666 err
= qemu_strtoui(str
, &endptr
, 16, &res
);
668 g_assert_cmpint(err
, ==, 0);
669 g_assert_cmphex(res
, ==, 0x123);
670 g_assert(endptr
== str
+ strlen(str
));
675 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
677 g_assert_cmpint(err
, ==, 0);
678 g_assert_cmphex(res
, ==, 0x123);
679 g_assert(endptr
== str
+ strlen(str
));
684 err
= qemu_strtoui(str
, &endptr
, 16, &res
);
686 g_assert_cmpint(err
, ==, 0);
687 g_assert_cmphex(res
, ==, 0);
688 g_assert(endptr
== str
+ 1);
691 static void test_qemu_strtoui_max(void)
693 char *str
= g_strdup_printf("%u", UINT_MAX
);
695 const char *endptr
= &f
;
696 unsigned int res
= 999;
699 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
701 g_assert_cmpint(err
, ==, 0);
702 g_assert_cmphex(res
, ==, UINT_MAX
);
703 g_assert(endptr
== str
+ strlen(str
));
707 static void test_qemu_strtoui_overflow(void)
709 char *str
= g_strdup_printf("%lld", (long long)UINT_MAX
+ 1ll);
711 const char *endptr
= &f
;
712 unsigned int res
= 999;
715 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
717 g_assert_cmpint(err
, ==, -ERANGE
);
718 g_assert_cmphex(res
, ==, UINT_MAX
);
719 g_assert(endptr
== str
+ strlen(str
));
723 static void test_qemu_strtoui_underflow(void)
725 char *str
= g_strdup_printf("%lld", (long long)INT_MIN
- 1ll);
727 const char *endptr
= &f
;
728 unsigned int res
= 999;
731 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
733 g_assert_cmpint(err
, ==, -ERANGE
);
734 g_assert_cmpuint(res
, ==, (unsigned int)-1);
735 g_assert(endptr
== str
+ strlen(str
));
739 static void test_qemu_strtoui_negative(void)
741 const char *str
= " \t -321";
743 const char *endptr
= &f
;
744 unsigned int res
= 999;
747 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
749 g_assert_cmpint(err
, ==, 0);
750 g_assert_cmpuint(res
, ==, (unsigned int)-321);
751 g_assert(endptr
== str
+ strlen(str
));
754 static void test_qemu_strtoui_full_correct(void)
756 const char *str
= "123";
757 unsigned int res
= 999;
760 err
= qemu_strtoui(str
, NULL
, 0, &res
);
762 g_assert_cmpint(err
, ==, 0);
763 g_assert_cmpuint(res
, ==, 123);
766 static void test_qemu_strtoui_full_null(void)
768 unsigned int res
= 999;
771 err
= qemu_strtoui(NULL
, NULL
, 0, &res
);
773 g_assert_cmpint(err
, ==, -EINVAL
);
776 static void test_qemu_strtoui_full_empty(void)
778 const char *str
= "";
779 unsigned int res
= 999;
782 err
= qemu_strtoui(str
, NULL
, 0, &res
);
784 g_assert_cmpint(err
, ==, -EINVAL
);
786 static void test_qemu_strtoui_full_negative(void)
788 const char *str
= " \t -321";
789 unsigned int res
= 999;
792 err
= qemu_strtoui(str
, NULL
, 0, &res
);
793 g_assert_cmpint(err
, ==, 0);
794 g_assert_cmpuint(res
, ==, (unsigned int)-321);
797 static void test_qemu_strtoui_full_trailing(void)
799 const char *str
= "123xxx";
803 err
= qemu_strtoui(str
, NULL
, 0, &res
);
805 g_assert_cmpint(err
, ==, -EINVAL
);
808 static void test_qemu_strtoui_full_max(void)
810 char *str
= g_strdup_printf("%u", UINT_MAX
);
811 unsigned int res
= 999;
814 err
= qemu_strtoui(str
, NULL
, 0, &res
);
816 g_assert_cmpint(err
, ==, 0);
817 g_assert_cmphex(res
, ==, UINT_MAX
);
821 static void test_qemu_strtol_correct(void)
823 const char *str
= "12345 foo";
825 const char *endptr
= &f
;
829 err
= qemu_strtol(str
, &endptr
, 0, &res
);
831 g_assert_cmpint(err
, ==, 0);
832 g_assert_cmpint(res
, ==, 12345);
833 g_assert(endptr
== str
+ 5);
836 static void test_qemu_strtol_null(void)
839 const char *endptr
= &f
;
843 err
= qemu_strtol(NULL
, &endptr
, 0, &res
);
845 g_assert_cmpint(err
, ==, -EINVAL
);
846 g_assert(endptr
== NULL
);
849 static void test_qemu_strtol_empty(void)
851 const char *str
= "";
853 const char *endptr
= &f
;
857 err
= qemu_strtol(str
, &endptr
, 0, &res
);
859 g_assert_cmpint(err
, ==, -EINVAL
);
860 g_assert(endptr
== str
);
863 static void test_qemu_strtol_whitespace(void)
865 const char *str
= " \t ";
867 const char *endptr
= &f
;
871 err
= qemu_strtol(str
, &endptr
, 0, &res
);
873 g_assert_cmpint(err
, ==, -EINVAL
);
874 g_assert(endptr
== str
);
877 static void test_qemu_strtol_invalid(void)
879 const char *str
= " xxxx \t abc";
881 const char *endptr
= &f
;
885 err
= qemu_strtol(str
, &endptr
, 0, &res
);
887 g_assert_cmpint(err
, ==, -EINVAL
);
888 g_assert(endptr
== str
);
891 static void test_qemu_strtol_trailing(void)
893 const char *str
= "123xxx";
895 const char *endptr
= &f
;
899 err
= qemu_strtol(str
, &endptr
, 0, &res
);
901 g_assert_cmpint(err
, ==, 0);
902 g_assert_cmpint(res
, ==, 123);
903 g_assert(endptr
== str
+ 3);
906 static void test_qemu_strtol_octal(void)
908 const char *str
= "0123";
910 const char *endptr
= &f
;
914 err
= qemu_strtol(str
, &endptr
, 8, &res
);
916 g_assert_cmpint(err
, ==, 0);
917 g_assert_cmpint(res
, ==, 0123);
918 g_assert(endptr
== str
+ strlen(str
));
922 err
= qemu_strtol(str
, &endptr
, 0, &res
);
924 g_assert_cmpint(err
, ==, 0);
925 g_assert_cmpint(res
, ==, 0123);
926 g_assert(endptr
== str
+ strlen(str
));
929 static void test_qemu_strtol_decimal(void)
931 const char *str
= "0123";
933 const char *endptr
= &f
;
937 err
= qemu_strtol(str
, &endptr
, 10, &res
);
939 g_assert_cmpint(err
, ==, 0);
940 g_assert_cmpint(res
, ==, 123);
941 g_assert(endptr
== str
+ strlen(str
));
946 err
= qemu_strtol(str
, &endptr
, 0, &res
);
948 g_assert_cmpint(err
, ==, 0);
949 g_assert_cmpint(res
, ==, 123);
950 g_assert(endptr
== str
+ strlen(str
));
953 static void test_qemu_strtol_hex(void)
955 const char *str
= "0123";
957 const char *endptr
= &f
;
961 err
= qemu_strtol(str
, &endptr
, 16, &res
);
963 g_assert_cmpint(err
, ==, 0);
964 g_assert_cmpint(res
, ==, 0x123);
965 g_assert(endptr
== str
+ strlen(str
));
970 err
= qemu_strtol(str
, &endptr
, 0, &res
);
972 g_assert_cmpint(err
, ==, 0);
973 g_assert_cmpint(res
, ==, 0x123);
974 g_assert(endptr
== str
+ strlen(str
));
979 err
= qemu_strtol(str
, &endptr
, 16, &res
);
981 g_assert_cmpint(err
, ==, 0);
982 g_assert_cmpint(res
, ==, 0);
983 g_assert(endptr
== str
+ 1);
986 static void test_qemu_strtol_max(void)
988 char *str
= g_strdup_printf("%ld", LONG_MAX
);
990 const char *endptr
= &f
;
994 err
= qemu_strtol(str
, &endptr
, 0, &res
);
996 g_assert_cmpint(err
, ==, 0);
997 g_assert_cmpint(res
, ==, LONG_MAX
);
998 g_assert(endptr
== str
+ strlen(str
));
1002 static void test_qemu_strtol_overflow(void)
1004 const char *str
= "99999999999999999999999999999999999999999999";
1006 const char *endptr
= &f
;
1010 err
= qemu_strtol(str
, &endptr
, 0, &res
);
1012 g_assert_cmpint(err
, ==, -ERANGE
);
1013 g_assert_cmpint(res
, ==, LONG_MAX
);
1014 g_assert(endptr
== str
+ strlen(str
));
1017 static void test_qemu_strtol_underflow(void)
1019 const char *str
= "-99999999999999999999999999999999999999999999";
1021 const char *endptr
= &f
;
1025 err
= qemu_strtol(str
, &endptr
, 0, &res
);
1027 g_assert_cmpint(err
, ==, -ERANGE
);
1028 g_assert_cmpint(res
, ==, LONG_MIN
);
1029 g_assert(endptr
== str
+ strlen(str
));
1032 static void test_qemu_strtol_negative(void)
1034 const char *str
= " \t -321";
1036 const char *endptr
= &f
;
1040 err
= qemu_strtol(str
, &endptr
, 0, &res
);
1042 g_assert_cmpint(err
, ==, 0);
1043 g_assert_cmpint(res
, ==, -321);
1044 g_assert(endptr
== str
+ strlen(str
));
1047 static void test_qemu_strtol_full_correct(void)
1049 const char *str
= "123";
1053 err
= qemu_strtol(str
, NULL
, 0, &res
);
1055 g_assert_cmpint(err
, ==, 0);
1056 g_assert_cmpint(res
, ==, 123);
1059 static void test_qemu_strtol_full_null(void)
1062 const char *endptr
= &f
;
1066 err
= qemu_strtol(NULL
, &endptr
, 0, &res
);
1068 g_assert_cmpint(err
, ==, -EINVAL
);
1069 g_assert(endptr
== NULL
);
1072 static void test_qemu_strtol_full_empty(void)
1074 const char *str
= "";
1078 err
= qemu_strtol(str
, NULL
, 0, &res
);
1080 g_assert_cmpint(err
, ==, -EINVAL
);
1083 static void test_qemu_strtol_full_negative(void)
1085 const char *str
= " \t -321";
1089 err
= qemu_strtol(str
, NULL
, 0, &res
);
1091 g_assert_cmpint(err
, ==, 0);
1092 g_assert_cmpint(res
, ==, -321);
1095 static void test_qemu_strtol_full_trailing(void)
1097 const char *str
= "123xxx";
1101 err
= qemu_strtol(str
, NULL
, 0, &res
);
1103 g_assert_cmpint(err
, ==, -EINVAL
);
1106 static void test_qemu_strtol_full_max(void)
1108 char *str
= g_strdup_printf("%ld", LONG_MAX
);
1112 err
= qemu_strtol(str
, NULL
, 0, &res
);
1114 g_assert_cmpint(err
, ==, 0);
1115 g_assert_cmpint(res
, ==, LONG_MAX
);
1119 static void test_qemu_strtoul_correct(void)
1121 const char *str
= "12345 foo";
1123 const char *endptr
= &f
;
1124 unsigned long res
= 999;
1127 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1129 g_assert_cmpint(err
, ==, 0);
1130 g_assert_cmpuint(res
, ==, 12345);
1131 g_assert(endptr
== str
+ 5);
1134 static void test_qemu_strtoul_null(void)
1137 const char *endptr
= &f
;
1138 unsigned long res
= 999;
1141 err
= qemu_strtoul(NULL
, &endptr
, 0, &res
);
1143 g_assert_cmpint(err
, ==, -EINVAL
);
1144 g_assert(endptr
== NULL
);
1147 static void test_qemu_strtoul_empty(void)
1149 const char *str
= "";
1151 const char *endptr
= &f
;
1152 unsigned long res
= 999;
1155 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1157 g_assert_cmpint(err
, ==, -EINVAL
);
1158 g_assert(endptr
== str
);
1161 static void test_qemu_strtoul_whitespace(void)
1163 const char *str
= " \t ";
1165 const char *endptr
= &f
;
1166 unsigned long res
= 999;
1169 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1171 g_assert_cmpint(err
, ==, -EINVAL
);
1172 g_assert(endptr
== str
);
1175 static void test_qemu_strtoul_invalid(void)
1177 const char *str
= " xxxx \t abc";
1179 const char *endptr
= &f
;
1180 unsigned long res
= 999;
1183 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1185 g_assert_cmpint(err
, ==, -EINVAL
);
1186 g_assert(endptr
== str
);
1189 static void test_qemu_strtoul_trailing(void)
1191 const char *str
= "123xxx";
1193 const char *endptr
= &f
;
1194 unsigned long res
= 999;
1197 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1199 g_assert_cmpint(err
, ==, 0);
1200 g_assert_cmpuint(res
, ==, 123);
1201 g_assert(endptr
== str
+ 3);
1204 static void test_qemu_strtoul_octal(void)
1206 const char *str
= "0123";
1208 const char *endptr
= &f
;
1209 unsigned long res
= 999;
1212 err
= qemu_strtoul(str
, &endptr
, 8, &res
);
1214 g_assert_cmpint(err
, ==, 0);
1215 g_assert_cmpuint(res
, ==, 0123);
1216 g_assert(endptr
== str
+ strlen(str
));
1220 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1222 g_assert_cmpint(err
, ==, 0);
1223 g_assert_cmpuint(res
, ==, 0123);
1224 g_assert(endptr
== str
+ strlen(str
));
1227 static void test_qemu_strtoul_decimal(void)
1229 const char *str
= "0123";
1231 const char *endptr
= &f
;
1232 unsigned long res
= 999;
1235 err
= qemu_strtoul(str
, &endptr
, 10, &res
);
1237 g_assert_cmpint(err
, ==, 0);
1238 g_assert_cmpuint(res
, ==, 123);
1239 g_assert(endptr
== str
+ strlen(str
));
1244 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1246 g_assert_cmpint(err
, ==, 0);
1247 g_assert_cmpuint(res
, ==, 123);
1248 g_assert(endptr
== str
+ strlen(str
));
1251 static void test_qemu_strtoul_hex(void)
1253 const char *str
= "0123";
1255 const char *endptr
= &f
;
1256 unsigned long res
= 999;
1259 err
= qemu_strtoul(str
, &endptr
, 16, &res
);
1261 g_assert_cmpint(err
, ==, 0);
1262 g_assert_cmphex(res
, ==, 0x123);
1263 g_assert(endptr
== str
+ strlen(str
));
1268 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1270 g_assert_cmpint(err
, ==, 0);
1271 g_assert_cmphex(res
, ==, 0x123);
1272 g_assert(endptr
== str
+ strlen(str
));
1277 err
= qemu_strtoul(str
, &endptr
, 16, &res
);
1279 g_assert_cmpint(err
, ==, 0);
1280 g_assert_cmphex(res
, ==, 0);
1281 g_assert(endptr
== str
+ 1);
1284 static void test_qemu_strtoul_max(void)
1286 char *str
= g_strdup_printf("%lu", ULONG_MAX
);
1288 const char *endptr
= &f
;
1289 unsigned long res
= 999;
1292 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1294 g_assert_cmpint(err
, ==, 0);
1295 g_assert_cmphex(res
, ==, ULONG_MAX
);
1296 g_assert(endptr
== str
+ strlen(str
));
1300 static void test_qemu_strtoul_overflow(void)
1302 const char *str
= "99999999999999999999999999999999999999999999";
1304 const char *endptr
= &f
;
1305 unsigned long res
= 999;
1308 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1310 g_assert_cmpint(err
, ==, -ERANGE
);
1311 g_assert_cmphex(res
, ==, ULONG_MAX
);
1312 g_assert(endptr
== str
+ strlen(str
));
1315 static void test_qemu_strtoul_underflow(void)
1317 const char *str
= "-99999999999999999999999999999999999999999999";
1319 const char *endptr
= &f
;
1320 unsigned long res
= 999;
1323 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1325 g_assert_cmpint(err
, ==, -ERANGE
);
1326 g_assert_cmpuint(res
, ==, -1ul);
1327 g_assert(endptr
== str
+ strlen(str
));
1330 static void test_qemu_strtoul_negative(void)
1332 const char *str
= " \t -321";
1334 const char *endptr
= &f
;
1335 unsigned long res
= 999;
1338 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1340 g_assert_cmpint(err
, ==, 0);
1341 g_assert_cmpuint(res
, ==, -321ul);
1342 g_assert(endptr
== str
+ strlen(str
));
1345 static void test_qemu_strtoul_full_correct(void)
1347 const char *str
= "123";
1348 unsigned long res
= 999;
1351 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1353 g_assert_cmpint(err
, ==, 0);
1354 g_assert_cmpuint(res
, ==, 123);
1357 static void test_qemu_strtoul_full_null(void)
1359 unsigned long res
= 999;
1362 err
= qemu_strtoul(NULL
, NULL
, 0, &res
);
1364 g_assert_cmpint(err
, ==, -EINVAL
);
1367 static void test_qemu_strtoul_full_empty(void)
1369 const char *str
= "";
1370 unsigned long res
= 999;
1373 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1375 g_assert_cmpint(err
, ==, -EINVAL
);
1377 static void test_qemu_strtoul_full_negative(void)
1379 const char *str
= " \t -321";
1380 unsigned long res
= 999;
1383 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1384 g_assert_cmpint(err
, ==, 0);
1385 g_assert_cmpuint(res
, ==, -321ul);
1388 static void test_qemu_strtoul_full_trailing(void)
1390 const char *str
= "123xxx";
1394 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1396 g_assert_cmpint(err
, ==, -EINVAL
);
1399 static void test_qemu_strtoul_full_max(void)
1401 char *str
= g_strdup_printf("%lu", ULONG_MAX
);
1402 unsigned long res
= 999;
1405 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1407 g_assert_cmpint(err
, ==, 0);
1408 g_assert_cmphex(res
, ==, ULONG_MAX
);
1412 static void test_qemu_strtoi64_correct(void)
1414 const char *str
= "12345 foo";
1416 const char *endptr
= &f
;
1420 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1422 g_assert_cmpint(err
, ==, 0);
1423 g_assert_cmpint(res
, ==, 12345);
1424 g_assert(endptr
== str
+ 5);
1427 static void test_qemu_strtoi64_null(void)
1430 const char *endptr
= &f
;
1434 err
= qemu_strtoi64(NULL
, &endptr
, 0, &res
);
1436 g_assert_cmpint(err
, ==, -EINVAL
);
1437 g_assert(endptr
== NULL
);
1440 static void test_qemu_strtoi64_empty(void)
1442 const char *str
= "";
1444 const char *endptr
= &f
;
1448 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1450 g_assert_cmpint(err
, ==, -EINVAL
);
1451 g_assert(endptr
== str
);
1454 static void test_qemu_strtoi64_whitespace(void)
1456 const char *str
= " \t ";
1458 const char *endptr
= &f
;
1462 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1464 g_assert_cmpint(err
, ==, -EINVAL
);
1465 g_assert(endptr
== str
);
1468 static void test_qemu_strtoi64_invalid(void)
1470 const char *str
= " xxxx \t abc";
1472 const char *endptr
= &f
;
1476 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1478 g_assert_cmpint(err
, ==, -EINVAL
);
1479 g_assert(endptr
== str
);
1482 static void test_qemu_strtoi64_trailing(void)
1484 const char *str
= "123xxx";
1486 const char *endptr
= &f
;
1490 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1492 g_assert_cmpint(err
, ==, 0);
1493 g_assert_cmpint(res
, ==, 123);
1494 g_assert(endptr
== str
+ 3);
1497 static void test_qemu_strtoi64_octal(void)
1499 const char *str
= "0123";
1501 const char *endptr
= &f
;
1505 err
= qemu_strtoi64(str
, &endptr
, 8, &res
);
1507 g_assert_cmpint(err
, ==, 0);
1508 g_assert_cmpint(res
, ==, 0123);
1509 g_assert(endptr
== str
+ strlen(str
));
1513 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1515 g_assert_cmpint(err
, ==, 0);
1516 g_assert_cmpint(res
, ==, 0123);
1517 g_assert(endptr
== str
+ strlen(str
));
1520 static void test_qemu_strtoi64_decimal(void)
1522 const char *str
= "0123";
1524 const char *endptr
= &f
;
1528 err
= qemu_strtoi64(str
, &endptr
, 10, &res
);
1530 g_assert_cmpint(err
, ==, 0);
1531 g_assert_cmpint(res
, ==, 123);
1532 g_assert(endptr
== str
+ strlen(str
));
1537 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1539 g_assert_cmpint(err
, ==, 0);
1540 g_assert_cmpint(res
, ==, 123);
1541 g_assert(endptr
== str
+ strlen(str
));
1544 static void test_qemu_strtoi64_hex(void)
1546 const char *str
= "0123";
1548 const char *endptr
= &f
;
1552 err
= qemu_strtoi64(str
, &endptr
, 16, &res
);
1554 g_assert_cmpint(err
, ==, 0);
1555 g_assert_cmpint(res
, ==, 0x123);
1556 g_assert(endptr
== str
+ strlen(str
));
1561 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1563 g_assert_cmpint(err
, ==, 0);
1564 g_assert_cmpint(res
, ==, 0x123);
1565 g_assert(endptr
== str
+ strlen(str
));
1570 err
= qemu_strtoi64(str
, &endptr
, 16, &res
);
1572 g_assert_cmpint(err
, ==, 0);
1573 g_assert_cmpint(res
, ==, 0);
1574 g_assert(endptr
== str
+ 1);
1577 static void test_qemu_strtoi64_max(void)
1579 char *str
= g_strdup_printf("%lld", LLONG_MAX
);
1581 const char *endptr
= &f
;
1585 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1587 g_assert_cmpint(err
, ==, 0);
1588 g_assert_cmpint(res
, ==, LLONG_MAX
);
1589 g_assert(endptr
== str
+ strlen(str
));
1593 static void test_qemu_strtoi64_overflow(void)
1595 const char *str
= "99999999999999999999999999999999999999999999";
1597 const char *endptr
= &f
;
1601 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1603 g_assert_cmpint(err
, ==, -ERANGE
);
1604 g_assert_cmpint(res
, ==, LLONG_MAX
);
1605 g_assert(endptr
== str
+ strlen(str
));
1608 static void test_qemu_strtoi64_underflow(void)
1610 const char *str
= "-99999999999999999999999999999999999999999999";
1612 const char *endptr
= &f
;
1616 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1618 g_assert_cmpint(err
, ==, -ERANGE
);
1619 g_assert_cmpint(res
, ==, LLONG_MIN
);
1620 g_assert(endptr
== str
+ strlen(str
));
1623 static void test_qemu_strtoi64_negative(void)
1625 const char *str
= " \t -321";
1627 const char *endptr
= &f
;
1631 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1633 g_assert_cmpint(err
, ==, 0);
1634 g_assert_cmpint(res
, ==, -321);
1635 g_assert(endptr
== str
+ strlen(str
));
1638 static void test_qemu_strtoi64_full_correct(void)
1640 const char *str
= "123";
1644 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1646 g_assert_cmpint(err
, ==, 0);
1647 g_assert_cmpint(res
, ==, 123);
1650 static void test_qemu_strtoi64_full_null(void)
1655 err
= qemu_strtoi64(NULL
, NULL
, 0, &res
);
1657 g_assert_cmpint(err
, ==, -EINVAL
);
1660 static void test_qemu_strtoi64_full_empty(void)
1662 const char *str
= "";
1666 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1668 g_assert_cmpint(err
, ==, -EINVAL
);
1671 static void test_qemu_strtoi64_full_negative(void)
1673 const char *str
= " \t -321";
1677 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1679 g_assert_cmpint(err
, ==, 0);
1680 g_assert_cmpint(res
, ==, -321);
1683 static void test_qemu_strtoi64_full_trailing(void)
1685 const char *str
= "123xxx";
1689 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1691 g_assert_cmpint(err
, ==, -EINVAL
);
1694 static void test_qemu_strtoi64_full_max(void)
1697 char *str
= g_strdup_printf("%lld", LLONG_MAX
);
1701 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1703 g_assert_cmpint(err
, ==, 0);
1704 g_assert_cmpint(res
, ==, LLONG_MAX
);
1708 static void test_qemu_strtou64_correct(void)
1710 const char *str
= "12345 foo";
1712 const char *endptr
= &f
;
1716 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1718 g_assert_cmpint(err
, ==, 0);
1719 g_assert_cmpuint(res
, ==, 12345);
1720 g_assert(endptr
== str
+ 5);
1723 static void test_qemu_strtou64_null(void)
1726 const char *endptr
= &f
;
1730 err
= qemu_strtou64(NULL
, &endptr
, 0, &res
);
1732 g_assert_cmpint(err
, ==, -EINVAL
);
1733 g_assert(endptr
== NULL
);
1736 static void test_qemu_strtou64_empty(void)
1738 const char *str
= "";
1740 const char *endptr
= &f
;
1744 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1746 g_assert_cmpint(err
, ==, -EINVAL
);
1747 g_assert(endptr
== str
);
1750 static void test_qemu_strtou64_whitespace(void)
1752 const char *str
= " \t ";
1754 const char *endptr
= &f
;
1758 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1760 g_assert_cmpint(err
, ==, -EINVAL
);
1761 g_assert(endptr
== str
);
1764 static void test_qemu_strtou64_invalid(void)
1766 const char *str
= " xxxx \t abc";
1768 const char *endptr
= &f
;
1772 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1774 g_assert_cmpint(err
, ==, -EINVAL
);
1775 g_assert(endptr
== str
);
1778 static void test_qemu_strtou64_trailing(void)
1780 const char *str
= "123xxx";
1782 const char *endptr
= &f
;
1786 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1788 g_assert_cmpint(err
, ==, 0);
1789 g_assert_cmpuint(res
, ==, 123);
1790 g_assert(endptr
== str
+ 3);
1793 static void test_qemu_strtou64_octal(void)
1795 const char *str
= "0123";
1797 const char *endptr
= &f
;
1801 err
= qemu_strtou64(str
, &endptr
, 8, &res
);
1803 g_assert_cmpint(err
, ==, 0);
1804 g_assert_cmpuint(res
, ==, 0123);
1805 g_assert(endptr
== str
+ strlen(str
));
1809 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1811 g_assert_cmpint(err
, ==, 0);
1812 g_assert_cmpuint(res
, ==, 0123);
1813 g_assert(endptr
== str
+ strlen(str
));
1816 static void test_qemu_strtou64_decimal(void)
1818 const char *str
= "0123";
1820 const char *endptr
= &f
;
1824 err
= qemu_strtou64(str
, &endptr
, 10, &res
);
1826 g_assert_cmpint(err
, ==, 0);
1827 g_assert_cmpuint(res
, ==, 123);
1828 g_assert(endptr
== str
+ strlen(str
));
1833 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1835 g_assert_cmpint(err
, ==, 0);
1836 g_assert_cmpuint(res
, ==, 123);
1837 g_assert(endptr
== str
+ strlen(str
));
1840 static void test_qemu_strtou64_hex(void)
1842 const char *str
= "0123";
1844 const char *endptr
= &f
;
1848 err
= qemu_strtou64(str
, &endptr
, 16, &res
);
1850 g_assert_cmpint(err
, ==, 0);
1851 g_assert_cmphex(res
, ==, 0x123);
1852 g_assert(endptr
== str
+ strlen(str
));
1857 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1859 g_assert_cmpint(err
, ==, 0);
1860 g_assert_cmphex(res
, ==, 0x123);
1861 g_assert(endptr
== str
+ strlen(str
));
1866 err
= qemu_strtou64(str
, &endptr
, 16, &res
);
1868 g_assert_cmpint(err
, ==, 0);
1869 g_assert_cmphex(res
, ==, 0);
1870 g_assert(endptr
== str
+ 1);
1873 static void test_qemu_strtou64_max(void)
1875 char *str
= g_strdup_printf("%llu", ULLONG_MAX
);
1877 const char *endptr
= &f
;
1881 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1883 g_assert_cmpint(err
, ==, 0);
1884 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1885 g_assert(endptr
== str
+ strlen(str
));
1889 static void test_qemu_strtou64_overflow(void)
1891 const char *str
= "99999999999999999999999999999999999999999999";
1893 const char *endptr
= &f
;
1897 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1899 g_assert_cmpint(err
, ==, -ERANGE
);
1900 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1901 g_assert(endptr
== str
+ strlen(str
));
1904 static void test_qemu_strtou64_underflow(void)
1906 const char *str
= "-99999999999999999999999999999999999999999999";
1908 const char *endptr
= &f
;
1912 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1914 g_assert_cmpint(err
, ==, -ERANGE
);
1915 g_assert_cmphex(res
, ==, -1ull);
1916 g_assert(endptr
== str
+ strlen(str
));
1919 static void test_qemu_strtou64_negative(void)
1921 const char *str
= " \t -321";
1923 const char *endptr
= &f
;
1927 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1929 g_assert_cmpint(err
, ==, 0);
1930 g_assert_cmpuint(res
, ==, -321ull);
1931 g_assert(endptr
== str
+ strlen(str
));
1934 static void test_qemu_strtou64_full_correct(void)
1936 const char *str
= "18446744073709551614";
1940 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1942 g_assert_cmpint(err
, ==, 0);
1943 g_assert_cmpuint(res
, ==, 18446744073709551614ull);
1946 static void test_qemu_strtou64_full_null(void)
1951 err
= qemu_strtou64(NULL
, NULL
, 0, &res
);
1953 g_assert_cmpint(err
, ==, -EINVAL
);
1956 static void test_qemu_strtou64_full_empty(void)
1958 const char *str
= "";
1962 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1964 g_assert_cmpint(err
, ==, -EINVAL
);
1967 static void test_qemu_strtou64_full_negative(void)
1969 const char *str
= " \t -321";
1973 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1975 g_assert_cmpint(err
, ==, 0);
1976 g_assert_cmpuint(res
, ==, -321ull);
1979 static void test_qemu_strtou64_full_trailing(void)
1981 const char *str
= "18446744073709551614xxxxxx";
1985 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1987 g_assert_cmpint(err
, ==, -EINVAL
);
1990 static void test_qemu_strtou64_full_max(void)
1992 char *str
= g_strdup_printf("%lld", ULLONG_MAX
);
1996 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1998 g_assert_cmpint(err
, ==, 0);
1999 g_assert_cmphex(res
, ==, ULLONG_MAX
);
2003 static void test_qemu_strtosz_simple(void)
2013 err
= qemu_strtosz(str
, &endptr
, &res
);
2014 g_assert_cmpint(err
, ==, 0);
2015 g_assert_cmpint(res
, ==, 0);
2016 g_assert(endptr
== str
+ 1);
2018 /* Leading 0 gives decimal results, not octal */
2022 err
= qemu_strtosz(str
, &endptr
, &res
);
2023 g_assert_cmpint(err
, ==, 0);
2024 g_assert_cmpint(res
, ==, 8);
2025 g_assert(endptr
== str
+ 2);
2027 /* Leading space is ignored */
2031 err
= qemu_strtosz(str
, &endptr
, &res
);
2032 g_assert_cmpint(err
, ==, 0);
2033 g_assert_cmpint(res
, ==, 12345);
2034 g_assert(endptr
== str
+ 6);
2037 err
= qemu_strtosz(str
, NULL
, &res
);
2038 g_assert_cmpint(err
, ==, 0);
2039 g_assert_cmpint(res
, ==, 12345);
2041 str
= "9007199254740991"; /* 2^53-1 */
2044 err
= qemu_strtosz(str
, &endptr
, &res
);
2045 g_assert_cmpint(err
, ==, 0);
2046 g_assert_cmpint(res
, ==, 0x1fffffffffffff);
2047 g_assert(endptr
== str
+ 16);
2049 str
= "9007199254740992"; /* 2^53 */
2052 err
= qemu_strtosz(str
, &endptr
, &res
);
2053 g_assert_cmpint(err
, ==, 0);
2054 g_assert_cmpint(res
, ==, 0x20000000000000);
2055 g_assert(endptr
== str
+ 16);
2057 str
= "9007199254740993"; /* 2^53+1 */
2060 err
= qemu_strtosz(str
, &endptr
, &res
);
2061 g_assert_cmpint(err
, ==, 0);
2062 g_assert_cmpint(res
, ==, 0x20000000000001);
2063 g_assert(endptr
== str
+ 16);
2065 str
= "18446744073709549568"; /* 0xfffffffffffff800 (53 msbs set) */
2068 err
= qemu_strtosz(str
, &endptr
, &res
);
2069 g_assert_cmpint(err
, ==, 0);
2070 g_assert_cmpint(res
, ==, 0xfffffffffffff800);
2071 g_assert(endptr
== str
+ 20);
2073 str
= "18446744073709550591"; /* 0xfffffffffffffbff */
2076 err
= qemu_strtosz(str
, &endptr
, &res
);
2077 g_assert_cmpint(err
, ==, 0);
2078 g_assert_cmpint(res
, ==, 0xfffffffffffffbff);
2079 g_assert(endptr
== str
+ 20);
2081 str
= "18446744073709551615"; /* 0xffffffffffffffff */
2084 err
= qemu_strtosz(str
, &endptr
, &res
);
2085 g_assert_cmpint(err
, ==, 0);
2086 g_assert_cmpint(res
, ==, 0xffffffffffffffff);
2087 g_assert(endptr
== str
+ 20);
2090 static void test_qemu_strtosz_hex(void)
2100 err
= qemu_strtosz(str
, &endptr
, &res
);
2101 g_assert_cmpint(err
, ==, 0);
2102 g_assert_cmpint(res
, ==, 0);
2103 g_assert(endptr
== str
+ 3);
2108 err
= qemu_strtosz(str
, &endptr
, &res
);
2109 g_assert_cmpint(err
, ==, 0);
2110 g_assert_cmpint(res
, ==, 171);
2111 g_assert(endptr
== str
+ 4);
2116 err
= qemu_strtosz(str
, &endptr
, &res
);
2117 g_assert_cmpint(err
, ==, 0);
2118 g_assert_cmpint(res
, ==, 174);
2119 g_assert(endptr
== str
+ 4);
2122 static void test_qemu_strtosz_units(void)
2124 const char *none
= "1";
2125 const char *b
= "1B";
2126 const char *k
= "1K";
2127 const char *m
= "1M";
2128 const char *g
= "1G";
2129 const char *t
= "1T";
2130 const char *p
= "1P";
2131 const char *e
= "1E";
2139 err
= qemu_strtosz_MiB(none
, &endptr
, &res
);
2140 g_assert_cmpint(err
, ==, 0);
2141 g_assert_cmpint(res
, ==, MiB
);
2142 g_assert(endptr
== none
+ 1);
2146 err
= qemu_strtosz(b
, &endptr
, &res
);
2147 g_assert_cmpint(err
, ==, 0);
2148 g_assert_cmpint(res
, ==, 1);
2149 g_assert(endptr
== b
+ 2);
2153 err
= qemu_strtosz(k
, &endptr
, &res
);
2154 g_assert_cmpint(err
, ==, 0);
2155 g_assert_cmpint(res
, ==, KiB
);
2156 g_assert(endptr
== k
+ 2);
2160 err
= qemu_strtosz(m
, &endptr
, &res
);
2161 g_assert_cmpint(err
, ==, 0);
2162 g_assert_cmpint(res
, ==, MiB
);
2163 g_assert(endptr
== m
+ 2);
2167 err
= qemu_strtosz(g
, &endptr
, &res
);
2168 g_assert_cmpint(err
, ==, 0);
2169 g_assert_cmpint(res
, ==, GiB
);
2170 g_assert(endptr
== g
+ 2);
2174 err
= qemu_strtosz(t
, &endptr
, &res
);
2175 g_assert_cmpint(err
, ==, 0);
2176 g_assert_cmpint(res
, ==, TiB
);
2177 g_assert(endptr
== t
+ 2);
2181 err
= qemu_strtosz(p
, &endptr
, &res
);
2182 g_assert_cmpint(err
, ==, 0);
2183 g_assert_cmpint(res
, ==, PiB
);
2184 g_assert(endptr
== p
+ 2);
2188 err
= qemu_strtosz(e
, &endptr
, &res
);
2189 g_assert_cmpint(err
, ==, 0);
2190 g_assert_cmpint(res
, ==, EiB
);
2191 g_assert(endptr
== e
+ 2);
2194 static void test_qemu_strtosz_float(void)
2204 err
= qemu_strtosz(str
, &endptr
, &res
);
2205 g_assert_cmpint(err
, ==, 0);
2206 g_assert_cmpint(res
, ==, EiB
/ 2);
2207 g_assert(endptr
== str
+ 4);
2209 /* For convenience, a fraction of 0 is tolerated even on bytes */
2213 err
= qemu_strtosz(str
, &endptr
, &res
);
2214 g_assert_cmpint(err
, ==, 0);
2215 g_assert_cmpint(res
, ==, 1);
2216 g_assert(endptr
== str
+ 4);
2218 /* An empty fraction is tolerated */
2222 err
= qemu_strtosz(str
, &endptr
, &res
);
2223 g_assert_cmpint(err
, ==, 0);
2224 g_assert_cmpint(res
, ==, 1024);
2225 g_assert(endptr
== str
+ 3);
2227 /* For convenience, we permit values that are not byte-exact */
2231 err
= qemu_strtosz(str
, &endptr
, &res
);
2232 g_assert_cmpint(err
, ==, 0);
2233 g_assert_cmpint(res
, ==, (uint64_t) (12.345 * MiB
+ 0.5));
2234 g_assert(endptr
== str
+ 7);
2237 static void test_qemu_strtosz_invalid(void)
2242 uint64_t res
= 0xbaadf00d;
2246 err
= qemu_strtosz(str
, &endptr
, &res
);
2247 g_assert_cmpint(err
, ==, -EINVAL
);
2248 g_assert_cmpint(res
, ==, 0xbaadf00d);
2249 g_assert(endptr
== str
);
2253 err
= qemu_strtosz(str
, &endptr
, &res
);
2254 g_assert_cmpint(err
, ==, -EINVAL
);
2255 g_assert_cmpint(res
, ==, 0xbaadf00d);
2256 g_assert(endptr
== str
);
2260 err
= qemu_strtosz(str
, &endptr
, &res
);
2261 g_assert_cmpint(err
, ==, -EINVAL
);
2262 g_assert_cmpint(res
, ==, 0xbaadf00d);
2263 g_assert(endptr
== str
);
2267 err
= qemu_strtosz(str
, &endptr
, &res
);
2268 g_assert_cmpint(err
, ==, -EINVAL
);
2269 g_assert_cmpint(res
, ==, 0xbaadf00d);
2270 g_assert(endptr
== str
);
2274 err
= qemu_strtosz(str
, &endptr
, &res
);
2275 g_assert_cmpint(err
, ==, -EINVAL
);
2276 g_assert_cmpint(res
, ==, 0xbaadf00d);
2277 g_assert(endptr
== str
);
2279 /* Fractional values require scale larger than bytes */
2282 err
= qemu_strtosz(str
, &endptr
, &res
);
2283 g_assert_cmpint(err
, ==, -EINVAL
);
2284 g_assert_cmpint(res
, ==, 0xbaadf00d);
2285 g_assert(endptr
== str
);
2289 err
= qemu_strtosz(str
, &endptr
, &res
);
2290 g_assert_cmpint(err
, ==, -EINVAL
);
2291 g_assert_cmpint(res
, ==, 0xbaadf00d);
2292 g_assert(endptr
== str
);
2294 /* No floating point exponents */
2297 err
= qemu_strtosz(str
, &endptr
, &res
);
2298 g_assert_cmpint(err
, ==, -EINVAL
);
2299 g_assert_cmpint(res
, ==, 0xbaadf00d);
2300 g_assert(endptr
== str
);
2304 err
= qemu_strtosz(str
, &endptr
, &res
);
2305 g_assert_cmpint(err
, ==, -EINVAL
);
2306 g_assert_cmpint(res
, ==, 0xbaadf00d);
2307 g_assert(endptr
== str
);
2309 /* No hex fractions */
2312 err
= qemu_strtosz(str
, &endptr
, &res
);
2313 g_assert_cmpint(err
, ==, -EINVAL
);
2314 g_assert_cmpint(res
, ==, 0xbaadf00d);
2315 g_assert(endptr
== str
);
2320 err
= qemu_strtosz(str
, &endptr
, &res
);
2321 g_assert_cmpint(err
, ==, -EINVAL
);
2322 g_assert_cmpint(res
, ==, 0xbaadf00d);
2323 g_assert(endptr
== str
);
2325 /* No negative values */
2328 err
= qemu_strtosz(str
, &endptr
, &res
);
2329 g_assert_cmpint(err
, ==, -EINVAL
);
2330 g_assert_cmpint(res
, ==, 0xbaadf00d);
2331 g_assert(endptr
== str
);
2335 err
= qemu_strtosz(str
, &endptr
, &res
);
2336 g_assert_cmpint(err
, ==, -EINVAL
);
2337 g_assert_cmpint(res
, ==, 0xbaadf00d);
2338 g_assert(endptr
== str
);
2341 static void test_qemu_strtosz_trailing(void)
2351 err
= qemu_strtosz_MiB(str
, &endptr
, &res
);
2352 g_assert_cmpint(err
, ==, 0);
2353 g_assert_cmpint(res
, ==, 123 * MiB
);
2354 g_assert(endptr
== str
+ 3);
2357 err
= qemu_strtosz(str
, NULL
, &res
);
2358 g_assert_cmpint(err
, ==, -EINVAL
);
2359 g_assert_cmpint(res
, ==, 0xbaadf00d);
2364 err
= qemu_strtosz(str
, &endptr
, &res
);
2365 g_assert_cmpint(err
, ==, 0);
2366 g_assert_cmpint(res
, ==, 1024);
2367 g_assert(endptr
== str
+ 2);
2370 err
= qemu_strtosz(str
, NULL
, &res
);
2371 g_assert_cmpint(err
, ==, -EINVAL
);
2372 g_assert_cmpint(res
, ==, 0xbaadf00d);
2377 err
= qemu_strtosz(str
, &endptr
, &res
);
2378 g_assert_cmpint(err
, ==, 0);
2379 g_assert_cmpint(res
, ==, 0);
2380 g_assert(endptr
== str
+ 1);
2383 err
= qemu_strtosz(str
, NULL
, &res
);
2384 g_assert_cmpint(err
, ==, -EINVAL
);
2385 g_assert_cmpint(res
, ==, 0xbaadf00d);
2390 err
= qemu_strtosz(str
, &endptr
, &res
);
2391 g_assert_cmpint(err
, ==, 0);
2392 g_assert_cmpint(res
, ==, 0);
2393 g_assert(endptr
== str
+ 2);
2396 err
= qemu_strtosz(str
, NULL
, &res
);
2397 g_assert_cmpint(err
, ==, -EINVAL
);
2398 g_assert_cmpint(res
, ==, 0xbaadf00d);
2403 err
= qemu_strtosz(str
, &endptr
, &res
);
2404 g_assert_cmpint(err
, ==, 0);
2405 g_assert_cmpint(res
, ==, 123);
2406 g_assert(endptr
== str
+ 3);
2409 err
= qemu_strtosz(str
, NULL
, &res
);
2410 g_assert_cmpint(err
, ==, -EINVAL
);
2411 g_assert_cmpint(res
, ==, 0xbaadf00d);
2414 static void test_qemu_strtosz_erange(void)
2419 uint64_t res
= 0xbaadf00d;
2421 str
= "18446744073709551616"; /* 2^64; see strtosz_simple for 2^64-1 */
2423 err
= qemu_strtosz(str
, &endptr
, &res
);
2424 g_assert_cmpint(err
, ==, -ERANGE
);
2425 g_assert_cmpint(res
, ==, 0xbaadf00d);
2426 g_assert(endptr
== str
+ 20);
2430 err
= qemu_strtosz(str
, &endptr
, &res
);
2431 g_assert_cmpint(err
, ==, -ERANGE
);
2432 g_assert_cmpint(res
, ==, 0xbaadf00d);
2433 g_assert(endptr
== str
+ 3);
2436 static void test_qemu_strtosz_metric(void)
2446 err
= qemu_strtosz_metric(str
, &endptr
, &res
);
2447 g_assert_cmpint(err
, ==, 0);
2448 g_assert_cmpint(res
, ==, 12345000);
2449 g_assert(endptr
== str
+ 6);
2454 err
= qemu_strtosz_metric(str
, &endptr
, &res
);
2455 g_assert_cmpint(err
, ==, 0);
2456 g_assert_cmpint(res
, ==, 12345000);
2457 g_assert(endptr
== str
+ 7);
2460 static void test_freq_to_str(void)
2464 str
= freq_to_str(999);
2465 g_assert_cmpstr(str
, ==, "999 Hz");
2468 str
= freq_to_str(1000);
2469 g_assert_cmpstr(str
, ==, "1 KHz");
2472 str
= freq_to_str(1010);
2473 g_assert_cmpstr(str
, ==, "1.01 KHz");
2477 static void test_size_to_str(void)
2481 str
= size_to_str(0);
2482 g_assert_cmpstr(str
, ==, "0 B");
2485 str
= size_to_str(1);
2486 g_assert_cmpstr(str
, ==, "1 B");
2489 str
= size_to_str(1016);
2490 g_assert_cmpstr(str
, ==, "0.992 KiB");
2493 str
= size_to_str(1024);
2494 g_assert_cmpstr(str
, ==, "1 KiB");
2497 str
= size_to_str(512ull << 20);
2498 g_assert_cmpstr(str
, ==, "512 MiB");
2502 static void test_iec_binary_prefix(void)
2504 g_assert_cmpstr(iec_binary_prefix(0), ==, "");
2505 g_assert_cmpstr(iec_binary_prefix(10), ==, "Ki");
2506 g_assert_cmpstr(iec_binary_prefix(20), ==, "Mi");
2507 g_assert_cmpstr(iec_binary_prefix(30), ==, "Gi");
2508 g_assert_cmpstr(iec_binary_prefix(40), ==, "Ti");
2509 g_assert_cmpstr(iec_binary_prefix(50), ==, "Pi");
2510 g_assert_cmpstr(iec_binary_prefix(60), ==, "Ei");
2513 static void test_si_prefix(void)
2515 g_assert_cmpstr(si_prefix(-18), ==, "a");
2516 g_assert_cmpstr(si_prefix(-15), ==, "f");
2517 g_assert_cmpstr(si_prefix(-12), ==, "p");
2518 g_assert_cmpstr(si_prefix(-9), ==, "n");
2519 g_assert_cmpstr(si_prefix(-6), ==, "u");
2520 g_assert_cmpstr(si_prefix(-3), ==, "m");
2521 g_assert_cmpstr(si_prefix(0), ==, "");
2522 g_assert_cmpstr(si_prefix(3), ==, "K");
2523 g_assert_cmpstr(si_prefix(6), ==, "M");
2524 g_assert_cmpstr(si_prefix(9), ==, "G");
2525 g_assert_cmpstr(si_prefix(12), ==, "T");
2526 g_assert_cmpstr(si_prefix(15), ==, "P");
2527 g_assert_cmpstr(si_prefix(18), ==, "E");
2530 int main(int argc
, char **argv
)
2532 g_test_init(&argc
, &argv
, NULL
);
2534 g_test_add_func("/cutils/parse_uint/null", test_parse_uint_null
);
2535 g_test_add_func("/cutils/parse_uint/empty", test_parse_uint_empty
);
2536 g_test_add_func("/cutils/parse_uint/whitespace",
2537 test_parse_uint_whitespace
);
2538 g_test_add_func("/cutils/parse_uint/invalid", test_parse_uint_invalid
);
2539 g_test_add_func("/cutils/parse_uint/trailing", test_parse_uint_trailing
);
2540 g_test_add_func("/cutils/parse_uint/correct", test_parse_uint_correct
);
2541 g_test_add_func("/cutils/parse_uint/octal", test_parse_uint_octal
);
2542 g_test_add_func("/cutils/parse_uint/decimal", test_parse_uint_decimal
);
2543 g_test_add_func("/cutils/parse_uint/llong_max", test_parse_uint_llong_max
);
2544 g_test_add_func("/cutils/parse_uint/overflow", test_parse_uint_overflow
);
2545 g_test_add_func("/cutils/parse_uint/negative", test_parse_uint_negative
);
2546 g_test_add_func("/cutils/parse_uint_full/trailing",
2547 test_parse_uint_full_trailing
);
2548 g_test_add_func("/cutils/parse_uint_full/correct",
2549 test_parse_uint_full_correct
);
2551 /* qemu_strtoi() tests */
2552 g_test_add_func("/cutils/qemu_strtoi/correct",
2553 test_qemu_strtoi_correct
);
2554 g_test_add_func("/cutils/qemu_strtoi/null",
2555 test_qemu_strtoi_null
);
2556 g_test_add_func("/cutils/qemu_strtoi/empty",
2557 test_qemu_strtoi_empty
);
2558 g_test_add_func("/cutils/qemu_strtoi/whitespace",
2559 test_qemu_strtoi_whitespace
);
2560 g_test_add_func("/cutils/qemu_strtoi/invalid",
2561 test_qemu_strtoi_invalid
);
2562 g_test_add_func("/cutils/qemu_strtoi/trailing",
2563 test_qemu_strtoi_trailing
);
2564 g_test_add_func("/cutils/qemu_strtoi/octal",
2565 test_qemu_strtoi_octal
);
2566 g_test_add_func("/cutils/qemu_strtoi/decimal",
2567 test_qemu_strtoi_decimal
);
2568 g_test_add_func("/cutils/qemu_strtoi/hex",
2569 test_qemu_strtoi_hex
);
2570 g_test_add_func("/cutils/qemu_strtoi/max",
2571 test_qemu_strtoi_max
);
2572 g_test_add_func("/cutils/qemu_strtoi/overflow",
2573 test_qemu_strtoi_overflow
);
2574 g_test_add_func("/cutils/qemu_strtoi/underflow",
2575 test_qemu_strtoi_underflow
);
2576 g_test_add_func("/cutils/qemu_strtoi/negative",
2577 test_qemu_strtoi_negative
);
2578 g_test_add_func("/cutils/qemu_strtoi_full/correct",
2579 test_qemu_strtoi_full_correct
);
2580 g_test_add_func("/cutils/qemu_strtoi_full/null",
2581 test_qemu_strtoi_full_null
);
2582 g_test_add_func("/cutils/qemu_strtoi_full/empty",
2583 test_qemu_strtoi_full_empty
);
2584 g_test_add_func("/cutils/qemu_strtoi_full/negative",
2585 test_qemu_strtoi_full_negative
);
2586 g_test_add_func("/cutils/qemu_strtoi_full/trailing",
2587 test_qemu_strtoi_full_trailing
);
2588 g_test_add_func("/cutils/qemu_strtoi_full/max",
2589 test_qemu_strtoi_full_max
);
2591 /* qemu_strtoui() tests */
2592 g_test_add_func("/cutils/qemu_strtoui/correct",
2593 test_qemu_strtoui_correct
);
2594 g_test_add_func("/cutils/qemu_strtoui/null",
2595 test_qemu_strtoui_null
);
2596 g_test_add_func("/cutils/qemu_strtoui/empty",
2597 test_qemu_strtoui_empty
);
2598 g_test_add_func("/cutils/qemu_strtoui/whitespace",
2599 test_qemu_strtoui_whitespace
);
2600 g_test_add_func("/cutils/qemu_strtoui/invalid",
2601 test_qemu_strtoui_invalid
);
2602 g_test_add_func("/cutils/qemu_strtoui/trailing",
2603 test_qemu_strtoui_trailing
);
2604 g_test_add_func("/cutils/qemu_strtoui/octal",
2605 test_qemu_strtoui_octal
);
2606 g_test_add_func("/cutils/qemu_strtoui/decimal",
2607 test_qemu_strtoui_decimal
);
2608 g_test_add_func("/cutils/qemu_strtoui/hex",
2609 test_qemu_strtoui_hex
);
2610 g_test_add_func("/cutils/qemu_strtoui/max",
2611 test_qemu_strtoui_max
);
2612 g_test_add_func("/cutils/qemu_strtoui/overflow",
2613 test_qemu_strtoui_overflow
);
2614 g_test_add_func("/cutils/qemu_strtoui/underflow",
2615 test_qemu_strtoui_underflow
);
2616 g_test_add_func("/cutils/qemu_strtoui/negative",
2617 test_qemu_strtoui_negative
);
2618 g_test_add_func("/cutils/qemu_strtoui_full/correct",
2619 test_qemu_strtoui_full_correct
);
2620 g_test_add_func("/cutils/qemu_strtoui_full/null",
2621 test_qemu_strtoui_full_null
);
2622 g_test_add_func("/cutils/qemu_strtoui_full/empty",
2623 test_qemu_strtoui_full_empty
);
2624 g_test_add_func("/cutils/qemu_strtoui_full/negative",
2625 test_qemu_strtoui_full_negative
);
2626 g_test_add_func("/cutils/qemu_strtoui_full/trailing",
2627 test_qemu_strtoui_full_trailing
);
2628 g_test_add_func("/cutils/qemu_strtoui_full/max",
2629 test_qemu_strtoui_full_max
);
2631 /* qemu_strtol() tests */
2632 g_test_add_func("/cutils/qemu_strtol/correct",
2633 test_qemu_strtol_correct
);
2634 g_test_add_func("/cutils/qemu_strtol/null",
2635 test_qemu_strtol_null
);
2636 g_test_add_func("/cutils/qemu_strtol/empty",
2637 test_qemu_strtol_empty
);
2638 g_test_add_func("/cutils/qemu_strtol/whitespace",
2639 test_qemu_strtol_whitespace
);
2640 g_test_add_func("/cutils/qemu_strtol/invalid",
2641 test_qemu_strtol_invalid
);
2642 g_test_add_func("/cutils/qemu_strtol/trailing",
2643 test_qemu_strtol_trailing
);
2644 g_test_add_func("/cutils/qemu_strtol/octal",
2645 test_qemu_strtol_octal
);
2646 g_test_add_func("/cutils/qemu_strtol/decimal",
2647 test_qemu_strtol_decimal
);
2648 g_test_add_func("/cutils/qemu_strtol/hex",
2649 test_qemu_strtol_hex
);
2650 g_test_add_func("/cutils/qemu_strtol/max",
2651 test_qemu_strtol_max
);
2652 g_test_add_func("/cutils/qemu_strtol/overflow",
2653 test_qemu_strtol_overflow
);
2654 g_test_add_func("/cutils/qemu_strtol/underflow",
2655 test_qemu_strtol_underflow
);
2656 g_test_add_func("/cutils/qemu_strtol/negative",
2657 test_qemu_strtol_negative
);
2658 g_test_add_func("/cutils/qemu_strtol_full/correct",
2659 test_qemu_strtol_full_correct
);
2660 g_test_add_func("/cutils/qemu_strtol_full/null",
2661 test_qemu_strtol_full_null
);
2662 g_test_add_func("/cutils/qemu_strtol_full/empty",
2663 test_qemu_strtol_full_empty
);
2664 g_test_add_func("/cutils/qemu_strtol_full/negative",
2665 test_qemu_strtol_full_negative
);
2666 g_test_add_func("/cutils/qemu_strtol_full/trailing",
2667 test_qemu_strtol_full_trailing
);
2668 g_test_add_func("/cutils/qemu_strtol_full/max",
2669 test_qemu_strtol_full_max
);
2671 /* qemu_strtoul() tests */
2672 g_test_add_func("/cutils/qemu_strtoul/correct",
2673 test_qemu_strtoul_correct
);
2674 g_test_add_func("/cutils/qemu_strtoul/null",
2675 test_qemu_strtoul_null
);
2676 g_test_add_func("/cutils/qemu_strtoul/empty",
2677 test_qemu_strtoul_empty
);
2678 g_test_add_func("/cutils/qemu_strtoul/whitespace",
2679 test_qemu_strtoul_whitespace
);
2680 g_test_add_func("/cutils/qemu_strtoul/invalid",
2681 test_qemu_strtoul_invalid
);
2682 g_test_add_func("/cutils/qemu_strtoul/trailing",
2683 test_qemu_strtoul_trailing
);
2684 g_test_add_func("/cutils/qemu_strtoul/octal",
2685 test_qemu_strtoul_octal
);
2686 g_test_add_func("/cutils/qemu_strtoul/decimal",
2687 test_qemu_strtoul_decimal
);
2688 g_test_add_func("/cutils/qemu_strtoul/hex",
2689 test_qemu_strtoul_hex
);
2690 g_test_add_func("/cutils/qemu_strtoul/max",
2691 test_qemu_strtoul_max
);
2692 g_test_add_func("/cutils/qemu_strtoul/overflow",
2693 test_qemu_strtoul_overflow
);
2694 g_test_add_func("/cutils/qemu_strtoul/underflow",
2695 test_qemu_strtoul_underflow
);
2696 g_test_add_func("/cutils/qemu_strtoul/negative",
2697 test_qemu_strtoul_negative
);
2698 g_test_add_func("/cutils/qemu_strtoul_full/correct",
2699 test_qemu_strtoul_full_correct
);
2700 g_test_add_func("/cutils/qemu_strtoul_full/null",
2701 test_qemu_strtoul_full_null
);
2702 g_test_add_func("/cutils/qemu_strtoul_full/empty",
2703 test_qemu_strtoul_full_empty
);
2704 g_test_add_func("/cutils/qemu_strtoul_full/negative",
2705 test_qemu_strtoul_full_negative
);
2706 g_test_add_func("/cutils/qemu_strtoul_full/trailing",
2707 test_qemu_strtoul_full_trailing
);
2708 g_test_add_func("/cutils/qemu_strtoul_full/max",
2709 test_qemu_strtoul_full_max
);
2711 /* qemu_strtoi64() tests */
2712 g_test_add_func("/cutils/qemu_strtoi64/correct",
2713 test_qemu_strtoi64_correct
);
2714 g_test_add_func("/cutils/qemu_strtoi64/null",
2715 test_qemu_strtoi64_null
);
2716 g_test_add_func("/cutils/qemu_strtoi64/empty",
2717 test_qemu_strtoi64_empty
);
2718 g_test_add_func("/cutils/qemu_strtoi64/whitespace",
2719 test_qemu_strtoi64_whitespace
);
2720 g_test_add_func("/cutils/qemu_strtoi64/invalid"
2722 test_qemu_strtoi64_invalid
);
2723 g_test_add_func("/cutils/qemu_strtoi64/trailing",
2724 test_qemu_strtoi64_trailing
);
2725 g_test_add_func("/cutils/qemu_strtoi64/octal",
2726 test_qemu_strtoi64_octal
);
2727 g_test_add_func("/cutils/qemu_strtoi64/decimal",
2728 test_qemu_strtoi64_decimal
);
2729 g_test_add_func("/cutils/qemu_strtoi64/hex",
2730 test_qemu_strtoi64_hex
);
2731 g_test_add_func("/cutils/qemu_strtoi64/max",
2732 test_qemu_strtoi64_max
);
2733 g_test_add_func("/cutils/qemu_strtoi64/overflow",
2734 test_qemu_strtoi64_overflow
);
2735 g_test_add_func("/cutils/qemu_strtoi64/underflow",
2736 test_qemu_strtoi64_underflow
);
2737 g_test_add_func("/cutils/qemu_strtoi64/negative",
2738 test_qemu_strtoi64_negative
);
2739 g_test_add_func("/cutils/qemu_strtoi64_full/correct",
2740 test_qemu_strtoi64_full_correct
);
2741 g_test_add_func("/cutils/qemu_strtoi64_full/null",
2742 test_qemu_strtoi64_full_null
);
2743 g_test_add_func("/cutils/qemu_strtoi64_full/empty",
2744 test_qemu_strtoi64_full_empty
);
2745 g_test_add_func("/cutils/qemu_strtoi64_full/negative",
2746 test_qemu_strtoi64_full_negative
);
2747 g_test_add_func("/cutils/qemu_strtoi64_full/trailing",
2748 test_qemu_strtoi64_full_trailing
);
2749 g_test_add_func("/cutils/qemu_strtoi64_full/max",
2750 test_qemu_strtoi64_full_max
);
2752 /* qemu_strtou64() tests */
2753 g_test_add_func("/cutils/qemu_strtou64/correct",
2754 test_qemu_strtou64_correct
);
2755 g_test_add_func("/cutils/qemu_strtou64/null",
2756 test_qemu_strtou64_null
);
2757 g_test_add_func("/cutils/qemu_strtou64/empty",
2758 test_qemu_strtou64_empty
);
2759 g_test_add_func("/cutils/qemu_strtou64/whitespace",
2760 test_qemu_strtou64_whitespace
);
2761 g_test_add_func("/cutils/qemu_strtou64/invalid",
2762 test_qemu_strtou64_invalid
);
2763 g_test_add_func("/cutils/qemu_strtou64/trailing",
2764 test_qemu_strtou64_trailing
);
2765 g_test_add_func("/cutils/qemu_strtou64/octal",
2766 test_qemu_strtou64_octal
);
2767 g_test_add_func("/cutils/qemu_strtou64/decimal",
2768 test_qemu_strtou64_decimal
);
2769 g_test_add_func("/cutils/qemu_strtou64/hex",
2770 test_qemu_strtou64_hex
);
2771 g_test_add_func("/cutils/qemu_strtou64/max",
2772 test_qemu_strtou64_max
);
2773 g_test_add_func("/cutils/qemu_strtou64/overflow",
2774 test_qemu_strtou64_overflow
);
2775 g_test_add_func("/cutils/qemu_strtou64/underflow",
2776 test_qemu_strtou64_underflow
);
2777 g_test_add_func("/cutils/qemu_strtou64/negative",
2778 test_qemu_strtou64_negative
);
2779 g_test_add_func("/cutils/qemu_strtou64_full/correct",
2780 test_qemu_strtou64_full_correct
);
2781 g_test_add_func("/cutils/qemu_strtou64_full/null",
2782 test_qemu_strtou64_full_null
);
2783 g_test_add_func("/cutils/qemu_strtou64_full/empty",
2784 test_qemu_strtou64_full_empty
);
2785 g_test_add_func("/cutils/qemu_strtou64_full/negative",
2786 test_qemu_strtou64_full_negative
);
2787 g_test_add_func("/cutils/qemu_strtou64_full/trailing",
2788 test_qemu_strtou64_full_trailing
);
2789 g_test_add_func("/cutils/qemu_strtou64_full/max",
2790 test_qemu_strtou64_full_max
);
2792 g_test_add_func("/cutils/strtosz/simple",
2793 test_qemu_strtosz_simple
);
2794 g_test_add_func("/cutils/strtosz/hex",
2795 test_qemu_strtosz_hex
);
2796 g_test_add_func("/cutils/strtosz/units",
2797 test_qemu_strtosz_units
);
2798 g_test_add_func("/cutils/strtosz/float",
2799 test_qemu_strtosz_float
);
2800 g_test_add_func("/cutils/strtosz/invalid",
2801 test_qemu_strtosz_invalid
);
2802 g_test_add_func("/cutils/strtosz/trailing",
2803 test_qemu_strtosz_trailing
);
2804 g_test_add_func("/cutils/strtosz/erange",
2805 test_qemu_strtosz_erange
);
2806 g_test_add_func("/cutils/strtosz/metric",
2807 test_qemu_strtosz_metric
);
2809 g_test_add_func("/cutils/size_to_str",
2811 g_test_add_func("/cutils/freq_to_str",
2813 g_test_add_func("/cutils/iec_binary_prefix",
2814 test_iec_binary_prefix
);
2815 g_test_add_func("/cutils/si_prefix",
2817 return g_test_run();