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/units.h"
30 #include "qemu/cutils.h"
31 #include "qemu/units.h"
33 static void test_parse_uint_null(void)
35 unsigned long long i
= 999;
40 r
= parse_uint(NULL
, &i
, &endptr
, 0);
42 g_assert_cmpint(r
, ==, -EINVAL
);
43 g_assert_cmpint(i
, ==, 0);
44 g_assert(endptr
== NULL
);
47 static void test_parse_uint_empty(void)
49 unsigned long long i
= 999;
55 r
= parse_uint(str
, &i
, &endptr
, 0);
57 g_assert_cmpint(r
, ==, -EINVAL
);
58 g_assert_cmpint(i
, ==, 0);
59 g_assert(endptr
== str
);
62 static void test_parse_uint_whitespace(void)
64 unsigned long long i
= 999;
67 const char *str
= " \t ";
70 r
= parse_uint(str
, &i
, &endptr
, 0);
72 g_assert_cmpint(r
, ==, -EINVAL
);
73 g_assert_cmpint(i
, ==, 0);
74 g_assert(endptr
== str
);
78 static void test_parse_uint_invalid(void)
80 unsigned long long i
= 999;
83 const char *str
= " \t xxx";
86 r
= parse_uint(str
, &i
, &endptr
, 0);
88 g_assert_cmpint(r
, ==, -EINVAL
);
89 g_assert_cmpint(i
, ==, 0);
90 g_assert(endptr
== str
);
94 static void test_parse_uint_trailing(void)
96 unsigned long long i
= 999;
99 const char *str
= "123xxx";
102 r
= parse_uint(str
, &i
, &endptr
, 0);
104 g_assert_cmpint(r
, ==, 0);
105 g_assert_cmpint(i
, ==, 123);
106 g_assert(endptr
== str
+ 3);
109 static void test_parse_uint_correct(void)
111 unsigned long long i
= 999;
114 const char *str
= "123";
117 r
= parse_uint(str
, &i
, &endptr
, 0);
119 g_assert_cmpint(r
, ==, 0);
120 g_assert_cmpint(i
, ==, 123);
121 g_assert(endptr
== str
+ strlen(str
));
124 static void test_parse_uint_octal(void)
126 unsigned long long i
= 999;
129 const char *str
= "0123";
132 r
= parse_uint(str
, &i
, &endptr
, 0);
134 g_assert_cmpint(r
, ==, 0);
135 g_assert_cmpint(i
, ==, 0123);
136 g_assert(endptr
== str
+ strlen(str
));
139 static void test_parse_uint_decimal(void)
141 unsigned long long i
= 999;
144 const char *str
= "0123";
147 r
= parse_uint(str
, &i
, &endptr
, 10);
149 g_assert_cmpint(r
, ==, 0);
150 g_assert_cmpint(i
, ==, 123);
151 g_assert(endptr
== str
+ strlen(str
));
155 static void test_parse_uint_llong_max(void)
157 unsigned long long i
= 999;
160 char *str
= g_strdup_printf("%llu", (unsigned long long)LLONG_MAX
+ 1);
163 r
= parse_uint(str
, &i
, &endptr
, 0);
165 g_assert_cmpint(r
, ==, 0);
166 g_assert_cmpint(i
, ==, (unsigned long long)LLONG_MAX
+ 1);
167 g_assert(endptr
== str
+ strlen(str
));
172 static void test_parse_uint_overflow(void)
174 unsigned long long i
= 999;
177 const char *str
= "99999999999999999999999999999999999999";
180 r
= parse_uint(str
, &i
, &endptr
, 0);
182 g_assert_cmpint(r
, ==, -ERANGE
);
183 g_assert_cmpint(i
, ==, ULLONG_MAX
);
184 g_assert(endptr
== str
+ strlen(str
));
187 static void test_parse_uint_negative(void)
189 unsigned long long i
= 999;
192 const char *str
= " \t -321";
195 r
= parse_uint(str
, &i
, &endptr
, 0);
197 g_assert_cmpint(r
, ==, -ERANGE
);
198 g_assert_cmpint(i
, ==, 0);
199 g_assert(endptr
== str
+ strlen(str
));
203 static void test_parse_uint_full_trailing(void)
205 unsigned long long i
= 999;
206 const char *str
= "123xxx";
209 r
= parse_uint_full(str
, &i
, 0);
211 g_assert_cmpint(r
, ==, -EINVAL
);
212 g_assert_cmpint(i
, ==, 0);
215 static void test_parse_uint_full_correct(void)
217 unsigned long long i
= 999;
218 const char *str
= "123";
221 r
= parse_uint_full(str
, &i
, 0);
223 g_assert_cmpint(r
, ==, 0);
224 g_assert_cmpint(i
, ==, 123);
227 static void test_qemu_strtoi_correct(void)
229 const char *str
= "12345 foo";
231 const char *endptr
= &f
;
235 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
237 g_assert_cmpint(err
, ==, 0);
238 g_assert_cmpint(res
, ==, 12345);
239 g_assert(endptr
== str
+ 5);
242 static void test_qemu_strtoi_null(void)
245 const char *endptr
= &f
;
249 err
= qemu_strtoi(NULL
, &endptr
, 0, &res
);
251 g_assert_cmpint(err
, ==, -EINVAL
);
252 g_assert(endptr
== NULL
);
255 static void test_qemu_strtoi_empty(void)
257 const char *str
= "";
259 const char *endptr
= &f
;
263 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
265 g_assert_cmpint(err
, ==, -EINVAL
);
266 g_assert(endptr
== str
);
269 static void test_qemu_strtoi_whitespace(void)
271 const char *str
= " \t ";
273 const char *endptr
= &f
;
277 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
279 g_assert_cmpint(err
, ==, -EINVAL
);
280 g_assert(endptr
== str
);
283 static void test_qemu_strtoi_invalid(void)
285 const char *str
= " xxxx \t abc";
287 const char *endptr
= &f
;
291 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
293 g_assert_cmpint(err
, ==, -EINVAL
);
294 g_assert(endptr
== str
);
297 static void test_qemu_strtoi_trailing(void)
299 const char *str
= "123xxx";
301 const char *endptr
= &f
;
305 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
307 g_assert_cmpint(err
, ==, 0);
308 g_assert_cmpint(res
, ==, 123);
309 g_assert(endptr
== str
+ 3);
312 static void test_qemu_strtoi_octal(void)
314 const char *str
= "0123";
316 const char *endptr
= &f
;
320 err
= qemu_strtoi(str
, &endptr
, 8, &res
);
322 g_assert_cmpint(err
, ==, 0);
323 g_assert_cmpint(res
, ==, 0123);
324 g_assert(endptr
== str
+ strlen(str
));
328 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
330 g_assert_cmpint(err
, ==, 0);
331 g_assert_cmpint(res
, ==, 0123);
332 g_assert(endptr
== str
+ strlen(str
));
335 static void test_qemu_strtoi_decimal(void)
337 const char *str
= "0123";
339 const char *endptr
= &f
;
343 err
= qemu_strtoi(str
, &endptr
, 10, &res
);
345 g_assert_cmpint(err
, ==, 0);
346 g_assert_cmpint(res
, ==, 123);
347 g_assert(endptr
== str
+ strlen(str
));
352 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
354 g_assert_cmpint(err
, ==, 0);
355 g_assert_cmpint(res
, ==, 123);
356 g_assert(endptr
== str
+ strlen(str
));
359 static void test_qemu_strtoi_hex(void)
361 const char *str
= "0123";
363 const char *endptr
= &f
;
367 err
= qemu_strtoi(str
, &endptr
, 16, &res
);
369 g_assert_cmpint(err
, ==, 0);
370 g_assert_cmpint(res
, ==, 0x123);
371 g_assert(endptr
== str
+ strlen(str
));
376 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
378 g_assert_cmpint(err
, ==, 0);
379 g_assert_cmpint(res
, ==, 0x123);
380 g_assert(endptr
== str
+ strlen(str
));
383 static void test_qemu_strtoi_max(void)
385 char *str
= g_strdup_printf("%d", INT_MAX
);
387 const char *endptr
= &f
;
391 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
393 g_assert_cmpint(err
, ==, 0);
394 g_assert_cmpint(res
, ==, INT_MAX
);
395 g_assert(endptr
== str
+ strlen(str
));
399 static void test_qemu_strtoi_overflow(void)
401 char *str
= g_strdup_printf("%lld", (long long)INT_MAX
+ 1ll);
403 const char *endptr
= &f
;
407 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
409 g_assert_cmpint(err
, ==, -ERANGE
);
410 g_assert_cmpint(res
, ==, INT_MAX
);
411 g_assert(endptr
== str
+ strlen(str
));
415 static void test_qemu_strtoi_underflow(void)
417 char *str
= g_strdup_printf("%lld", (long long)INT_MIN
- 1ll);
419 const char *endptr
= &f
;
423 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
425 g_assert_cmpint(err
, ==, -ERANGE
);
426 g_assert_cmpint(res
, ==, INT_MIN
);
427 g_assert(endptr
== str
+ strlen(str
));
431 static void test_qemu_strtoi_negative(void)
433 const char *str
= " \t -321";
435 const char *endptr
= &f
;
439 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
441 g_assert_cmpint(err
, ==, 0);
442 g_assert_cmpint(res
, ==, -321);
443 g_assert(endptr
== str
+ strlen(str
));
446 static void test_qemu_strtoi_full_correct(void)
448 const char *str
= "123";
452 err
= qemu_strtoi(str
, NULL
, 0, &res
);
454 g_assert_cmpint(err
, ==, 0);
455 g_assert_cmpint(res
, ==, 123);
458 static void test_qemu_strtoi_full_null(void)
461 const char *endptr
= &f
;
465 err
= qemu_strtoi(NULL
, &endptr
, 0, &res
);
467 g_assert_cmpint(err
, ==, -EINVAL
);
468 g_assert(endptr
== NULL
);
471 static void test_qemu_strtoi_full_empty(void)
473 const char *str
= "";
477 err
= qemu_strtoi(str
, NULL
, 0, &res
);
479 g_assert_cmpint(err
, ==, -EINVAL
);
482 static void test_qemu_strtoi_full_negative(void)
484 const char *str
= " \t -321";
488 err
= qemu_strtoi(str
, NULL
, 0, &res
);
490 g_assert_cmpint(err
, ==, 0);
491 g_assert_cmpint(res
, ==, -321);
494 static void test_qemu_strtoi_full_trailing(void)
496 const char *str
= "123xxx";
500 err
= qemu_strtoi(str
, NULL
, 0, &res
);
502 g_assert_cmpint(err
, ==, -EINVAL
);
505 static void test_qemu_strtoi_full_max(void)
507 char *str
= g_strdup_printf("%d", INT_MAX
);
511 err
= qemu_strtoi(str
, NULL
, 0, &res
);
513 g_assert_cmpint(err
, ==, 0);
514 g_assert_cmpint(res
, ==, INT_MAX
);
518 static void test_qemu_strtoui_correct(void)
520 const char *str
= "12345 foo";
522 const char *endptr
= &f
;
523 unsigned int res
= 999;
526 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
528 g_assert_cmpint(err
, ==, 0);
529 g_assert_cmpuint(res
, ==, 12345);
530 g_assert(endptr
== str
+ 5);
533 static void test_qemu_strtoui_null(void)
536 const char *endptr
= &f
;
537 unsigned int res
= 999;
540 err
= qemu_strtoui(NULL
, &endptr
, 0, &res
);
542 g_assert_cmpint(err
, ==, -EINVAL
);
543 g_assert(endptr
== NULL
);
546 static void test_qemu_strtoui_empty(void)
548 const char *str
= "";
550 const char *endptr
= &f
;
551 unsigned int res
= 999;
554 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
556 g_assert_cmpint(err
, ==, -EINVAL
);
557 g_assert(endptr
== str
);
560 static void test_qemu_strtoui_whitespace(void)
562 const char *str
= " \t ";
564 const char *endptr
= &f
;
565 unsigned int res
= 999;
568 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
570 g_assert_cmpint(err
, ==, -EINVAL
);
571 g_assert(endptr
== str
);
574 static void test_qemu_strtoui_invalid(void)
576 const char *str
= " xxxx \t abc";
578 const char *endptr
= &f
;
579 unsigned int res
= 999;
582 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
584 g_assert_cmpint(err
, ==, -EINVAL
);
585 g_assert(endptr
== str
);
588 static void test_qemu_strtoui_trailing(void)
590 const char *str
= "123xxx";
592 const char *endptr
= &f
;
593 unsigned int res
= 999;
596 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
598 g_assert_cmpint(err
, ==, 0);
599 g_assert_cmpuint(res
, ==, 123);
600 g_assert(endptr
== str
+ 3);
603 static void test_qemu_strtoui_octal(void)
605 const char *str
= "0123";
607 const char *endptr
= &f
;
608 unsigned int res
= 999;
611 err
= qemu_strtoui(str
, &endptr
, 8, &res
);
613 g_assert_cmpint(err
, ==, 0);
614 g_assert_cmpuint(res
, ==, 0123);
615 g_assert(endptr
== str
+ strlen(str
));
619 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
621 g_assert_cmpint(err
, ==, 0);
622 g_assert_cmpuint(res
, ==, 0123);
623 g_assert(endptr
== str
+ strlen(str
));
626 static void test_qemu_strtoui_decimal(void)
628 const char *str
= "0123";
630 const char *endptr
= &f
;
631 unsigned int res
= 999;
634 err
= qemu_strtoui(str
, &endptr
, 10, &res
);
636 g_assert_cmpint(err
, ==, 0);
637 g_assert_cmpuint(res
, ==, 123);
638 g_assert(endptr
== str
+ strlen(str
));
643 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
645 g_assert_cmpint(err
, ==, 0);
646 g_assert_cmpuint(res
, ==, 123);
647 g_assert(endptr
== str
+ strlen(str
));
650 static void test_qemu_strtoui_hex(void)
652 const char *str
= "0123";
654 const char *endptr
= &f
;
655 unsigned int res
= 999;
658 err
= qemu_strtoui(str
, &endptr
, 16, &res
);
660 g_assert_cmpint(err
, ==, 0);
661 g_assert_cmphex(res
, ==, 0x123);
662 g_assert(endptr
== str
+ strlen(str
));
667 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
669 g_assert_cmpint(err
, ==, 0);
670 g_assert_cmphex(res
, ==, 0x123);
671 g_assert(endptr
== str
+ strlen(str
));
674 static void test_qemu_strtoui_max(void)
676 char *str
= g_strdup_printf("%u", UINT_MAX
);
678 const char *endptr
= &f
;
679 unsigned int res
= 999;
682 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
684 g_assert_cmpint(err
, ==, 0);
685 g_assert_cmphex(res
, ==, UINT_MAX
);
686 g_assert(endptr
== str
+ strlen(str
));
690 static void test_qemu_strtoui_overflow(void)
692 char *str
= g_strdup_printf("%lld", (long long)UINT_MAX
+ 1ll);
694 const char *endptr
= &f
;
695 unsigned int res
= 999;
698 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
700 g_assert_cmpint(err
, ==, -ERANGE
);
701 g_assert_cmphex(res
, ==, UINT_MAX
);
702 g_assert(endptr
== str
+ strlen(str
));
706 static void test_qemu_strtoui_underflow(void)
708 char *str
= g_strdup_printf("%lld", (long long)INT_MIN
- 1ll);
710 const char *endptr
= &f
;
711 unsigned int res
= 999;
714 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
716 g_assert_cmpint(err
, ==, -ERANGE
);
717 g_assert_cmpuint(res
, ==, (unsigned int)-1);
718 g_assert(endptr
== str
+ strlen(str
));
722 static void test_qemu_strtoui_negative(void)
724 const char *str
= " \t -321";
726 const char *endptr
= &f
;
727 unsigned int res
= 999;
730 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
732 g_assert_cmpint(err
, ==, 0);
733 g_assert_cmpuint(res
, ==, (unsigned int)-321);
734 g_assert(endptr
== str
+ strlen(str
));
737 static void test_qemu_strtoui_full_correct(void)
739 const char *str
= "123";
740 unsigned int res
= 999;
743 err
= qemu_strtoui(str
, NULL
, 0, &res
);
745 g_assert_cmpint(err
, ==, 0);
746 g_assert_cmpuint(res
, ==, 123);
749 static void test_qemu_strtoui_full_null(void)
751 unsigned int res
= 999;
754 err
= qemu_strtoui(NULL
, NULL
, 0, &res
);
756 g_assert_cmpint(err
, ==, -EINVAL
);
759 static void test_qemu_strtoui_full_empty(void)
761 const char *str
= "";
762 unsigned int res
= 999;
765 err
= qemu_strtoui(str
, NULL
, 0, &res
);
767 g_assert_cmpint(err
, ==, -EINVAL
);
769 static void test_qemu_strtoui_full_negative(void)
771 const char *str
= " \t -321";
772 unsigned int res
= 999;
775 err
= qemu_strtoui(str
, NULL
, 0, &res
);
776 g_assert_cmpint(err
, ==, 0);
777 g_assert_cmpuint(res
, ==, (unsigned int)-321);
780 static void test_qemu_strtoui_full_trailing(void)
782 const char *str
= "123xxx";
786 err
= qemu_strtoui(str
, NULL
, 0, &res
);
788 g_assert_cmpint(err
, ==, -EINVAL
);
791 static void test_qemu_strtoui_full_max(void)
793 char *str
= g_strdup_printf("%u", UINT_MAX
);
794 unsigned int res
= 999;
797 err
= qemu_strtoui(str
, NULL
, 0, &res
);
799 g_assert_cmpint(err
, ==, 0);
800 g_assert_cmphex(res
, ==, UINT_MAX
);
804 static void test_qemu_strtol_correct(void)
806 const char *str
= "12345 foo";
808 const char *endptr
= &f
;
812 err
= qemu_strtol(str
, &endptr
, 0, &res
);
814 g_assert_cmpint(err
, ==, 0);
815 g_assert_cmpint(res
, ==, 12345);
816 g_assert(endptr
== str
+ 5);
819 static void test_qemu_strtol_null(void)
822 const char *endptr
= &f
;
826 err
= qemu_strtol(NULL
, &endptr
, 0, &res
);
828 g_assert_cmpint(err
, ==, -EINVAL
);
829 g_assert(endptr
== NULL
);
832 static void test_qemu_strtol_empty(void)
834 const char *str
= "";
836 const char *endptr
= &f
;
840 err
= qemu_strtol(str
, &endptr
, 0, &res
);
842 g_assert_cmpint(err
, ==, -EINVAL
);
843 g_assert(endptr
== str
);
846 static void test_qemu_strtol_whitespace(void)
848 const char *str
= " \t ";
850 const char *endptr
= &f
;
854 err
= qemu_strtol(str
, &endptr
, 0, &res
);
856 g_assert_cmpint(err
, ==, -EINVAL
);
857 g_assert(endptr
== str
);
860 static void test_qemu_strtol_invalid(void)
862 const char *str
= " xxxx \t abc";
864 const char *endptr
= &f
;
868 err
= qemu_strtol(str
, &endptr
, 0, &res
);
870 g_assert_cmpint(err
, ==, -EINVAL
);
871 g_assert(endptr
== str
);
874 static void test_qemu_strtol_trailing(void)
876 const char *str
= "123xxx";
878 const char *endptr
= &f
;
882 err
= qemu_strtol(str
, &endptr
, 0, &res
);
884 g_assert_cmpint(err
, ==, 0);
885 g_assert_cmpint(res
, ==, 123);
886 g_assert(endptr
== str
+ 3);
889 static void test_qemu_strtol_octal(void)
891 const char *str
= "0123";
893 const char *endptr
= &f
;
897 err
= qemu_strtol(str
, &endptr
, 8, &res
);
899 g_assert_cmpint(err
, ==, 0);
900 g_assert_cmpint(res
, ==, 0123);
901 g_assert(endptr
== str
+ strlen(str
));
905 err
= qemu_strtol(str
, &endptr
, 0, &res
);
907 g_assert_cmpint(err
, ==, 0);
908 g_assert_cmpint(res
, ==, 0123);
909 g_assert(endptr
== str
+ strlen(str
));
912 static void test_qemu_strtol_decimal(void)
914 const char *str
= "0123";
916 const char *endptr
= &f
;
920 err
= qemu_strtol(str
, &endptr
, 10, &res
);
922 g_assert_cmpint(err
, ==, 0);
923 g_assert_cmpint(res
, ==, 123);
924 g_assert(endptr
== str
+ strlen(str
));
929 err
= qemu_strtol(str
, &endptr
, 0, &res
);
931 g_assert_cmpint(err
, ==, 0);
932 g_assert_cmpint(res
, ==, 123);
933 g_assert(endptr
== str
+ strlen(str
));
936 static void test_qemu_strtol_hex(void)
938 const char *str
= "0123";
940 const char *endptr
= &f
;
944 err
= qemu_strtol(str
, &endptr
, 16, &res
);
946 g_assert_cmpint(err
, ==, 0);
947 g_assert_cmpint(res
, ==, 0x123);
948 g_assert(endptr
== str
+ strlen(str
));
953 err
= qemu_strtol(str
, &endptr
, 0, &res
);
955 g_assert_cmpint(err
, ==, 0);
956 g_assert_cmpint(res
, ==, 0x123);
957 g_assert(endptr
== str
+ strlen(str
));
960 static void test_qemu_strtol_max(void)
962 char *str
= g_strdup_printf("%ld", LONG_MAX
);
964 const char *endptr
= &f
;
968 err
= qemu_strtol(str
, &endptr
, 0, &res
);
970 g_assert_cmpint(err
, ==, 0);
971 g_assert_cmpint(res
, ==, LONG_MAX
);
972 g_assert(endptr
== str
+ strlen(str
));
976 static void test_qemu_strtol_overflow(void)
978 const char *str
= "99999999999999999999999999999999999999999999";
980 const char *endptr
= &f
;
984 err
= qemu_strtol(str
, &endptr
, 0, &res
);
986 g_assert_cmpint(err
, ==, -ERANGE
);
987 g_assert_cmpint(res
, ==, LONG_MAX
);
988 g_assert(endptr
== str
+ strlen(str
));
991 static void test_qemu_strtol_underflow(void)
993 const char *str
= "-99999999999999999999999999999999999999999999";
995 const char *endptr
= &f
;
999 err
= qemu_strtol(str
, &endptr
, 0, &res
);
1001 g_assert_cmpint(err
, ==, -ERANGE
);
1002 g_assert_cmpint(res
, ==, LONG_MIN
);
1003 g_assert(endptr
== str
+ strlen(str
));
1006 static void test_qemu_strtol_negative(void)
1008 const char *str
= " \t -321";
1010 const char *endptr
= &f
;
1014 err
= qemu_strtol(str
, &endptr
, 0, &res
);
1016 g_assert_cmpint(err
, ==, 0);
1017 g_assert_cmpint(res
, ==, -321);
1018 g_assert(endptr
== str
+ strlen(str
));
1021 static void test_qemu_strtol_full_correct(void)
1023 const char *str
= "123";
1027 err
= qemu_strtol(str
, NULL
, 0, &res
);
1029 g_assert_cmpint(err
, ==, 0);
1030 g_assert_cmpint(res
, ==, 123);
1033 static void test_qemu_strtol_full_null(void)
1036 const char *endptr
= &f
;
1040 err
= qemu_strtol(NULL
, &endptr
, 0, &res
);
1042 g_assert_cmpint(err
, ==, -EINVAL
);
1043 g_assert(endptr
== NULL
);
1046 static void test_qemu_strtol_full_empty(void)
1048 const char *str
= "";
1052 err
= qemu_strtol(str
, NULL
, 0, &res
);
1054 g_assert_cmpint(err
, ==, -EINVAL
);
1057 static void test_qemu_strtol_full_negative(void)
1059 const char *str
= " \t -321";
1063 err
= qemu_strtol(str
, NULL
, 0, &res
);
1065 g_assert_cmpint(err
, ==, 0);
1066 g_assert_cmpint(res
, ==, -321);
1069 static void test_qemu_strtol_full_trailing(void)
1071 const char *str
= "123xxx";
1075 err
= qemu_strtol(str
, NULL
, 0, &res
);
1077 g_assert_cmpint(err
, ==, -EINVAL
);
1080 static void test_qemu_strtol_full_max(void)
1082 char *str
= g_strdup_printf("%ld", LONG_MAX
);
1086 err
= qemu_strtol(str
, NULL
, 0, &res
);
1088 g_assert_cmpint(err
, ==, 0);
1089 g_assert_cmpint(res
, ==, LONG_MAX
);
1093 static void test_qemu_strtoul_correct(void)
1095 const char *str
= "12345 foo";
1097 const char *endptr
= &f
;
1098 unsigned long res
= 999;
1101 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1103 g_assert_cmpint(err
, ==, 0);
1104 g_assert_cmpuint(res
, ==, 12345);
1105 g_assert(endptr
== str
+ 5);
1108 static void test_qemu_strtoul_null(void)
1111 const char *endptr
= &f
;
1112 unsigned long res
= 999;
1115 err
= qemu_strtoul(NULL
, &endptr
, 0, &res
);
1117 g_assert_cmpint(err
, ==, -EINVAL
);
1118 g_assert(endptr
== NULL
);
1121 static void test_qemu_strtoul_empty(void)
1123 const char *str
= "";
1125 const char *endptr
= &f
;
1126 unsigned long res
= 999;
1129 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1131 g_assert_cmpint(err
, ==, -EINVAL
);
1132 g_assert(endptr
== str
);
1135 static void test_qemu_strtoul_whitespace(void)
1137 const char *str
= " \t ";
1139 const char *endptr
= &f
;
1140 unsigned long res
= 999;
1143 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1145 g_assert_cmpint(err
, ==, -EINVAL
);
1146 g_assert(endptr
== str
);
1149 static void test_qemu_strtoul_invalid(void)
1151 const char *str
= " xxxx \t abc";
1153 const char *endptr
= &f
;
1154 unsigned long res
= 999;
1157 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1159 g_assert_cmpint(err
, ==, -EINVAL
);
1160 g_assert(endptr
== str
);
1163 static void test_qemu_strtoul_trailing(void)
1165 const char *str
= "123xxx";
1167 const char *endptr
= &f
;
1168 unsigned long res
= 999;
1171 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1173 g_assert_cmpint(err
, ==, 0);
1174 g_assert_cmpuint(res
, ==, 123);
1175 g_assert(endptr
== str
+ 3);
1178 static void test_qemu_strtoul_octal(void)
1180 const char *str
= "0123";
1182 const char *endptr
= &f
;
1183 unsigned long res
= 999;
1186 err
= qemu_strtoul(str
, &endptr
, 8, &res
);
1188 g_assert_cmpint(err
, ==, 0);
1189 g_assert_cmpuint(res
, ==, 0123);
1190 g_assert(endptr
== str
+ strlen(str
));
1194 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1196 g_assert_cmpint(err
, ==, 0);
1197 g_assert_cmpuint(res
, ==, 0123);
1198 g_assert(endptr
== str
+ strlen(str
));
1201 static void test_qemu_strtoul_decimal(void)
1203 const char *str
= "0123";
1205 const char *endptr
= &f
;
1206 unsigned long res
= 999;
1209 err
= qemu_strtoul(str
, &endptr
, 10, &res
);
1211 g_assert_cmpint(err
, ==, 0);
1212 g_assert_cmpuint(res
, ==, 123);
1213 g_assert(endptr
== str
+ strlen(str
));
1218 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1220 g_assert_cmpint(err
, ==, 0);
1221 g_assert_cmpuint(res
, ==, 123);
1222 g_assert(endptr
== str
+ strlen(str
));
1225 static void test_qemu_strtoul_hex(void)
1227 const char *str
= "0123";
1229 const char *endptr
= &f
;
1230 unsigned long res
= 999;
1233 err
= qemu_strtoul(str
, &endptr
, 16, &res
);
1235 g_assert_cmpint(err
, ==, 0);
1236 g_assert_cmphex(res
, ==, 0x123);
1237 g_assert(endptr
== str
+ strlen(str
));
1242 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1244 g_assert_cmpint(err
, ==, 0);
1245 g_assert_cmphex(res
, ==, 0x123);
1246 g_assert(endptr
== str
+ strlen(str
));
1249 static void test_qemu_strtoul_max(void)
1251 char *str
= g_strdup_printf("%lu", ULONG_MAX
);
1253 const char *endptr
= &f
;
1254 unsigned long res
= 999;
1257 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1259 g_assert_cmpint(err
, ==, 0);
1260 g_assert_cmphex(res
, ==, ULONG_MAX
);
1261 g_assert(endptr
== str
+ strlen(str
));
1265 static void test_qemu_strtoul_overflow(void)
1267 const char *str
= "99999999999999999999999999999999999999999999";
1269 const char *endptr
= &f
;
1270 unsigned long res
= 999;
1273 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1275 g_assert_cmpint(err
, ==, -ERANGE
);
1276 g_assert_cmphex(res
, ==, ULONG_MAX
);
1277 g_assert(endptr
== str
+ strlen(str
));
1280 static void test_qemu_strtoul_underflow(void)
1282 const char *str
= "-99999999999999999999999999999999999999999999";
1284 const char *endptr
= &f
;
1285 unsigned long res
= 999;
1288 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1290 g_assert_cmpint(err
, ==, -ERANGE
);
1291 g_assert_cmpuint(res
, ==, -1ul);
1292 g_assert(endptr
== str
+ strlen(str
));
1295 static void test_qemu_strtoul_negative(void)
1297 const char *str
= " \t -321";
1299 const char *endptr
= &f
;
1300 unsigned long res
= 999;
1303 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1305 g_assert_cmpint(err
, ==, 0);
1306 g_assert_cmpuint(res
, ==, -321ul);
1307 g_assert(endptr
== str
+ strlen(str
));
1310 static void test_qemu_strtoul_full_correct(void)
1312 const char *str
= "123";
1313 unsigned long res
= 999;
1316 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1318 g_assert_cmpint(err
, ==, 0);
1319 g_assert_cmpuint(res
, ==, 123);
1322 static void test_qemu_strtoul_full_null(void)
1324 unsigned long res
= 999;
1327 err
= qemu_strtoul(NULL
, NULL
, 0, &res
);
1329 g_assert_cmpint(err
, ==, -EINVAL
);
1332 static void test_qemu_strtoul_full_empty(void)
1334 const char *str
= "";
1335 unsigned long res
= 999;
1338 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1340 g_assert_cmpint(err
, ==, -EINVAL
);
1342 static void test_qemu_strtoul_full_negative(void)
1344 const char *str
= " \t -321";
1345 unsigned long res
= 999;
1348 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1349 g_assert_cmpint(err
, ==, 0);
1350 g_assert_cmpuint(res
, ==, -321ul);
1353 static void test_qemu_strtoul_full_trailing(void)
1355 const char *str
= "123xxx";
1359 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1361 g_assert_cmpint(err
, ==, -EINVAL
);
1364 static void test_qemu_strtoul_full_max(void)
1366 char *str
= g_strdup_printf("%lu", ULONG_MAX
);
1367 unsigned long res
= 999;
1370 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1372 g_assert_cmpint(err
, ==, 0);
1373 g_assert_cmphex(res
, ==, ULONG_MAX
);
1377 static void test_qemu_strtoi64_correct(void)
1379 const char *str
= "12345 foo";
1381 const char *endptr
= &f
;
1385 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1387 g_assert_cmpint(err
, ==, 0);
1388 g_assert_cmpint(res
, ==, 12345);
1389 g_assert(endptr
== str
+ 5);
1392 static void test_qemu_strtoi64_null(void)
1395 const char *endptr
= &f
;
1399 err
= qemu_strtoi64(NULL
, &endptr
, 0, &res
);
1401 g_assert_cmpint(err
, ==, -EINVAL
);
1402 g_assert(endptr
== NULL
);
1405 static void test_qemu_strtoi64_empty(void)
1407 const char *str
= "";
1409 const char *endptr
= &f
;
1413 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1415 g_assert_cmpint(err
, ==, -EINVAL
);
1416 g_assert(endptr
== str
);
1419 static void test_qemu_strtoi64_whitespace(void)
1421 const char *str
= " \t ";
1423 const char *endptr
= &f
;
1427 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1429 g_assert_cmpint(err
, ==, -EINVAL
);
1430 g_assert(endptr
== str
);
1433 static void test_qemu_strtoi64_invalid(void)
1435 const char *str
= " xxxx \t abc";
1437 const char *endptr
= &f
;
1441 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1443 g_assert_cmpint(err
, ==, -EINVAL
);
1444 g_assert(endptr
== str
);
1447 static void test_qemu_strtoi64_trailing(void)
1449 const char *str
= "123xxx";
1451 const char *endptr
= &f
;
1455 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1457 g_assert_cmpint(err
, ==, 0);
1458 g_assert_cmpint(res
, ==, 123);
1459 g_assert(endptr
== str
+ 3);
1462 static void test_qemu_strtoi64_octal(void)
1464 const char *str
= "0123";
1466 const char *endptr
= &f
;
1470 err
= qemu_strtoi64(str
, &endptr
, 8, &res
);
1472 g_assert_cmpint(err
, ==, 0);
1473 g_assert_cmpint(res
, ==, 0123);
1474 g_assert(endptr
== str
+ strlen(str
));
1478 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1480 g_assert_cmpint(err
, ==, 0);
1481 g_assert_cmpint(res
, ==, 0123);
1482 g_assert(endptr
== str
+ strlen(str
));
1485 static void test_qemu_strtoi64_decimal(void)
1487 const char *str
= "0123";
1489 const char *endptr
= &f
;
1493 err
= qemu_strtoi64(str
, &endptr
, 10, &res
);
1495 g_assert_cmpint(err
, ==, 0);
1496 g_assert_cmpint(res
, ==, 123);
1497 g_assert(endptr
== str
+ strlen(str
));
1502 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1504 g_assert_cmpint(err
, ==, 0);
1505 g_assert_cmpint(res
, ==, 123);
1506 g_assert(endptr
== str
+ strlen(str
));
1509 static void test_qemu_strtoi64_hex(void)
1511 const char *str
= "0123";
1513 const char *endptr
= &f
;
1517 err
= qemu_strtoi64(str
, &endptr
, 16, &res
);
1519 g_assert_cmpint(err
, ==, 0);
1520 g_assert_cmpint(res
, ==, 0x123);
1521 g_assert(endptr
== str
+ strlen(str
));
1526 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1528 g_assert_cmpint(err
, ==, 0);
1529 g_assert_cmpint(res
, ==, 0x123);
1530 g_assert(endptr
== str
+ strlen(str
));
1533 static void test_qemu_strtoi64_max(void)
1535 char *str
= g_strdup_printf("%lld", LLONG_MAX
);
1537 const char *endptr
= &f
;
1541 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1543 g_assert_cmpint(err
, ==, 0);
1544 g_assert_cmpint(res
, ==, LLONG_MAX
);
1545 g_assert(endptr
== str
+ strlen(str
));
1549 static void test_qemu_strtoi64_overflow(void)
1551 const char *str
= "99999999999999999999999999999999999999999999";
1553 const char *endptr
= &f
;
1557 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1559 g_assert_cmpint(err
, ==, -ERANGE
);
1560 g_assert_cmpint(res
, ==, LLONG_MAX
);
1561 g_assert(endptr
== str
+ strlen(str
));
1564 static void test_qemu_strtoi64_underflow(void)
1566 const char *str
= "-99999999999999999999999999999999999999999999";
1568 const char *endptr
= &f
;
1572 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1574 g_assert_cmpint(err
, ==, -ERANGE
);
1575 g_assert_cmpint(res
, ==, LLONG_MIN
);
1576 g_assert(endptr
== str
+ strlen(str
));
1579 static void test_qemu_strtoi64_negative(void)
1581 const char *str
= " \t -321";
1583 const char *endptr
= &f
;
1587 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1589 g_assert_cmpint(err
, ==, 0);
1590 g_assert_cmpint(res
, ==, -321);
1591 g_assert(endptr
== str
+ strlen(str
));
1594 static void test_qemu_strtoi64_full_correct(void)
1596 const char *str
= "123";
1600 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1602 g_assert_cmpint(err
, ==, 0);
1603 g_assert_cmpint(res
, ==, 123);
1606 static void test_qemu_strtoi64_full_null(void)
1611 err
= qemu_strtoi64(NULL
, NULL
, 0, &res
);
1613 g_assert_cmpint(err
, ==, -EINVAL
);
1616 static void test_qemu_strtoi64_full_empty(void)
1618 const char *str
= "";
1622 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1624 g_assert_cmpint(err
, ==, -EINVAL
);
1627 static void test_qemu_strtoi64_full_negative(void)
1629 const char *str
= " \t -321";
1633 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1635 g_assert_cmpint(err
, ==, 0);
1636 g_assert_cmpint(res
, ==, -321);
1639 static void test_qemu_strtoi64_full_trailing(void)
1641 const char *str
= "123xxx";
1645 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1647 g_assert_cmpint(err
, ==, -EINVAL
);
1650 static void test_qemu_strtoi64_full_max(void)
1653 char *str
= g_strdup_printf("%lld", LLONG_MAX
);
1657 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1659 g_assert_cmpint(err
, ==, 0);
1660 g_assert_cmpint(res
, ==, LLONG_MAX
);
1664 static void test_qemu_strtou64_correct(void)
1666 const char *str
= "12345 foo";
1668 const char *endptr
= &f
;
1672 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1674 g_assert_cmpint(err
, ==, 0);
1675 g_assert_cmpuint(res
, ==, 12345);
1676 g_assert(endptr
== str
+ 5);
1679 static void test_qemu_strtou64_null(void)
1682 const char *endptr
= &f
;
1686 err
= qemu_strtou64(NULL
, &endptr
, 0, &res
);
1688 g_assert_cmpint(err
, ==, -EINVAL
);
1689 g_assert(endptr
== NULL
);
1692 static void test_qemu_strtou64_empty(void)
1694 const char *str
= "";
1696 const char *endptr
= &f
;
1700 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1702 g_assert_cmpint(err
, ==, -EINVAL
);
1703 g_assert(endptr
== str
);
1706 static void test_qemu_strtou64_whitespace(void)
1708 const char *str
= " \t ";
1710 const char *endptr
= &f
;
1714 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1716 g_assert_cmpint(err
, ==, -EINVAL
);
1717 g_assert(endptr
== str
);
1720 static void test_qemu_strtou64_invalid(void)
1722 const char *str
= " xxxx \t abc";
1724 const char *endptr
= &f
;
1728 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1730 g_assert_cmpint(err
, ==, -EINVAL
);
1731 g_assert(endptr
== str
);
1734 static void test_qemu_strtou64_trailing(void)
1736 const char *str
= "123xxx";
1738 const char *endptr
= &f
;
1742 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1744 g_assert_cmpint(err
, ==, 0);
1745 g_assert_cmpuint(res
, ==, 123);
1746 g_assert(endptr
== str
+ 3);
1749 static void test_qemu_strtou64_octal(void)
1751 const char *str
= "0123";
1753 const char *endptr
= &f
;
1757 err
= qemu_strtou64(str
, &endptr
, 8, &res
);
1759 g_assert_cmpint(err
, ==, 0);
1760 g_assert_cmpuint(res
, ==, 0123);
1761 g_assert(endptr
== str
+ strlen(str
));
1765 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1767 g_assert_cmpint(err
, ==, 0);
1768 g_assert_cmpuint(res
, ==, 0123);
1769 g_assert(endptr
== str
+ strlen(str
));
1772 static void test_qemu_strtou64_decimal(void)
1774 const char *str
= "0123";
1776 const char *endptr
= &f
;
1780 err
= qemu_strtou64(str
, &endptr
, 10, &res
);
1782 g_assert_cmpint(err
, ==, 0);
1783 g_assert_cmpuint(res
, ==, 123);
1784 g_assert(endptr
== str
+ strlen(str
));
1789 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1791 g_assert_cmpint(err
, ==, 0);
1792 g_assert_cmpuint(res
, ==, 123);
1793 g_assert(endptr
== str
+ strlen(str
));
1796 static void test_qemu_strtou64_hex(void)
1798 const char *str
= "0123";
1800 const char *endptr
= &f
;
1804 err
= qemu_strtou64(str
, &endptr
, 16, &res
);
1806 g_assert_cmpint(err
, ==, 0);
1807 g_assert_cmphex(res
, ==, 0x123);
1808 g_assert(endptr
== str
+ strlen(str
));
1813 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1815 g_assert_cmpint(err
, ==, 0);
1816 g_assert_cmphex(res
, ==, 0x123);
1817 g_assert(endptr
== str
+ strlen(str
));
1820 static void test_qemu_strtou64_max(void)
1822 char *str
= g_strdup_printf("%llu", ULLONG_MAX
);
1824 const char *endptr
= &f
;
1828 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1830 g_assert_cmpint(err
, ==, 0);
1831 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1832 g_assert(endptr
== str
+ strlen(str
));
1836 static void test_qemu_strtou64_overflow(void)
1838 const char *str
= "99999999999999999999999999999999999999999999";
1840 const char *endptr
= &f
;
1844 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1846 g_assert_cmpint(err
, ==, -ERANGE
);
1847 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1848 g_assert(endptr
== str
+ strlen(str
));
1851 static void test_qemu_strtou64_underflow(void)
1853 const char *str
= "-99999999999999999999999999999999999999999999";
1855 const char *endptr
= &f
;
1859 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1861 g_assert_cmpint(err
, ==, -ERANGE
);
1862 g_assert_cmphex(res
, ==, -1ull);
1863 g_assert(endptr
== str
+ strlen(str
));
1866 static void test_qemu_strtou64_negative(void)
1868 const char *str
= " \t -321";
1870 const char *endptr
= &f
;
1874 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1876 g_assert_cmpint(err
, ==, 0);
1877 g_assert_cmpuint(res
, ==, -321ull);
1878 g_assert(endptr
== str
+ strlen(str
));
1881 static void test_qemu_strtou64_full_correct(void)
1883 const char *str
= "18446744073709551614";
1887 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1889 g_assert_cmpint(err
, ==, 0);
1890 g_assert_cmpuint(res
, ==, 18446744073709551614ull);
1893 static void test_qemu_strtou64_full_null(void)
1898 err
= qemu_strtou64(NULL
, NULL
, 0, &res
);
1900 g_assert_cmpint(err
, ==, -EINVAL
);
1903 static void test_qemu_strtou64_full_empty(void)
1905 const char *str
= "";
1909 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1911 g_assert_cmpint(err
, ==, -EINVAL
);
1914 static void test_qemu_strtou64_full_negative(void)
1916 const char *str
= " \t -321";
1920 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1922 g_assert_cmpint(err
, ==, 0);
1923 g_assert_cmpuint(res
, ==, -321ull);
1926 static void test_qemu_strtou64_full_trailing(void)
1928 const char *str
= "18446744073709551614xxxxxx";
1932 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1934 g_assert_cmpint(err
, ==, -EINVAL
);
1937 static void test_qemu_strtou64_full_max(void)
1939 char *str
= g_strdup_printf("%lld", ULLONG_MAX
);
1943 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1945 g_assert_cmpint(err
, ==, 0);
1946 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1950 static void test_qemu_strtosz_simple(void)
1955 uint64_t res
= 0xbaadf00d;
1958 err
= qemu_strtosz(str
, &endptr
, &res
);
1959 g_assert_cmpint(err
, ==, 0);
1960 g_assert_cmpint(res
, ==, 0);
1961 g_assert(endptr
== str
+ 1);
1964 err
= qemu_strtosz(str
, &endptr
, &res
);
1965 g_assert_cmpint(err
, ==, 0);
1966 g_assert_cmpint(res
, ==, 12345);
1967 g_assert(endptr
== str
+ 5);
1969 err
= qemu_strtosz(str
, NULL
, &res
);
1970 g_assert_cmpint(err
, ==, 0);
1971 g_assert_cmpint(res
, ==, 12345);
1973 /* Note: precision is 53 bits since we're parsing with strtod() */
1975 str
= "9007199254740991"; /* 2^53-1 */
1976 err
= qemu_strtosz(str
, &endptr
, &res
);
1977 g_assert_cmpint(err
, ==, 0);
1978 g_assert_cmpint(res
, ==, 0x1fffffffffffff);
1979 g_assert(endptr
== str
+ 16);
1981 str
= "9007199254740992"; /* 2^53 */
1982 err
= qemu_strtosz(str
, &endptr
, &res
);
1983 g_assert_cmpint(err
, ==, 0);
1984 g_assert_cmpint(res
, ==, 0x20000000000000);
1985 g_assert(endptr
== str
+ 16);
1987 str
= "9007199254740993"; /* 2^53+1 */
1988 err
= qemu_strtosz(str
, &endptr
, &res
);
1989 g_assert_cmpint(err
, ==, 0);
1990 g_assert_cmpint(res
, ==, 0x20000000000000); /* rounded to 53 bits */
1991 g_assert(endptr
== str
+ 16);
1993 str
= "18446744073709549568"; /* 0xfffffffffffff800 (53 msbs set) */
1994 err
= qemu_strtosz(str
, &endptr
, &res
);
1995 g_assert_cmpint(err
, ==, 0);
1996 g_assert_cmpint(res
, ==, 0xfffffffffffff800);
1997 g_assert(endptr
== str
+ 20);
1999 str
= "18446744073709550591"; /* 0xfffffffffffffbff */
2000 err
= qemu_strtosz(str
, &endptr
, &res
);
2001 g_assert_cmpint(err
, ==, 0);
2002 g_assert_cmpint(res
, ==, 0xfffffffffffff800); /* rounded to 53 bits */
2003 g_assert(endptr
== str
+ 20);
2005 /* 0x7ffffffffffffe00..0x7fffffffffffffff get rounded to
2006 * 0x8000000000000000, thus -ERANGE; see test_qemu_strtosz_erange() */
2009 static void test_qemu_strtosz_units(void)
2011 const char *none
= "1";
2012 const char *b
= "1B";
2013 const char *k
= "1K";
2014 const char *m
= "1M";
2015 const char *g
= "1G";
2016 const char *t
= "1T";
2017 const char *p
= "1P";
2018 const char *e
= "1E";
2021 uint64_t res
= 0xbaadf00d;
2024 err
= qemu_strtosz_MiB(none
, &endptr
, &res
);
2025 g_assert_cmpint(err
, ==, 0);
2026 g_assert_cmpint(res
, ==, MiB
);
2027 g_assert(endptr
== none
+ 1);
2029 err
= qemu_strtosz(b
, &endptr
, &res
);
2030 g_assert_cmpint(err
, ==, 0);
2031 g_assert_cmpint(res
, ==, 1);
2032 g_assert(endptr
== b
+ 2);
2034 err
= qemu_strtosz(k
, &endptr
, &res
);
2035 g_assert_cmpint(err
, ==, 0);
2036 g_assert_cmpint(res
, ==, KiB
);
2037 g_assert(endptr
== k
+ 2);
2039 err
= qemu_strtosz(m
, &endptr
, &res
);
2040 g_assert_cmpint(err
, ==, 0);
2041 g_assert_cmpint(res
, ==, MiB
);
2042 g_assert(endptr
== m
+ 2);
2044 err
= qemu_strtosz(g
, &endptr
, &res
);
2045 g_assert_cmpint(err
, ==, 0);
2046 g_assert_cmpint(res
, ==, GiB
);
2047 g_assert(endptr
== g
+ 2);
2049 err
= qemu_strtosz(t
, &endptr
, &res
);
2050 g_assert_cmpint(err
, ==, 0);
2051 g_assert_cmpint(res
, ==, TiB
);
2052 g_assert(endptr
== t
+ 2);
2054 err
= qemu_strtosz(p
, &endptr
, &res
);
2055 g_assert_cmpint(err
, ==, 0);
2056 g_assert_cmpint(res
, ==, PiB
);
2057 g_assert(endptr
== p
+ 2);
2059 err
= qemu_strtosz(e
, &endptr
, &res
);
2060 g_assert_cmpint(err
, ==, 0);
2061 g_assert_cmpint(res
, ==, EiB
);
2062 g_assert(endptr
== e
+ 2);
2065 static void test_qemu_strtosz_float(void)
2067 const char *str
= "12.345M";
2070 uint64_t res
= 0xbaadf00d;
2072 err
= qemu_strtosz(str
, &endptr
, &res
);
2073 g_assert_cmpint(err
, ==, 0);
2074 g_assert_cmpint(res
, ==, 12.345 * MiB
);
2075 g_assert(endptr
== str
+ 7);
2078 static void test_qemu_strtosz_invalid(void)
2083 uint64_t res
= 0xbaadf00d;
2086 err
= qemu_strtosz(str
, &endptr
, &res
);
2087 g_assert_cmpint(err
, ==, -EINVAL
);
2088 g_assert(endptr
== str
);
2091 err
= qemu_strtosz(str
, &endptr
, &res
);
2092 g_assert_cmpint(err
, ==, -EINVAL
);
2093 g_assert(endptr
== str
);
2096 err
= qemu_strtosz(str
, &endptr
, &res
);
2097 g_assert_cmpint(err
, ==, -EINVAL
);
2098 g_assert(endptr
== str
);
2101 err
= qemu_strtosz(str
, &endptr
, &res
);
2102 g_assert_cmpint(err
, ==, -EINVAL
);
2103 g_assert(endptr
== str
);
2106 err
= qemu_strtosz(str
, &endptr
, &res
);
2107 g_assert_cmpint(err
, ==, -EINVAL
);
2108 g_assert(endptr
== str
);
2111 static void test_qemu_strtosz_trailing(void)
2116 uint64_t res
= 0xbaadf00d;
2119 err
= qemu_strtosz_MiB(str
, &endptr
, &res
);
2120 g_assert_cmpint(res
, ==, 123 * MiB
);
2121 g_assert(endptr
== str
+ 3);
2123 err
= qemu_strtosz(str
, NULL
, &res
);
2124 g_assert_cmpint(err
, ==, -EINVAL
);
2127 err
= qemu_strtosz(str
, &endptr
, &res
);
2128 g_assert_cmpint(err
, ==, 0);
2129 g_assert_cmpint(res
, ==, 1024);
2130 g_assert(endptr
== str
+ 2);
2132 err
= qemu_strtosz(str
, NULL
, &res
);
2133 g_assert_cmpint(err
, ==, -EINVAL
);
2136 static void test_qemu_strtosz_erange(void)
2141 uint64_t res
= 0xbaadf00d;
2144 err
= qemu_strtosz(str
, &endptr
, &res
);
2145 g_assert_cmpint(err
, ==, -ERANGE
);
2146 g_assert(endptr
== str
+ 2);
2148 str
= "18446744073709550592"; /* 0xfffffffffffffc00 */
2149 err
= qemu_strtosz(str
, &endptr
, &res
);
2150 g_assert_cmpint(err
, ==, -ERANGE
);
2151 g_assert(endptr
== str
+ 20);
2153 str
= "18446744073709551615"; /* 2^64-1 */
2154 err
= qemu_strtosz(str
, &endptr
, &res
);
2155 g_assert_cmpint(err
, ==, -ERANGE
);
2156 g_assert(endptr
== str
+ 20);
2158 str
= "18446744073709551616"; /* 2^64 */
2159 err
= qemu_strtosz(str
, &endptr
, &res
);
2160 g_assert_cmpint(err
, ==, -ERANGE
);
2161 g_assert(endptr
== str
+ 20);
2164 err
= qemu_strtosz(str
, &endptr
, &res
);
2165 g_assert_cmpint(err
, ==, -ERANGE
);
2166 g_assert(endptr
== str
+ 3);
2169 static void test_qemu_strtosz_metric(void)
2171 const char *str
= "12345k";
2174 uint64_t res
= 0xbaadf00d;
2176 err
= qemu_strtosz_metric(str
, &endptr
, &res
);
2177 g_assert_cmpint(err
, ==, 0);
2178 g_assert_cmpint(res
, ==, 12345000);
2179 g_assert(endptr
== str
+ 6);
2182 int main(int argc
, char **argv
)
2184 g_test_init(&argc
, &argv
, NULL
);
2186 g_test_add_func("/cutils/parse_uint/null", test_parse_uint_null
);
2187 g_test_add_func("/cutils/parse_uint/empty", test_parse_uint_empty
);
2188 g_test_add_func("/cutils/parse_uint/whitespace",
2189 test_parse_uint_whitespace
);
2190 g_test_add_func("/cutils/parse_uint/invalid", test_parse_uint_invalid
);
2191 g_test_add_func("/cutils/parse_uint/trailing", test_parse_uint_trailing
);
2192 g_test_add_func("/cutils/parse_uint/correct", test_parse_uint_correct
);
2193 g_test_add_func("/cutils/parse_uint/octal", test_parse_uint_octal
);
2194 g_test_add_func("/cutils/parse_uint/decimal", test_parse_uint_decimal
);
2195 g_test_add_func("/cutils/parse_uint/llong_max", test_parse_uint_llong_max
);
2196 g_test_add_func("/cutils/parse_uint/overflow", test_parse_uint_overflow
);
2197 g_test_add_func("/cutils/parse_uint/negative", test_parse_uint_negative
);
2198 g_test_add_func("/cutils/parse_uint_full/trailing",
2199 test_parse_uint_full_trailing
);
2200 g_test_add_func("/cutils/parse_uint_full/correct",
2201 test_parse_uint_full_correct
);
2203 /* qemu_strtoi() tests */
2204 g_test_add_func("/cutils/qemu_strtoi/correct",
2205 test_qemu_strtoi_correct
);
2206 g_test_add_func("/cutils/qemu_strtoi/null",
2207 test_qemu_strtoi_null
);
2208 g_test_add_func("/cutils/qemu_strtoi/empty",
2209 test_qemu_strtoi_empty
);
2210 g_test_add_func("/cutils/qemu_strtoi/whitespace",
2211 test_qemu_strtoi_whitespace
);
2212 g_test_add_func("/cutils/qemu_strtoi/invalid",
2213 test_qemu_strtoi_invalid
);
2214 g_test_add_func("/cutils/qemu_strtoi/trailing",
2215 test_qemu_strtoi_trailing
);
2216 g_test_add_func("/cutils/qemu_strtoi/octal",
2217 test_qemu_strtoi_octal
);
2218 g_test_add_func("/cutils/qemu_strtoi/decimal",
2219 test_qemu_strtoi_decimal
);
2220 g_test_add_func("/cutils/qemu_strtoi/hex",
2221 test_qemu_strtoi_hex
);
2222 g_test_add_func("/cutils/qemu_strtoi/max",
2223 test_qemu_strtoi_max
);
2224 g_test_add_func("/cutils/qemu_strtoi/overflow",
2225 test_qemu_strtoi_overflow
);
2226 g_test_add_func("/cutils/qemu_strtoi/underflow",
2227 test_qemu_strtoi_underflow
);
2228 g_test_add_func("/cutils/qemu_strtoi/negative",
2229 test_qemu_strtoi_negative
);
2230 g_test_add_func("/cutils/qemu_strtoi_full/correct",
2231 test_qemu_strtoi_full_correct
);
2232 g_test_add_func("/cutils/qemu_strtoi_full/null",
2233 test_qemu_strtoi_full_null
);
2234 g_test_add_func("/cutils/qemu_strtoi_full/empty",
2235 test_qemu_strtoi_full_empty
);
2236 g_test_add_func("/cutils/qemu_strtoi_full/negative",
2237 test_qemu_strtoi_full_negative
);
2238 g_test_add_func("/cutils/qemu_strtoi_full/trailing",
2239 test_qemu_strtoi_full_trailing
);
2240 g_test_add_func("/cutils/qemu_strtoi_full/max",
2241 test_qemu_strtoi_full_max
);
2243 /* qemu_strtoui() tests */
2244 g_test_add_func("/cutils/qemu_strtoui/correct",
2245 test_qemu_strtoui_correct
);
2246 g_test_add_func("/cutils/qemu_strtoui/null",
2247 test_qemu_strtoui_null
);
2248 g_test_add_func("/cutils/qemu_strtoui/empty",
2249 test_qemu_strtoui_empty
);
2250 g_test_add_func("/cutils/qemu_strtoui/whitespace",
2251 test_qemu_strtoui_whitespace
);
2252 g_test_add_func("/cutils/qemu_strtoui/invalid",
2253 test_qemu_strtoui_invalid
);
2254 g_test_add_func("/cutils/qemu_strtoui/trailing",
2255 test_qemu_strtoui_trailing
);
2256 g_test_add_func("/cutils/qemu_strtoui/octal",
2257 test_qemu_strtoui_octal
);
2258 g_test_add_func("/cutils/qemu_strtoui/decimal",
2259 test_qemu_strtoui_decimal
);
2260 g_test_add_func("/cutils/qemu_strtoui/hex",
2261 test_qemu_strtoui_hex
);
2262 g_test_add_func("/cutils/qemu_strtoui/max",
2263 test_qemu_strtoui_max
);
2264 g_test_add_func("/cutils/qemu_strtoui/overflow",
2265 test_qemu_strtoui_overflow
);
2266 g_test_add_func("/cutils/qemu_strtoui/underflow",
2267 test_qemu_strtoui_underflow
);
2268 g_test_add_func("/cutils/qemu_strtoui/negative",
2269 test_qemu_strtoui_negative
);
2270 g_test_add_func("/cutils/qemu_strtoui_full/correct",
2271 test_qemu_strtoui_full_correct
);
2272 g_test_add_func("/cutils/qemu_strtoui_full/null",
2273 test_qemu_strtoui_full_null
);
2274 g_test_add_func("/cutils/qemu_strtoui_full/empty",
2275 test_qemu_strtoui_full_empty
);
2276 g_test_add_func("/cutils/qemu_strtoui_full/negative",
2277 test_qemu_strtoui_full_negative
);
2278 g_test_add_func("/cutils/qemu_strtoui_full/trailing",
2279 test_qemu_strtoui_full_trailing
);
2280 g_test_add_func("/cutils/qemu_strtoui_full/max",
2281 test_qemu_strtoui_full_max
);
2283 /* qemu_strtol() tests */
2284 g_test_add_func("/cutils/qemu_strtol/correct",
2285 test_qemu_strtol_correct
);
2286 g_test_add_func("/cutils/qemu_strtol/null",
2287 test_qemu_strtol_null
);
2288 g_test_add_func("/cutils/qemu_strtol/empty",
2289 test_qemu_strtol_empty
);
2290 g_test_add_func("/cutils/qemu_strtol/whitespace",
2291 test_qemu_strtol_whitespace
);
2292 g_test_add_func("/cutils/qemu_strtol/invalid",
2293 test_qemu_strtol_invalid
);
2294 g_test_add_func("/cutils/qemu_strtol/trailing",
2295 test_qemu_strtol_trailing
);
2296 g_test_add_func("/cutils/qemu_strtol/octal",
2297 test_qemu_strtol_octal
);
2298 g_test_add_func("/cutils/qemu_strtol/decimal",
2299 test_qemu_strtol_decimal
);
2300 g_test_add_func("/cutils/qemu_strtol/hex",
2301 test_qemu_strtol_hex
);
2302 g_test_add_func("/cutils/qemu_strtol/max",
2303 test_qemu_strtol_max
);
2304 g_test_add_func("/cutils/qemu_strtol/overflow",
2305 test_qemu_strtol_overflow
);
2306 g_test_add_func("/cutils/qemu_strtol/underflow",
2307 test_qemu_strtol_underflow
);
2308 g_test_add_func("/cutils/qemu_strtol/negative",
2309 test_qemu_strtol_negative
);
2310 g_test_add_func("/cutils/qemu_strtol_full/correct",
2311 test_qemu_strtol_full_correct
);
2312 g_test_add_func("/cutils/qemu_strtol_full/null",
2313 test_qemu_strtol_full_null
);
2314 g_test_add_func("/cutils/qemu_strtol_full/empty",
2315 test_qemu_strtol_full_empty
);
2316 g_test_add_func("/cutils/qemu_strtol_full/negative",
2317 test_qemu_strtol_full_negative
);
2318 g_test_add_func("/cutils/qemu_strtol_full/trailing",
2319 test_qemu_strtol_full_trailing
);
2320 g_test_add_func("/cutils/qemu_strtol_full/max",
2321 test_qemu_strtol_full_max
);
2323 /* qemu_strtoul() tests */
2324 g_test_add_func("/cutils/qemu_strtoul/correct",
2325 test_qemu_strtoul_correct
);
2326 g_test_add_func("/cutils/qemu_strtoul/null",
2327 test_qemu_strtoul_null
);
2328 g_test_add_func("/cutils/qemu_strtoul/empty",
2329 test_qemu_strtoul_empty
);
2330 g_test_add_func("/cutils/qemu_strtoul/whitespace",
2331 test_qemu_strtoul_whitespace
);
2332 g_test_add_func("/cutils/qemu_strtoul/invalid",
2333 test_qemu_strtoul_invalid
);
2334 g_test_add_func("/cutils/qemu_strtoul/trailing",
2335 test_qemu_strtoul_trailing
);
2336 g_test_add_func("/cutils/qemu_strtoul/octal",
2337 test_qemu_strtoul_octal
);
2338 g_test_add_func("/cutils/qemu_strtoul/decimal",
2339 test_qemu_strtoul_decimal
);
2340 g_test_add_func("/cutils/qemu_strtoul/hex",
2341 test_qemu_strtoul_hex
);
2342 g_test_add_func("/cutils/qemu_strtoul/max",
2343 test_qemu_strtoul_max
);
2344 g_test_add_func("/cutils/qemu_strtoul/overflow",
2345 test_qemu_strtoul_overflow
);
2346 g_test_add_func("/cutils/qemu_strtoul/underflow",
2347 test_qemu_strtoul_underflow
);
2348 g_test_add_func("/cutils/qemu_strtoul/negative",
2349 test_qemu_strtoul_negative
);
2350 g_test_add_func("/cutils/qemu_strtoul_full/correct",
2351 test_qemu_strtoul_full_correct
);
2352 g_test_add_func("/cutils/qemu_strtoul_full/null",
2353 test_qemu_strtoul_full_null
);
2354 g_test_add_func("/cutils/qemu_strtoul_full/empty",
2355 test_qemu_strtoul_full_empty
);
2356 g_test_add_func("/cutils/qemu_strtoul_full/negative",
2357 test_qemu_strtoul_full_negative
);
2358 g_test_add_func("/cutils/qemu_strtoul_full/trailing",
2359 test_qemu_strtoul_full_trailing
);
2360 g_test_add_func("/cutils/qemu_strtoul_full/max",
2361 test_qemu_strtoul_full_max
);
2363 /* qemu_strtoi64() tests */
2364 g_test_add_func("/cutils/qemu_strtoi64/correct",
2365 test_qemu_strtoi64_correct
);
2366 g_test_add_func("/cutils/qemu_strtoi64/null",
2367 test_qemu_strtoi64_null
);
2368 g_test_add_func("/cutils/qemu_strtoi64/empty",
2369 test_qemu_strtoi64_empty
);
2370 g_test_add_func("/cutils/qemu_strtoi64/whitespace",
2371 test_qemu_strtoi64_whitespace
);
2372 g_test_add_func("/cutils/qemu_strtoi64/invalid"
2374 test_qemu_strtoi64_invalid
);
2375 g_test_add_func("/cutils/qemu_strtoi64/trailing",
2376 test_qemu_strtoi64_trailing
);
2377 g_test_add_func("/cutils/qemu_strtoi64/octal",
2378 test_qemu_strtoi64_octal
);
2379 g_test_add_func("/cutils/qemu_strtoi64/decimal",
2380 test_qemu_strtoi64_decimal
);
2381 g_test_add_func("/cutils/qemu_strtoi64/hex",
2382 test_qemu_strtoi64_hex
);
2383 g_test_add_func("/cutils/qemu_strtoi64/max",
2384 test_qemu_strtoi64_max
);
2385 g_test_add_func("/cutils/qemu_strtoi64/overflow",
2386 test_qemu_strtoi64_overflow
);
2387 g_test_add_func("/cutils/qemu_strtoi64/underflow",
2388 test_qemu_strtoi64_underflow
);
2389 g_test_add_func("/cutils/qemu_strtoi64/negative",
2390 test_qemu_strtoi64_negative
);
2391 g_test_add_func("/cutils/qemu_strtoi64_full/correct",
2392 test_qemu_strtoi64_full_correct
);
2393 g_test_add_func("/cutils/qemu_strtoi64_full/null",
2394 test_qemu_strtoi64_full_null
);
2395 g_test_add_func("/cutils/qemu_strtoi64_full/empty",
2396 test_qemu_strtoi64_full_empty
);
2397 g_test_add_func("/cutils/qemu_strtoi64_full/negative",
2398 test_qemu_strtoi64_full_negative
);
2399 g_test_add_func("/cutils/qemu_strtoi64_full/trailing",
2400 test_qemu_strtoi64_full_trailing
);
2401 g_test_add_func("/cutils/qemu_strtoi64_full/max",
2402 test_qemu_strtoi64_full_max
);
2404 /* qemu_strtou64() tests */
2405 g_test_add_func("/cutils/qemu_strtou64/correct",
2406 test_qemu_strtou64_correct
);
2407 g_test_add_func("/cutils/qemu_strtou64/null",
2408 test_qemu_strtou64_null
);
2409 g_test_add_func("/cutils/qemu_strtou64/empty",
2410 test_qemu_strtou64_empty
);
2411 g_test_add_func("/cutils/qemu_strtou64/whitespace",
2412 test_qemu_strtou64_whitespace
);
2413 g_test_add_func("/cutils/qemu_strtou64/invalid",
2414 test_qemu_strtou64_invalid
);
2415 g_test_add_func("/cutils/qemu_strtou64/trailing",
2416 test_qemu_strtou64_trailing
);
2417 g_test_add_func("/cutils/qemu_strtou64/octal",
2418 test_qemu_strtou64_octal
);
2419 g_test_add_func("/cutils/qemu_strtou64/decimal",
2420 test_qemu_strtou64_decimal
);
2421 g_test_add_func("/cutils/qemu_strtou64/hex",
2422 test_qemu_strtou64_hex
);
2423 g_test_add_func("/cutils/qemu_strtou64/max",
2424 test_qemu_strtou64_max
);
2425 g_test_add_func("/cutils/qemu_strtou64/overflow",
2426 test_qemu_strtou64_overflow
);
2427 g_test_add_func("/cutils/qemu_strtou64/underflow",
2428 test_qemu_strtou64_underflow
);
2429 g_test_add_func("/cutils/qemu_strtou64/negative",
2430 test_qemu_strtou64_negative
);
2431 g_test_add_func("/cutils/qemu_strtou64_full/correct",
2432 test_qemu_strtou64_full_correct
);
2433 g_test_add_func("/cutils/qemu_strtou64_full/null",
2434 test_qemu_strtou64_full_null
);
2435 g_test_add_func("/cutils/qemu_strtou64_full/empty",
2436 test_qemu_strtou64_full_empty
);
2437 g_test_add_func("/cutils/qemu_strtou64_full/negative",
2438 test_qemu_strtou64_full_negative
);
2439 g_test_add_func("/cutils/qemu_strtou64_full/trailing",
2440 test_qemu_strtou64_full_trailing
);
2441 g_test_add_func("/cutils/qemu_strtou64_full/max",
2442 test_qemu_strtou64_full_max
);
2444 g_test_add_func("/cutils/strtosz/simple",
2445 test_qemu_strtosz_simple
);
2446 g_test_add_func("/cutils/strtosz/units",
2447 test_qemu_strtosz_units
);
2448 g_test_add_func("/cutils/strtosz/float",
2449 test_qemu_strtosz_float
);
2450 g_test_add_func("/cutils/strtosz/invalid",
2451 test_qemu_strtosz_invalid
);
2452 g_test_add_func("/cutils/strtosz/trailing",
2453 test_qemu_strtosz_trailing
);
2454 g_test_add_func("/cutils/strtosz/erange",
2455 test_qemu_strtosz_erange
);
2456 g_test_add_func("/cutils/strtosz/metric",
2457 test_qemu_strtosz_metric
);
2459 return g_test_run();