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"
30 #include "qemu/cutils.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_strtol_correct(void)
228 const char *str
= "12345 foo";
230 const char *endptr
= &f
;
234 err
= qemu_strtol(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_strtol_null(void)
244 const char *endptr
= &f
;
248 err
= qemu_strtol(NULL
, &endptr
, 0, &res
);
250 g_assert_cmpint(err
, ==, -EINVAL
);
251 g_assert(endptr
== NULL
);
254 static void test_qemu_strtol_empty(void)
256 const char *str
= "";
258 const char *endptr
= &f
;
262 err
= qemu_strtol(str
, &endptr
, 0, &res
);
264 g_assert_cmpint(err
, ==, -EINVAL
);
265 g_assert(endptr
== str
);
268 static void test_qemu_strtol_whitespace(void)
270 const char *str
= " \t ";
272 const char *endptr
= &f
;
276 err
= qemu_strtol(str
, &endptr
, 0, &res
);
278 g_assert_cmpint(err
, ==, -EINVAL
);
279 g_assert(endptr
== str
);
282 static void test_qemu_strtol_invalid(void)
284 const char *str
= " xxxx \t abc";
286 const char *endptr
= &f
;
290 err
= qemu_strtol(str
, &endptr
, 0, &res
);
292 g_assert_cmpint(err
, ==, -EINVAL
);
293 g_assert(endptr
== str
);
296 static void test_qemu_strtol_trailing(void)
298 const char *str
= "123xxx";
300 const char *endptr
= &f
;
304 err
= qemu_strtol(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_strtol_octal(void)
313 const char *str
= "0123";
315 const char *endptr
= &f
;
319 err
= qemu_strtol(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_strtol(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_strtol_decimal(void)
336 const char *str
= "0123";
338 const char *endptr
= &f
;
342 err
= qemu_strtol(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_strtol(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_strtol_hex(void)
360 const char *str
= "0123";
362 const char *endptr
= &f
;
366 err
= qemu_strtol(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_strtol(str
, &endptr
, 0, &res
);
377 g_assert_cmpint(err
, ==, 0);
378 g_assert_cmpint(res
, ==, 0x123);
379 g_assert(endptr
== str
+ strlen(str
));
382 static void test_qemu_strtol_max(void)
384 char *str
= g_strdup_printf("%ld", LONG_MAX
);
386 const char *endptr
= &f
;
390 err
= qemu_strtol(str
, &endptr
, 0, &res
);
392 g_assert_cmpint(err
, ==, 0);
393 g_assert_cmpint(res
, ==, LONG_MAX
);
394 g_assert(endptr
== str
+ strlen(str
));
398 static void test_qemu_strtol_overflow(void)
400 const char *str
= "99999999999999999999999999999999999999999999";
402 const char *endptr
= &f
;
406 err
= qemu_strtol(str
, &endptr
, 0, &res
);
408 g_assert_cmpint(err
, ==, -ERANGE
);
409 g_assert_cmpint(res
, ==, LONG_MAX
);
410 g_assert(endptr
== str
+ strlen(str
));
413 static void test_qemu_strtol_underflow(void)
415 const char *str
= "-99999999999999999999999999999999999999999999";
417 const char *endptr
= &f
;
421 err
= qemu_strtol(str
, &endptr
, 0, &res
);
423 g_assert_cmpint(err
, ==, -ERANGE
);
424 g_assert_cmpint(res
, ==, LONG_MIN
);
425 g_assert(endptr
== str
+ strlen(str
));
428 static void test_qemu_strtol_negative(void)
430 const char *str
= " \t -321";
432 const char *endptr
= &f
;
436 err
= qemu_strtol(str
, &endptr
, 0, &res
);
438 g_assert_cmpint(err
, ==, 0);
439 g_assert_cmpint(res
, ==, -321);
440 g_assert(endptr
== str
+ strlen(str
));
443 static void test_qemu_strtol_full_correct(void)
445 const char *str
= "123";
449 err
= qemu_strtol(str
, NULL
, 0, &res
);
451 g_assert_cmpint(err
, ==, 0);
452 g_assert_cmpint(res
, ==, 123);
455 static void test_qemu_strtol_full_null(void)
458 const char *endptr
= &f
;
462 err
= qemu_strtol(NULL
, &endptr
, 0, &res
);
464 g_assert_cmpint(err
, ==, -EINVAL
);
465 g_assert(endptr
== NULL
);
468 static void test_qemu_strtol_full_empty(void)
470 const char *str
= "";
474 err
= qemu_strtol(str
, NULL
, 0, &res
);
476 g_assert_cmpint(err
, ==, -EINVAL
);
479 static void test_qemu_strtol_full_negative(void)
481 const char *str
= " \t -321";
485 err
= qemu_strtol(str
, NULL
, 0, &res
);
487 g_assert_cmpint(err
, ==, 0);
488 g_assert_cmpint(res
, ==, -321);
491 static void test_qemu_strtol_full_trailing(void)
493 const char *str
= "123xxx";
497 err
= qemu_strtol(str
, NULL
, 0, &res
);
499 g_assert_cmpint(err
, ==, -EINVAL
);
502 static void test_qemu_strtol_full_max(void)
504 char *str
= g_strdup_printf("%ld", LONG_MAX
);
508 err
= qemu_strtol(str
, NULL
, 0, &res
);
510 g_assert_cmpint(err
, ==, 0);
511 g_assert_cmpint(res
, ==, LONG_MAX
);
515 static void test_qemu_strtoul_correct(void)
517 const char *str
= "12345 foo";
519 const char *endptr
= &f
;
520 unsigned long res
= 999;
523 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
525 g_assert_cmpint(err
, ==, 0);
526 g_assert_cmpuint(res
, ==, 12345);
527 g_assert(endptr
== str
+ 5);
530 static void test_qemu_strtoul_null(void)
533 const char *endptr
= &f
;
534 unsigned long res
= 999;
537 err
= qemu_strtoul(NULL
, &endptr
, 0, &res
);
539 g_assert_cmpint(err
, ==, -EINVAL
);
540 g_assert(endptr
== NULL
);
543 static void test_qemu_strtoul_empty(void)
545 const char *str
= "";
547 const char *endptr
= &f
;
548 unsigned long res
= 999;
551 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
553 g_assert_cmpint(err
, ==, -EINVAL
);
554 g_assert(endptr
== str
);
557 static void test_qemu_strtoul_whitespace(void)
559 const char *str
= " \t ";
561 const char *endptr
= &f
;
562 unsigned long res
= 999;
565 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
567 g_assert_cmpint(err
, ==, -EINVAL
);
568 g_assert(endptr
== str
);
571 static void test_qemu_strtoul_invalid(void)
573 const char *str
= " xxxx \t abc";
575 const char *endptr
= &f
;
576 unsigned long res
= 999;
579 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
581 g_assert_cmpint(err
, ==, -EINVAL
);
582 g_assert(endptr
== str
);
585 static void test_qemu_strtoul_trailing(void)
587 const char *str
= "123xxx";
589 const char *endptr
= &f
;
590 unsigned long res
= 999;
593 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
595 g_assert_cmpint(err
, ==, 0);
596 g_assert_cmpuint(res
, ==, 123);
597 g_assert(endptr
== str
+ 3);
600 static void test_qemu_strtoul_octal(void)
602 const char *str
= "0123";
604 const char *endptr
= &f
;
605 unsigned long res
= 999;
608 err
= qemu_strtoul(str
, &endptr
, 8, &res
);
610 g_assert_cmpint(err
, ==, 0);
611 g_assert_cmpuint(res
, ==, 0123);
612 g_assert(endptr
== str
+ strlen(str
));
616 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
618 g_assert_cmpint(err
, ==, 0);
619 g_assert_cmpuint(res
, ==, 0123);
620 g_assert(endptr
== str
+ strlen(str
));
623 static void test_qemu_strtoul_decimal(void)
625 const char *str
= "0123";
627 const char *endptr
= &f
;
628 unsigned long res
= 999;
631 err
= qemu_strtoul(str
, &endptr
, 10, &res
);
633 g_assert_cmpint(err
, ==, 0);
634 g_assert_cmpuint(res
, ==, 123);
635 g_assert(endptr
== str
+ strlen(str
));
640 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
642 g_assert_cmpint(err
, ==, 0);
643 g_assert_cmpuint(res
, ==, 123);
644 g_assert(endptr
== str
+ strlen(str
));
647 static void test_qemu_strtoul_hex(void)
649 const char *str
= "0123";
651 const char *endptr
= &f
;
652 unsigned long res
= 999;
655 err
= qemu_strtoul(str
, &endptr
, 16, &res
);
657 g_assert_cmpint(err
, ==, 0);
658 g_assert_cmphex(res
, ==, 0x123);
659 g_assert(endptr
== str
+ strlen(str
));
664 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
666 g_assert_cmpint(err
, ==, 0);
667 g_assert_cmphex(res
, ==, 0x123);
668 g_assert(endptr
== str
+ strlen(str
));
671 static void test_qemu_strtoul_max(void)
673 char *str
= g_strdup_printf("%lu", ULONG_MAX
);
675 const char *endptr
= &f
;
676 unsigned long res
= 999;
679 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
681 g_assert_cmpint(err
, ==, 0);
682 g_assert_cmphex(res
, ==, ULONG_MAX
);
683 g_assert(endptr
== str
+ strlen(str
));
687 static void test_qemu_strtoul_overflow(void)
689 const char *str
= "99999999999999999999999999999999999999999999";
691 const char *endptr
= &f
;
692 unsigned long res
= 999;
695 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
697 g_assert_cmpint(err
, ==, -ERANGE
);
698 g_assert_cmphex(res
, ==, ULONG_MAX
);
699 g_assert(endptr
== str
+ strlen(str
));
702 static void test_qemu_strtoul_underflow(void)
704 const char *str
= "-99999999999999999999999999999999999999999999";
706 const char *endptr
= &f
;
707 unsigned long res
= 999;
710 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
712 g_assert_cmpint(err
, ==, -ERANGE
);
713 g_assert_cmpuint(res
, ==, -1ul);
714 g_assert(endptr
== str
+ strlen(str
));
717 static void test_qemu_strtoul_negative(void)
719 const char *str
= " \t -321";
721 const char *endptr
= &f
;
722 unsigned long res
= 999;
725 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
727 g_assert_cmpint(err
, ==, 0);
728 g_assert_cmpuint(res
, ==, -321ul);
729 g_assert(endptr
== str
+ strlen(str
));
732 static void test_qemu_strtoul_full_correct(void)
734 const char *str
= "123";
735 unsigned long res
= 999;
738 err
= qemu_strtoul(str
, NULL
, 0, &res
);
740 g_assert_cmpint(err
, ==, 0);
741 g_assert_cmpuint(res
, ==, 123);
744 static void test_qemu_strtoul_full_null(void)
746 unsigned long res
= 999;
749 err
= qemu_strtoul(NULL
, NULL
, 0, &res
);
751 g_assert_cmpint(err
, ==, -EINVAL
);
754 static void test_qemu_strtoul_full_empty(void)
756 const char *str
= "";
757 unsigned long res
= 999;
760 err
= qemu_strtoul(str
, NULL
, 0, &res
);
762 g_assert_cmpint(err
, ==, -EINVAL
);
764 static void test_qemu_strtoul_full_negative(void)
766 const char *str
= " \t -321";
767 unsigned long res
= 999;
770 err
= qemu_strtoul(str
, NULL
, 0, &res
);
771 g_assert_cmpint(err
, ==, 0);
772 g_assert_cmpuint(res
, ==, -321ul);
775 static void test_qemu_strtoul_full_trailing(void)
777 const char *str
= "123xxx";
781 err
= qemu_strtoul(str
, NULL
, 0, &res
);
783 g_assert_cmpint(err
, ==, -EINVAL
);
786 static void test_qemu_strtoul_full_max(void)
788 char *str
= g_strdup_printf("%lu", ULONG_MAX
);
789 unsigned long res
= 999;
792 err
= qemu_strtoul(str
, NULL
, 0, &res
);
794 g_assert_cmpint(err
, ==, 0);
795 g_assert_cmphex(res
, ==, ULONG_MAX
);
799 static void test_qemu_strtoi64_correct(void)
801 const char *str
= "12345 foo";
803 const char *endptr
= &f
;
807 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
809 g_assert_cmpint(err
, ==, 0);
810 g_assert_cmpint(res
, ==, 12345);
811 g_assert(endptr
== str
+ 5);
814 static void test_qemu_strtoi64_null(void)
817 const char *endptr
= &f
;
821 err
= qemu_strtoi64(NULL
, &endptr
, 0, &res
);
823 g_assert_cmpint(err
, ==, -EINVAL
);
824 g_assert(endptr
== NULL
);
827 static void test_qemu_strtoi64_empty(void)
829 const char *str
= "";
831 const char *endptr
= &f
;
835 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
837 g_assert_cmpint(err
, ==, -EINVAL
);
838 g_assert(endptr
== str
);
841 static void test_qemu_strtoi64_whitespace(void)
843 const char *str
= " \t ";
845 const char *endptr
= &f
;
849 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
851 g_assert_cmpint(err
, ==, -EINVAL
);
852 g_assert(endptr
== str
);
855 static void test_qemu_strtoi64_invalid(void)
857 const char *str
= " xxxx \t abc";
859 const char *endptr
= &f
;
863 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
865 g_assert_cmpint(err
, ==, -EINVAL
);
866 g_assert(endptr
== str
);
869 static void test_qemu_strtoi64_trailing(void)
871 const char *str
= "123xxx";
873 const char *endptr
= &f
;
877 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
879 g_assert_cmpint(err
, ==, 0);
880 g_assert_cmpint(res
, ==, 123);
881 g_assert(endptr
== str
+ 3);
884 static void test_qemu_strtoi64_octal(void)
886 const char *str
= "0123";
888 const char *endptr
= &f
;
892 err
= qemu_strtoi64(str
, &endptr
, 8, &res
);
894 g_assert_cmpint(err
, ==, 0);
895 g_assert_cmpint(res
, ==, 0123);
896 g_assert(endptr
== str
+ strlen(str
));
900 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
902 g_assert_cmpint(err
, ==, 0);
903 g_assert_cmpint(res
, ==, 0123);
904 g_assert(endptr
== str
+ strlen(str
));
907 static void test_qemu_strtoi64_decimal(void)
909 const char *str
= "0123";
911 const char *endptr
= &f
;
915 err
= qemu_strtoi64(str
, &endptr
, 10, &res
);
917 g_assert_cmpint(err
, ==, 0);
918 g_assert_cmpint(res
, ==, 123);
919 g_assert(endptr
== str
+ strlen(str
));
924 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
926 g_assert_cmpint(err
, ==, 0);
927 g_assert_cmpint(res
, ==, 123);
928 g_assert(endptr
== str
+ strlen(str
));
931 static void test_qemu_strtoi64_hex(void)
933 const char *str
= "0123";
935 const char *endptr
= &f
;
939 err
= qemu_strtoi64(str
, &endptr
, 16, &res
);
941 g_assert_cmpint(err
, ==, 0);
942 g_assert_cmpint(res
, ==, 0x123);
943 g_assert(endptr
== str
+ strlen(str
));
948 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
950 g_assert_cmpint(err
, ==, 0);
951 g_assert_cmpint(res
, ==, 0x123);
952 g_assert(endptr
== str
+ strlen(str
));
955 static void test_qemu_strtoi64_max(void)
957 char *str
= g_strdup_printf("%lld", LLONG_MAX
);
959 const char *endptr
= &f
;
963 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
965 g_assert_cmpint(err
, ==, 0);
966 g_assert_cmpint(res
, ==, LLONG_MAX
);
967 g_assert(endptr
== str
+ strlen(str
));
971 static void test_qemu_strtoi64_overflow(void)
973 const char *str
= "99999999999999999999999999999999999999999999";
975 const char *endptr
= &f
;
979 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
981 g_assert_cmpint(err
, ==, -ERANGE
);
982 g_assert_cmpint(res
, ==, LLONG_MAX
);
983 g_assert(endptr
== str
+ strlen(str
));
986 static void test_qemu_strtoi64_underflow(void)
988 const char *str
= "-99999999999999999999999999999999999999999999";
990 const char *endptr
= &f
;
994 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
996 g_assert_cmpint(err
, ==, -ERANGE
);
997 g_assert_cmpint(res
, ==, LLONG_MIN
);
998 g_assert(endptr
== str
+ strlen(str
));
1001 static void test_qemu_strtoi64_negative(void)
1003 const char *str
= " \t -321";
1005 const char *endptr
= &f
;
1009 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1011 g_assert_cmpint(err
, ==, 0);
1012 g_assert_cmpint(res
, ==, -321);
1013 g_assert(endptr
== str
+ strlen(str
));
1016 static void test_qemu_strtoi64_full_correct(void)
1018 const char *str
= "123";
1022 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1024 g_assert_cmpint(err
, ==, 0);
1025 g_assert_cmpint(res
, ==, 123);
1028 static void test_qemu_strtoi64_full_null(void)
1033 err
= qemu_strtoi64(NULL
, NULL
, 0, &res
);
1035 g_assert_cmpint(err
, ==, -EINVAL
);
1038 static void test_qemu_strtoi64_full_empty(void)
1040 const char *str
= "";
1044 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1046 g_assert_cmpint(err
, ==, -EINVAL
);
1049 static void test_qemu_strtoi64_full_negative(void)
1051 const char *str
= " \t -321";
1055 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1057 g_assert_cmpint(err
, ==, 0);
1058 g_assert_cmpint(res
, ==, -321);
1061 static void test_qemu_strtoi64_full_trailing(void)
1063 const char *str
= "123xxx";
1067 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1069 g_assert_cmpint(err
, ==, -EINVAL
);
1072 static void test_qemu_strtoi64_full_max(void)
1075 char *str
= g_strdup_printf("%lld", LLONG_MAX
);
1079 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1081 g_assert_cmpint(err
, ==, 0);
1082 g_assert_cmpint(res
, ==, LLONG_MAX
);
1086 static void test_qemu_strtou64_correct(void)
1088 const char *str
= "12345 foo";
1090 const char *endptr
= &f
;
1094 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1096 g_assert_cmpint(err
, ==, 0);
1097 g_assert_cmpuint(res
, ==, 12345);
1098 g_assert(endptr
== str
+ 5);
1101 static void test_qemu_strtou64_null(void)
1104 const char *endptr
= &f
;
1108 err
= qemu_strtou64(NULL
, &endptr
, 0, &res
);
1110 g_assert_cmpint(err
, ==, -EINVAL
);
1111 g_assert(endptr
== NULL
);
1114 static void test_qemu_strtou64_empty(void)
1116 const char *str
= "";
1118 const char *endptr
= &f
;
1122 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1124 g_assert_cmpint(err
, ==, -EINVAL
);
1125 g_assert(endptr
== str
);
1128 static void test_qemu_strtou64_whitespace(void)
1130 const char *str
= " \t ";
1132 const char *endptr
= &f
;
1136 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1138 g_assert_cmpint(err
, ==, -EINVAL
);
1139 g_assert(endptr
== str
);
1142 static void test_qemu_strtou64_invalid(void)
1144 const char *str
= " xxxx \t abc";
1146 const char *endptr
= &f
;
1150 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1152 g_assert_cmpint(err
, ==, -EINVAL
);
1153 g_assert(endptr
== str
);
1156 static void test_qemu_strtou64_trailing(void)
1158 const char *str
= "123xxx";
1160 const char *endptr
= &f
;
1164 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1166 g_assert_cmpint(err
, ==, 0);
1167 g_assert_cmpuint(res
, ==, 123);
1168 g_assert(endptr
== str
+ 3);
1171 static void test_qemu_strtou64_octal(void)
1173 const char *str
= "0123";
1175 const char *endptr
= &f
;
1179 err
= qemu_strtou64(str
, &endptr
, 8, &res
);
1181 g_assert_cmpint(err
, ==, 0);
1182 g_assert_cmpuint(res
, ==, 0123);
1183 g_assert(endptr
== str
+ strlen(str
));
1187 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1189 g_assert_cmpint(err
, ==, 0);
1190 g_assert_cmpuint(res
, ==, 0123);
1191 g_assert(endptr
== str
+ strlen(str
));
1194 static void test_qemu_strtou64_decimal(void)
1196 const char *str
= "0123";
1198 const char *endptr
= &f
;
1202 err
= qemu_strtou64(str
, &endptr
, 10, &res
);
1204 g_assert_cmpint(err
, ==, 0);
1205 g_assert_cmpuint(res
, ==, 123);
1206 g_assert(endptr
== str
+ strlen(str
));
1211 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1213 g_assert_cmpint(err
, ==, 0);
1214 g_assert_cmpuint(res
, ==, 123);
1215 g_assert(endptr
== str
+ strlen(str
));
1218 static void test_qemu_strtou64_hex(void)
1220 const char *str
= "0123";
1222 const char *endptr
= &f
;
1226 err
= qemu_strtou64(str
, &endptr
, 16, &res
);
1228 g_assert_cmpint(err
, ==, 0);
1229 g_assert_cmphex(res
, ==, 0x123);
1230 g_assert(endptr
== str
+ strlen(str
));
1235 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1237 g_assert_cmpint(err
, ==, 0);
1238 g_assert_cmphex(res
, ==, 0x123);
1239 g_assert(endptr
== str
+ strlen(str
));
1242 static void test_qemu_strtou64_max(void)
1244 char *str
= g_strdup_printf("%llu", ULLONG_MAX
);
1246 const char *endptr
= &f
;
1250 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1252 g_assert_cmpint(err
, ==, 0);
1253 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1254 g_assert(endptr
== str
+ strlen(str
));
1258 static void test_qemu_strtou64_overflow(void)
1260 const char *str
= "99999999999999999999999999999999999999999999";
1262 const char *endptr
= &f
;
1266 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1268 g_assert_cmpint(err
, ==, -ERANGE
);
1269 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1270 g_assert(endptr
== str
+ strlen(str
));
1273 static void test_qemu_strtou64_underflow(void)
1275 const char *str
= "-99999999999999999999999999999999999999999999";
1277 const char *endptr
= &f
;
1281 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1283 g_assert_cmpint(err
, ==, -ERANGE
);
1284 g_assert_cmphex(res
, ==, -1ull);
1285 g_assert(endptr
== str
+ strlen(str
));
1288 static void test_qemu_strtou64_negative(void)
1290 const char *str
= " \t -321";
1292 const char *endptr
= &f
;
1296 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1298 g_assert_cmpint(err
, ==, 0);
1299 g_assert_cmpuint(res
, ==, -321ull);
1300 g_assert(endptr
== str
+ strlen(str
));
1303 static void test_qemu_strtou64_full_correct(void)
1305 const char *str
= "18446744073709551614";
1309 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1311 g_assert_cmpint(err
, ==, 0);
1312 g_assert_cmpuint(res
, ==, 18446744073709551614ull);
1315 static void test_qemu_strtou64_full_null(void)
1320 err
= qemu_strtou64(NULL
, NULL
, 0, &res
);
1322 g_assert_cmpint(err
, ==, -EINVAL
);
1325 static void test_qemu_strtou64_full_empty(void)
1327 const char *str
= "";
1331 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1333 g_assert_cmpint(err
, ==, -EINVAL
);
1336 static void test_qemu_strtou64_full_negative(void)
1338 const char *str
= " \t -321";
1342 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1344 g_assert_cmpint(err
, ==, 0);
1345 g_assert_cmpuint(res
, ==, -321ull);
1348 static void test_qemu_strtou64_full_trailing(void)
1350 const char *str
= "18446744073709551614xxxxxx";
1354 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1356 g_assert_cmpint(err
, ==, -EINVAL
);
1359 static void test_qemu_strtou64_full_max(void)
1361 char *str
= g_strdup_printf("%lld", ULLONG_MAX
);
1365 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1367 g_assert_cmpint(err
, ==, 0);
1368 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1372 static void test_qemu_strtosz_simple(void)
1375 char *endptr
= NULL
;
1377 uint64_t res
= 0xbaadf00d;
1380 err
= qemu_strtosz(str
, &endptr
, &res
);
1381 g_assert_cmpint(err
, ==, 0);
1382 g_assert_cmpint(res
, ==, 0);
1383 g_assert(endptr
== str
+ 1);
1386 err
= qemu_strtosz(str
, &endptr
, &res
);
1387 g_assert_cmpint(err
, ==, 0);
1388 g_assert_cmpint(res
, ==, 12345);
1389 g_assert(endptr
== str
+ 5);
1391 err
= qemu_strtosz(str
, NULL
, &res
);
1392 g_assert_cmpint(err
, ==, 0);
1393 g_assert_cmpint(res
, ==, 12345);
1395 /* Note: precision is 53 bits since we're parsing with strtod() */
1397 str
= "9007199254740991"; /* 2^53-1 */
1398 err
= qemu_strtosz(str
, &endptr
, &res
);
1399 g_assert_cmpint(err
, ==, 0);
1400 g_assert_cmpint(res
, ==, 0x1fffffffffffff);
1401 g_assert(endptr
== str
+ 16);
1403 str
= "9007199254740992"; /* 2^53 */
1404 err
= qemu_strtosz(str
, &endptr
, &res
);
1405 g_assert_cmpint(err
, ==, 0);
1406 g_assert_cmpint(res
, ==, 0x20000000000000);
1407 g_assert(endptr
== str
+ 16);
1409 str
= "9007199254740993"; /* 2^53+1 */
1410 err
= qemu_strtosz(str
, &endptr
, &res
);
1411 g_assert_cmpint(err
, ==, 0);
1412 g_assert_cmpint(res
, ==, 0x20000000000000); /* rounded to 53 bits */
1413 g_assert(endptr
== str
+ 16);
1415 str
= "18446744073709549568"; /* 0xfffffffffffff800 (53 msbs set) */
1416 err
= qemu_strtosz(str
, &endptr
, &res
);
1417 g_assert_cmpint(err
, ==, 0);
1418 g_assert_cmpint(res
, ==, 0xfffffffffffff800);
1419 g_assert(endptr
== str
+ 20);
1421 str
= "18446744073709550591"; /* 0xfffffffffffffbff */
1422 err
= qemu_strtosz(str
, &endptr
, &res
);
1423 g_assert_cmpint(err
, ==, 0);
1424 g_assert_cmpint(res
, ==, 0xfffffffffffff800); /* rounded to 53 bits */
1425 g_assert(endptr
== str
+ 20);
1427 /* 0x7ffffffffffffe00..0x7fffffffffffffff get rounded to
1428 * 0x8000000000000000, thus -ERANGE; see test_qemu_strtosz_erange() */
1431 static void test_qemu_strtosz_units(void)
1433 const char *none
= "1";
1434 const char *b
= "1B";
1435 const char *k
= "1K";
1436 const char *m
= "1M";
1437 const char *g
= "1G";
1438 const char *t
= "1T";
1439 const char *p
= "1P";
1440 const char *e
= "1E";
1442 char *endptr
= NULL
;
1443 uint64_t res
= 0xbaadf00d;
1446 err
= qemu_strtosz_MiB(none
, &endptr
, &res
);
1447 g_assert_cmpint(err
, ==, 0);
1448 g_assert_cmpint(res
, ==, M_BYTE
);
1449 g_assert(endptr
== none
+ 1);
1451 err
= qemu_strtosz(b
, &endptr
, &res
);
1452 g_assert_cmpint(err
, ==, 0);
1453 g_assert_cmpint(res
, ==, 1);
1454 g_assert(endptr
== b
+ 2);
1456 err
= qemu_strtosz(k
, &endptr
, &res
);
1457 g_assert_cmpint(err
, ==, 0);
1458 g_assert_cmpint(res
, ==, K_BYTE
);
1459 g_assert(endptr
== k
+ 2);
1461 err
= qemu_strtosz(m
, &endptr
, &res
);
1462 g_assert_cmpint(err
, ==, 0);
1463 g_assert_cmpint(res
, ==, M_BYTE
);
1464 g_assert(endptr
== m
+ 2);
1466 err
= qemu_strtosz(g
, &endptr
, &res
);
1467 g_assert_cmpint(err
, ==, 0);
1468 g_assert_cmpint(res
, ==, G_BYTE
);
1469 g_assert(endptr
== g
+ 2);
1471 err
= qemu_strtosz(t
, &endptr
, &res
);
1472 g_assert_cmpint(err
, ==, 0);
1473 g_assert_cmpint(res
, ==, T_BYTE
);
1474 g_assert(endptr
== t
+ 2);
1476 err
= qemu_strtosz(p
, &endptr
, &res
);
1477 g_assert_cmpint(err
, ==, 0);
1478 g_assert_cmpint(res
, ==, P_BYTE
);
1479 g_assert(endptr
== p
+ 2);
1481 err
= qemu_strtosz(e
, &endptr
, &res
);
1482 g_assert_cmpint(err
, ==, 0);
1483 g_assert_cmpint(res
, ==, E_BYTE
);
1484 g_assert(endptr
== e
+ 2);
1487 static void test_qemu_strtosz_float(void)
1489 const char *str
= "12.345M";
1491 char *endptr
= NULL
;
1492 uint64_t res
= 0xbaadf00d;
1494 err
= qemu_strtosz(str
, &endptr
, &res
);
1495 g_assert_cmpint(err
, ==, 0);
1496 g_assert_cmpint(res
, ==, 12.345 * M_BYTE
);
1497 g_assert(endptr
== str
+ 7);
1500 static void test_qemu_strtosz_invalid(void)
1503 char *endptr
= NULL
;
1505 uint64_t res
= 0xbaadf00d;
1508 err
= qemu_strtosz(str
, &endptr
, &res
);
1509 g_assert_cmpint(err
, ==, -EINVAL
);
1510 g_assert(endptr
== str
);
1513 err
= qemu_strtosz(str
, &endptr
, &res
);
1514 g_assert_cmpint(err
, ==, -EINVAL
);
1515 g_assert(endptr
== str
);
1518 err
= qemu_strtosz(str
, &endptr
, &res
);
1519 g_assert_cmpint(err
, ==, -EINVAL
);
1520 g_assert(endptr
== str
);
1523 static void test_qemu_strtosz_trailing(void)
1526 char *endptr
= NULL
;
1528 uint64_t res
= 0xbaadf00d;
1531 err
= qemu_strtosz_MiB(str
, &endptr
, &res
);
1532 g_assert_cmpint(res
, ==, 123 * M_BYTE
);
1533 g_assert(endptr
== str
+ 3);
1535 err
= qemu_strtosz(str
, NULL
, &res
);
1536 g_assert_cmpint(err
, ==, -EINVAL
);
1539 err
= qemu_strtosz(str
, &endptr
, &res
);
1540 g_assert_cmpint(err
, ==, 0);
1541 g_assert_cmpint(res
, ==, 1024);
1542 g_assert(endptr
== str
+ 2);
1544 err
= qemu_strtosz(str
, NULL
, &res
);
1545 g_assert_cmpint(err
, ==, -EINVAL
);
1548 static void test_qemu_strtosz_erange(void)
1551 char *endptr
= NULL
;
1553 uint64_t res
= 0xbaadf00d;
1556 err
= qemu_strtosz(str
, &endptr
, &res
);
1557 g_assert_cmpint(err
, ==, -ERANGE
);
1558 g_assert(endptr
== str
+ 2);
1560 str
= "18446744073709550592"; /* 0xfffffffffffffc00 */
1561 err
= qemu_strtosz(str
, &endptr
, &res
);
1562 g_assert_cmpint(err
, ==, -ERANGE
);
1563 g_assert(endptr
== str
+ 20);
1565 str
= "18446744073709551615"; /* 2^64-1 */
1566 err
= qemu_strtosz(str
, &endptr
, &res
);
1567 g_assert_cmpint(err
, ==, -ERANGE
);
1568 g_assert(endptr
== str
+ 20);
1570 str
= "18446744073709551616"; /* 2^64 */
1571 err
= qemu_strtosz(str
, &endptr
, &res
);
1572 g_assert_cmpint(err
, ==, -ERANGE
);
1573 g_assert(endptr
== str
+ 20);
1576 err
= qemu_strtosz(str
, &endptr
, &res
);
1577 g_assert_cmpint(err
, ==, -ERANGE
);
1578 g_assert(endptr
== str
+ 3);
1581 static void test_qemu_strtosz_metric(void)
1583 const char *str
= "12345k";
1585 char *endptr
= NULL
;
1586 uint64_t res
= 0xbaadf00d;
1588 err
= qemu_strtosz_metric(str
, &endptr
, &res
);
1589 g_assert_cmpint(err
, ==, 0);
1590 g_assert_cmpint(res
, ==, 12345000);
1591 g_assert(endptr
== str
+ 6);
1594 int main(int argc
, char **argv
)
1596 g_test_init(&argc
, &argv
, NULL
);
1598 g_test_add_func("/cutils/parse_uint/null", test_parse_uint_null
);
1599 g_test_add_func("/cutils/parse_uint/empty", test_parse_uint_empty
);
1600 g_test_add_func("/cutils/parse_uint/whitespace",
1601 test_parse_uint_whitespace
);
1602 g_test_add_func("/cutils/parse_uint/invalid", test_parse_uint_invalid
);
1603 g_test_add_func("/cutils/parse_uint/trailing", test_parse_uint_trailing
);
1604 g_test_add_func("/cutils/parse_uint/correct", test_parse_uint_correct
);
1605 g_test_add_func("/cutils/parse_uint/octal", test_parse_uint_octal
);
1606 g_test_add_func("/cutils/parse_uint/decimal", test_parse_uint_decimal
);
1607 g_test_add_func("/cutils/parse_uint/llong_max", test_parse_uint_llong_max
);
1608 g_test_add_func("/cutils/parse_uint/overflow", test_parse_uint_overflow
);
1609 g_test_add_func("/cutils/parse_uint/negative", test_parse_uint_negative
);
1610 g_test_add_func("/cutils/parse_uint_full/trailing",
1611 test_parse_uint_full_trailing
);
1612 g_test_add_func("/cutils/parse_uint_full/correct",
1613 test_parse_uint_full_correct
);
1615 /* qemu_strtol() tests */
1616 g_test_add_func("/cutils/qemu_strtol/correct",
1617 test_qemu_strtol_correct
);
1618 g_test_add_func("/cutils/qemu_strtol/null",
1619 test_qemu_strtol_null
);
1620 g_test_add_func("/cutils/qemu_strtol/empty",
1621 test_qemu_strtol_empty
);
1622 g_test_add_func("/cutils/qemu_strtol/whitespace",
1623 test_qemu_strtol_whitespace
);
1624 g_test_add_func("/cutils/qemu_strtol/invalid",
1625 test_qemu_strtol_invalid
);
1626 g_test_add_func("/cutils/qemu_strtol/trailing",
1627 test_qemu_strtol_trailing
);
1628 g_test_add_func("/cutils/qemu_strtol/octal",
1629 test_qemu_strtol_octal
);
1630 g_test_add_func("/cutils/qemu_strtol/decimal",
1631 test_qemu_strtol_decimal
);
1632 g_test_add_func("/cutils/qemu_strtol/hex",
1633 test_qemu_strtol_hex
);
1634 g_test_add_func("/cutils/qemu_strtol/max",
1635 test_qemu_strtol_max
);
1636 g_test_add_func("/cutils/qemu_strtol/overflow",
1637 test_qemu_strtol_overflow
);
1638 g_test_add_func("/cutils/qemu_strtol/underflow",
1639 test_qemu_strtol_underflow
);
1640 g_test_add_func("/cutils/qemu_strtol/negative",
1641 test_qemu_strtol_negative
);
1642 g_test_add_func("/cutils/qemu_strtol_full/correct",
1643 test_qemu_strtol_full_correct
);
1644 g_test_add_func("/cutils/qemu_strtol_full/null",
1645 test_qemu_strtol_full_null
);
1646 g_test_add_func("/cutils/qemu_strtol_full/empty",
1647 test_qemu_strtol_full_empty
);
1648 g_test_add_func("/cutils/qemu_strtol_full/negative",
1649 test_qemu_strtol_full_negative
);
1650 g_test_add_func("/cutils/qemu_strtol_full/trailing",
1651 test_qemu_strtol_full_trailing
);
1652 g_test_add_func("/cutils/qemu_strtol_full/max",
1653 test_qemu_strtol_full_max
);
1655 /* qemu_strtoul() tests */
1656 g_test_add_func("/cutils/qemu_strtoul/correct",
1657 test_qemu_strtoul_correct
);
1658 g_test_add_func("/cutils/qemu_strtoul/null",
1659 test_qemu_strtoul_null
);
1660 g_test_add_func("/cutils/qemu_strtoul/empty",
1661 test_qemu_strtoul_empty
);
1662 g_test_add_func("/cutils/qemu_strtoul/whitespace",
1663 test_qemu_strtoul_whitespace
);
1664 g_test_add_func("/cutils/qemu_strtoul/invalid",
1665 test_qemu_strtoul_invalid
);
1666 g_test_add_func("/cutils/qemu_strtoul/trailing",
1667 test_qemu_strtoul_trailing
);
1668 g_test_add_func("/cutils/qemu_strtoul/octal",
1669 test_qemu_strtoul_octal
);
1670 g_test_add_func("/cutils/qemu_strtoul/decimal",
1671 test_qemu_strtoul_decimal
);
1672 g_test_add_func("/cutils/qemu_strtoul/hex",
1673 test_qemu_strtoul_hex
);
1674 g_test_add_func("/cutils/qemu_strtoul/max",
1675 test_qemu_strtoul_max
);
1676 g_test_add_func("/cutils/qemu_strtoul/overflow",
1677 test_qemu_strtoul_overflow
);
1678 g_test_add_func("/cutils/qemu_strtoul/underflow",
1679 test_qemu_strtoul_underflow
);
1680 g_test_add_func("/cutils/qemu_strtoul/negative",
1681 test_qemu_strtoul_negative
);
1682 g_test_add_func("/cutils/qemu_strtoul_full/correct",
1683 test_qemu_strtoul_full_correct
);
1684 g_test_add_func("/cutils/qemu_strtoul_full/null",
1685 test_qemu_strtoul_full_null
);
1686 g_test_add_func("/cutils/qemu_strtoul_full/empty",
1687 test_qemu_strtoul_full_empty
);
1688 g_test_add_func("/cutils/qemu_strtoul_full/negative",
1689 test_qemu_strtoul_full_negative
);
1690 g_test_add_func("/cutils/qemu_strtoul_full/trailing",
1691 test_qemu_strtoul_full_trailing
);
1692 g_test_add_func("/cutils/qemu_strtoul_full/max",
1693 test_qemu_strtoul_full_max
);
1695 /* qemu_strtoi64() tests */
1696 g_test_add_func("/cutils/qemu_strtoi64/correct",
1697 test_qemu_strtoi64_correct
);
1698 g_test_add_func("/cutils/qemu_strtoi64/null",
1699 test_qemu_strtoi64_null
);
1700 g_test_add_func("/cutils/qemu_strtoi64/empty",
1701 test_qemu_strtoi64_empty
);
1702 g_test_add_func("/cutils/qemu_strtoi64/whitespace",
1703 test_qemu_strtoi64_whitespace
);
1704 g_test_add_func("/cutils/qemu_strtoi64/invalid"
1706 test_qemu_strtoi64_invalid
);
1707 g_test_add_func("/cutils/qemu_strtoi64/trailing",
1708 test_qemu_strtoi64_trailing
);
1709 g_test_add_func("/cutils/qemu_strtoi64/octal",
1710 test_qemu_strtoi64_octal
);
1711 g_test_add_func("/cutils/qemu_strtoi64/decimal",
1712 test_qemu_strtoi64_decimal
);
1713 g_test_add_func("/cutils/qemu_strtoi64/hex",
1714 test_qemu_strtoi64_hex
);
1715 g_test_add_func("/cutils/qemu_strtoi64/max",
1716 test_qemu_strtoi64_max
);
1717 g_test_add_func("/cutils/qemu_strtoi64/overflow",
1718 test_qemu_strtoi64_overflow
);
1719 g_test_add_func("/cutils/qemu_strtoi64/underflow",
1720 test_qemu_strtoi64_underflow
);
1721 g_test_add_func("/cutils/qemu_strtoi64/negative",
1722 test_qemu_strtoi64_negative
);
1723 g_test_add_func("/cutils/qemu_strtoi64_full/correct",
1724 test_qemu_strtoi64_full_correct
);
1725 g_test_add_func("/cutils/qemu_strtoi64_full/null",
1726 test_qemu_strtoi64_full_null
);
1727 g_test_add_func("/cutils/qemu_strtoi64_full/empty",
1728 test_qemu_strtoi64_full_empty
);
1729 g_test_add_func("/cutils/qemu_strtoi64_full/negative",
1730 test_qemu_strtoi64_full_negative
);
1731 g_test_add_func("/cutils/qemu_strtoi64_full/trailing",
1732 test_qemu_strtoi64_full_trailing
);
1733 g_test_add_func("/cutils/qemu_strtoi64_full/max",
1734 test_qemu_strtoi64_full_max
);
1736 /* qemu_strtou64() tests */
1737 g_test_add_func("/cutils/qemu_strtou64/correct",
1738 test_qemu_strtou64_correct
);
1739 g_test_add_func("/cutils/qemu_strtou64/null",
1740 test_qemu_strtou64_null
);
1741 g_test_add_func("/cutils/qemu_strtou64/empty",
1742 test_qemu_strtou64_empty
);
1743 g_test_add_func("/cutils/qemu_strtou64/whitespace",
1744 test_qemu_strtou64_whitespace
);
1745 g_test_add_func("/cutils/qemu_strtou64/invalid",
1746 test_qemu_strtou64_invalid
);
1747 g_test_add_func("/cutils/qemu_strtou64/trailing",
1748 test_qemu_strtou64_trailing
);
1749 g_test_add_func("/cutils/qemu_strtou64/octal",
1750 test_qemu_strtou64_octal
);
1751 g_test_add_func("/cutils/qemu_strtou64/decimal",
1752 test_qemu_strtou64_decimal
);
1753 g_test_add_func("/cutils/qemu_strtou64/hex",
1754 test_qemu_strtou64_hex
);
1755 g_test_add_func("/cutils/qemu_strtou64/max",
1756 test_qemu_strtou64_max
);
1757 g_test_add_func("/cutils/qemu_strtou64/overflow",
1758 test_qemu_strtou64_overflow
);
1759 g_test_add_func("/cutils/qemu_strtou64/underflow",
1760 test_qemu_strtou64_underflow
);
1761 g_test_add_func("/cutils/qemu_strtou64/negative",
1762 test_qemu_strtou64_negative
);
1763 g_test_add_func("/cutils/qemu_strtou64_full/correct",
1764 test_qemu_strtou64_full_correct
);
1765 g_test_add_func("/cutils/qemu_strtou64_full/null",
1766 test_qemu_strtou64_full_null
);
1767 g_test_add_func("/cutils/qemu_strtou64_full/empty",
1768 test_qemu_strtou64_full_empty
);
1769 g_test_add_func("/cutils/qemu_strtou64_full/negative",
1770 test_qemu_strtou64_full_negative
);
1771 g_test_add_func("/cutils/qemu_strtou64_full/trailing",
1772 test_qemu_strtou64_full_trailing
);
1773 g_test_add_func("/cutils/qemu_strtou64_full/max",
1774 test_qemu_strtou64_full_max
);
1776 g_test_add_func("/cutils/strtosz/simple",
1777 test_qemu_strtosz_simple
);
1778 g_test_add_func("/cutils/strtosz/units",
1779 test_qemu_strtosz_units
);
1780 g_test_add_func("/cutils/strtosz/float",
1781 test_qemu_strtosz_float
);
1782 g_test_add_func("/cutils/strtosz/invalid",
1783 test_qemu_strtosz_invalid
);
1784 g_test_add_func("/cutils/strtosz/trailing",
1785 test_qemu_strtosz_trailing
);
1786 g_test_add_func("/cutils/strtosz/erange",
1787 test_qemu_strtosz_erange
);
1788 g_test_add_func("/cutils/strtosz/metric",
1789 test_qemu_strtosz_metric
);
1791 return g_test_run();