osdep: Fix ROUND_UP(64-bit, 32-bit)
[qemu/kevin.git] / tests / test-cutils.c
blobf64a49b7fba1a7fa922f6af76d0a4d5795b422c8
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"
30 #include "qemu/cutils.h"
32 static void test_parse_uint_null(void)
34 unsigned long long i = 999;
35 char f = 'X';
36 char *endptr = &f;
37 int r;
39 r = parse_uint(NULL, &i, &endptr, 0);
41 g_assert_cmpint(r, ==, -EINVAL);
42 g_assert_cmpint(i, ==, 0);
43 g_assert(endptr == NULL);
46 static void test_parse_uint_empty(void)
48 unsigned long long i = 999;
49 char f = 'X';
50 char *endptr = &f;
51 const char *str = "";
52 int r;
54 r = parse_uint(str, &i, &endptr, 0);
56 g_assert_cmpint(r, ==, -EINVAL);
57 g_assert_cmpint(i, ==, 0);
58 g_assert(endptr == str);
61 static void test_parse_uint_whitespace(void)
63 unsigned long long i = 999;
64 char f = 'X';
65 char *endptr = &f;
66 const char *str = " \t ";
67 int r;
69 r = parse_uint(str, &i, &endptr, 0);
71 g_assert_cmpint(r, ==, -EINVAL);
72 g_assert_cmpint(i, ==, 0);
73 g_assert(endptr == str);
77 static void test_parse_uint_invalid(void)
79 unsigned long long i = 999;
80 char f = 'X';
81 char *endptr = &f;
82 const char *str = " \t xxx";
83 int r;
85 r = parse_uint(str, &i, &endptr, 0);
87 g_assert_cmpint(r, ==, -EINVAL);
88 g_assert_cmpint(i, ==, 0);
89 g_assert(endptr == str);
93 static void test_parse_uint_trailing(void)
95 unsigned long long i = 999;
96 char f = 'X';
97 char *endptr = &f;
98 const char *str = "123xxx";
99 int r;
101 r = parse_uint(str, &i, &endptr, 0);
103 g_assert_cmpint(r, ==, 0);
104 g_assert_cmpint(i, ==, 123);
105 g_assert(endptr == str + 3);
108 static void test_parse_uint_correct(void)
110 unsigned long long i = 999;
111 char f = 'X';
112 char *endptr = &f;
113 const char *str = "123";
114 int r;
116 r = parse_uint(str, &i, &endptr, 0);
118 g_assert_cmpint(r, ==, 0);
119 g_assert_cmpint(i, ==, 123);
120 g_assert(endptr == str + strlen(str));
123 static void test_parse_uint_octal(void)
125 unsigned long long i = 999;
126 char f = 'X';
127 char *endptr = &f;
128 const char *str = "0123";
129 int r;
131 r = parse_uint(str, &i, &endptr, 0);
133 g_assert_cmpint(r, ==, 0);
134 g_assert_cmpint(i, ==, 0123);
135 g_assert(endptr == str + strlen(str));
138 static void test_parse_uint_decimal(void)
140 unsigned long long i = 999;
141 char f = 'X';
142 char *endptr = &f;
143 const char *str = "0123";
144 int r;
146 r = parse_uint(str, &i, &endptr, 10);
148 g_assert_cmpint(r, ==, 0);
149 g_assert_cmpint(i, ==, 123);
150 g_assert(endptr == str + strlen(str));
154 static void test_parse_uint_llong_max(void)
156 unsigned long long i = 999;
157 char f = 'X';
158 char *endptr = &f;
159 char *str = g_strdup_printf("%llu", (unsigned long long)LLONG_MAX + 1);
160 int r;
162 r = parse_uint(str, &i, &endptr, 0);
164 g_assert_cmpint(r, ==, 0);
165 g_assert_cmpint(i, ==, (unsigned long long)LLONG_MAX + 1);
166 g_assert(endptr == str + strlen(str));
168 g_free(str);
171 static void test_parse_uint_overflow(void)
173 unsigned long long i = 999;
174 char f = 'X';
175 char *endptr = &f;
176 const char *str = "99999999999999999999999999999999999999";
177 int r;
179 r = parse_uint(str, &i, &endptr, 0);
181 g_assert_cmpint(r, ==, -ERANGE);
182 g_assert_cmpint(i, ==, ULLONG_MAX);
183 g_assert(endptr == str + strlen(str));
186 static void test_parse_uint_negative(void)
188 unsigned long long i = 999;
189 char f = 'X';
190 char *endptr = &f;
191 const char *str = " \t -321";
192 int r;
194 r = parse_uint(str, &i, &endptr, 0);
196 g_assert_cmpint(r, ==, -ERANGE);
197 g_assert_cmpint(i, ==, 0);
198 g_assert(endptr == str + strlen(str));
202 static void test_parse_uint_full_trailing(void)
204 unsigned long long i = 999;
205 const char *str = "123xxx";
206 int r;
208 r = parse_uint_full(str, &i, 0);
210 g_assert_cmpint(r, ==, -EINVAL);
211 g_assert_cmpint(i, ==, 0);
214 static void test_parse_uint_full_correct(void)
216 unsigned long long i = 999;
217 const char *str = "123";
218 int r;
220 r = parse_uint_full(str, &i, 0);
222 g_assert_cmpint(r, ==, 0);
223 g_assert_cmpint(i, ==, 123);
226 static void test_qemu_strtol_correct(void)
228 const char *str = "12345 foo";
229 char f = 'X';
230 const char *endptr = &f;
231 long res = 999;
232 int err;
234 err = qemu_strtol(str, &endptr, 0, &res);
236 g_assert_cmpint(err, ==, 0);
237 g_assert_cmpint(res, ==, 12345);
238 g_assert(endptr == str + 5);
241 static void test_qemu_strtol_null(void)
243 char f = 'X';
244 const char *endptr = &f;
245 long res = 999;
246 int err;
248 err = qemu_strtol(NULL, &endptr, 0, &res);
250 g_assert_cmpint(err, ==, -EINVAL);
251 g_assert(endptr == NULL);
254 static void test_qemu_strtol_empty(void)
256 const char *str = "";
257 char f = 'X';
258 const char *endptr = &f;
259 long res = 999;
260 int err;
262 err = qemu_strtol(str, &endptr, 0, &res);
264 g_assert_cmpint(err, ==, -EINVAL);
265 g_assert(endptr == str);
268 static void test_qemu_strtol_whitespace(void)
270 const char *str = " \t ";
271 char f = 'X';
272 const char *endptr = &f;
273 long res = 999;
274 int err;
276 err = qemu_strtol(str, &endptr, 0, &res);
278 g_assert_cmpint(err, ==, -EINVAL);
279 g_assert(endptr == str);
282 static void test_qemu_strtol_invalid(void)
284 const char *str = " xxxx \t abc";
285 char f = 'X';
286 const char *endptr = &f;
287 long res = 999;
288 int err;
290 err = qemu_strtol(str, &endptr, 0, &res);
292 g_assert_cmpint(err, ==, -EINVAL);
293 g_assert(endptr == str);
296 static void test_qemu_strtol_trailing(void)
298 const char *str = "123xxx";
299 char f = 'X';
300 const char *endptr = &f;
301 long res = 999;
302 int err;
304 err = qemu_strtol(str, &endptr, 0, &res);
306 g_assert_cmpint(err, ==, 0);
307 g_assert_cmpint(res, ==, 123);
308 g_assert(endptr == str + 3);
311 static void test_qemu_strtol_octal(void)
313 const char *str = "0123";
314 char f = 'X';
315 const char *endptr = &f;
316 long res = 999;
317 int err;
319 err = qemu_strtol(str, &endptr, 8, &res);
321 g_assert_cmpint(err, ==, 0);
322 g_assert_cmpint(res, ==, 0123);
323 g_assert(endptr == str + strlen(str));
325 res = 999;
326 endptr = &f;
327 err = qemu_strtol(str, &endptr, 0, &res);
329 g_assert_cmpint(err, ==, 0);
330 g_assert_cmpint(res, ==, 0123);
331 g_assert(endptr == str + strlen(str));
334 static void test_qemu_strtol_decimal(void)
336 const char *str = "0123";
337 char f = 'X';
338 const char *endptr = &f;
339 long res = 999;
340 int err;
342 err = qemu_strtol(str, &endptr, 10, &res);
344 g_assert_cmpint(err, ==, 0);
345 g_assert_cmpint(res, ==, 123);
346 g_assert(endptr == str + strlen(str));
348 str = "123";
349 res = 999;
350 endptr = &f;
351 err = qemu_strtol(str, &endptr, 0, &res);
353 g_assert_cmpint(err, ==, 0);
354 g_assert_cmpint(res, ==, 123);
355 g_assert(endptr == str + strlen(str));
358 static void test_qemu_strtol_hex(void)
360 const char *str = "0123";
361 char f = 'X';
362 const char *endptr = &f;
363 long res = 999;
364 int err;
366 err = qemu_strtol(str, &endptr, 16, &res);
368 g_assert_cmpint(err, ==, 0);
369 g_assert_cmpint(res, ==, 0x123);
370 g_assert(endptr == str + strlen(str));
372 str = "0x123";
373 res = 999;
374 endptr = &f;
375 err = qemu_strtol(str, &endptr, 0, &res);
377 g_assert_cmpint(err, ==, 0);
378 g_assert_cmpint(res, ==, 0x123);
379 g_assert(endptr == str + strlen(str));
382 static void test_qemu_strtol_max(void)
384 char *str = g_strdup_printf("%ld", LONG_MAX);
385 char f = 'X';
386 const char *endptr = &f;
387 long res = 999;
388 int err;
390 err = qemu_strtol(str, &endptr, 0, &res);
392 g_assert_cmpint(err, ==, 0);
393 g_assert_cmpint(res, ==, LONG_MAX);
394 g_assert(endptr == str + strlen(str));
395 g_free(str);
398 static void test_qemu_strtol_overflow(void)
400 const char *str = "99999999999999999999999999999999999999999999";
401 char f = 'X';
402 const char *endptr = &f;
403 long res = 999;
404 int err;
406 err = qemu_strtol(str, &endptr, 0, &res);
408 g_assert_cmpint(err, ==, -ERANGE);
409 g_assert_cmpint(res, ==, LONG_MAX);
410 g_assert(endptr == str + strlen(str));
413 static void test_qemu_strtol_underflow(void)
415 const char *str = "-99999999999999999999999999999999999999999999";
416 char f = 'X';
417 const char *endptr = &f;
418 long res = 999;
419 int err;
421 err = qemu_strtol(str, &endptr, 0, &res);
423 g_assert_cmpint(err, ==, -ERANGE);
424 g_assert_cmpint(res, ==, LONG_MIN);
425 g_assert(endptr == str + strlen(str));
428 static void test_qemu_strtol_negative(void)
430 const char *str = " \t -321";
431 char f = 'X';
432 const char *endptr = &f;
433 long res = 999;
434 int err;
436 err = qemu_strtol(str, &endptr, 0, &res);
438 g_assert_cmpint(err, ==, 0);
439 g_assert_cmpint(res, ==, -321);
440 g_assert(endptr == str + strlen(str));
443 static void test_qemu_strtol_full_correct(void)
445 const char *str = "123";
446 long res = 999;
447 int err;
449 err = qemu_strtol(str, NULL, 0, &res);
451 g_assert_cmpint(err, ==, 0);
452 g_assert_cmpint(res, ==, 123);
455 static void test_qemu_strtol_full_null(void)
457 char f = 'X';
458 const char *endptr = &f;
459 long res = 999;
460 int err;
462 err = qemu_strtol(NULL, &endptr, 0, &res);
464 g_assert_cmpint(err, ==, -EINVAL);
465 g_assert(endptr == NULL);
468 static void test_qemu_strtol_full_empty(void)
470 const char *str = "";
471 long res = 999L;
472 int err;
474 err = qemu_strtol(str, NULL, 0, &res);
476 g_assert_cmpint(err, ==, -EINVAL);
479 static void test_qemu_strtol_full_negative(void)
481 const char *str = " \t -321";
482 long res = 999;
483 int err;
485 err = qemu_strtol(str, NULL, 0, &res);
487 g_assert_cmpint(err, ==, 0);
488 g_assert_cmpint(res, ==, -321);
491 static void test_qemu_strtol_full_trailing(void)
493 const char *str = "123xxx";
494 long res;
495 int err;
497 err = qemu_strtol(str, NULL, 0, &res);
499 g_assert_cmpint(err, ==, -EINVAL);
502 static void test_qemu_strtol_full_max(void)
504 char *str = g_strdup_printf("%ld", LONG_MAX);
505 long res;
506 int err;
508 err = qemu_strtol(str, NULL, 0, &res);
510 g_assert_cmpint(err, ==, 0);
511 g_assert_cmpint(res, ==, LONG_MAX);
512 g_free(str);
515 static void test_qemu_strtoul_correct(void)
517 const char *str = "12345 foo";
518 char f = 'X';
519 const char *endptr = &f;
520 unsigned long res = 999;
521 int err;
523 err = qemu_strtoul(str, &endptr, 0, &res);
525 g_assert_cmpint(err, ==, 0);
526 g_assert_cmpuint(res, ==, 12345);
527 g_assert(endptr == str + 5);
530 static void test_qemu_strtoul_null(void)
532 char f = 'X';
533 const char *endptr = &f;
534 unsigned long res = 999;
535 int err;
537 err = qemu_strtoul(NULL, &endptr, 0, &res);
539 g_assert_cmpint(err, ==, -EINVAL);
540 g_assert(endptr == NULL);
543 static void test_qemu_strtoul_empty(void)
545 const char *str = "";
546 char f = 'X';
547 const char *endptr = &f;
548 unsigned long res = 999;
549 int err;
551 err = qemu_strtoul(str, &endptr, 0, &res);
553 g_assert_cmpint(err, ==, -EINVAL);
554 g_assert(endptr == str);
557 static void test_qemu_strtoul_whitespace(void)
559 const char *str = " \t ";
560 char f = 'X';
561 const char *endptr = &f;
562 unsigned long res = 999;
563 int err;
565 err = qemu_strtoul(str, &endptr, 0, &res);
567 g_assert_cmpint(err, ==, -EINVAL);
568 g_assert(endptr == str);
571 static void test_qemu_strtoul_invalid(void)
573 const char *str = " xxxx \t abc";
574 char f = 'X';
575 const char *endptr = &f;
576 unsigned long res = 999;
577 int err;
579 err = qemu_strtoul(str, &endptr, 0, &res);
581 g_assert_cmpint(err, ==, -EINVAL);
582 g_assert(endptr == str);
585 static void test_qemu_strtoul_trailing(void)
587 const char *str = "123xxx";
588 char f = 'X';
589 const char *endptr = &f;
590 unsigned long res = 999;
591 int err;
593 err = qemu_strtoul(str, &endptr, 0, &res);
595 g_assert_cmpint(err, ==, 0);
596 g_assert_cmpuint(res, ==, 123);
597 g_assert(endptr == str + 3);
600 static void test_qemu_strtoul_octal(void)
602 const char *str = "0123";
603 char f = 'X';
604 const char *endptr = &f;
605 unsigned long res = 999;
606 int err;
608 err = qemu_strtoul(str, &endptr, 8, &res);
610 g_assert_cmpint(err, ==, 0);
611 g_assert_cmpuint(res, ==, 0123);
612 g_assert(endptr == str + strlen(str));
614 res = 999;
615 endptr = &f;
616 err = qemu_strtoul(str, &endptr, 0, &res);
618 g_assert_cmpint(err, ==, 0);
619 g_assert_cmpuint(res, ==, 0123);
620 g_assert(endptr == str + strlen(str));
623 static void test_qemu_strtoul_decimal(void)
625 const char *str = "0123";
626 char f = 'X';
627 const char *endptr = &f;
628 unsigned long res = 999;
629 int err;
631 err = qemu_strtoul(str, &endptr, 10, &res);
633 g_assert_cmpint(err, ==, 0);
634 g_assert_cmpuint(res, ==, 123);
635 g_assert(endptr == str + strlen(str));
637 str = "123";
638 res = 999;
639 endptr = &f;
640 err = qemu_strtoul(str, &endptr, 0, &res);
642 g_assert_cmpint(err, ==, 0);
643 g_assert_cmpuint(res, ==, 123);
644 g_assert(endptr == str + strlen(str));
647 static void test_qemu_strtoul_hex(void)
649 const char *str = "0123";
650 char f = 'X';
651 const char *endptr = &f;
652 unsigned long res = 999;
653 int err;
655 err = qemu_strtoul(str, &endptr, 16, &res);
657 g_assert_cmpint(err, ==, 0);
658 g_assert_cmphex(res, ==, 0x123);
659 g_assert(endptr == str + strlen(str));
661 str = "0x123";
662 res = 999;
663 endptr = &f;
664 err = qemu_strtoul(str, &endptr, 0, &res);
666 g_assert_cmpint(err, ==, 0);
667 g_assert_cmphex(res, ==, 0x123);
668 g_assert(endptr == str + strlen(str));
671 static void test_qemu_strtoul_max(void)
673 char *str = g_strdup_printf("%lu", ULONG_MAX);
674 char f = 'X';
675 const char *endptr = &f;
676 unsigned long res = 999;
677 int err;
679 err = qemu_strtoul(str, &endptr, 0, &res);
681 g_assert_cmpint(err, ==, 0);
682 g_assert_cmphex(res, ==, ULONG_MAX);
683 g_assert(endptr == str + strlen(str));
684 g_free(str);
687 static void test_qemu_strtoul_overflow(void)
689 const char *str = "99999999999999999999999999999999999999999999";
690 char f = 'X';
691 const char *endptr = &f;
692 unsigned long res = 999;
693 int err;
695 err = qemu_strtoul(str, &endptr, 0, &res);
697 g_assert_cmpint(err, ==, -ERANGE);
698 g_assert_cmphex(res, ==, ULONG_MAX);
699 g_assert(endptr == str + strlen(str));
702 static void test_qemu_strtoul_underflow(void)
704 const char *str = "-99999999999999999999999999999999999999999999";
705 char f = 'X';
706 const char *endptr = &f;
707 unsigned long res = 999;
708 int err;
710 err = qemu_strtoul(str, &endptr, 0, &res);
712 g_assert_cmpint(err, ==, -ERANGE);
713 g_assert_cmpuint(res, ==, -1ul);
714 g_assert(endptr == str + strlen(str));
717 static void test_qemu_strtoul_negative(void)
719 const char *str = " \t -321";
720 char f = 'X';
721 const char *endptr = &f;
722 unsigned long res = 999;
723 int err;
725 err = qemu_strtoul(str, &endptr, 0, &res);
727 g_assert_cmpint(err, ==, 0);
728 g_assert_cmpuint(res, ==, -321ul);
729 g_assert(endptr == str + strlen(str));
732 static void test_qemu_strtoul_full_correct(void)
734 const char *str = "123";
735 unsigned long res = 999;
736 int err;
738 err = qemu_strtoul(str, NULL, 0, &res);
740 g_assert_cmpint(err, ==, 0);
741 g_assert_cmpuint(res, ==, 123);
744 static void test_qemu_strtoul_full_null(void)
746 unsigned long res = 999;
747 int err;
749 err = qemu_strtoul(NULL, NULL, 0, &res);
751 g_assert_cmpint(err, ==, -EINVAL);
754 static void test_qemu_strtoul_full_empty(void)
756 const char *str = "";
757 unsigned long res = 999;
758 int err;
760 err = qemu_strtoul(str, NULL, 0, &res);
762 g_assert_cmpint(err, ==, -EINVAL);
764 static void test_qemu_strtoul_full_negative(void)
766 const char *str = " \t -321";
767 unsigned long res = 999;
768 int err;
770 err = qemu_strtoul(str, NULL, 0, &res);
771 g_assert_cmpint(err, ==, 0);
772 g_assert_cmpuint(res, ==, -321ul);
775 static void test_qemu_strtoul_full_trailing(void)
777 const char *str = "123xxx";
778 unsigned long res;
779 int err;
781 err = qemu_strtoul(str, NULL, 0, &res);
783 g_assert_cmpint(err, ==, -EINVAL);
786 static void test_qemu_strtoul_full_max(void)
788 char *str = g_strdup_printf("%lu", ULONG_MAX);
789 unsigned long res = 999;
790 int err;
792 err = qemu_strtoul(str, NULL, 0, &res);
794 g_assert_cmpint(err, ==, 0);
795 g_assert_cmphex(res, ==, ULONG_MAX);
796 g_free(str);
799 static void test_qemu_strtoi64_correct(void)
801 const char *str = "12345 foo";
802 char f = 'X';
803 const char *endptr = &f;
804 int64_t res = 999;
805 int err;
807 err = qemu_strtoi64(str, &endptr, 0, &res);
809 g_assert_cmpint(err, ==, 0);
810 g_assert_cmpint(res, ==, 12345);
811 g_assert(endptr == str + 5);
814 static void test_qemu_strtoi64_null(void)
816 char f = 'X';
817 const char *endptr = &f;
818 int64_t res = 999;
819 int err;
821 err = qemu_strtoi64(NULL, &endptr, 0, &res);
823 g_assert_cmpint(err, ==, -EINVAL);
824 g_assert(endptr == NULL);
827 static void test_qemu_strtoi64_empty(void)
829 const char *str = "";
830 char f = 'X';
831 const char *endptr = &f;
832 int64_t res = 999;
833 int err;
835 err = qemu_strtoi64(str, &endptr, 0, &res);
837 g_assert_cmpint(err, ==, -EINVAL);
838 g_assert(endptr == str);
841 static void test_qemu_strtoi64_whitespace(void)
843 const char *str = " \t ";
844 char f = 'X';
845 const char *endptr = &f;
846 int64_t res = 999;
847 int err;
849 err = qemu_strtoi64(str, &endptr, 0, &res);
851 g_assert_cmpint(err, ==, -EINVAL);
852 g_assert(endptr == str);
855 static void test_qemu_strtoi64_invalid(void)
857 const char *str = " xxxx \t abc";
858 char f = 'X';
859 const char *endptr = &f;
860 int64_t res = 999;
861 int err;
863 err = qemu_strtoi64(str, &endptr, 0, &res);
865 g_assert_cmpint(err, ==, -EINVAL);
866 g_assert(endptr == str);
869 static void test_qemu_strtoi64_trailing(void)
871 const char *str = "123xxx";
872 char f = 'X';
873 const char *endptr = &f;
874 int64_t res = 999;
875 int err;
877 err = qemu_strtoi64(str, &endptr, 0, &res);
879 g_assert_cmpint(err, ==, 0);
880 g_assert_cmpint(res, ==, 123);
881 g_assert(endptr == str + 3);
884 static void test_qemu_strtoi64_octal(void)
886 const char *str = "0123";
887 char f = 'X';
888 const char *endptr = &f;
889 int64_t res = 999;
890 int err;
892 err = qemu_strtoi64(str, &endptr, 8, &res);
894 g_assert_cmpint(err, ==, 0);
895 g_assert_cmpint(res, ==, 0123);
896 g_assert(endptr == str + strlen(str));
898 endptr = &f;
899 res = 999;
900 err = qemu_strtoi64(str, &endptr, 0, &res);
902 g_assert_cmpint(err, ==, 0);
903 g_assert_cmpint(res, ==, 0123);
904 g_assert(endptr == str + strlen(str));
907 static void test_qemu_strtoi64_decimal(void)
909 const char *str = "0123";
910 char f = 'X';
911 const char *endptr = &f;
912 int64_t res = 999;
913 int err;
915 err = qemu_strtoi64(str, &endptr, 10, &res);
917 g_assert_cmpint(err, ==, 0);
918 g_assert_cmpint(res, ==, 123);
919 g_assert(endptr == str + strlen(str));
921 str = "123";
922 endptr = &f;
923 res = 999;
924 err = qemu_strtoi64(str, &endptr, 0, &res);
926 g_assert_cmpint(err, ==, 0);
927 g_assert_cmpint(res, ==, 123);
928 g_assert(endptr == str + strlen(str));
931 static void test_qemu_strtoi64_hex(void)
933 const char *str = "0123";
934 char f = 'X';
935 const char *endptr = &f;
936 int64_t res = 999;
937 int err;
939 err = qemu_strtoi64(str, &endptr, 16, &res);
941 g_assert_cmpint(err, ==, 0);
942 g_assert_cmpint(res, ==, 0x123);
943 g_assert(endptr == str + strlen(str));
945 str = "0x123";
946 endptr = &f;
947 res = 999;
948 err = qemu_strtoi64(str, &endptr, 0, &res);
950 g_assert_cmpint(err, ==, 0);
951 g_assert_cmpint(res, ==, 0x123);
952 g_assert(endptr == str + strlen(str));
955 static void test_qemu_strtoi64_max(void)
957 char *str = g_strdup_printf("%lld", LLONG_MAX);
958 char f = 'X';
959 const char *endptr = &f;
960 int64_t res = 999;
961 int err;
963 err = qemu_strtoi64(str, &endptr, 0, &res);
965 g_assert_cmpint(err, ==, 0);
966 g_assert_cmpint(res, ==, LLONG_MAX);
967 g_assert(endptr == str + strlen(str));
968 g_free(str);
971 static void test_qemu_strtoi64_overflow(void)
973 const char *str = "99999999999999999999999999999999999999999999";
974 char f = 'X';
975 const char *endptr = &f;
976 int64_t res = 999;
977 int err;
979 err = qemu_strtoi64(str, &endptr, 0, &res);
981 g_assert_cmpint(err, ==, -ERANGE);
982 g_assert_cmpint(res, ==, LLONG_MAX);
983 g_assert(endptr == str + strlen(str));
986 static void test_qemu_strtoi64_underflow(void)
988 const char *str = "-99999999999999999999999999999999999999999999";
989 char f = 'X';
990 const char *endptr = &f;
991 int64_t res = 999;
992 int err;
994 err = qemu_strtoi64(str, &endptr, 0, &res);
996 g_assert_cmpint(err, ==, -ERANGE);
997 g_assert_cmpint(res, ==, LLONG_MIN);
998 g_assert(endptr == str + strlen(str));
1001 static void test_qemu_strtoi64_negative(void)
1003 const char *str = " \t -321";
1004 char f = 'X';
1005 const char *endptr = &f;
1006 int64_t res = 999;
1007 int err;
1009 err = qemu_strtoi64(str, &endptr, 0, &res);
1011 g_assert_cmpint(err, ==, 0);
1012 g_assert_cmpint(res, ==, -321);
1013 g_assert(endptr == str + strlen(str));
1016 static void test_qemu_strtoi64_full_correct(void)
1018 const char *str = "123";
1019 int64_t res = 999;
1020 int err;
1022 err = qemu_strtoi64(str, NULL, 0, &res);
1024 g_assert_cmpint(err, ==, 0);
1025 g_assert_cmpint(res, ==, 123);
1028 static void test_qemu_strtoi64_full_null(void)
1030 int64_t res = 999;
1031 int err;
1033 err = qemu_strtoi64(NULL, NULL, 0, &res);
1035 g_assert_cmpint(err, ==, -EINVAL);
1038 static void test_qemu_strtoi64_full_empty(void)
1040 const char *str = "";
1041 int64_t res = 999;
1042 int err;
1044 err = qemu_strtoi64(str, NULL, 0, &res);
1046 g_assert_cmpint(err, ==, -EINVAL);
1049 static void test_qemu_strtoi64_full_negative(void)
1051 const char *str = " \t -321";
1052 int64_t res = 999;
1053 int err;
1055 err = qemu_strtoi64(str, NULL, 0, &res);
1057 g_assert_cmpint(err, ==, 0);
1058 g_assert_cmpint(res, ==, -321);
1061 static void test_qemu_strtoi64_full_trailing(void)
1063 const char *str = "123xxx";
1064 int64_t res = 999;
1065 int err;
1067 err = qemu_strtoi64(str, NULL, 0, &res);
1069 g_assert_cmpint(err, ==, -EINVAL);
1072 static void test_qemu_strtoi64_full_max(void)
1075 char *str = g_strdup_printf("%lld", LLONG_MAX);
1076 int64_t res;
1077 int err;
1079 err = qemu_strtoi64(str, NULL, 0, &res);
1081 g_assert_cmpint(err, ==, 0);
1082 g_assert_cmpint(res, ==, LLONG_MAX);
1083 g_free(str);
1086 static void test_qemu_strtou64_correct(void)
1088 const char *str = "12345 foo";
1089 char f = 'X';
1090 const char *endptr = &f;
1091 uint64_t res = 999;
1092 int err;
1094 err = qemu_strtou64(str, &endptr, 0, &res);
1096 g_assert_cmpint(err, ==, 0);
1097 g_assert_cmpuint(res, ==, 12345);
1098 g_assert(endptr == str + 5);
1101 static void test_qemu_strtou64_null(void)
1103 char f = 'X';
1104 const char *endptr = &f;
1105 uint64_t res = 999;
1106 int err;
1108 err = qemu_strtou64(NULL, &endptr, 0, &res);
1110 g_assert_cmpint(err, ==, -EINVAL);
1111 g_assert(endptr == NULL);
1114 static void test_qemu_strtou64_empty(void)
1116 const char *str = "";
1117 char f = 'X';
1118 const char *endptr = &f;
1119 uint64_t res = 999;
1120 int err;
1122 err = qemu_strtou64(str, &endptr, 0, &res);
1124 g_assert_cmpint(err, ==, -EINVAL);
1125 g_assert(endptr == str);
1128 static void test_qemu_strtou64_whitespace(void)
1130 const char *str = " \t ";
1131 char f = 'X';
1132 const char *endptr = &f;
1133 uint64_t res = 999;
1134 int err;
1136 err = qemu_strtou64(str, &endptr, 0, &res);
1138 g_assert_cmpint(err, ==, -EINVAL);
1139 g_assert(endptr == str);
1142 static void test_qemu_strtou64_invalid(void)
1144 const char *str = " xxxx \t abc";
1145 char f = 'X';
1146 const char *endptr = &f;
1147 uint64_t res = 999;
1148 int err;
1150 err = qemu_strtou64(str, &endptr, 0, &res);
1152 g_assert_cmpint(err, ==, -EINVAL);
1153 g_assert(endptr == str);
1156 static void test_qemu_strtou64_trailing(void)
1158 const char *str = "123xxx";
1159 char f = 'X';
1160 const char *endptr = &f;
1161 uint64_t res = 999;
1162 int err;
1164 err = qemu_strtou64(str, &endptr, 0, &res);
1166 g_assert_cmpint(err, ==, 0);
1167 g_assert_cmpuint(res, ==, 123);
1168 g_assert(endptr == str + 3);
1171 static void test_qemu_strtou64_octal(void)
1173 const char *str = "0123";
1174 char f = 'X';
1175 const char *endptr = &f;
1176 uint64_t res = 999;
1177 int err;
1179 err = qemu_strtou64(str, &endptr, 8, &res);
1181 g_assert_cmpint(err, ==, 0);
1182 g_assert_cmpuint(res, ==, 0123);
1183 g_assert(endptr == str + strlen(str));
1185 endptr = &f;
1186 res = 999;
1187 err = qemu_strtou64(str, &endptr, 0, &res);
1189 g_assert_cmpint(err, ==, 0);
1190 g_assert_cmpuint(res, ==, 0123);
1191 g_assert(endptr == str + strlen(str));
1194 static void test_qemu_strtou64_decimal(void)
1196 const char *str = "0123";
1197 char f = 'X';
1198 const char *endptr = &f;
1199 uint64_t res = 999;
1200 int err;
1202 err = qemu_strtou64(str, &endptr, 10, &res);
1204 g_assert_cmpint(err, ==, 0);
1205 g_assert_cmpuint(res, ==, 123);
1206 g_assert(endptr == str + strlen(str));
1208 str = "123";
1209 endptr = &f;
1210 res = 999;
1211 err = qemu_strtou64(str, &endptr, 0, &res);
1213 g_assert_cmpint(err, ==, 0);
1214 g_assert_cmpuint(res, ==, 123);
1215 g_assert(endptr == str + strlen(str));
1218 static void test_qemu_strtou64_hex(void)
1220 const char *str = "0123";
1221 char f = 'X';
1222 const char *endptr = &f;
1223 uint64_t res = 999;
1224 int err;
1226 err = qemu_strtou64(str, &endptr, 16, &res);
1228 g_assert_cmpint(err, ==, 0);
1229 g_assert_cmphex(res, ==, 0x123);
1230 g_assert(endptr == str + strlen(str));
1232 str = "0x123";
1233 endptr = &f;
1234 res = 999;
1235 err = qemu_strtou64(str, &endptr, 0, &res);
1237 g_assert_cmpint(err, ==, 0);
1238 g_assert_cmphex(res, ==, 0x123);
1239 g_assert(endptr == str + strlen(str));
1242 static void test_qemu_strtou64_max(void)
1244 char *str = g_strdup_printf("%llu", ULLONG_MAX);
1245 char f = 'X';
1246 const char *endptr = &f;
1247 uint64_t res = 999;
1248 int err;
1250 err = qemu_strtou64(str, &endptr, 0, &res);
1252 g_assert_cmpint(err, ==, 0);
1253 g_assert_cmphex(res, ==, ULLONG_MAX);
1254 g_assert(endptr == str + strlen(str));
1255 g_free(str);
1258 static void test_qemu_strtou64_overflow(void)
1260 const char *str = "99999999999999999999999999999999999999999999";
1261 char f = 'X';
1262 const char *endptr = &f;
1263 uint64_t res = 999;
1264 int err;
1266 err = qemu_strtou64(str, &endptr, 0, &res);
1268 g_assert_cmpint(err, ==, -ERANGE);
1269 g_assert_cmphex(res, ==, ULLONG_MAX);
1270 g_assert(endptr == str + strlen(str));
1273 static void test_qemu_strtou64_underflow(void)
1275 const char *str = "-99999999999999999999999999999999999999999999";
1276 char f = 'X';
1277 const char *endptr = &f;
1278 uint64_t res = 999;
1279 int err;
1281 err = qemu_strtou64(str, &endptr, 0, &res);
1283 g_assert_cmpint(err, ==, -ERANGE);
1284 g_assert_cmphex(res, ==, -1ull);
1285 g_assert(endptr == str + strlen(str));
1288 static void test_qemu_strtou64_negative(void)
1290 const char *str = " \t -321";
1291 char f = 'X';
1292 const char *endptr = &f;
1293 uint64_t res = 999;
1294 int err;
1296 err = qemu_strtou64(str, &endptr, 0, &res);
1298 g_assert_cmpint(err, ==, 0);
1299 g_assert_cmpuint(res, ==, -321ull);
1300 g_assert(endptr == str + strlen(str));
1303 static void test_qemu_strtou64_full_correct(void)
1305 const char *str = "18446744073709551614";
1306 uint64_t res = 999;
1307 int err;
1309 err = qemu_strtou64(str, NULL, 0, &res);
1311 g_assert_cmpint(err, ==, 0);
1312 g_assert_cmpuint(res, ==, 18446744073709551614ull);
1315 static void test_qemu_strtou64_full_null(void)
1317 uint64_t res = 999;
1318 int err;
1320 err = qemu_strtou64(NULL, NULL, 0, &res);
1322 g_assert_cmpint(err, ==, -EINVAL);
1325 static void test_qemu_strtou64_full_empty(void)
1327 const char *str = "";
1328 uint64_t res = 999;
1329 int err;
1331 err = qemu_strtou64(str, NULL, 0, &res);
1333 g_assert_cmpint(err, ==, -EINVAL);
1336 static void test_qemu_strtou64_full_negative(void)
1338 const char *str = " \t -321";
1339 uint64_t res = 999;
1340 int err;
1342 err = qemu_strtou64(str, NULL, 0, &res);
1344 g_assert_cmpint(err, ==, 0);
1345 g_assert_cmpuint(res, ==, -321ull);
1348 static void test_qemu_strtou64_full_trailing(void)
1350 const char *str = "18446744073709551614xxxxxx";
1351 uint64_t res = 999;
1352 int err;
1354 err = qemu_strtou64(str, NULL, 0, &res);
1356 g_assert_cmpint(err, ==, -EINVAL);
1359 static void test_qemu_strtou64_full_max(void)
1361 char *str = g_strdup_printf("%lld", ULLONG_MAX);
1362 uint64_t res = 999;
1363 int err;
1365 err = qemu_strtou64(str, NULL, 0, &res);
1367 g_assert_cmpint(err, ==, 0);
1368 g_assert_cmphex(res, ==, ULLONG_MAX);
1369 g_free(str);
1372 static void test_qemu_strtosz_simple(void)
1374 const char *str;
1375 char *endptr = NULL;
1376 int err;
1377 uint64_t res = 0xbaadf00d;
1379 str = "0";
1380 err = qemu_strtosz(str, &endptr, &res);
1381 g_assert_cmpint(err, ==, 0);
1382 g_assert_cmpint(res, ==, 0);
1383 g_assert(endptr == str + 1);
1385 str = "12345";
1386 err = qemu_strtosz(str, &endptr, &res);
1387 g_assert_cmpint(err, ==, 0);
1388 g_assert_cmpint(res, ==, 12345);
1389 g_assert(endptr == str + 5);
1391 err = qemu_strtosz(str, NULL, &res);
1392 g_assert_cmpint(err, ==, 0);
1393 g_assert_cmpint(res, ==, 12345);
1395 /* Note: precision is 53 bits since we're parsing with strtod() */
1397 str = "9007199254740991"; /* 2^53-1 */
1398 err = qemu_strtosz(str, &endptr, &res);
1399 g_assert_cmpint(err, ==, 0);
1400 g_assert_cmpint(res, ==, 0x1fffffffffffff);
1401 g_assert(endptr == str + 16);
1403 str = "9007199254740992"; /* 2^53 */
1404 err = qemu_strtosz(str, &endptr, &res);
1405 g_assert_cmpint(err, ==, 0);
1406 g_assert_cmpint(res, ==, 0x20000000000000);
1407 g_assert(endptr == str + 16);
1409 str = "9007199254740993"; /* 2^53+1 */
1410 err = qemu_strtosz(str, &endptr, &res);
1411 g_assert_cmpint(err, ==, 0);
1412 g_assert_cmpint(res, ==, 0x20000000000000); /* rounded to 53 bits */
1413 g_assert(endptr == str + 16);
1415 str = "18446744073709549568"; /* 0xfffffffffffff800 (53 msbs set) */
1416 err = qemu_strtosz(str, &endptr, &res);
1417 g_assert_cmpint(err, ==, 0);
1418 g_assert_cmpint(res, ==, 0xfffffffffffff800);
1419 g_assert(endptr == str + 20);
1421 str = "18446744073709550591"; /* 0xfffffffffffffbff */
1422 err = qemu_strtosz(str, &endptr, &res);
1423 g_assert_cmpint(err, ==, 0);
1424 g_assert_cmpint(res, ==, 0xfffffffffffff800); /* rounded to 53 bits */
1425 g_assert(endptr == str + 20);
1427 /* 0x7ffffffffffffe00..0x7fffffffffffffff get rounded to
1428 * 0x8000000000000000, thus -ERANGE; see test_qemu_strtosz_erange() */
1431 static void test_qemu_strtosz_units(void)
1433 const char *none = "1";
1434 const char *b = "1B";
1435 const char *k = "1K";
1436 const char *m = "1M";
1437 const char *g = "1G";
1438 const char *t = "1T";
1439 const char *p = "1P";
1440 const char *e = "1E";
1441 int err;
1442 char *endptr = NULL;
1443 uint64_t res = 0xbaadf00d;
1445 /* default is M */
1446 err = qemu_strtosz_MiB(none, &endptr, &res);
1447 g_assert_cmpint(err, ==, 0);
1448 g_assert_cmpint(res, ==, M_BYTE);
1449 g_assert(endptr == none + 1);
1451 err = qemu_strtosz(b, &endptr, &res);
1452 g_assert_cmpint(err, ==, 0);
1453 g_assert_cmpint(res, ==, 1);
1454 g_assert(endptr == b + 2);
1456 err = qemu_strtosz(k, &endptr, &res);
1457 g_assert_cmpint(err, ==, 0);
1458 g_assert_cmpint(res, ==, K_BYTE);
1459 g_assert(endptr == k + 2);
1461 err = qemu_strtosz(m, &endptr, &res);
1462 g_assert_cmpint(err, ==, 0);
1463 g_assert_cmpint(res, ==, M_BYTE);
1464 g_assert(endptr == m + 2);
1466 err = qemu_strtosz(g, &endptr, &res);
1467 g_assert_cmpint(err, ==, 0);
1468 g_assert_cmpint(res, ==, G_BYTE);
1469 g_assert(endptr == g + 2);
1471 err = qemu_strtosz(t, &endptr, &res);
1472 g_assert_cmpint(err, ==, 0);
1473 g_assert_cmpint(res, ==, T_BYTE);
1474 g_assert(endptr == t + 2);
1476 err = qemu_strtosz(p, &endptr, &res);
1477 g_assert_cmpint(err, ==, 0);
1478 g_assert_cmpint(res, ==, P_BYTE);
1479 g_assert(endptr == p + 2);
1481 err = qemu_strtosz(e, &endptr, &res);
1482 g_assert_cmpint(err, ==, 0);
1483 g_assert_cmpint(res, ==, E_BYTE);
1484 g_assert(endptr == e + 2);
1487 static void test_qemu_strtosz_float(void)
1489 const char *str = "12.345M";
1490 int err;
1491 char *endptr = NULL;
1492 uint64_t res = 0xbaadf00d;
1494 err = qemu_strtosz(str, &endptr, &res);
1495 g_assert_cmpint(err, ==, 0);
1496 g_assert_cmpint(res, ==, 12.345 * M_BYTE);
1497 g_assert(endptr == str + 7);
1500 static void test_qemu_strtosz_invalid(void)
1502 const char *str;
1503 char *endptr = NULL;
1504 int err;
1505 uint64_t res = 0xbaadf00d;
1507 str = "";
1508 err = qemu_strtosz(str, &endptr, &res);
1509 g_assert_cmpint(err, ==, -EINVAL);
1510 g_assert(endptr == str);
1512 str = " \t ";
1513 err = qemu_strtosz(str, &endptr, &res);
1514 g_assert_cmpint(err, ==, -EINVAL);
1515 g_assert(endptr == str);
1517 str = "crap";
1518 err = qemu_strtosz(str, &endptr, &res);
1519 g_assert_cmpint(err, ==, -EINVAL);
1520 g_assert(endptr == str);
1523 static void test_qemu_strtosz_trailing(void)
1525 const char *str;
1526 char *endptr = NULL;
1527 int err;
1528 uint64_t res = 0xbaadf00d;
1530 str = "123xxx";
1531 err = qemu_strtosz_MiB(str, &endptr, &res);
1532 g_assert_cmpint(res, ==, 123 * M_BYTE);
1533 g_assert(endptr == str + 3);
1535 err = qemu_strtosz(str, NULL, &res);
1536 g_assert_cmpint(err, ==, -EINVAL);
1538 str = "1kiB";
1539 err = qemu_strtosz(str, &endptr, &res);
1540 g_assert_cmpint(err, ==, 0);
1541 g_assert_cmpint(res, ==, 1024);
1542 g_assert(endptr == str + 2);
1544 err = qemu_strtosz(str, NULL, &res);
1545 g_assert_cmpint(err, ==, -EINVAL);
1548 static void test_qemu_strtosz_erange(void)
1550 const char *str;
1551 char *endptr = NULL;
1552 int err;
1553 uint64_t res = 0xbaadf00d;
1555 str = "-1";
1556 err = qemu_strtosz(str, &endptr, &res);
1557 g_assert_cmpint(err, ==, -ERANGE);
1558 g_assert(endptr == str + 2);
1560 str = "18446744073709550592"; /* 0xfffffffffffffc00 */
1561 err = qemu_strtosz(str, &endptr, &res);
1562 g_assert_cmpint(err, ==, -ERANGE);
1563 g_assert(endptr == str + 20);
1565 str = "18446744073709551615"; /* 2^64-1 */
1566 err = qemu_strtosz(str, &endptr, &res);
1567 g_assert_cmpint(err, ==, -ERANGE);
1568 g_assert(endptr == str + 20);
1570 str = "18446744073709551616"; /* 2^64 */
1571 err = qemu_strtosz(str, &endptr, &res);
1572 g_assert_cmpint(err, ==, -ERANGE);
1573 g_assert(endptr == str + 20);
1575 str = "20E";
1576 err = qemu_strtosz(str, &endptr, &res);
1577 g_assert_cmpint(err, ==, -ERANGE);
1578 g_assert(endptr == str + 3);
1581 static void test_qemu_strtosz_metric(void)
1583 const char *str = "12345k";
1584 int err;
1585 char *endptr = NULL;
1586 uint64_t res = 0xbaadf00d;
1588 err = qemu_strtosz_metric(str, &endptr, &res);
1589 g_assert_cmpint(err, ==, 0);
1590 g_assert_cmpint(res, ==, 12345000);
1591 g_assert(endptr == str + 6);
1594 int main(int argc, char **argv)
1596 g_test_init(&argc, &argv, NULL);
1598 g_test_add_func("/cutils/parse_uint/null", test_parse_uint_null);
1599 g_test_add_func("/cutils/parse_uint/empty", test_parse_uint_empty);
1600 g_test_add_func("/cutils/parse_uint/whitespace",
1601 test_parse_uint_whitespace);
1602 g_test_add_func("/cutils/parse_uint/invalid", test_parse_uint_invalid);
1603 g_test_add_func("/cutils/parse_uint/trailing", test_parse_uint_trailing);
1604 g_test_add_func("/cutils/parse_uint/correct", test_parse_uint_correct);
1605 g_test_add_func("/cutils/parse_uint/octal", test_parse_uint_octal);
1606 g_test_add_func("/cutils/parse_uint/decimal", test_parse_uint_decimal);
1607 g_test_add_func("/cutils/parse_uint/llong_max", test_parse_uint_llong_max);
1608 g_test_add_func("/cutils/parse_uint/overflow", test_parse_uint_overflow);
1609 g_test_add_func("/cutils/parse_uint/negative", test_parse_uint_negative);
1610 g_test_add_func("/cutils/parse_uint_full/trailing",
1611 test_parse_uint_full_trailing);
1612 g_test_add_func("/cutils/parse_uint_full/correct",
1613 test_parse_uint_full_correct);
1615 /* qemu_strtol() tests */
1616 g_test_add_func("/cutils/qemu_strtol/correct",
1617 test_qemu_strtol_correct);
1618 g_test_add_func("/cutils/qemu_strtol/null",
1619 test_qemu_strtol_null);
1620 g_test_add_func("/cutils/qemu_strtol/empty",
1621 test_qemu_strtol_empty);
1622 g_test_add_func("/cutils/qemu_strtol/whitespace",
1623 test_qemu_strtol_whitespace);
1624 g_test_add_func("/cutils/qemu_strtol/invalid",
1625 test_qemu_strtol_invalid);
1626 g_test_add_func("/cutils/qemu_strtol/trailing",
1627 test_qemu_strtol_trailing);
1628 g_test_add_func("/cutils/qemu_strtol/octal",
1629 test_qemu_strtol_octal);
1630 g_test_add_func("/cutils/qemu_strtol/decimal",
1631 test_qemu_strtol_decimal);
1632 g_test_add_func("/cutils/qemu_strtol/hex",
1633 test_qemu_strtol_hex);
1634 g_test_add_func("/cutils/qemu_strtol/max",
1635 test_qemu_strtol_max);
1636 g_test_add_func("/cutils/qemu_strtol/overflow",
1637 test_qemu_strtol_overflow);
1638 g_test_add_func("/cutils/qemu_strtol/underflow",
1639 test_qemu_strtol_underflow);
1640 g_test_add_func("/cutils/qemu_strtol/negative",
1641 test_qemu_strtol_negative);
1642 g_test_add_func("/cutils/qemu_strtol_full/correct",
1643 test_qemu_strtol_full_correct);
1644 g_test_add_func("/cutils/qemu_strtol_full/null",
1645 test_qemu_strtol_full_null);
1646 g_test_add_func("/cutils/qemu_strtol_full/empty",
1647 test_qemu_strtol_full_empty);
1648 g_test_add_func("/cutils/qemu_strtol_full/negative",
1649 test_qemu_strtol_full_negative);
1650 g_test_add_func("/cutils/qemu_strtol_full/trailing",
1651 test_qemu_strtol_full_trailing);
1652 g_test_add_func("/cutils/qemu_strtol_full/max",
1653 test_qemu_strtol_full_max);
1655 /* qemu_strtoul() tests */
1656 g_test_add_func("/cutils/qemu_strtoul/correct",
1657 test_qemu_strtoul_correct);
1658 g_test_add_func("/cutils/qemu_strtoul/null",
1659 test_qemu_strtoul_null);
1660 g_test_add_func("/cutils/qemu_strtoul/empty",
1661 test_qemu_strtoul_empty);
1662 g_test_add_func("/cutils/qemu_strtoul/whitespace",
1663 test_qemu_strtoul_whitespace);
1664 g_test_add_func("/cutils/qemu_strtoul/invalid",
1665 test_qemu_strtoul_invalid);
1666 g_test_add_func("/cutils/qemu_strtoul/trailing",
1667 test_qemu_strtoul_trailing);
1668 g_test_add_func("/cutils/qemu_strtoul/octal",
1669 test_qemu_strtoul_octal);
1670 g_test_add_func("/cutils/qemu_strtoul/decimal",
1671 test_qemu_strtoul_decimal);
1672 g_test_add_func("/cutils/qemu_strtoul/hex",
1673 test_qemu_strtoul_hex);
1674 g_test_add_func("/cutils/qemu_strtoul/max",
1675 test_qemu_strtoul_max);
1676 g_test_add_func("/cutils/qemu_strtoul/overflow",
1677 test_qemu_strtoul_overflow);
1678 g_test_add_func("/cutils/qemu_strtoul/underflow",
1679 test_qemu_strtoul_underflow);
1680 g_test_add_func("/cutils/qemu_strtoul/negative",
1681 test_qemu_strtoul_negative);
1682 g_test_add_func("/cutils/qemu_strtoul_full/correct",
1683 test_qemu_strtoul_full_correct);
1684 g_test_add_func("/cutils/qemu_strtoul_full/null",
1685 test_qemu_strtoul_full_null);
1686 g_test_add_func("/cutils/qemu_strtoul_full/empty",
1687 test_qemu_strtoul_full_empty);
1688 g_test_add_func("/cutils/qemu_strtoul_full/negative",
1689 test_qemu_strtoul_full_negative);
1690 g_test_add_func("/cutils/qemu_strtoul_full/trailing",
1691 test_qemu_strtoul_full_trailing);
1692 g_test_add_func("/cutils/qemu_strtoul_full/max",
1693 test_qemu_strtoul_full_max);
1695 /* qemu_strtoi64() tests */
1696 g_test_add_func("/cutils/qemu_strtoi64/correct",
1697 test_qemu_strtoi64_correct);
1698 g_test_add_func("/cutils/qemu_strtoi64/null",
1699 test_qemu_strtoi64_null);
1700 g_test_add_func("/cutils/qemu_strtoi64/empty",
1701 test_qemu_strtoi64_empty);
1702 g_test_add_func("/cutils/qemu_strtoi64/whitespace",
1703 test_qemu_strtoi64_whitespace);
1704 g_test_add_func("/cutils/qemu_strtoi64/invalid"
1706 test_qemu_strtoi64_invalid);
1707 g_test_add_func("/cutils/qemu_strtoi64/trailing",
1708 test_qemu_strtoi64_trailing);
1709 g_test_add_func("/cutils/qemu_strtoi64/octal",
1710 test_qemu_strtoi64_octal);
1711 g_test_add_func("/cutils/qemu_strtoi64/decimal",
1712 test_qemu_strtoi64_decimal);
1713 g_test_add_func("/cutils/qemu_strtoi64/hex",
1714 test_qemu_strtoi64_hex);
1715 g_test_add_func("/cutils/qemu_strtoi64/max",
1716 test_qemu_strtoi64_max);
1717 g_test_add_func("/cutils/qemu_strtoi64/overflow",
1718 test_qemu_strtoi64_overflow);
1719 g_test_add_func("/cutils/qemu_strtoi64/underflow",
1720 test_qemu_strtoi64_underflow);
1721 g_test_add_func("/cutils/qemu_strtoi64/negative",
1722 test_qemu_strtoi64_negative);
1723 g_test_add_func("/cutils/qemu_strtoi64_full/correct",
1724 test_qemu_strtoi64_full_correct);
1725 g_test_add_func("/cutils/qemu_strtoi64_full/null",
1726 test_qemu_strtoi64_full_null);
1727 g_test_add_func("/cutils/qemu_strtoi64_full/empty",
1728 test_qemu_strtoi64_full_empty);
1729 g_test_add_func("/cutils/qemu_strtoi64_full/negative",
1730 test_qemu_strtoi64_full_negative);
1731 g_test_add_func("/cutils/qemu_strtoi64_full/trailing",
1732 test_qemu_strtoi64_full_trailing);
1733 g_test_add_func("/cutils/qemu_strtoi64_full/max",
1734 test_qemu_strtoi64_full_max);
1736 /* qemu_strtou64() tests */
1737 g_test_add_func("/cutils/qemu_strtou64/correct",
1738 test_qemu_strtou64_correct);
1739 g_test_add_func("/cutils/qemu_strtou64/null",
1740 test_qemu_strtou64_null);
1741 g_test_add_func("/cutils/qemu_strtou64/empty",
1742 test_qemu_strtou64_empty);
1743 g_test_add_func("/cutils/qemu_strtou64/whitespace",
1744 test_qemu_strtou64_whitespace);
1745 g_test_add_func("/cutils/qemu_strtou64/invalid",
1746 test_qemu_strtou64_invalid);
1747 g_test_add_func("/cutils/qemu_strtou64/trailing",
1748 test_qemu_strtou64_trailing);
1749 g_test_add_func("/cutils/qemu_strtou64/octal",
1750 test_qemu_strtou64_octal);
1751 g_test_add_func("/cutils/qemu_strtou64/decimal",
1752 test_qemu_strtou64_decimal);
1753 g_test_add_func("/cutils/qemu_strtou64/hex",
1754 test_qemu_strtou64_hex);
1755 g_test_add_func("/cutils/qemu_strtou64/max",
1756 test_qemu_strtou64_max);
1757 g_test_add_func("/cutils/qemu_strtou64/overflow",
1758 test_qemu_strtou64_overflow);
1759 g_test_add_func("/cutils/qemu_strtou64/underflow",
1760 test_qemu_strtou64_underflow);
1761 g_test_add_func("/cutils/qemu_strtou64/negative",
1762 test_qemu_strtou64_negative);
1763 g_test_add_func("/cutils/qemu_strtou64_full/correct",
1764 test_qemu_strtou64_full_correct);
1765 g_test_add_func("/cutils/qemu_strtou64_full/null",
1766 test_qemu_strtou64_full_null);
1767 g_test_add_func("/cutils/qemu_strtou64_full/empty",
1768 test_qemu_strtou64_full_empty);
1769 g_test_add_func("/cutils/qemu_strtou64_full/negative",
1770 test_qemu_strtou64_full_negative);
1771 g_test_add_func("/cutils/qemu_strtou64_full/trailing",
1772 test_qemu_strtou64_full_trailing);
1773 g_test_add_func("/cutils/qemu_strtou64_full/max",
1774 test_qemu_strtou64_full_max);
1776 g_test_add_func("/cutils/strtosz/simple",
1777 test_qemu_strtosz_simple);
1778 g_test_add_func("/cutils/strtosz/units",
1779 test_qemu_strtosz_units);
1780 g_test_add_func("/cutils/strtosz/float",
1781 test_qemu_strtosz_float);
1782 g_test_add_func("/cutils/strtosz/invalid",
1783 test_qemu_strtosz_invalid);
1784 g_test_add_func("/cutils/strtosz/trailing",
1785 test_qemu_strtosz_trailing);
1786 g_test_add_func("/cutils/strtosz/erange",
1787 test_qemu_strtosz_erange);
1788 g_test_add_func("/cutils/strtosz/metric",
1789 test_qemu_strtosz_metric);
1791 return g_test_run();