ppc/pnv: Add POWER10 quads
[qemu.git] / tests / unit / test-cutils.c
blob98671f1ac30e2f15e74dfdb4ef277e559cfc59a3
1 /*
2 * cutils.c unit-tests
4 * Copyright (C) 2013 Red Hat Inc.
6 * Authors:
7 * Eduardo Habkost <ehabkost@redhat.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
28 #include "qemu/osdep.h"
29 #include "qemu/units.h"
30 #include "qemu/cutils.h"
31 #include "qemu/units.h"
33 static void test_parse_uint_null(void)
35 unsigned long long i = 999;
36 char f = 'X';
37 char *endptr = &f;
38 int r;
40 r = parse_uint(NULL, &i, &endptr, 0);
42 g_assert_cmpint(r, ==, -EINVAL);
43 g_assert_cmpint(i, ==, 0);
44 g_assert(endptr == NULL);
47 static void test_parse_uint_empty(void)
49 unsigned long long i = 999;
50 char f = 'X';
51 char *endptr = &f;
52 const char *str = "";
53 int r;
55 r = parse_uint(str, &i, &endptr, 0);
57 g_assert_cmpint(r, ==, -EINVAL);
58 g_assert_cmpint(i, ==, 0);
59 g_assert(endptr == str);
62 static void test_parse_uint_whitespace(void)
64 unsigned long long i = 999;
65 char f = 'X';
66 char *endptr = &f;
67 const char *str = " \t ";
68 int r;
70 r = parse_uint(str, &i, &endptr, 0);
72 g_assert_cmpint(r, ==, -EINVAL);
73 g_assert_cmpint(i, ==, 0);
74 g_assert(endptr == str);
78 static void test_parse_uint_invalid(void)
80 unsigned long long i = 999;
81 char f = 'X';
82 char *endptr = &f;
83 const char *str = " \t xxx";
84 int r;
86 r = parse_uint(str, &i, &endptr, 0);
88 g_assert_cmpint(r, ==, -EINVAL);
89 g_assert_cmpint(i, ==, 0);
90 g_assert(endptr == str);
94 static void test_parse_uint_trailing(void)
96 unsigned long long i = 999;
97 char f = 'X';
98 char *endptr = &f;
99 const char *str = "123xxx";
100 int r;
102 r = parse_uint(str, &i, &endptr, 0);
104 g_assert_cmpint(r, ==, 0);
105 g_assert_cmpint(i, ==, 123);
106 g_assert(endptr == str + 3);
109 static void test_parse_uint_correct(void)
111 unsigned long long i = 999;
112 char f = 'X';
113 char *endptr = &f;
114 const char *str = "123";
115 int r;
117 r = parse_uint(str, &i, &endptr, 0);
119 g_assert_cmpint(r, ==, 0);
120 g_assert_cmpint(i, ==, 123);
121 g_assert(endptr == str + strlen(str));
124 static void test_parse_uint_octal(void)
126 unsigned long long i = 999;
127 char f = 'X';
128 char *endptr = &f;
129 const char *str = "0123";
130 int r;
132 r = parse_uint(str, &i, &endptr, 0);
134 g_assert_cmpint(r, ==, 0);
135 g_assert_cmpint(i, ==, 0123);
136 g_assert(endptr == str + strlen(str));
139 static void test_parse_uint_decimal(void)
141 unsigned long long i = 999;
142 char f = 'X';
143 char *endptr = &f;
144 const char *str = "0123";
145 int r;
147 r = parse_uint(str, &i, &endptr, 10);
149 g_assert_cmpint(r, ==, 0);
150 g_assert_cmpint(i, ==, 123);
151 g_assert(endptr == str + strlen(str));
155 static void test_parse_uint_llong_max(void)
157 unsigned long long i = 999;
158 char f = 'X';
159 char *endptr = &f;
160 char *str = g_strdup_printf("%llu", (unsigned long long)LLONG_MAX + 1);
161 int r;
163 r = parse_uint(str, &i, &endptr, 0);
165 g_assert_cmpint(r, ==, 0);
166 g_assert_cmpint(i, ==, (unsigned long long)LLONG_MAX + 1);
167 g_assert(endptr == str + strlen(str));
169 g_free(str);
172 static void test_parse_uint_overflow(void)
174 unsigned long long i = 999;
175 char f = 'X';
176 char *endptr = &f;
177 const char *str = "99999999999999999999999999999999999999";
178 int r;
180 r = parse_uint(str, &i, &endptr, 0);
182 g_assert_cmpint(r, ==, -ERANGE);
183 g_assert_cmpint(i, ==, ULLONG_MAX);
184 g_assert(endptr == str + strlen(str));
187 static void test_parse_uint_negative(void)
189 unsigned long long i = 999;
190 char f = 'X';
191 char *endptr = &f;
192 const char *str = " \t -321";
193 int r;
195 r = parse_uint(str, &i, &endptr, 0);
197 g_assert_cmpint(r, ==, -ERANGE);
198 g_assert_cmpint(i, ==, 0);
199 g_assert(endptr == str + strlen(str));
203 static void test_parse_uint_full_trailing(void)
205 unsigned long long i = 999;
206 const char *str = "123xxx";
207 int r;
209 r = parse_uint_full(str, &i, 0);
211 g_assert_cmpint(r, ==, -EINVAL);
212 g_assert_cmpint(i, ==, 0);
215 static void test_parse_uint_full_correct(void)
217 unsigned long long i = 999;
218 const char *str = "123";
219 int r;
221 r = parse_uint_full(str, &i, 0);
223 g_assert_cmpint(r, ==, 0);
224 g_assert_cmpint(i, ==, 123);
227 static void test_qemu_strtoi_correct(void)
229 const char *str = "12345 foo";
230 char f = 'X';
231 const char *endptr = &f;
232 int res = 999;
233 int err;
235 err = qemu_strtoi(str, &endptr, 0, &res);
237 g_assert_cmpint(err, ==, 0);
238 g_assert_cmpint(res, ==, 12345);
239 g_assert(endptr == str + 5);
242 static void test_qemu_strtoi_null(void)
244 char f = 'X';
245 const char *endptr = &f;
246 int res = 999;
247 int err;
249 err = qemu_strtoi(NULL, &endptr, 0, &res);
251 g_assert_cmpint(err, ==, -EINVAL);
252 g_assert(endptr == NULL);
255 static void test_qemu_strtoi_empty(void)
257 const char *str = "";
258 char f = 'X';
259 const char *endptr = &f;
260 int res = 999;
261 int err;
263 err = qemu_strtoi(str, &endptr, 0, &res);
265 g_assert_cmpint(err, ==, -EINVAL);
266 g_assert(endptr == str);
269 static void test_qemu_strtoi_whitespace(void)
271 const char *str = " \t ";
272 char f = 'X';
273 const char *endptr = &f;
274 int res = 999;
275 int err;
277 err = qemu_strtoi(str, &endptr, 0, &res);
279 g_assert_cmpint(err, ==, -EINVAL);
280 g_assert(endptr == str);
283 static void test_qemu_strtoi_invalid(void)
285 const char *str = " xxxx \t abc";
286 char f = 'X';
287 const char *endptr = &f;
288 int res = 999;
289 int err;
291 err = qemu_strtoi(str, &endptr, 0, &res);
293 g_assert_cmpint(err, ==, -EINVAL);
294 g_assert(endptr == str);
297 static void test_qemu_strtoi_trailing(void)
299 const char *str = "123xxx";
300 char f = 'X';
301 const char *endptr = &f;
302 int res = 999;
303 int err;
305 err = qemu_strtoi(str, &endptr, 0, &res);
307 g_assert_cmpint(err, ==, 0);
308 g_assert_cmpint(res, ==, 123);
309 g_assert(endptr == str + 3);
312 static void test_qemu_strtoi_octal(void)
314 const char *str = "0123";
315 char f = 'X';
316 const char *endptr = &f;
317 int res = 999;
318 int err;
320 err = qemu_strtoi(str, &endptr, 8, &res);
322 g_assert_cmpint(err, ==, 0);
323 g_assert_cmpint(res, ==, 0123);
324 g_assert(endptr == str + strlen(str));
326 res = 999;
327 endptr = &f;
328 err = qemu_strtoi(str, &endptr, 0, &res);
330 g_assert_cmpint(err, ==, 0);
331 g_assert_cmpint(res, ==, 0123);
332 g_assert(endptr == str + strlen(str));
335 static void test_qemu_strtoi_decimal(void)
337 const char *str = "0123";
338 char f = 'X';
339 const char *endptr = &f;
340 int res = 999;
341 int err;
343 err = qemu_strtoi(str, &endptr, 10, &res);
345 g_assert_cmpint(err, ==, 0);
346 g_assert_cmpint(res, ==, 123);
347 g_assert(endptr == str + strlen(str));
349 str = "123";
350 res = 999;
351 endptr = &f;
352 err = qemu_strtoi(str, &endptr, 0, &res);
354 g_assert_cmpint(err, ==, 0);
355 g_assert_cmpint(res, ==, 123);
356 g_assert(endptr == str + strlen(str));
359 static void test_qemu_strtoi_hex(void)
361 const char *str = "0123";
362 char f = 'X';
363 const char *endptr = &f;
364 int res = 999;
365 int err;
367 err = qemu_strtoi(str, &endptr, 16, &res);
369 g_assert_cmpint(err, ==, 0);
370 g_assert_cmpint(res, ==, 0x123);
371 g_assert(endptr == str + strlen(str));
373 str = "0x123";
374 res = 999;
375 endptr = &f;
376 err = qemu_strtoi(str, &endptr, 0, &res);
378 g_assert_cmpint(err, ==, 0);
379 g_assert_cmpint(res, ==, 0x123);
380 g_assert(endptr == str + strlen(str));
382 str = "0x";
383 res = 999;
384 endptr = &f;
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);
395 char f = 'X';
396 const char *endptr = &f;
397 int res = 999;
398 int err;
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));
405 g_free(str);
408 static void test_qemu_strtoi_overflow(void)
410 char *str = g_strdup_printf("%lld", (long long)INT_MAX + 1ll);
411 char f = 'X';
412 const char *endptr = &f;
413 int res = 999;
414 int err;
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));
421 g_free(str);
424 static void test_qemu_strtoi_underflow(void)
426 char *str = g_strdup_printf("%lld", (long long)INT_MIN - 1ll);
427 char f = 'X';
428 const char *endptr = &f;
429 int res = 999;
430 int err;
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));
437 g_free(str);
440 static void test_qemu_strtoi_negative(void)
442 const char *str = " \t -321";
443 char f = 'X';
444 const char *endptr = &f;
445 int res = 999;
446 int err;
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";
458 int res = 999;
459 int err;
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)
469 char f = 'X';
470 const char *endptr = &f;
471 int res = 999;
472 int err;
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 = "";
483 int res = 999L;
484 int err;
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";
494 int res = 999;
495 int err;
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";
506 int res;
507 int err;
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);
517 int res;
518 int err;
520 err = qemu_strtoi(str, NULL, 0, &res);
522 g_assert_cmpint(err, ==, 0);
523 g_assert_cmpint(res, ==, INT_MAX);
524 g_free(str);
527 static void test_qemu_strtoui_correct(void)
529 const char *str = "12345 foo";
530 char f = 'X';
531 const char *endptr = &f;
532 unsigned int res = 999;
533 int err;
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)
544 char f = 'X';
545 const char *endptr = &f;
546 unsigned int res = 999;
547 int err;
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 = "";
558 char f = 'X';
559 const char *endptr = &f;
560 unsigned int res = 999;
561 int err;
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 ";
572 char f = 'X';
573 const char *endptr = &f;
574 unsigned int res = 999;
575 int err;
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";
586 char f = 'X';
587 const char *endptr = &f;
588 unsigned int res = 999;
589 int err;
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";
600 char f = 'X';
601 const char *endptr = &f;
602 unsigned int res = 999;
603 int err;
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";
615 char f = 'X';
616 const char *endptr = &f;
617 unsigned int res = 999;
618 int err;
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));
626 res = 999;
627 endptr = &f;
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";
638 char f = 'X';
639 const char *endptr = &f;
640 unsigned int res = 999;
641 int err;
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));
649 str = "123";
650 res = 999;
651 endptr = &f;
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";
662 char f = 'X';
663 const char *endptr = &f;
664 unsigned int res = 999;
665 int err;
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));
673 str = "0x123";
674 res = 999;
675 endptr = &f;
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));
682 str = "0x";
683 res = 999;
684 endptr = &f;
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);
695 char f = 'X';
696 const char *endptr = &f;
697 unsigned int res = 999;
698 int err;
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));
705 g_free(str);
708 static void test_qemu_strtoui_overflow(void)
710 char *str = g_strdup_printf("%lld", (long long)UINT_MAX + 1ll);
711 char f = 'X';
712 const char *endptr = &f;
713 unsigned int res = 999;
714 int err;
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));
721 g_free(str);
724 static void test_qemu_strtoui_underflow(void)
726 char *str = g_strdup_printf("%lld", (long long)INT_MIN - 1ll);
727 char f = 'X';
728 const char *endptr = &f;
729 unsigned int res = 999;
730 int err;
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));
737 g_free(str);
740 static void test_qemu_strtoui_negative(void)
742 const char *str = " \t -321";
743 char f = 'X';
744 const char *endptr = &f;
745 unsigned int res = 999;
746 int err;
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;
759 int err;
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;
770 int err;
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;
781 int err;
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;
791 int err;
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";
801 unsigned int res;
802 int err;
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;
813 int err;
815 err = qemu_strtoui(str, NULL, 0, &res);
817 g_assert_cmpint(err, ==, 0);
818 g_assert_cmphex(res, ==, UINT_MAX);
819 g_free(str);
822 static void test_qemu_strtol_correct(void)
824 const char *str = "12345 foo";
825 char f = 'X';
826 const char *endptr = &f;
827 long res = 999;
828 int err;
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)
839 char f = 'X';
840 const char *endptr = &f;
841 long res = 999;
842 int err;
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 = "";
853 char f = 'X';
854 const char *endptr = &f;
855 long res = 999;
856 int err;
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 ";
867 char f = 'X';
868 const char *endptr = &f;
869 long res = 999;
870 int err;
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";
881 char f = 'X';
882 const char *endptr = &f;
883 long res = 999;
884 int err;
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";
895 char f = 'X';
896 const char *endptr = &f;
897 long res = 999;
898 int err;
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";
910 char f = 'X';
911 const char *endptr = &f;
912 long res = 999;
913 int err;
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));
921 res = 999;
922 endptr = &f;
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";
933 char f = 'X';
934 const char *endptr = &f;
935 long res = 999;
936 int err;
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));
944 str = "123";
945 res = 999;
946 endptr = &f;
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";
957 char f = 'X';
958 const char *endptr = &f;
959 long res = 999;
960 int err;
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));
968 str = "0x123";
969 res = 999;
970 endptr = &f;
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));
977 str = "0x";
978 res = 999;
979 endptr = &f;
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);
990 char f = 'X';
991 const char *endptr = &f;
992 long res = 999;
993 int err;
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));
1000 g_free(str);
1003 static void test_qemu_strtol_overflow(void)
1005 const char *str = "99999999999999999999999999999999999999999999";
1006 char f = 'X';
1007 const char *endptr = &f;
1008 long res = 999;
1009 int err;
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";
1021 char f = 'X';
1022 const char *endptr = &f;
1023 long res = 999;
1024 int err;
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";
1036 char f = 'X';
1037 const char *endptr = &f;
1038 long res = 999;
1039 int err;
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";
1051 long res = 999;
1052 int err;
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)
1062 char f = 'X';
1063 const char *endptr = &f;
1064 long res = 999;
1065 int err;
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 = "";
1076 long res = 999L;
1077 int err;
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";
1087 long res = 999;
1088 int err;
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";
1099 long res;
1100 int err;
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);
1110 long res;
1111 int err;
1113 err = qemu_strtol(str, NULL, 0, &res);
1115 g_assert_cmpint(err, ==, 0);
1116 g_assert_cmpint(res, ==, LONG_MAX);
1117 g_free(str);
1120 static void test_qemu_strtoul_correct(void)
1122 const char *str = "12345 foo";
1123 char f = 'X';
1124 const char *endptr = &f;
1125 unsigned long res = 999;
1126 int err;
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)
1137 char f = 'X';
1138 const char *endptr = &f;
1139 unsigned long res = 999;
1140 int err;
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 = "";
1151 char f = 'X';
1152 const char *endptr = &f;
1153 unsigned long res = 999;
1154 int err;
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 ";
1165 char f = 'X';
1166 const char *endptr = &f;
1167 unsigned long res = 999;
1168 int err;
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";
1179 char f = 'X';
1180 const char *endptr = &f;
1181 unsigned long res = 999;
1182 int err;
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";
1193 char f = 'X';
1194 const char *endptr = &f;
1195 unsigned long res = 999;
1196 int err;
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";
1208 char f = 'X';
1209 const char *endptr = &f;
1210 unsigned long res = 999;
1211 int err;
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));
1219 res = 999;
1220 endptr = &f;
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";
1231 char f = 'X';
1232 const char *endptr = &f;
1233 unsigned long res = 999;
1234 int err;
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));
1242 str = "123";
1243 res = 999;
1244 endptr = &f;
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";
1255 char f = 'X';
1256 const char *endptr = &f;
1257 unsigned long res = 999;
1258 int err;
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));
1266 str = "0x123";
1267 res = 999;
1268 endptr = &f;
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));
1275 str = "0x";
1276 res = 999;
1277 endptr = &f;
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);
1288 char f = 'X';
1289 const char *endptr = &f;
1290 unsigned long res = 999;
1291 int err;
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));
1298 g_free(str);
1301 static void test_qemu_strtoul_overflow(void)
1303 const char *str = "99999999999999999999999999999999999999999999";
1304 char f = 'X';
1305 const char *endptr = &f;
1306 unsigned long res = 999;
1307 int err;
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";
1319 char f = 'X';
1320 const char *endptr = &f;
1321 unsigned long res = 999;
1322 int err;
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";
1334 char f = 'X';
1335 const char *endptr = &f;
1336 unsigned long res = 999;
1337 int err;
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;
1350 int err;
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;
1361 int err;
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;
1372 int err;
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;
1382 int err;
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";
1392 unsigned long res;
1393 int err;
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;
1404 int err;
1406 err = qemu_strtoul(str, NULL, 0, &res);
1408 g_assert_cmpint(err, ==, 0);
1409 g_assert_cmphex(res, ==, ULONG_MAX);
1410 g_free(str);
1413 static void test_qemu_strtoi64_correct(void)
1415 const char *str = "12345 foo";
1416 char f = 'X';
1417 const char *endptr = &f;
1418 int64_t res = 999;
1419 int err;
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)
1430 char f = 'X';
1431 const char *endptr = &f;
1432 int64_t res = 999;
1433 int err;
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 = "";
1444 char f = 'X';
1445 const char *endptr = &f;
1446 int64_t res = 999;
1447 int err;
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 ";
1458 char f = 'X';
1459 const char *endptr = &f;
1460 int64_t res = 999;
1461 int err;
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";
1472 char f = 'X';
1473 const char *endptr = &f;
1474 int64_t res = 999;
1475 int err;
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";
1486 char f = 'X';
1487 const char *endptr = &f;
1488 int64_t res = 999;
1489 int err;
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";
1501 char f = 'X';
1502 const char *endptr = &f;
1503 int64_t res = 999;
1504 int err;
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));
1512 endptr = &f;
1513 res = 999;
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";
1524 char f = 'X';
1525 const char *endptr = &f;
1526 int64_t res = 999;
1527 int err;
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));
1535 str = "123";
1536 endptr = &f;
1537 res = 999;
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";
1548 char f = 'X';
1549 const char *endptr = &f;
1550 int64_t res = 999;
1551 int err;
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));
1559 str = "0x123";
1560 endptr = &f;
1561 res = 999;
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));
1568 str = "0x";
1569 endptr = &f;
1570 res = 999;
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);
1581 char f = 'X';
1582 const char *endptr = &f;
1583 int64_t res = 999;
1584 int err;
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));
1591 g_free(str);
1594 static void test_qemu_strtoi64_overflow(void)
1596 const char *str = "99999999999999999999999999999999999999999999";
1597 char f = 'X';
1598 const char *endptr = &f;
1599 int64_t res = 999;
1600 int err;
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";
1612 char f = 'X';
1613 const char *endptr = &f;
1614 int64_t res = 999;
1615 int err;
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";
1627 char f = 'X';
1628 const char *endptr = &f;
1629 int64_t res = 999;
1630 int err;
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";
1642 int64_t res = 999;
1643 int err;
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)
1653 int64_t res = 999;
1654 int err;
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 = "";
1664 int64_t res = 999;
1665 int err;
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";
1675 int64_t res = 999;
1676 int err;
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";
1687 int64_t res = 999;
1688 int err;
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);
1699 int64_t res;
1700 int err;
1702 err = qemu_strtoi64(str, NULL, 0, &res);
1704 g_assert_cmpint(err, ==, 0);
1705 g_assert_cmpint(res, ==, LLONG_MAX);
1706 g_free(str);
1709 static void test_qemu_strtou64_correct(void)
1711 const char *str = "12345 foo";
1712 char f = 'X';
1713 const char *endptr = &f;
1714 uint64_t res = 999;
1715 int err;
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)
1726 char f = 'X';
1727 const char *endptr = &f;
1728 uint64_t res = 999;
1729 int err;
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 = "";
1740 char f = 'X';
1741 const char *endptr = &f;
1742 uint64_t res = 999;
1743 int err;
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 ";
1754 char f = 'X';
1755 const char *endptr = &f;
1756 uint64_t res = 999;
1757 int err;
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";
1768 char f = 'X';
1769 const char *endptr = &f;
1770 uint64_t res = 999;
1771 int err;
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";
1782 char f = 'X';
1783 const char *endptr = &f;
1784 uint64_t res = 999;
1785 int err;
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";
1797 char f = 'X';
1798 const char *endptr = &f;
1799 uint64_t res = 999;
1800 int err;
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));
1808 endptr = &f;
1809 res = 999;
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";
1820 char f = 'X';
1821 const char *endptr = &f;
1822 uint64_t res = 999;
1823 int err;
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));
1831 str = "123";
1832 endptr = &f;
1833 res = 999;
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";
1844 char f = 'X';
1845 const char *endptr = &f;
1846 uint64_t res = 999;
1847 int err;
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));
1855 str = "0x123";
1856 endptr = &f;
1857 res = 999;
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));
1864 str = "0x";
1865 endptr = &f;
1866 res = 999;
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);
1877 char f = 'X';
1878 const char *endptr = &f;
1879 uint64_t res = 999;
1880 int err;
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));
1887 g_free(str);
1890 static void test_qemu_strtou64_overflow(void)
1892 const char *str = "99999999999999999999999999999999999999999999";
1893 char f = 'X';
1894 const char *endptr = &f;
1895 uint64_t res = 999;
1896 int err;
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";
1908 char f = 'X';
1909 const char *endptr = &f;
1910 uint64_t res = 999;
1911 int err;
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";
1923 char f = 'X';
1924 const char *endptr = &f;
1925 uint64_t res = 999;
1926 int err;
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";
1938 uint64_t res = 999;
1939 int err;
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)
1949 uint64_t res = 999;
1950 int err;
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 = "";
1960 uint64_t res = 999;
1961 int err;
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";
1971 uint64_t res = 999;
1972 int err;
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";
1983 uint64_t res = 999;
1984 int err;
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);
1994 uint64_t res = 999;
1995 int err;
1997 err = qemu_strtou64(str, NULL, 0, &res);
1999 g_assert_cmpint(err, ==, 0);
2000 g_assert_cmphex(res, ==, ULLONG_MAX);
2001 g_free(str);
2004 static void test_qemu_strtosz_simple(void)
2006 const char *str;
2007 const char *endptr;
2008 int err;
2009 uint64_t res;
2011 str = "0";
2012 endptr = str;
2013 res = 0xbaadf00d;
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 */
2020 str = "08";
2021 endptr = str;
2022 res = 0xbaadf00d;
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 */
2029 str = " 12345";
2030 endptr = str;
2031 res = 0xbaadf00d;
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);
2037 res = 0xbaadf00d;
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 */
2043 endptr = str;
2044 res = 0xbaadf00d;
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 */
2051 endptr = str;
2052 res = 0xbaadf00d;
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 */
2059 endptr = str;
2060 res = 0xbaadf00d;
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) */
2067 endptr = str;
2068 res = 0xbaadf00d;
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 */
2075 endptr = str;
2076 res = 0xbaadf00d;
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 */
2083 endptr = str;
2084 res = 0xbaadf00d;
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)
2093 const char *str;
2094 const char *endptr;
2095 int err;
2096 uint64_t res;
2098 str = "0x0";
2099 endptr = str;
2100 res = 0xbaadf00d;
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);
2106 str = "0xab";
2107 endptr = str;
2108 res = 0xbaadf00d;
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);
2114 str = "0xae";
2115 endptr = str;
2116 res = 0xbaadf00d;
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";
2133 int err;
2134 const char *endptr;
2135 uint64_t res;
2137 /* default is M */
2138 endptr = NULL;
2139 res = 0xbaadf00d;
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);
2145 endptr = NULL;
2146 res = 0xbaadf00d;
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);
2152 endptr = NULL;
2153 res = 0xbaadf00d;
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);
2159 endptr = NULL;
2160 res = 0xbaadf00d;
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);
2166 endptr = NULL;
2167 res = 0xbaadf00d;
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);
2173 endptr = NULL;
2174 res = 0xbaadf00d;
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);
2180 endptr = NULL;
2181 res = 0xbaadf00d;
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);
2187 endptr = NULL;
2188 res = 0xbaadf00d;
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)
2197 const char *str;
2198 int err;
2199 const char *endptr;
2200 uint64_t res;
2202 str = "0.5E";
2203 endptr = str;
2204 res = 0xbaadf00d;
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 */
2211 str = "1.0B";
2212 endptr = str;
2213 res = 0xbaadf00d;
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 */
2220 str = "1.k";
2221 endptr = str;
2222 res = 0xbaadf00d;
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 */
2229 str = "12.345M";
2230 endptr = str;
2231 res = 0xbaadf00d;
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)
2240 const char *str;
2241 const char *endptr;
2242 int err;
2243 uint64_t res = 0xbaadf00d;
2245 str = "";
2246 endptr = NULL;
2247 err = qemu_strtosz(str, &endptr, &res);
2248 g_assert_cmpint(err, ==, -EINVAL);
2249 g_assert_cmpint(res, ==, 0xbaadf00d);
2250 g_assert(endptr == str);
2252 str = " \t ";
2253 endptr = NULL;
2254 err = qemu_strtosz(str, &endptr, &res);
2255 g_assert_cmpint(err, ==, -EINVAL);
2256 g_assert_cmpint(res, ==, 0xbaadf00d);
2257 g_assert(endptr == str);
2259 str = "crap";
2260 endptr = NULL;
2261 err = qemu_strtosz(str, &endptr, &res);
2262 g_assert_cmpint(err, ==, -EINVAL);
2263 g_assert_cmpint(res, ==, 0xbaadf00d);
2264 g_assert(endptr == str);
2266 str = "inf";
2267 endptr = NULL;
2268 err = qemu_strtosz(str, &endptr, &res);
2269 g_assert_cmpint(err, ==, -EINVAL);
2270 g_assert_cmpint(res, ==, 0xbaadf00d);
2271 g_assert(endptr == str);
2273 str = "NaN";
2274 endptr = NULL;
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 */
2281 str = "1.1B";
2282 endptr = NULL;
2283 err = qemu_strtosz(str, &endptr, &res);
2284 g_assert_cmpint(err, ==, -EINVAL);
2285 g_assert_cmpint(res, ==, 0xbaadf00d);
2286 g_assert(endptr == str);
2288 str = "1.1";
2289 endptr = NULL;
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 */
2296 str = "1.5e1k";
2297 endptr = NULL;
2298 err = qemu_strtosz(str, &endptr, &res);
2299 g_assert_cmpint(err, ==, -EINVAL);
2300 g_assert_cmpint(res, ==, 0xbaadf00d);
2301 g_assert(endptr == str);
2303 str = "1.5E+0k";
2304 endptr = NULL;
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 */
2311 str = "0x1.8k";
2312 endptr = NULL;
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 */
2319 str = "-0";
2320 endptr = NULL;
2321 err = qemu_strtosz(str, &endptr, &res);
2322 g_assert_cmpint(err, ==, -EINVAL);
2323 g_assert_cmpint(res, ==, 0xbaadf00d);
2324 g_assert(endptr == str);
2326 str = "-1";
2327 endptr = NULL;
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)
2336 const char *str;
2337 const char *endptr;
2338 int err;
2339 uint64_t res;
2341 str = "123xxx";
2342 endptr = NULL;
2343 res = 0xbaadf00d;
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);
2349 res = 0xbaadf00d;
2350 err = qemu_strtosz(str, NULL, &res);
2351 g_assert_cmpint(err, ==, -EINVAL);
2352 g_assert_cmpint(res, ==, 0xbaadf00d);
2354 str = "1kiB";
2355 endptr = NULL;
2356 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);
2362 res = 0xbaadf00d;
2363 err = qemu_strtosz(str, NULL, &res);
2364 g_assert_cmpint(err, ==, -EINVAL);
2365 g_assert_cmpint(res, ==, 0xbaadf00d);
2367 str = "0x";
2368 endptr = NULL;
2369 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);
2375 res = 0xbaadf00d;
2376 err = qemu_strtosz(str, NULL, &res);
2377 g_assert_cmpint(err, ==, -EINVAL);
2378 g_assert_cmpint(res, ==, 0xbaadf00d);
2380 str = "0.NaN";
2381 endptr = NULL;
2382 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);
2388 res = 0xbaadf00d;
2389 err = qemu_strtosz(str, NULL, &res);
2390 g_assert_cmpint(err, ==, -EINVAL);
2391 g_assert_cmpint(res, ==, 0xbaadf00d);
2393 str = "123-45";
2394 endptr = NULL;
2395 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);
2401 res = 0xbaadf00d;
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)
2409 const char *str;
2410 const char *endptr;
2411 int err;
2412 uint64_t res = 0xbaadf00d;
2414 str = "18446744073709551616"; /* 2^64; see strtosz_simple for 2^64-1 */
2415 endptr = NULL;
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);
2421 str = "20E";
2422 endptr = NULL;
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)
2431 const char *str;
2432 int err;
2433 const char *endptr;
2434 uint64_t res;
2436 str = "12345k";
2437 endptr = str;
2438 res = 0xbaadf00d;
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);
2444 str = "12.345M";
2445 endptr = str;
2446 res = 0xbaadf00d;
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();