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
));
385 err
= qemu_strtoi(str
, &endptr
, 16, &res
);
387 g_assert_cmpint(err
, ==, 0);
388 g_assert_cmpint(res
, ==, 0);
389 g_assert(endptr
== str
+ 1);
392 static void test_qemu_strtoi_max(void)
394 char *str
= g_strdup_printf("%d", INT_MAX
);
396 const char *endptr
= &f
;
400 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
402 g_assert_cmpint(err
, ==, 0);
403 g_assert_cmpint(res
, ==, INT_MAX
);
404 g_assert(endptr
== str
+ strlen(str
));
408 static void test_qemu_strtoi_overflow(void)
410 char *str
= g_strdup_printf("%lld", (long long)INT_MAX
+ 1ll);
412 const char *endptr
= &f
;
416 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
418 g_assert_cmpint(err
, ==, -ERANGE
);
419 g_assert_cmpint(res
, ==, INT_MAX
);
420 g_assert(endptr
== str
+ strlen(str
));
424 static void test_qemu_strtoi_underflow(void)
426 char *str
= g_strdup_printf("%lld", (long long)INT_MIN
- 1ll);
428 const char *endptr
= &f
;
432 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
434 g_assert_cmpint(err
, ==, -ERANGE
);
435 g_assert_cmpint(res
, ==, INT_MIN
);
436 g_assert(endptr
== str
+ strlen(str
));
440 static void test_qemu_strtoi_negative(void)
442 const char *str
= " \t -321";
444 const char *endptr
= &f
;
448 err
= qemu_strtoi(str
, &endptr
, 0, &res
);
450 g_assert_cmpint(err
, ==, 0);
451 g_assert_cmpint(res
, ==, -321);
452 g_assert(endptr
== str
+ strlen(str
));
455 static void test_qemu_strtoi_full_correct(void)
457 const char *str
= "123";
461 err
= qemu_strtoi(str
, NULL
, 0, &res
);
463 g_assert_cmpint(err
, ==, 0);
464 g_assert_cmpint(res
, ==, 123);
467 static void test_qemu_strtoi_full_null(void)
470 const char *endptr
= &f
;
474 err
= qemu_strtoi(NULL
, &endptr
, 0, &res
);
476 g_assert_cmpint(err
, ==, -EINVAL
);
477 g_assert(endptr
== NULL
);
480 static void test_qemu_strtoi_full_empty(void)
482 const char *str
= "";
486 err
= qemu_strtoi(str
, NULL
, 0, &res
);
488 g_assert_cmpint(err
, ==, -EINVAL
);
491 static void test_qemu_strtoi_full_negative(void)
493 const char *str
= " \t -321";
497 err
= qemu_strtoi(str
, NULL
, 0, &res
);
499 g_assert_cmpint(err
, ==, 0);
500 g_assert_cmpint(res
, ==, -321);
503 static void test_qemu_strtoi_full_trailing(void)
505 const char *str
= "123xxx";
509 err
= qemu_strtoi(str
, NULL
, 0, &res
);
511 g_assert_cmpint(err
, ==, -EINVAL
);
514 static void test_qemu_strtoi_full_max(void)
516 char *str
= g_strdup_printf("%d", INT_MAX
);
520 err
= qemu_strtoi(str
, NULL
, 0, &res
);
522 g_assert_cmpint(err
, ==, 0);
523 g_assert_cmpint(res
, ==, INT_MAX
);
527 static void test_qemu_strtoui_correct(void)
529 const char *str
= "12345 foo";
531 const char *endptr
= &f
;
532 unsigned int res
= 999;
535 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
537 g_assert_cmpint(err
, ==, 0);
538 g_assert_cmpuint(res
, ==, 12345);
539 g_assert(endptr
== str
+ 5);
542 static void test_qemu_strtoui_null(void)
545 const char *endptr
= &f
;
546 unsigned int res
= 999;
549 err
= qemu_strtoui(NULL
, &endptr
, 0, &res
);
551 g_assert_cmpint(err
, ==, -EINVAL
);
552 g_assert(endptr
== NULL
);
555 static void test_qemu_strtoui_empty(void)
557 const char *str
= "";
559 const char *endptr
= &f
;
560 unsigned int res
= 999;
563 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
565 g_assert_cmpint(err
, ==, -EINVAL
);
566 g_assert(endptr
== str
);
569 static void test_qemu_strtoui_whitespace(void)
571 const char *str
= " \t ";
573 const char *endptr
= &f
;
574 unsigned int res
= 999;
577 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
579 g_assert_cmpint(err
, ==, -EINVAL
);
580 g_assert(endptr
== str
);
583 static void test_qemu_strtoui_invalid(void)
585 const char *str
= " xxxx \t abc";
587 const char *endptr
= &f
;
588 unsigned int res
= 999;
591 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
593 g_assert_cmpint(err
, ==, -EINVAL
);
594 g_assert(endptr
== str
);
597 static void test_qemu_strtoui_trailing(void)
599 const char *str
= "123xxx";
601 const char *endptr
= &f
;
602 unsigned int res
= 999;
605 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
607 g_assert_cmpint(err
, ==, 0);
608 g_assert_cmpuint(res
, ==, 123);
609 g_assert(endptr
== str
+ 3);
612 static void test_qemu_strtoui_octal(void)
614 const char *str
= "0123";
616 const char *endptr
= &f
;
617 unsigned int res
= 999;
620 err
= qemu_strtoui(str
, &endptr
, 8, &res
);
622 g_assert_cmpint(err
, ==, 0);
623 g_assert_cmpuint(res
, ==, 0123);
624 g_assert(endptr
== str
+ strlen(str
));
628 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
630 g_assert_cmpint(err
, ==, 0);
631 g_assert_cmpuint(res
, ==, 0123);
632 g_assert(endptr
== str
+ strlen(str
));
635 static void test_qemu_strtoui_decimal(void)
637 const char *str
= "0123";
639 const char *endptr
= &f
;
640 unsigned int res
= 999;
643 err
= qemu_strtoui(str
, &endptr
, 10, &res
);
645 g_assert_cmpint(err
, ==, 0);
646 g_assert_cmpuint(res
, ==, 123);
647 g_assert(endptr
== str
+ strlen(str
));
652 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
654 g_assert_cmpint(err
, ==, 0);
655 g_assert_cmpuint(res
, ==, 123);
656 g_assert(endptr
== str
+ strlen(str
));
659 static void test_qemu_strtoui_hex(void)
661 const char *str
= "0123";
663 const char *endptr
= &f
;
664 unsigned int res
= 999;
667 err
= qemu_strtoui(str
, &endptr
, 16, &res
);
669 g_assert_cmpint(err
, ==, 0);
670 g_assert_cmphex(res
, ==, 0x123);
671 g_assert(endptr
== str
+ strlen(str
));
676 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
678 g_assert_cmpint(err
, ==, 0);
679 g_assert_cmphex(res
, ==, 0x123);
680 g_assert(endptr
== str
+ strlen(str
));
685 err
= qemu_strtoui(str
, &endptr
, 16, &res
);
687 g_assert_cmpint(err
, ==, 0);
688 g_assert_cmphex(res
, ==, 0);
689 g_assert(endptr
== str
+ 1);
692 static void test_qemu_strtoui_max(void)
694 char *str
= g_strdup_printf("%u", UINT_MAX
);
696 const char *endptr
= &f
;
697 unsigned int res
= 999;
700 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
702 g_assert_cmpint(err
, ==, 0);
703 g_assert_cmphex(res
, ==, UINT_MAX
);
704 g_assert(endptr
== str
+ strlen(str
));
708 static void test_qemu_strtoui_overflow(void)
710 char *str
= g_strdup_printf("%lld", (long long)UINT_MAX
+ 1ll);
712 const char *endptr
= &f
;
713 unsigned int res
= 999;
716 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
718 g_assert_cmpint(err
, ==, -ERANGE
);
719 g_assert_cmphex(res
, ==, UINT_MAX
);
720 g_assert(endptr
== str
+ strlen(str
));
724 static void test_qemu_strtoui_underflow(void)
726 char *str
= g_strdup_printf("%lld", (long long)INT_MIN
- 1ll);
728 const char *endptr
= &f
;
729 unsigned int res
= 999;
732 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
734 g_assert_cmpint(err
, ==, -ERANGE
);
735 g_assert_cmpuint(res
, ==, (unsigned int)-1);
736 g_assert(endptr
== str
+ strlen(str
));
740 static void test_qemu_strtoui_negative(void)
742 const char *str
= " \t -321";
744 const char *endptr
= &f
;
745 unsigned int res
= 999;
748 err
= qemu_strtoui(str
, &endptr
, 0, &res
);
750 g_assert_cmpint(err
, ==, 0);
751 g_assert_cmpuint(res
, ==, (unsigned int)-321);
752 g_assert(endptr
== str
+ strlen(str
));
755 static void test_qemu_strtoui_full_correct(void)
757 const char *str
= "123";
758 unsigned int res
= 999;
761 err
= qemu_strtoui(str
, NULL
, 0, &res
);
763 g_assert_cmpint(err
, ==, 0);
764 g_assert_cmpuint(res
, ==, 123);
767 static void test_qemu_strtoui_full_null(void)
769 unsigned int res
= 999;
772 err
= qemu_strtoui(NULL
, NULL
, 0, &res
);
774 g_assert_cmpint(err
, ==, -EINVAL
);
777 static void test_qemu_strtoui_full_empty(void)
779 const char *str
= "";
780 unsigned int res
= 999;
783 err
= qemu_strtoui(str
, NULL
, 0, &res
);
785 g_assert_cmpint(err
, ==, -EINVAL
);
787 static void test_qemu_strtoui_full_negative(void)
789 const char *str
= " \t -321";
790 unsigned int res
= 999;
793 err
= qemu_strtoui(str
, NULL
, 0, &res
);
794 g_assert_cmpint(err
, ==, 0);
795 g_assert_cmpuint(res
, ==, (unsigned int)-321);
798 static void test_qemu_strtoui_full_trailing(void)
800 const char *str
= "123xxx";
804 err
= qemu_strtoui(str
, NULL
, 0, &res
);
806 g_assert_cmpint(err
, ==, -EINVAL
);
809 static void test_qemu_strtoui_full_max(void)
811 char *str
= g_strdup_printf("%u", UINT_MAX
);
812 unsigned int res
= 999;
815 err
= qemu_strtoui(str
, NULL
, 0, &res
);
817 g_assert_cmpint(err
, ==, 0);
818 g_assert_cmphex(res
, ==, UINT_MAX
);
822 static void test_qemu_strtol_correct(void)
824 const char *str
= "12345 foo";
826 const char *endptr
= &f
;
830 err
= qemu_strtol(str
, &endptr
, 0, &res
);
832 g_assert_cmpint(err
, ==, 0);
833 g_assert_cmpint(res
, ==, 12345);
834 g_assert(endptr
== str
+ 5);
837 static void test_qemu_strtol_null(void)
840 const char *endptr
= &f
;
844 err
= qemu_strtol(NULL
, &endptr
, 0, &res
);
846 g_assert_cmpint(err
, ==, -EINVAL
);
847 g_assert(endptr
== NULL
);
850 static void test_qemu_strtol_empty(void)
852 const char *str
= "";
854 const char *endptr
= &f
;
858 err
= qemu_strtol(str
, &endptr
, 0, &res
);
860 g_assert_cmpint(err
, ==, -EINVAL
);
861 g_assert(endptr
== str
);
864 static void test_qemu_strtol_whitespace(void)
866 const char *str
= " \t ";
868 const char *endptr
= &f
;
872 err
= qemu_strtol(str
, &endptr
, 0, &res
);
874 g_assert_cmpint(err
, ==, -EINVAL
);
875 g_assert(endptr
== str
);
878 static void test_qemu_strtol_invalid(void)
880 const char *str
= " xxxx \t abc";
882 const char *endptr
= &f
;
886 err
= qemu_strtol(str
, &endptr
, 0, &res
);
888 g_assert_cmpint(err
, ==, -EINVAL
);
889 g_assert(endptr
== str
);
892 static void test_qemu_strtol_trailing(void)
894 const char *str
= "123xxx";
896 const char *endptr
= &f
;
900 err
= qemu_strtol(str
, &endptr
, 0, &res
);
902 g_assert_cmpint(err
, ==, 0);
903 g_assert_cmpint(res
, ==, 123);
904 g_assert(endptr
== str
+ 3);
907 static void test_qemu_strtol_octal(void)
909 const char *str
= "0123";
911 const char *endptr
= &f
;
915 err
= qemu_strtol(str
, &endptr
, 8, &res
);
917 g_assert_cmpint(err
, ==, 0);
918 g_assert_cmpint(res
, ==, 0123);
919 g_assert(endptr
== str
+ strlen(str
));
923 err
= qemu_strtol(str
, &endptr
, 0, &res
);
925 g_assert_cmpint(err
, ==, 0);
926 g_assert_cmpint(res
, ==, 0123);
927 g_assert(endptr
== str
+ strlen(str
));
930 static void test_qemu_strtol_decimal(void)
932 const char *str
= "0123";
934 const char *endptr
= &f
;
938 err
= qemu_strtol(str
, &endptr
, 10, &res
);
940 g_assert_cmpint(err
, ==, 0);
941 g_assert_cmpint(res
, ==, 123);
942 g_assert(endptr
== str
+ strlen(str
));
947 err
= qemu_strtol(str
, &endptr
, 0, &res
);
949 g_assert_cmpint(err
, ==, 0);
950 g_assert_cmpint(res
, ==, 123);
951 g_assert(endptr
== str
+ strlen(str
));
954 static void test_qemu_strtol_hex(void)
956 const char *str
= "0123";
958 const char *endptr
= &f
;
962 err
= qemu_strtol(str
, &endptr
, 16, &res
);
964 g_assert_cmpint(err
, ==, 0);
965 g_assert_cmpint(res
, ==, 0x123);
966 g_assert(endptr
== str
+ strlen(str
));
971 err
= qemu_strtol(str
, &endptr
, 0, &res
);
973 g_assert_cmpint(err
, ==, 0);
974 g_assert_cmpint(res
, ==, 0x123);
975 g_assert(endptr
== str
+ strlen(str
));
980 err
= qemu_strtol(str
, &endptr
, 16, &res
);
982 g_assert_cmpint(err
, ==, 0);
983 g_assert_cmpint(res
, ==, 0);
984 g_assert(endptr
== str
+ 1);
987 static void test_qemu_strtol_max(void)
989 char *str
= g_strdup_printf("%ld", LONG_MAX
);
991 const char *endptr
= &f
;
995 err
= qemu_strtol(str
, &endptr
, 0, &res
);
997 g_assert_cmpint(err
, ==, 0);
998 g_assert_cmpint(res
, ==, LONG_MAX
);
999 g_assert(endptr
== str
+ strlen(str
));
1003 static void test_qemu_strtol_overflow(void)
1005 const char *str
= "99999999999999999999999999999999999999999999";
1007 const char *endptr
= &f
;
1011 err
= qemu_strtol(str
, &endptr
, 0, &res
);
1013 g_assert_cmpint(err
, ==, -ERANGE
);
1014 g_assert_cmpint(res
, ==, LONG_MAX
);
1015 g_assert(endptr
== str
+ strlen(str
));
1018 static void test_qemu_strtol_underflow(void)
1020 const char *str
= "-99999999999999999999999999999999999999999999";
1022 const char *endptr
= &f
;
1026 err
= qemu_strtol(str
, &endptr
, 0, &res
);
1028 g_assert_cmpint(err
, ==, -ERANGE
);
1029 g_assert_cmpint(res
, ==, LONG_MIN
);
1030 g_assert(endptr
== str
+ strlen(str
));
1033 static void test_qemu_strtol_negative(void)
1035 const char *str
= " \t -321";
1037 const char *endptr
= &f
;
1041 err
= qemu_strtol(str
, &endptr
, 0, &res
);
1043 g_assert_cmpint(err
, ==, 0);
1044 g_assert_cmpint(res
, ==, -321);
1045 g_assert(endptr
== str
+ strlen(str
));
1048 static void test_qemu_strtol_full_correct(void)
1050 const char *str
= "123";
1054 err
= qemu_strtol(str
, NULL
, 0, &res
);
1056 g_assert_cmpint(err
, ==, 0);
1057 g_assert_cmpint(res
, ==, 123);
1060 static void test_qemu_strtol_full_null(void)
1063 const char *endptr
= &f
;
1067 err
= qemu_strtol(NULL
, &endptr
, 0, &res
);
1069 g_assert_cmpint(err
, ==, -EINVAL
);
1070 g_assert(endptr
== NULL
);
1073 static void test_qemu_strtol_full_empty(void)
1075 const char *str
= "";
1079 err
= qemu_strtol(str
, NULL
, 0, &res
);
1081 g_assert_cmpint(err
, ==, -EINVAL
);
1084 static void test_qemu_strtol_full_negative(void)
1086 const char *str
= " \t -321";
1090 err
= qemu_strtol(str
, NULL
, 0, &res
);
1092 g_assert_cmpint(err
, ==, 0);
1093 g_assert_cmpint(res
, ==, -321);
1096 static void test_qemu_strtol_full_trailing(void)
1098 const char *str
= "123xxx";
1102 err
= qemu_strtol(str
, NULL
, 0, &res
);
1104 g_assert_cmpint(err
, ==, -EINVAL
);
1107 static void test_qemu_strtol_full_max(void)
1109 char *str
= g_strdup_printf("%ld", LONG_MAX
);
1113 err
= qemu_strtol(str
, NULL
, 0, &res
);
1115 g_assert_cmpint(err
, ==, 0);
1116 g_assert_cmpint(res
, ==, LONG_MAX
);
1120 static void test_qemu_strtoul_correct(void)
1122 const char *str
= "12345 foo";
1124 const char *endptr
= &f
;
1125 unsigned long res
= 999;
1128 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1130 g_assert_cmpint(err
, ==, 0);
1131 g_assert_cmpuint(res
, ==, 12345);
1132 g_assert(endptr
== str
+ 5);
1135 static void test_qemu_strtoul_null(void)
1138 const char *endptr
= &f
;
1139 unsigned long res
= 999;
1142 err
= qemu_strtoul(NULL
, &endptr
, 0, &res
);
1144 g_assert_cmpint(err
, ==, -EINVAL
);
1145 g_assert(endptr
== NULL
);
1148 static void test_qemu_strtoul_empty(void)
1150 const char *str
= "";
1152 const char *endptr
= &f
;
1153 unsigned long res
= 999;
1156 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1158 g_assert_cmpint(err
, ==, -EINVAL
);
1159 g_assert(endptr
== str
);
1162 static void test_qemu_strtoul_whitespace(void)
1164 const char *str
= " \t ";
1166 const char *endptr
= &f
;
1167 unsigned long res
= 999;
1170 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1172 g_assert_cmpint(err
, ==, -EINVAL
);
1173 g_assert(endptr
== str
);
1176 static void test_qemu_strtoul_invalid(void)
1178 const char *str
= " xxxx \t abc";
1180 const char *endptr
= &f
;
1181 unsigned long res
= 999;
1184 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1186 g_assert_cmpint(err
, ==, -EINVAL
);
1187 g_assert(endptr
== str
);
1190 static void test_qemu_strtoul_trailing(void)
1192 const char *str
= "123xxx";
1194 const char *endptr
= &f
;
1195 unsigned long res
= 999;
1198 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1200 g_assert_cmpint(err
, ==, 0);
1201 g_assert_cmpuint(res
, ==, 123);
1202 g_assert(endptr
== str
+ 3);
1205 static void test_qemu_strtoul_octal(void)
1207 const char *str
= "0123";
1209 const char *endptr
= &f
;
1210 unsigned long res
= 999;
1213 err
= qemu_strtoul(str
, &endptr
, 8, &res
);
1215 g_assert_cmpint(err
, ==, 0);
1216 g_assert_cmpuint(res
, ==, 0123);
1217 g_assert(endptr
== str
+ strlen(str
));
1221 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1223 g_assert_cmpint(err
, ==, 0);
1224 g_assert_cmpuint(res
, ==, 0123);
1225 g_assert(endptr
== str
+ strlen(str
));
1228 static void test_qemu_strtoul_decimal(void)
1230 const char *str
= "0123";
1232 const char *endptr
= &f
;
1233 unsigned long res
= 999;
1236 err
= qemu_strtoul(str
, &endptr
, 10, &res
);
1238 g_assert_cmpint(err
, ==, 0);
1239 g_assert_cmpuint(res
, ==, 123);
1240 g_assert(endptr
== str
+ strlen(str
));
1245 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1247 g_assert_cmpint(err
, ==, 0);
1248 g_assert_cmpuint(res
, ==, 123);
1249 g_assert(endptr
== str
+ strlen(str
));
1252 static void test_qemu_strtoul_hex(void)
1254 const char *str
= "0123";
1256 const char *endptr
= &f
;
1257 unsigned long res
= 999;
1260 err
= qemu_strtoul(str
, &endptr
, 16, &res
);
1262 g_assert_cmpint(err
, ==, 0);
1263 g_assert_cmphex(res
, ==, 0x123);
1264 g_assert(endptr
== str
+ strlen(str
));
1269 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1271 g_assert_cmpint(err
, ==, 0);
1272 g_assert_cmphex(res
, ==, 0x123);
1273 g_assert(endptr
== str
+ strlen(str
));
1278 err
= qemu_strtoul(str
, &endptr
, 16, &res
);
1280 g_assert_cmpint(err
, ==, 0);
1281 g_assert_cmphex(res
, ==, 0);
1282 g_assert(endptr
== str
+ 1);
1285 static void test_qemu_strtoul_max(void)
1287 char *str
= g_strdup_printf("%lu", ULONG_MAX
);
1289 const char *endptr
= &f
;
1290 unsigned long res
= 999;
1293 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1295 g_assert_cmpint(err
, ==, 0);
1296 g_assert_cmphex(res
, ==, ULONG_MAX
);
1297 g_assert(endptr
== str
+ strlen(str
));
1301 static void test_qemu_strtoul_overflow(void)
1303 const char *str
= "99999999999999999999999999999999999999999999";
1305 const char *endptr
= &f
;
1306 unsigned long res
= 999;
1309 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1311 g_assert_cmpint(err
, ==, -ERANGE
);
1312 g_assert_cmphex(res
, ==, ULONG_MAX
);
1313 g_assert(endptr
== str
+ strlen(str
));
1316 static void test_qemu_strtoul_underflow(void)
1318 const char *str
= "-99999999999999999999999999999999999999999999";
1320 const char *endptr
= &f
;
1321 unsigned long res
= 999;
1324 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1326 g_assert_cmpint(err
, ==, -ERANGE
);
1327 g_assert_cmpuint(res
, ==, -1ul);
1328 g_assert(endptr
== str
+ strlen(str
));
1331 static void test_qemu_strtoul_negative(void)
1333 const char *str
= " \t -321";
1335 const char *endptr
= &f
;
1336 unsigned long res
= 999;
1339 err
= qemu_strtoul(str
, &endptr
, 0, &res
);
1341 g_assert_cmpint(err
, ==, 0);
1342 g_assert_cmpuint(res
, ==, -321ul);
1343 g_assert(endptr
== str
+ strlen(str
));
1346 static void test_qemu_strtoul_full_correct(void)
1348 const char *str
= "123";
1349 unsigned long res
= 999;
1352 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1354 g_assert_cmpint(err
, ==, 0);
1355 g_assert_cmpuint(res
, ==, 123);
1358 static void test_qemu_strtoul_full_null(void)
1360 unsigned long res
= 999;
1363 err
= qemu_strtoul(NULL
, NULL
, 0, &res
);
1365 g_assert_cmpint(err
, ==, -EINVAL
);
1368 static void test_qemu_strtoul_full_empty(void)
1370 const char *str
= "";
1371 unsigned long res
= 999;
1374 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1376 g_assert_cmpint(err
, ==, -EINVAL
);
1378 static void test_qemu_strtoul_full_negative(void)
1380 const char *str
= " \t -321";
1381 unsigned long res
= 999;
1384 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1385 g_assert_cmpint(err
, ==, 0);
1386 g_assert_cmpuint(res
, ==, -321ul);
1389 static void test_qemu_strtoul_full_trailing(void)
1391 const char *str
= "123xxx";
1395 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1397 g_assert_cmpint(err
, ==, -EINVAL
);
1400 static void test_qemu_strtoul_full_max(void)
1402 char *str
= g_strdup_printf("%lu", ULONG_MAX
);
1403 unsigned long res
= 999;
1406 err
= qemu_strtoul(str
, NULL
, 0, &res
);
1408 g_assert_cmpint(err
, ==, 0);
1409 g_assert_cmphex(res
, ==, ULONG_MAX
);
1413 static void test_qemu_strtoi64_correct(void)
1415 const char *str
= "12345 foo";
1417 const char *endptr
= &f
;
1421 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1423 g_assert_cmpint(err
, ==, 0);
1424 g_assert_cmpint(res
, ==, 12345);
1425 g_assert(endptr
== str
+ 5);
1428 static void test_qemu_strtoi64_null(void)
1431 const char *endptr
= &f
;
1435 err
= qemu_strtoi64(NULL
, &endptr
, 0, &res
);
1437 g_assert_cmpint(err
, ==, -EINVAL
);
1438 g_assert(endptr
== NULL
);
1441 static void test_qemu_strtoi64_empty(void)
1443 const char *str
= "";
1445 const char *endptr
= &f
;
1449 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1451 g_assert_cmpint(err
, ==, -EINVAL
);
1452 g_assert(endptr
== str
);
1455 static void test_qemu_strtoi64_whitespace(void)
1457 const char *str
= " \t ";
1459 const char *endptr
= &f
;
1463 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1465 g_assert_cmpint(err
, ==, -EINVAL
);
1466 g_assert(endptr
== str
);
1469 static void test_qemu_strtoi64_invalid(void)
1471 const char *str
= " xxxx \t abc";
1473 const char *endptr
= &f
;
1477 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1479 g_assert_cmpint(err
, ==, -EINVAL
);
1480 g_assert(endptr
== str
);
1483 static void test_qemu_strtoi64_trailing(void)
1485 const char *str
= "123xxx";
1487 const char *endptr
= &f
;
1491 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1493 g_assert_cmpint(err
, ==, 0);
1494 g_assert_cmpint(res
, ==, 123);
1495 g_assert(endptr
== str
+ 3);
1498 static void test_qemu_strtoi64_octal(void)
1500 const char *str
= "0123";
1502 const char *endptr
= &f
;
1506 err
= qemu_strtoi64(str
, &endptr
, 8, &res
);
1508 g_assert_cmpint(err
, ==, 0);
1509 g_assert_cmpint(res
, ==, 0123);
1510 g_assert(endptr
== str
+ strlen(str
));
1514 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1516 g_assert_cmpint(err
, ==, 0);
1517 g_assert_cmpint(res
, ==, 0123);
1518 g_assert(endptr
== str
+ strlen(str
));
1521 static void test_qemu_strtoi64_decimal(void)
1523 const char *str
= "0123";
1525 const char *endptr
= &f
;
1529 err
= qemu_strtoi64(str
, &endptr
, 10, &res
);
1531 g_assert_cmpint(err
, ==, 0);
1532 g_assert_cmpint(res
, ==, 123);
1533 g_assert(endptr
== str
+ strlen(str
));
1538 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1540 g_assert_cmpint(err
, ==, 0);
1541 g_assert_cmpint(res
, ==, 123);
1542 g_assert(endptr
== str
+ strlen(str
));
1545 static void test_qemu_strtoi64_hex(void)
1547 const char *str
= "0123";
1549 const char *endptr
= &f
;
1553 err
= qemu_strtoi64(str
, &endptr
, 16, &res
);
1555 g_assert_cmpint(err
, ==, 0);
1556 g_assert_cmpint(res
, ==, 0x123);
1557 g_assert(endptr
== str
+ strlen(str
));
1562 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1564 g_assert_cmpint(err
, ==, 0);
1565 g_assert_cmpint(res
, ==, 0x123);
1566 g_assert(endptr
== str
+ strlen(str
));
1571 err
= qemu_strtoi64(str
, &endptr
, 16, &res
);
1573 g_assert_cmpint(err
, ==, 0);
1574 g_assert_cmpint(res
, ==, 0);
1575 g_assert(endptr
== str
+ 1);
1578 static void test_qemu_strtoi64_max(void)
1580 char *str
= g_strdup_printf("%lld", LLONG_MAX
);
1582 const char *endptr
= &f
;
1586 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1588 g_assert_cmpint(err
, ==, 0);
1589 g_assert_cmpint(res
, ==, LLONG_MAX
);
1590 g_assert(endptr
== str
+ strlen(str
));
1594 static void test_qemu_strtoi64_overflow(void)
1596 const char *str
= "99999999999999999999999999999999999999999999";
1598 const char *endptr
= &f
;
1602 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1604 g_assert_cmpint(err
, ==, -ERANGE
);
1605 g_assert_cmpint(res
, ==, LLONG_MAX
);
1606 g_assert(endptr
== str
+ strlen(str
));
1609 static void test_qemu_strtoi64_underflow(void)
1611 const char *str
= "-99999999999999999999999999999999999999999999";
1613 const char *endptr
= &f
;
1617 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1619 g_assert_cmpint(err
, ==, -ERANGE
);
1620 g_assert_cmpint(res
, ==, LLONG_MIN
);
1621 g_assert(endptr
== str
+ strlen(str
));
1624 static void test_qemu_strtoi64_negative(void)
1626 const char *str
= " \t -321";
1628 const char *endptr
= &f
;
1632 err
= qemu_strtoi64(str
, &endptr
, 0, &res
);
1634 g_assert_cmpint(err
, ==, 0);
1635 g_assert_cmpint(res
, ==, -321);
1636 g_assert(endptr
== str
+ strlen(str
));
1639 static void test_qemu_strtoi64_full_correct(void)
1641 const char *str
= "123";
1645 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1647 g_assert_cmpint(err
, ==, 0);
1648 g_assert_cmpint(res
, ==, 123);
1651 static void test_qemu_strtoi64_full_null(void)
1656 err
= qemu_strtoi64(NULL
, NULL
, 0, &res
);
1658 g_assert_cmpint(err
, ==, -EINVAL
);
1661 static void test_qemu_strtoi64_full_empty(void)
1663 const char *str
= "";
1667 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1669 g_assert_cmpint(err
, ==, -EINVAL
);
1672 static void test_qemu_strtoi64_full_negative(void)
1674 const char *str
= " \t -321";
1678 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1680 g_assert_cmpint(err
, ==, 0);
1681 g_assert_cmpint(res
, ==, -321);
1684 static void test_qemu_strtoi64_full_trailing(void)
1686 const char *str
= "123xxx";
1690 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1692 g_assert_cmpint(err
, ==, -EINVAL
);
1695 static void test_qemu_strtoi64_full_max(void)
1698 char *str
= g_strdup_printf("%lld", LLONG_MAX
);
1702 err
= qemu_strtoi64(str
, NULL
, 0, &res
);
1704 g_assert_cmpint(err
, ==, 0);
1705 g_assert_cmpint(res
, ==, LLONG_MAX
);
1709 static void test_qemu_strtou64_correct(void)
1711 const char *str
= "12345 foo";
1713 const char *endptr
= &f
;
1717 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1719 g_assert_cmpint(err
, ==, 0);
1720 g_assert_cmpuint(res
, ==, 12345);
1721 g_assert(endptr
== str
+ 5);
1724 static void test_qemu_strtou64_null(void)
1727 const char *endptr
= &f
;
1731 err
= qemu_strtou64(NULL
, &endptr
, 0, &res
);
1733 g_assert_cmpint(err
, ==, -EINVAL
);
1734 g_assert(endptr
== NULL
);
1737 static void test_qemu_strtou64_empty(void)
1739 const char *str
= "";
1741 const char *endptr
= &f
;
1745 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1747 g_assert_cmpint(err
, ==, -EINVAL
);
1748 g_assert(endptr
== str
);
1751 static void test_qemu_strtou64_whitespace(void)
1753 const char *str
= " \t ";
1755 const char *endptr
= &f
;
1759 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1761 g_assert_cmpint(err
, ==, -EINVAL
);
1762 g_assert(endptr
== str
);
1765 static void test_qemu_strtou64_invalid(void)
1767 const char *str
= " xxxx \t abc";
1769 const char *endptr
= &f
;
1773 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1775 g_assert_cmpint(err
, ==, -EINVAL
);
1776 g_assert(endptr
== str
);
1779 static void test_qemu_strtou64_trailing(void)
1781 const char *str
= "123xxx";
1783 const char *endptr
= &f
;
1787 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1789 g_assert_cmpint(err
, ==, 0);
1790 g_assert_cmpuint(res
, ==, 123);
1791 g_assert(endptr
== str
+ 3);
1794 static void test_qemu_strtou64_octal(void)
1796 const char *str
= "0123";
1798 const char *endptr
= &f
;
1802 err
= qemu_strtou64(str
, &endptr
, 8, &res
);
1804 g_assert_cmpint(err
, ==, 0);
1805 g_assert_cmpuint(res
, ==, 0123);
1806 g_assert(endptr
== str
+ strlen(str
));
1810 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1812 g_assert_cmpint(err
, ==, 0);
1813 g_assert_cmpuint(res
, ==, 0123);
1814 g_assert(endptr
== str
+ strlen(str
));
1817 static void test_qemu_strtou64_decimal(void)
1819 const char *str
= "0123";
1821 const char *endptr
= &f
;
1825 err
= qemu_strtou64(str
, &endptr
, 10, &res
);
1827 g_assert_cmpint(err
, ==, 0);
1828 g_assert_cmpuint(res
, ==, 123);
1829 g_assert(endptr
== str
+ strlen(str
));
1834 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1836 g_assert_cmpint(err
, ==, 0);
1837 g_assert_cmpuint(res
, ==, 123);
1838 g_assert(endptr
== str
+ strlen(str
));
1841 static void test_qemu_strtou64_hex(void)
1843 const char *str
= "0123";
1845 const char *endptr
= &f
;
1849 err
= qemu_strtou64(str
, &endptr
, 16, &res
);
1851 g_assert_cmpint(err
, ==, 0);
1852 g_assert_cmphex(res
, ==, 0x123);
1853 g_assert(endptr
== str
+ strlen(str
));
1858 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1860 g_assert_cmpint(err
, ==, 0);
1861 g_assert_cmphex(res
, ==, 0x123);
1862 g_assert(endptr
== str
+ strlen(str
));
1867 err
= qemu_strtou64(str
, &endptr
, 16, &res
);
1869 g_assert_cmpint(err
, ==, 0);
1870 g_assert_cmphex(res
, ==, 0);
1871 g_assert(endptr
== str
+ 1);
1874 static void test_qemu_strtou64_max(void)
1876 char *str
= g_strdup_printf("%llu", ULLONG_MAX
);
1878 const char *endptr
= &f
;
1882 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1884 g_assert_cmpint(err
, ==, 0);
1885 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1886 g_assert(endptr
== str
+ strlen(str
));
1890 static void test_qemu_strtou64_overflow(void)
1892 const char *str
= "99999999999999999999999999999999999999999999";
1894 const char *endptr
= &f
;
1898 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1900 g_assert_cmpint(err
, ==, -ERANGE
);
1901 g_assert_cmphex(res
, ==, ULLONG_MAX
);
1902 g_assert(endptr
== str
+ strlen(str
));
1905 static void test_qemu_strtou64_underflow(void)
1907 const char *str
= "-99999999999999999999999999999999999999999999";
1909 const char *endptr
= &f
;
1913 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1915 g_assert_cmpint(err
, ==, -ERANGE
);
1916 g_assert_cmphex(res
, ==, -1ull);
1917 g_assert(endptr
== str
+ strlen(str
));
1920 static void test_qemu_strtou64_negative(void)
1922 const char *str
= " \t -321";
1924 const char *endptr
= &f
;
1928 err
= qemu_strtou64(str
, &endptr
, 0, &res
);
1930 g_assert_cmpint(err
, ==, 0);
1931 g_assert_cmpuint(res
, ==, -321ull);
1932 g_assert(endptr
== str
+ strlen(str
));
1935 static void test_qemu_strtou64_full_correct(void)
1937 const char *str
= "18446744073709551614";
1941 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1943 g_assert_cmpint(err
, ==, 0);
1944 g_assert_cmpuint(res
, ==, 18446744073709551614ull);
1947 static void test_qemu_strtou64_full_null(void)
1952 err
= qemu_strtou64(NULL
, NULL
, 0, &res
);
1954 g_assert_cmpint(err
, ==, -EINVAL
);
1957 static void test_qemu_strtou64_full_empty(void)
1959 const char *str
= "";
1963 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1965 g_assert_cmpint(err
, ==, -EINVAL
);
1968 static void test_qemu_strtou64_full_negative(void)
1970 const char *str
= " \t -321";
1974 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1976 g_assert_cmpint(err
, ==, 0);
1977 g_assert_cmpuint(res
, ==, -321ull);
1980 static void test_qemu_strtou64_full_trailing(void)
1982 const char *str
= "18446744073709551614xxxxxx";
1986 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1988 g_assert_cmpint(err
, ==, -EINVAL
);
1991 static void test_qemu_strtou64_full_max(void)
1993 char *str
= g_strdup_printf("%lld", ULLONG_MAX
);
1997 err
= qemu_strtou64(str
, NULL
, 0, &res
);
1999 g_assert_cmpint(err
, ==, 0);
2000 g_assert_cmphex(res
, ==, ULLONG_MAX
);
2004 static void test_qemu_strtosz_simple(void)
2014 err
= qemu_strtosz(str
, &endptr
, &res
);
2015 g_assert_cmpint(err
, ==, 0);
2016 g_assert_cmpint(res
, ==, 0);
2017 g_assert(endptr
== str
+ 1);
2019 /* Leading 0 gives decimal results, not octal */
2023 err
= qemu_strtosz(str
, &endptr
, &res
);
2024 g_assert_cmpint(err
, ==, 0);
2025 g_assert_cmpint(res
, ==, 8);
2026 g_assert(endptr
== str
+ 2);
2028 /* Leading space is ignored */
2032 err
= qemu_strtosz(str
, &endptr
, &res
);
2033 g_assert_cmpint(err
, ==, 0);
2034 g_assert_cmpint(res
, ==, 12345);
2035 g_assert(endptr
== str
+ 6);
2038 err
= qemu_strtosz(str
, NULL
, &res
);
2039 g_assert_cmpint(err
, ==, 0);
2040 g_assert_cmpint(res
, ==, 12345);
2042 str
= "9007199254740991"; /* 2^53-1 */
2045 err
= qemu_strtosz(str
, &endptr
, &res
);
2046 g_assert_cmpint(err
, ==, 0);
2047 g_assert_cmpint(res
, ==, 0x1fffffffffffff);
2048 g_assert(endptr
== str
+ 16);
2050 str
= "9007199254740992"; /* 2^53 */
2053 err
= qemu_strtosz(str
, &endptr
, &res
);
2054 g_assert_cmpint(err
, ==, 0);
2055 g_assert_cmpint(res
, ==, 0x20000000000000);
2056 g_assert(endptr
== str
+ 16);
2058 str
= "9007199254740993"; /* 2^53+1 */
2061 err
= qemu_strtosz(str
, &endptr
, &res
);
2062 g_assert_cmpint(err
, ==, 0);
2063 g_assert_cmpint(res
, ==, 0x20000000000001);
2064 g_assert(endptr
== str
+ 16);
2066 str
= "18446744073709549568"; /* 0xfffffffffffff800 (53 msbs set) */
2069 err
= qemu_strtosz(str
, &endptr
, &res
);
2070 g_assert_cmpint(err
, ==, 0);
2071 g_assert_cmpint(res
, ==, 0xfffffffffffff800);
2072 g_assert(endptr
== str
+ 20);
2074 str
= "18446744073709550591"; /* 0xfffffffffffffbff */
2077 err
= qemu_strtosz(str
, &endptr
, &res
);
2078 g_assert_cmpint(err
, ==, 0);
2079 g_assert_cmpint(res
, ==, 0xfffffffffffffbff);
2080 g_assert(endptr
== str
+ 20);
2082 str
= "18446744073709551615"; /* 0xffffffffffffffff */
2085 err
= qemu_strtosz(str
, &endptr
, &res
);
2086 g_assert_cmpint(err
, ==, 0);
2087 g_assert_cmpint(res
, ==, 0xffffffffffffffff);
2088 g_assert(endptr
== str
+ 20);
2091 static void test_qemu_strtosz_hex(void)
2101 err
= qemu_strtosz(str
, &endptr
, &res
);
2102 g_assert_cmpint(err
, ==, 0);
2103 g_assert_cmpint(res
, ==, 0);
2104 g_assert(endptr
== str
+ 3);
2109 err
= qemu_strtosz(str
, &endptr
, &res
);
2110 g_assert_cmpint(err
, ==, 0);
2111 g_assert_cmpint(res
, ==, 171);
2112 g_assert(endptr
== str
+ 4);
2117 err
= qemu_strtosz(str
, &endptr
, &res
);
2118 g_assert_cmpint(err
, ==, 0);
2119 g_assert_cmpint(res
, ==, 174);
2120 g_assert(endptr
== str
+ 4);
2123 static void test_qemu_strtosz_units(void)
2125 const char *none
= "1";
2126 const char *b
= "1B";
2127 const char *k
= "1K";
2128 const char *m
= "1M";
2129 const char *g
= "1G";
2130 const char *t
= "1T";
2131 const char *p
= "1P";
2132 const char *e
= "1E";
2140 err
= qemu_strtosz_MiB(none
, &endptr
, &res
);
2141 g_assert_cmpint(err
, ==, 0);
2142 g_assert_cmpint(res
, ==, MiB
);
2143 g_assert(endptr
== none
+ 1);
2147 err
= qemu_strtosz(b
, &endptr
, &res
);
2148 g_assert_cmpint(err
, ==, 0);
2149 g_assert_cmpint(res
, ==, 1);
2150 g_assert(endptr
== b
+ 2);
2154 err
= qemu_strtosz(k
, &endptr
, &res
);
2155 g_assert_cmpint(err
, ==, 0);
2156 g_assert_cmpint(res
, ==, KiB
);
2157 g_assert(endptr
== k
+ 2);
2161 err
= qemu_strtosz(m
, &endptr
, &res
);
2162 g_assert_cmpint(err
, ==, 0);
2163 g_assert_cmpint(res
, ==, MiB
);
2164 g_assert(endptr
== m
+ 2);
2168 err
= qemu_strtosz(g
, &endptr
, &res
);
2169 g_assert_cmpint(err
, ==, 0);
2170 g_assert_cmpint(res
, ==, GiB
);
2171 g_assert(endptr
== g
+ 2);
2175 err
= qemu_strtosz(t
, &endptr
, &res
);
2176 g_assert_cmpint(err
, ==, 0);
2177 g_assert_cmpint(res
, ==, TiB
);
2178 g_assert(endptr
== t
+ 2);
2182 err
= qemu_strtosz(p
, &endptr
, &res
);
2183 g_assert_cmpint(err
, ==, 0);
2184 g_assert_cmpint(res
, ==, PiB
);
2185 g_assert(endptr
== p
+ 2);
2189 err
= qemu_strtosz(e
, &endptr
, &res
);
2190 g_assert_cmpint(err
, ==, 0);
2191 g_assert_cmpint(res
, ==, EiB
);
2192 g_assert(endptr
== e
+ 2);
2195 static void test_qemu_strtosz_float(void)
2205 err
= qemu_strtosz(str
, &endptr
, &res
);
2206 g_assert_cmpint(err
, ==, 0);
2207 g_assert_cmpint(res
, ==, EiB
/ 2);
2208 g_assert(endptr
== str
+ 4);
2210 /* For convenience, a fraction of 0 is tolerated even on bytes */
2214 err
= qemu_strtosz(str
, &endptr
, &res
);
2215 g_assert_cmpint(err
, ==, 0);
2216 g_assert_cmpint(res
, ==, 1);
2217 g_assert(endptr
== str
+ 4);
2219 /* An empty fraction is tolerated */
2223 err
= qemu_strtosz(str
, &endptr
, &res
);
2224 g_assert_cmpint(err
, ==, 0);
2225 g_assert_cmpint(res
, ==, 1024);
2226 g_assert(endptr
== str
+ 3);
2228 /* For convenience, we permit values that are not byte-exact */
2232 err
= qemu_strtosz(str
, &endptr
, &res
);
2233 g_assert_cmpint(err
, ==, 0);
2234 g_assert_cmpint(res
, ==, (uint64_t) (12.345 * MiB
+ 0.5));
2235 g_assert(endptr
== str
+ 7);
2238 static void test_qemu_strtosz_invalid(void)
2243 uint64_t res
= 0xbaadf00d;
2247 err
= qemu_strtosz(str
, &endptr
, &res
);
2248 g_assert_cmpint(err
, ==, -EINVAL
);
2249 g_assert_cmpint(res
, ==, 0xbaadf00d);
2250 g_assert(endptr
== str
);
2254 err
= qemu_strtosz(str
, &endptr
, &res
);
2255 g_assert_cmpint(err
, ==, -EINVAL
);
2256 g_assert_cmpint(res
, ==, 0xbaadf00d);
2257 g_assert(endptr
== str
);
2261 err
= qemu_strtosz(str
, &endptr
, &res
);
2262 g_assert_cmpint(err
, ==, -EINVAL
);
2263 g_assert_cmpint(res
, ==, 0xbaadf00d);
2264 g_assert(endptr
== str
);
2268 err
= qemu_strtosz(str
, &endptr
, &res
);
2269 g_assert_cmpint(err
, ==, -EINVAL
);
2270 g_assert_cmpint(res
, ==, 0xbaadf00d);
2271 g_assert(endptr
== str
);
2275 err
= qemu_strtosz(str
, &endptr
, &res
);
2276 g_assert_cmpint(err
, ==, -EINVAL
);
2277 g_assert_cmpint(res
, ==, 0xbaadf00d);
2278 g_assert(endptr
== str
);
2280 /* Fractional values require scale larger than bytes */
2283 err
= qemu_strtosz(str
, &endptr
, &res
);
2284 g_assert_cmpint(err
, ==, -EINVAL
);
2285 g_assert_cmpint(res
, ==, 0xbaadf00d);
2286 g_assert(endptr
== str
);
2290 err
= qemu_strtosz(str
, &endptr
, &res
);
2291 g_assert_cmpint(err
, ==, -EINVAL
);
2292 g_assert_cmpint(res
, ==, 0xbaadf00d);
2293 g_assert(endptr
== str
);
2295 /* No floating point exponents */
2298 err
= qemu_strtosz(str
, &endptr
, &res
);
2299 g_assert_cmpint(err
, ==, -EINVAL
);
2300 g_assert_cmpint(res
, ==, 0xbaadf00d);
2301 g_assert(endptr
== str
);
2305 err
= qemu_strtosz(str
, &endptr
, &res
);
2306 g_assert_cmpint(err
, ==, -EINVAL
);
2307 g_assert_cmpint(res
, ==, 0xbaadf00d);
2308 g_assert(endptr
== str
);
2310 /* No hex fractions */
2313 err
= qemu_strtosz(str
, &endptr
, &res
);
2314 g_assert_cmpint(err
, ==, -EINVAL
);
2315 g_assert_cmpint(res
, ==, 0xbaadf00d);
2316 g_assert(endptr
== str
);
2318 /* No negative values */
2321 err
= qemu_strtosz(str
, &endptr
, &res
);
2322 g_assert_cmpint(err
, ==, -EINVAL
);
2323 g_assert_cmpint(res
, ==, 0xbaadf00d);
2324 g_assert(endptr
== str
);
2328 err
= qemu_strtosz(str
, &endptr
, &res
);
2329 g_assert_cmpint(err
, ==, -EINVAL
);
2330 g_assert_cmpint(res
, ==, 0xbaadf00d);
2331 g_assert(endptr
== str
);
2334 static void test_qemu_strtosz_trailing(void)
2344 err
= qemu_strtosz_MiB(str
, &endptr
, &res
);
2345 g_assert_cmpint(err
, ==, 0);
2346 g_assert_cmpint(res
, ==, 123 * MiB
);
2347 g_assert(endptr
== str
+ 3);
2350 err
= qemu_strtosz(str
, NULL
, &res
);
2351 g_assert_cmpint(err
, ==, -EINVAL
);
2352 g_assert_cmpint(res
, ==, 0xbaadf00d);
2357 err
= qemu_strtosz(str
, &endptr
, &res
);
2358 g_assert_cmpint(err
, ==, 0);
2359 g_assert_cmpint(res
, ==, 1024);
2360 g_assert(endptr
== str
+ 2);
2363 err
= qemu_strtosz(str
, NULL
, &res
);
2364 g_assert_cmpint(err
, ==, -EINVAL
);
2365 g_assert_cmpint(res
, ==, 0xbaadf00d);
2370 err
= qemu_strtosz(str
, &endptr
, &res
);
2371 g_assert_cmpint(err
, ==, 0);
2372 g_assert_cmpint(res
, ==, 0);
2373 g_assert(endptr
== str
+ 1);
2376 err
= qemu_strtosz(str
, NULL
, &res
);
2377 g_assert_cmpint(err
, ==, -EINVAL
);
2378 g_assert_cmpint(res
, ==, 0xbaadf00d);
2383 err
= qemu_strtosz(str
, &endptr
, &res
);
2384 g_assert_cmpint(err
, ==, 0);
2385 g_assert_cmpint(res
, ==, 0);
2386 g_assert(endptr
== str
+ 2);
2389 err
= qemu_strtosz(str
, NULL
, &res
);
2390 g_assert_cmpint(err
, ==, -EINVAL
);
2391 g_assert_cmpint(res
, ==, 0xbaadf00d);
2396 err
= qemu_strtosz(str
, &endptr
, &res
);
2397 g_assert_cmpint(err
, ==, 0);
2398 g_assert_cmpint(res
, ==, 123);
2399 g_assert(endptr
== str
+ 3);
2402 err
= qemu_strtosz(str
, NULL
, &res
);
2403 g_assert_cmpint(err
, ==, -EINVAL
);
2404 g_assert_cmpint(res
, ==, 0xbaadf00d);
2407 static void test_qemu_strtosz_erange(void)
2412 uint64_t res
= 0xbaadf00d;
2414 str
= "18446744073709551616"; /* 2^64; see strtosz_simple for 2^64-1 */
2416 err
= qemu_strtosz(str
, &endptr
, &res
);
2417 g_assert_cmpint(err
, ==, -ERANGE
);
2418 g_assert_cmpint(res
, ==, 0xbaadf00d);
2419 g_assert(endptr
== str
+ 20);
2423 err
= qemu_strtosz(str
, &endptr
, &res
);
2424 g_assert_cmpint(err
, ==, -ERANGE
);
2425 g_assert_cmpint(res
, ==, 0xbaadf00d);
2426 g_assert(endptr
== str
+ 3);
2429 static void test_qemu_strtosz_metric(void)
2439 err
= qemu_strtosz_metric(str
, &endptr
, &res
);
2440 g_assert_cmpint(err
, ==, 0);
2441 g_assert_cmpint(res
, ==, 12345000);
2442 g_assert(endptr
== str
+ 6);
2447 err
= qemu_strtosz_metric(str
, &endptr
, &res
);
2448 g_assert_cmpint(err
, ==, 0);
2449 g_assert_cmpint(res
, ==, 12345000);
2450 g_assert(endptr
== str
+ 7);
2453 int main(int argc
, char **argv
)
2455 g_test_init(&argc
, &argv
, NULL
);
2457 g_test_add_func("/cutils/parse_uint/null", test_parse_uint_null
);
2458 g_test_add_func("/cutils/parse_uint/empty", test_parse_uint_empty
);
2459 g_test_add_func("/cutils/parse_uint/whitespace",
2460 test_parse_uint_whitespace
);
2461 g_test_add_func("/cutils/parse_uint/invalid", test_parse_uint_invalid
);
2462 g_test_add_func("/cutils/parse_uint/trailing", test_parse_uint_trailing
);
2463 g_test_add_func("/cutils/parse_uint/correct", test_parse_uint_correct
);
2464 g_test_add_func("/cutils/parse_uint/octal", test_parse_uint_octal
);
2465 g_test_add_func("/cutils/parse_uint/decimal", test_parse_uint_decimal
);
2466 g_test_add_func("/cutils/parse_uint/llong_max", test_parse_uint_llong_max
);
2467 g_test_add_func("/cutils/parse_uint/overflow", test_parse_uint_overflow
);
2468 g_test_add_func("/cutils/parse_uint/negative", test_parse_uint_negative
);
2469 g_test_add_func("/cutils/parse_uint_full/trailing",
2470 test_parse_uint_full_trailing
);
2471 g_test_add_func("/cutils/parse_uint_full/correct",
2472 test_parse_uint_full_correct
);
2474 /* qemu_strtoi() tests */
2475 g_test_add_func("/cutils/qemu_strtoi/correct",
2476 test_qemu_strtoi_correct
);
2477 g_test_add_func("/cutils/qemu_strtoi/null",
2478 test_qemu_strtoi_null
);
2479 g_test_add_func("/cutils/qemu_strtoi/empty",
2480 test_qemu_strtoi_empty
);
2481 g_test_add_func("/cutils/qemu_strtoi/whitespace",
2482 test_qemu_strtoi_whitespace
);
2483 g_test_add_func("/cutils/qemu_strtoi/invalid",
2484 test_qemu_strtoi_invalid
);
2485 g_test_add_func("/cutils/qemu_strtoi/trailing",
2486 test_qemu_strtoi_trailing
);
2487 g_test_add_func("/cutils/qemu_strtoi/octal",
2488 test_qemu_strtoi_octal
);
2489 g_test_add_func("/cutils/qemu_strtoi/decimal",
2490 test_qemu_strtoi_decimal
);
2491 g_test_add_func("/cutils/qemu_strtoi/hex",
2492 test_qemu_strtoi_hex
);
2493 g_test_add_func("/cutils/qemu_strtoi/max",
2494 test_qemu_strtoi_max
);
2495 g_test_add_func("/cutils/qemu_strtoi/overflow",
2496 test_qemu_strtoi_overflow
);
2497 g_test_add_func("/cutils/qemu_strtoi/underflow",
2498 test_qemu_strtoi_underflow
);
2499 g_test_add_func("/cutils/qemu_strtoi/negative",
2500 test_qemu_strtoi_negative
);
2501 g_test_add_func("/cutils/qemu_strtoi_full/correct",
2502 test_qemu_strtoi_full_correct
);
2503 g_test_add_func("/cutils/qemu_strtoi_full/null",
2504 test_qemu_strtoi_full_null
);
2505 g_test_add_func("/cutils/qemu_strtoi_full/empty",
2506 test_qemu_strtoi_full_empty
);
2507 g_test_add_func("/cutils/qemu_strtoi_full/negative",
2508 test_qemu_strtoi_full_negative
);
2509 g_test_add_func("/cutils/qemu_strtoi_full/trailing",
2510 test_qemu_strtoi_full_trailing
);
2511 g_test_add_func("/cutils/qemu_strtoi_full/max",
2512 test_qemu_strtoi_full_max
);
2514 /* qemu_strtoui() tests */
2515 g_test_add_func("/cutils/qemu_strtoui/correct",
2516 test_qemu_strtoui_correct
);
2517 g_test_add_func("/cutils/qemu_strtoui/null",
2518 test_qemu_strtoui_null
);
2519 g_test_add_func("/cutils/qemu_strtoui/empty",
2520 test_qemu_strtoui_empty
);
2521 g_test_add_func("/cutils/qemu_strtoui/whitespace",
2522 test_qemu_strtoui_whitespace
);
2523 g_test_add_func("/cutils/qemu_strtoui/invalid",
2524 test_qemu_strtoui_invalid
);
2525 g_test_add_func("/cutils/qemu_strtoui/trailing",
2526 test_qemu_strtoui_trailing
);
2527 g_test_add_func("/cutils/qemu_strtoui/octal",
2528 test_qemu_strtoui_octal
);
2529 g_test_add_func("/cutils/qemu_strtoui/decimal",
2530 test_qemu_strtoui_decimal
);
2531 g_test_add_func("/cutils/qemu_strtoui/hex",
2532 test_qemu_strtoui_hex
);
2533 g_test_add_func("/cutils/qemu_strtoui/max",
2534 test_qemu_strtoui_max
);
2535 g_test_add_func("/cutils/qemu_strtoui/overflow",
2536 test_qemu_strtoui_overflow
);
2537 g_test_add_func("/cutils/qemu_strtoui/underflow",
2538 test_qemu_strtoui_underflow
);
2539 g_test_add_func("/cutils/qemu_strtoui/negative",
2540 test_qemu_strtoui_negative
);
2541 g_test_add_func("/cutils/qemu_strtoui_full/correct",
2542 test_qemu_strtoui_full_correct
);
2543 g_test_add_func("/cutils/qemu_strtoui_full/null",
2544 test_qemu_strtoui_full_null
);
2545 g_test_add_func("/cutils/qemu_strtoui_full/empty",
2546 test_qemu_strtoui_full_empty
);
2547 g_test_add_func("/cutils/qemu_strtoui_full/negative",
2548 test_qemu_strtoui_full_negative
);
2549 g_test_add_func("/cutils/qemu_strtoui_full/trailing",
2550 test_qemu_strtoui_full_trailing
);
2551 g_test_add_func("/cutils/qemu_strtoui_full/max",
2552 test_qemu_strtoui_full_max
);
2554 /* qemu_strtol() tests */
2555 g_test_add_func("/cutils/qemu_strtol/correct",
2556 test_qemu_strtol_correct
);
2557 g_test_add_func("/cutils/qemu_strtol/null",
2558 test_qemu_strtol_null
);
2559 g_test_add_func("/cutils/qemu_strtol/empty",
2560 test_qemu_strtol_empty
);
2561 g_test_add_func("/cutils/qemu_strtol/whitespace",
2562 test_qemu_strtol_whitespace
);
2563 g_test_add_func("/cutils/qemu_strtol/invalid",
2564 test_qemu_strtol_invalid
);
2565 g_test_add_func("/cutils/qemu_strtol/trailing",
2566 test_qemu_strtol_trailing
);
2567 g_test_add_func("/cutils/qemu_strtol/octal",
2568 test_qemu_strtol_octal
);
2569 g_test_add_func("/cutils/qemu_strtol/decimal",
2570 test_qemu_strtol_decimal
);
2571 g_test_add_func("/cutils/qemu_strtol/hex",
2572 test_qemu_strtol_hex
);
2573 g_test_add_func("/cutils/qemu_strtol/max",
2574 test_qemu_strtol_max
);
2575 g_test_add_func("/cutils/qemu_strtol/overflow",
2576 test_qemu_strtol_overflow
);
2577 g_test_add_func("/cutils/qemu_strtol/underflow",
2578 test_qemu_strtol_underflow
);
2579 g_test_add_func("/cutils/qemu_strtol/negative",
2580 test_qemu_strtol_negative
);
2581 g_test_add_func("/cutils/qemu_strtol_full/correct",
2582 test_qemu_strtol_full_correct
);
2583 g_test_add_func("/cutils/qemu_strtol_full/null",
2584 test_qemu_strtol_full_null
);
2585 g_test_add_func("/cutils/qemu_strtol_full/empty",
2586 test_qemu_strtol_full_empty
);
2587 g_test_add_func("/cutils/qemu_strtol_full/negative",
2588 test_qemu_strtol_full_negative
);
2589 g_test_add_func("/cutils/qemu_strtol_full/trailing",
2590 test_qemu_strtol_full_trailing
);
2591 g_test_add_func("/cutils/qemu_strtol_full/max",
2592 test_qemu_strtol_full_max
);
2594 /* qemu_strtoul() tests */
2595 g_test_add_func("/cutils/qemu_strtoul/correct",
2596 test_qemu_strtoul_correct
);
2597 g_test_add_func("/cutils/qemu_strtoul/null",
2598 test_qemu_strtoul_null
);
2599 g_test_add_func("/cutils/qemu_strtoul/empty",
2600 test_qemu_strtoul_empty
);
2601 g_test_add_func("/cutils/qemu_strtoul/whitespace",
2602 test_qemu_strtoul_whitespace
);
2603 g_test_add_func("/cutils/qemu_strtoul/invalid",
2604 test_qemu_strtoul_invalid
);
2605 g_test_add_func("/cutils/qemu_strtoul/trailing",
2606 test_qemu_strtoul_trailing
);
2607 g_test_add_func("/cutils/qemu_strtoul/octal",
2608 test_qemu_strtoul_octal
);
2609 g_test_add_func("/cutils/qemu_strtoul/decimal",
2610 test_qemu_strtoul_decimal
);
2611 g_test_add_func("/cutils/qemu_strtoul/hex",
2612 test_qemu_strtoul_hex
);
2613 g_test_add_func("/cutils/qemu_strtoul/max",
2614 test_qemu_strtoul_max
);
2615 g_test_add_func("/cutils/qemu_strtoul/overflow",
2616 test_qemu_strtoul_overflow
);
2617 g_test_add_func("/cutils/qemu_strtoul/underflow",
2618 test_qemu_strtoul_underflow
);
2619 g_test_add_func("/cutils/qemu_strtoul/negative",
2620 test_qemu_strtoul_negative
);
2621 g_test_add_func("/cutils/qemu_strtoul_full/correct",
2622 test_qemu_strtoul_full_correct
);
2623 g_test_add_func("/cutils/qemu_strtoul_full/null",
2624 test_qemu_strtoul_full_null
);
2625 g_test_add_func("/cutils/qemu_strtoul_full/empty",
2626 test_qemu_strtoul_full_empty
);
2627 g_test_add_func("/cutils/qemu_strtoul_full/negative",
2628 test_qemu_strtoul_full_negative
);
2629 g_test_add_func("/cutils/qemu_strtoul_full/trailing",
2630 test_qemu_strtoul_full_trailing
);
2631 g_test_add_func("/cutils/qemu_strtoul_full/max",
2632 test_qemu_strtoul_full_max
);
2634 /* qemu_strtoi64() tests */
2635 g_test_add_func("/cutils/qemu_strtoi64/correct",
2636 test_qemu_strtoi64_correct
);
2637 g_test_add_func("/cutils/qemu_strtoi64/null",
2638 test_qemu_strtoi64_null
);
2639 g_test_add_func("/cutils/qemu_strtoi64/empty",
2640 test_qemu_strtoi64_empty
);
2641 g_test_add_func("/cutils/qemu_strtoi64/whitespace",
2642 test_qemu_strtoi64_whitespace
);
2643 g_test_add_func("/cutils/qemu_strtoi64/invalid"
2645 test_qemu_strtoi64_invalid
);
2646 g_test_add_func("/cutils/qemu_strtoi64/trailing",
2647 test_qemu_strtoi64_trailing
);
2648 g_test_add_func("/cutils/qemu_strtoi64/octal",
2649 test_qemu_strtoi64_octal
);
2650 g_test_add_func("/cutils/qemu_strtoi64/decimal",
2651 test_qemu_strtoi64_decimal
);
2652 g_test_add_func("/cutils/qemu_strtoi64/hex",
2653 test_qemu_strtoi64_hex
);
2654 g_test_add_func("/cutils/qemu_strtoi64/max",
2655 test_qemu_strtoi64_max
);
2656 g_test_add_func("/cutils/qemu_strtoi64/overflow",
2657 test_qemu_strtoi64_overflow
);
2658 g_test_add_func("/cutils/qemu_strtoi64/underflow",
2659 test_qemu_strtoi64_underflow
);
2660 g_test_add_func("/cutils/qemu_strtoi64/negative",
2661 test_qemu_strtoi64_negative
);
2662 g_test_add_func("/cutils/qemu_strtoi64_full/correct",
2663 test_qemu_strtoi64_full_correct
);
2664 g_test_add_func("/cutils/qemu_strtoi64_full/null",
2665 test_qemu_strtoi64_full_null
);
2666 g_test_add_func("/cutils/qemu_strtoi64_full/empty",
2667 test_qemu_strtoi64_full_empty
);
2668 g_test_add_func("/cutils/qemu_strtoi64_full/negative",
2669 test_qemu_strtoi64_full_negative
);
2670 g_test_add_func("/cutils/qemu_strtoi64_full/trailing",
2671 test_qemu_strtoi64_full_trailing
);
2672 g_test_add_func("/cutils/qemu_strtoi64_full/max",
2673 test_qemu_strtoi64_full_max
);
2675 /* qemu_strtou64() tests */
2676 g_test_add_func("/cutils/qemu_strtou64/correct",
2677 test_qemu_strtou64_correct
);
2678 g_test_add_func("/cutils/qemu_strtou64/null",
2679 test_qemu_strtou64_null
);
2680 g_test_add_func("/cutils/qemu_strtou64/empty",
2681 test_qemu_strtou64_empty
);
2682 g_test_add_func("/cutils/qemu_strtou64/whitespace",
2683 test_qemu_strtou64_whitespace
);
2684 g_test_add_func("/cutils/qemu_strtou64/invalid",
2685 test_qemu_strtou64_invalid
);
2686 g_test_add_func("/cutils/qemu_strtou64/trailing",
2687 test_qemu_strtou64_trailing
);
2688 g_test_add_func("/cutils/qemu_strtou64/octal",
2689 test_qemu_strtou64_octal
);
2690 g_test_add_func("/cutils/qemu_strtou64/decimal",
2691 test_qemu_strtou64_decimal
);
2692 g_test_add_func("/cutils/qemu_strtou64/hex",
2693 test_qemu_strtou64_hex
);
2694 g_test_add_func("/cutils/qemu_strtou64/max",
2695 test_qemu_strtou64_max
);
2696 g_test_add_func("/cutils/qemu_strtou64/overflow",
2697 test_qemu_strtou64_overflow
);
2698 g_test_add_func("/cutils/qemu_strtou64/underflow",
2699 test_qemu_strtou64_underflow
);
2700 g_test_add_func("/cutils/qemu_strtou64/negative",
2701 test_qemu_strtou64_negative
);
2702 g_test_add_func("/cutils/qemu_strtou64_full/correct",
2703 test_qemu_strtou64_full_correct
);
2704 g_test_add_func("/cutils/qemu_strtou64_full/null",
2705 test_qemu_strtou64_full_null
);
2706 g_test_add_func("/cutils/qemu_strtou64_full/empty",
2707 test_qemu_strtou64_full_empty
);
2708 g_test_add_func("/cutils/qemu_strtou64_full/negative",
2709 test_qemu_strtou64_full_negative
);
2710 g_test_add_func("/cutils/qemu_strtou64_full/trailing",
2711 test_qemu_strtou64_full_trailing
);
2712 g_test_add_func("/cutils/qemu_strtou64_full/max",
2713 test_qemu_strtou64_full_max
);
2715 g_test_add_func("/cutils/strtosz/simple",
2716 test_qemu_strtosz_simple
);
2717 g_test_add_func("/cutils/strtosz/hex",
2718 test_qemu_strtosz_hex
);
2719 g_test_add_func("/cutils/strtosz/units",
2720 test_qemu_strtosz_units
);
2721 g_test_add_func("/cutils/strtosz/float",
2722 test_qemu_strtosz_float
);
2723 g_test_add_func("/cutils/strtosz/invalid",
2724 test_qemu_strtosz_invalid
);
2725 g_test_add_func("/cutils/strtosz/trailing",
2726 test_qemu_strtosz_trailing
);
2727 g_test_add_func("/cutils/strtosz/erange",
2728 test_qemu_strtosz_erange
);
2729 g_test_add_func("/cutils/strtosz/metric",
2730 test_qemu_strtosz_metric
);
2732 return g_test_run();