net/vde: print error on vde_open() failure
[qemu/kevin.git] / tests / test-cutils.c
blob64a489c2e96bdc7577dc44c3966190dbb2358d19
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_strtoi_correct(void)
228 const char *str = "12345 foo";
229 char f = 'X';
230 const char *endptr = &f;
231 int res = 999;
232 int err;
234 err = qemu_strtoi(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_strtoi_null(void)
243 char f = 'X';
244 const char *endptr = &f;
245 int res = 999;
246 int err;
248 err = qemu_strtoi(NULL, &endptr, 0, &res);
250 g_assert_cmpint(err, ==, -EINVAL);
251 g_assert(endptr == NULL);
254 static void test_qemu_strtoi_empty(void)
256 const char *str = "";
257 char f = 'X';
258 const char *endptr = &f;
259 int res = 999;
260 int err;
262 err = qemu_strtoi(str, &endptr, 0, &res);
264 g_assert_cmpint(err, ==, -EINVAL);
265 g_assert(endptr == str);
268 static void test_qemu_strtoi_whitespace(void)
270 const char *str = " \t ";
271 char f = 'X';
272 const char *endptr = &f;
273 int res = 999;
274 int err;
276 err = qemu_strtoi(str, &endptr, 0, &res);
278 g_assert_cmpint(err, ==, -EINVAL);
279 g_assert(endptr == str);
282 static void test_qemu_strtoi_invalid(void)
284 const char *str = " xxxx \t abc";
285 char f = 'X';
286 const char *endptr = &f;
287 int res = 999;
288 int err;
290 err = qemu_strtoi(str, &endptr, 0, &res);
292 g_assert_cmpint(err, ==, -EINVAL);
293 g_assert(endptr == str);
296 static void test_qemu_strtoi_trailing(void)
298 const char *str = "123xxx";
299 char f = 'X';
300 const char *endptr = &f;
301 int res = 999;
302 int err;
304 err = qemu_strtoi(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_strtoi_octal(void)
313 const char *str = "0123";
314 char f = 'X';
315 const char *endptr = &f;
316 int res = 999;
317 int err;
319 err = qemu_strtoi(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_strtoi(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_strtoi_decimal(void)
336 const char *str = "0123";
337 char f = 'X';
338 const char *endptr = &f;
339 int res = 999;
340 int err;
342 err = qemu_strtoi(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_strtoi(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_strtoi_hex(void)
360 const char *str = "0123";
361 char f = 'X';
362 const char *endptr = &f;
363 int res = 999;
364 int err;
366 err = qemu_strtoi(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_strtoi(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_strtoi_max(void)
384 char *str = g_strdup_printf("%d", INT_MAX);
385 char f = 'X';
386 const char *endptr = &f;
387 int res = 999;
388 int err;
390 err = qemu_strtoi(str, &endptr, 0, &res);
392 g_assert_cmpint(err, ==, 0);
393 g_assert_cmpint(res, ==, INT_MAX);
394 g_assert(endptr == str + strlen(str));
395 g_free(str);
398 static void test_qemu_strtoi_overflow(void)
400 char *str = g_strdup_printf("%lld", (long long)INT_MAX + 1ll);
401 char f = 'X';
402 const char *endptr = &f;
403 int res = 999;
404 int err;
406 err = qemu_strtoi(str, &endptr, 0, &res);
408 g_assert_cmpint(err, ==, -ERANGE);
409 g_assert_cmpint(res, ==, INT_MAX);
410 g_assert(endptr == str + strlen(str));
411 g_free(str);
414 static void test_qemu_strtoi_underflow(void)
416 char *str = g_strdup_printf("%lld", (long long)INT_MIN - 1ll);
417 char f = 'X';
418 const char *endptr = &f;
419 int res = 999;
420 int err;
422 err = qemu_strtoi(str, &endptr, 0, &res);
424 g_assert_cmpint(err, ==, -ERANGE);
425 g_assert_cmpint(res, ==, INT_MIN);
426 g_assert(endptr == str + strlen(str));
427 g_free(str);
430 static void test_qemu_strtoi_negative(void)
432 const char *str = " \t -321";
433 char f = 'X';
434 const char *endptr = &f;
435 int res = 999;
436 int err;
438 err = qemu_strtoi(str, &endptr, 0, &res);
440 g_assert_cmpint(err, ==, 0);
441 g_assert_cmpint(res, ==, -321);
442 g_assert(endptr == str + strlen(str));
445 static void test_qemu_strtoi_full_correct(void)
447 const char *str = "123";
448 int res = 999;
449 int err;
451 err = qemu_strtoi(str, NULL, 0, &res);
453 g_assert_cmpint(err, ==, 0);
454 g_assert_cmpint(res, ==, 123);
457 static void test_qemu_strtoi_full_null(void)
459 char f = 'X';
460 const char *endptr = &f;
461 int res = 999;
462 int err;
464 err = qemu_strtoi(NULL, &endptr, 0, &res);
466 g_assert_cmpint(err, ==, -EINVAL);
467 g_assert(endptr == NULL);
470 static void test_qemu_strtoi_full_empty(void)
472 const char *str = "";
473 int res = 999L;
474 int err;
476 err = qemu_strtoi(str, NULL, 0, &res);
478 g_assert_cmpint(err, ==, -EINVAL);
481 static void test_qemu_strtoi_full_negative(void)
483 const char *str = " \t -321";
484 int res = 999;
485 int err;
487 err = qemu_strtoi(str, NULL, 0, &res);
489 g_assert_cmpint(err, ==, 0);
490 g_assert_cmpint(res, ==, -321);
493 static void test_qemu_strtoi_full_trailing(void)
495 const char *str = "123xxx";
496 int res;
497 int err;
499 err = qemu_strtoi(str, NULL, 0, &res);
501 g_assert_cmpint(err, ==, -EINVAL);
504 static void test_qemu_strtoi_full_max(void)
506 char *str = g_strdup_printf("%d", INT_MAX);
507 int res;
508 int err;
510 err = qemu_strtoi(str, NULL, 0, &res);
512 g_assert_cmpint(err, ==, 0);
513 g_assert_cmpint(res, ==, INT_MAX);
514 g_free(str);
517 static void test_qemu_strtoui_correct(void)
519 const char *str = "12345 foo";
520 char f = 'X';
521 const char *endptr = &f;
522 unsigned int res = 999;
523 int err;
525 err = qemu_strtoui(str, &endptr, 0, &res);
527 g_assert_cmpint(err, ==, 0);
528 g_assert_cmpuint(res, ==, 12345);
529 g_assert(endptr == str + 5);
532 static void test_qemu_strtoui_null(void)
534 char f = 'X';
535 const char *endptr = &f;
536 unsigned int res = 999;
537 int err;
539 err = qemu_strtoui(NULL, &endptr, 0, &res);
541 g_assert_cmpint(err, ==, -EINVAL);
542 g_assert(endptr == NULL);
545 static void test_qemu_strtoui_empty(void)
547 const char *str = "";
548 char f = 'X';
549 const char *endptr = &f;
550 unsigned int res = 999;
551 int err;
553 err = qemu_strtoui(str, &endptr, 0, &res);
555 g_assert_cmpint(err, ==, -EINVAL);
556 g_assert(endptr == str);
559 static void test_qemu_strtoui_whitespace(void)
561 const char *str = " \t ";
562 char f = 'X';
563 const char *endptr = &f;
564 unsigned int res = 999;
565 int err;
567 err = qemu_strtoui(str, &endptr, 0, &res);
569 g_assert_cmpint(err, ==, -EINVAL);
570 g_assert(endptr == str);
573 static void test_qemu_strtoui_invalid(void)
575 const char *str = " xxxx \t abc";
576 char f = 'X';
577 const char *endptr = &f;
578 unsigned int res = 999;
579 int err;
581 err = qemu_strtoui(str, &endptr, 0, &res);
583 g_assert_cmpint(err, ==, -EINVAL);
584 g_assert(endptr == str);
587 static void test_qemu_strtoui_trailing(void)
589 const char *str = "123xxx";
590 char f = 'X';
591 const char *endptr = &f;
592 unsigned int res = 999;
593 int err;
595 err = qemu_strtoui(str, &endptr, 0, &res);
597 g_assert_cmpint(err, ==, 0);
598 g_assert_cmpuint(res, ==, 123);
599 g_assert(endptr == str + 3);
602 static void test_qemu_strtoui_octal(void)
604 const char *str = "0123";
605 char f = 'X';
606 const char *endptr = &f;
607 unsigned int res = 999;
608 int err;
610 err = qemu_strtoui(str, &endptr, 8, &res);
612 g_assert_cmpint(err, ==, 0);
613 g_assert_cmpuint(res, ==, 0123);
614 g_assert(endptr == str + strlen(str));
616 res = 999;
617 endptr = &f;
618 err = qemu_strtoui(str, &endptr, 0, &res);
620 g_assert_cmpint(err, ==, 0);
621 g_assert_cmpuint(res, ==, 0123);
622 g_assert(endptr == str + strlen(str));
625 static void test_qemu_strtoui_decimal(void)
627 const char *str = "0123";
628 char f = 'X';
629 const char *endptr = &f;
630 unsigned int res = 999;
631 int err;
633 err = qemu_strtoui(str, &endptr, 10, &res);
635 g_assert_cmpint(err, ==, 0);
636 g_assert_cmpuint(res, ==, 123);
637 g_assert(endptr == str + strlen(str));
639 str = "123";
640 res = 999;
641 endptr = &f;
642 err = qemu_strtoui(str, &endptr, 0, &res);
644 g_assert_cmpint(err, ==, 0);
645 g_assert_cmpuint(res, ==, 123);
646 g_assert(endptr == str + strlen(str));
649 static void test_qemu_strtoui_hex(void)
651 const char *str = "0123";
652 char f = 'X';
653 const char *endptr = &f;
654 unsigned int res = 999;
655 int err;
657 err = qemu_strtoui(str, &endptr, 16, &res);
659 g_assert_cmpint(err, ==, 0);
660 g_assert_cmphex(res, ==, 0x123);
661 g_assert(endptr == str + strlen(str));
663 str = "0x123";
664 res = 999;
665 endptr = &f;
666 err = qemu_strtoui(str, &endptr, 0, &res);
668 g_assert_cmpint(err, ==, 0);
669 g_assert_cmphex(res, ==, 0x123);
670 g_assert(endptr == str + strlen(str));
673 static void test_qemu_strtoui_max(void)
675 char *str = g_strdup_printf("%u", UINT_MAX);
676 char f = 'X';
677 const char *endptr = &f;
678 unsigned int res = 999;
679 int err;
681 err = qemu_strtoui(str, &endptr, 0, &res);
683 g_assert_cmpint(err, ==, 0);
684 g_assert_cmphex(res, ==, UINT_MAX);
685 g_assert(endptr == str + strlen(str));
686 g_free(str);
689 static void test_qemu_strtoui_overflow(void)
691 char *str = g_strdup_printf("%lld", (long long)UINT_MAX + 1ll);
692 char f = 'X';
693 const char *endptr = &f;
694 unsigned int res = 999;
695 int err;
697 err = qemu_strtoui(str, &endptr, 0, &res);
699 g_assert_cmpint(err, ==, -ERANGE);
700 g_assert_cmphex(res, ==, UINT_MAX);
701 g_assert(endptr == str + strlen(str));
702 g_free(str);
705 static void test_qemu_strtoui_underflow(void)
707 char *str = g_strdup_printf("%lld", (long long)INT_MIN - 1ll);
708 char f = 'X';
709 const char *endptr = &f;
710 unsigned int res = 999;
711 int err;
713 err = qemu_strtoui(str, &endptr, 0, &res);
715 g_assert_cmpint(err, ==, -ERANGE);
716 g_assert_cmpuint(res, ==, (unsigned int)-1);
717 g_assert(endptr == str + strlen(str));
718 g_free(str);
721 static void test_qemu_strtoui_negative(void)
723 const char *str = " \t -321";
724 char f = 'X';
725 const char *endptr = &f;
726 unsigned int res = 999;
727 int err;
729 err = qemu_strtoui(str, &endptr, 0, &res);
731 g_assert_cmpint(err, ==, 0);
732 g_assert_cmpuint(res, ==, (unsigned int)-321);
733 g_assert(endptr == str + strlen(str));
736 static void test_qemu_strtoui_full_correct(void)
738 const char *str = "123";
739 unsigned int res = 999;
740 int err;
742 err = qemu_strtoui(str, NULL, 0, &res);
744 g_assert_cmpint(err, ==, 0);
745 g_assert_cmpuint(res, ==, 123);
748 static void test_qemu_strtoui_full_null(void)
750 unsigned int res = 999;
751 int err;
753 err = qemu_strtoui(NULL, NULL, 0, &res);
755 g_assert_cmpint(err, ==, -EINVAL);
758 static void test_qemu_strtoui_full_empty(void)
760 const char *str = "";
761 unsigned int res = 999;
762 int err;
764 err = qemu_strtoui(str, NULL, 0, &res);
766 g_assert_cmpint(err, ==, -EINVAL);
768 static void test_qemu_strtoui_full_negative(void)
770 const char *str = " \t -321";
771 unsigned int res = 999;
772 int err;
774 err = qemu_strtoui(str, NULL, 0, &res);
775 g_assert_cmpint(err, ==, 0);
776 g_assert_cmpuint(res, ==, (unsigned int)-321);
779 static void test_qemu_strtoui_full_trailing(void)
781 const char *str = "123xxx";
782 unsigned int res;
783 int err;
785 err = qemu_strtoui(str, NULL, 0, &res);
787 g_assert_cmpint(err, ==, -EINVAL);
790 static void test_qemu_strtoui_full_max(void)
792 char *str = g_strdup_printf("%u", UINT_MAX);
793 unsigned int res = 999;
794 int err;
796 err = qemu_strtoui(str, NULL, 0, &res);
798 g_assert_cmpint(err, ==, 0);
799 g_assert_cmphex(res, ==, UINT_MAX);
800 g_free(str);
803 static void test_qemu_strtol_correct(void)
805 const char *str = "12345 foo";
806 char f = 'X';
807 const char *endptr = &f;
808 long res = 999;
809 int err;
811 err = qemu_strtol(str, &endptr, 0, &res);
813 g_assert_cmpint(err, ==, 0);
814 g_assert_cmpint(res, ==, 12345);
815 g_assert(endptr == str + 5);
818 static void test_qemu_strtol_null(void)
820 char f = 'X';
821 const char *endptr = &f;
822 long res = 999;
823 int err;
825 err = qemu_strtol(NULL, &endptr, 0, &res);
827 g_assert_cmpint(err, ==, -EINVAL);
828 g_assert(endptr == NULL);
831 static void test_qemu_strtol_empty(void)
833 const char *str = "";
834 char f = 'X';
835 const char *endptr = &f;
836 long res = 999;
837 int err;
839 err = qemu_strtol(str, &endptr, 0, &res);
841 g_assert_cmpint(err, ==, -EINVAL);
842 g_assert(endptr == str);
845 static void test_qemu_strtol_whitespace(void)
847 const char *str = " \t ";
848 char f = 'X';
849 const char *endptr = &f;
850 long res = 999;
851 int err;
853 err = qemu_strtol(str, &endptr, 0, &res);
855 g_assert_cmpint(err, ==, -EINVAL);
856 g_assert(endptr == str);
859 static void test_qemu_strtol_invalid(void)
861 const char *str = " xxxx \t abc";
862 char f = 'X';
863 const char *endptr = &f;
864 long res = 999;
865 int err;
867 err = qemu_strtol(str, &endptr, 0, &res);
869 g_assert_cmpint(err, ==, -EINVAL);
870 g_assert(endptr == str);
873 static void test_qemu_strtol_trailing(void)
875 const char *str = "123xxx";
876 char f = 'X';
877 const char *endptr = &f;
878 long res = 999;
879 int err;
881 err = qemu_strtol(str, &endptr, 0, &res);
883 g_assert_cmpint(err, ==, 0);
884 g_assert_cmpint(res, ==, 123);
885 g_assert(endptr == str + 3);
888 static void test_qemu_strtol_octal(void)
890 const char *str = "0123";
891 char f = 'X';
892 const char *endptr = &f;
893 long res = 999;
894 int err;
896 err = qemu_strtol(str, &endptr, 8, &res);
898 g_assert_cmpint(err, ==, 0);
899 g_assert_cmpint(res, ==, 0123);
900 g_assert(endptr == str + strlen(str));
902 res = 999;
903 endptr = &f;
904 err = qemu_strtol(str, &endptr, 0, &res);
906 g_assert_cmpint(err, ==, 0);
907 g_assert_cmpint(res, ==, 0123);
908 g_assert(endptr == str + strlen(str));
911 static void test_qemu_strtol_decimal(void)
913 const char *str = "0123";
914 char f = 'X';
915 const char *endptr = &f;
916 long res = 999;
917 int err;
919 err = qemu_strtol(str, &endptr, 10, &res);
921 g_assert_cmpint(err, ==, 0);
922 g_assert_cmpint(res, ==, 123);
923 g_assert(endptr == str + strlen(str));
925 str = "123";
926 res = 999;
927 endptr = &f;
928 err = qemu_strtol(str, &endptr, 0, &res);
930 g_assert_cmpint(err, ==, 0);
931 g_assert_cmpint(res, ==, 123);
932 g_assert(endptr == str + strlen(str));
935 static void test_qemu_strtol_hex(void)
937 const char *str = "0123";
938 char f = 'X';
939 const char *endptr = &f;
940 long res = 999;
941 int err;
943 err = qemu_strtol(str, &endptr, 16, &res);
945 g_assert_cmpint(err, ==, 0);
946 g_assert_cmpint(res, ==, 0x123);
947 g_assert(endptr == str + strlen(str));
949 str = "0x123";
950 res = 999;
951 endptr = &f;
952 err = qemu_strtol(str, &endptr, 0, &res);
954 g_assert_cmpint(err, ==, 0);
955 g_assert_cmpint(res, ==, 0x123);
956 g_assert(endptr == str + strlen(str));
959 static void test_qemu_strtol_max(void)
961 char *str = g_strdup_printf("%ld", LONG_MAX);
962 char f = 'X';
963 const char *endptr = &f;
964 long res = 999;
965 int err;
967 err = qemu_strtol(str, &endptr, 0, &res);
969 g_assert_cmpint(err, ==, 0);
970 g_assert_cmpint(res, ==, LONG_MAX);
971 g_assert(endptr == str + strlen(str));
972 g_free(str);
975 static void test_qemu_strtol_overflow(void)
977 const char *str = "99999999999999999999999999999999999999999999";
978 char f = 'X';
979 const char *endptr = &f;
980 long res = 999;
981 int err;
983 err = qemu_strtol(str, &endptr, 0, &res);
985 g_assert_cmpint(err, ==, -ERANGE);
986 g_assert_cmpint(res, ==, LONG_MAX);
987 g_assert(endptr == str + strlen(str));
990 static void test_qemu_strtol_underflow(void)
992 const char *str = "-99999999999999999999999999999999999999999999";
993 char f = 'X';
994 const char *endptr = &f;
995 long res = 999;
996 int err;
998 err = qemu_strtol(str, &endptr, 0, &res);
1000 g_assert_cmpint(err, ==, -ERANGE);
1001 g_assert_cmpint(res, ==, LONG_MIN);
1002 g_assert(endptr == str + strlen(str));
1005 static void test_qemu_strtol_negative(void)
1007 const char *str = " \t -321";
1008 char f = 'X';
1009 const char *endptr = &f;
1010 long res = 999;
1011 int err;
1013 err = qemu_strtol(str, &endptr, 0, &res);
1015 g_assert_cmpint(err, ==, 0);
1016 g_assert_cmpint(res, ==, -321);
1017 g_assert(endptr == str + strlen(str));
1020 static void test_qemu_strtol_full_correct(void)
1022 const char *str = "123";
1023 long res = 999;
1024 int err;
1026 err = qemu_strtol(str, NULL, 0, &res);
1028 g_assert_cmpint(err, ==, 0);
1029 g_assert_cmpint(res, ==, 123);
1032 static void test_qemu_strtol_full_null(void)
1034 char f = 'X';
1035 const char *endptr = &f;
1036 long res = 999;
1037 int err;
1039 err = qemu_strtol(NULL, &endptr, 0, &res);
1041 g_assert_cmpint(err, ==, -EINVAL);
1042 g_assert(endptr == NULL);
1045 static void test_qemu_strtol_full_empty(void)
1047 const char *str = "";
1048 long res = 999L;
1049 int err;
1051 err = qemu_strtol(str, NULL, 0, &res);
1053 g_assert_cmpint(err, ==, -EINVAL);
1056 static void test_qemu_strtol_full_negative(void)
1058 const char *str = " \t -321";
1059 long res = 999;
1060 int err;
1062 err = qemu_strtol(str, NULL, 0, &res);
1064 g_assert_cmpint(err, ==, 0);
1065 g_assert_cmpint(res, ==, -321);
1068 static void test_qemu_strtol_full_trailing(void)
1070 const char *str = "123xxx";
1071 long res;
1072 int err;
1074 err = qemu_strtol(str, NULL, 0, &res);
1076 g_assert_cmpint(err, ==, -EINVAL);
1079 static void test_qemu_strtol_full_max(void)
1081 char *str = g_strdup_printf("%ld", LONG_MAX);
1082 long res;
1083 int err;
1085 err = qemu_strtol(str, NULL, 0, &res);
1087 g_assert_cmpint(err, ==, 0);
1088 g_assert_cmpint(res, ==, LONG_MAX);
1089 g_free(str);
1092 static void test_qemu_strtoul_correct(void)
1094 const char *str = "12345 foo";
1095 char f = 'X';
1096 const char *endptr = &f;
1097 unsigned long res = 999;
1098 int err;
1100 err = qemu_strtoul(str, &endptr, 0, &res);
1102 g_assert_cmpint(err, ==, 0);
1103 g_assert_cmpuint(res, ==, 12345);
1104 g_assert(endptr == str + 5);
1107 static void test_qemu_strtoul_null(void)
1109 char f = 'X';
1110 const char *endptr = &f;
1111 unsigned long res = 999;
1112 int err;
1114 err = qemu_strtoul(NULL, &endptr, 0, &res);
1116 g_assert_cmpint(err, ==, -EINVAL);
1117 g_assert(endptr == NULL);
1120 static void test_qemu_strtoul_empty(void)
1122 const char *str = "";
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, ==, -EINVAL);
1131 g_assert(endptr == str);
1134 static void test_qemu_strtoul_whitespace(void)
1136 const char *str = " \t ";
1137 char f = 'X';
1138 const char *endptr = &f;
1139 unsigned long res = 999;
1140 int err;
1142 err = qemu_strtoul(str, &endptr, 0, &res);
1144 g_assert_cmpint(err, ==, -EINVAL);
1145 g_assert(endptr == str);
1148 static void test_qemu_strtoul_invalid(void)
1150 const char *str = " xxxx \t abc";
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_trailing(void)
1164 const char *str = "123xxx";
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, ==, 0);
1173 g_assert_cmpuint(res, ==, 123);
1174 g_assert(endptr == str + 3);
1177 static void test_qemu_strtoul_octal(void)
1179 const char *str = "0123";
1180 char f = 'X';
1181 const char *endptr = &f;
1182 unsigned long res = 999;
1183 int err;
1185 err = qemu_strtoul(str, &endptr, 8, &res);
1187 g_assert_cmpint(err, ==, 0);
1188 g_assert_cmpuint(res, ==, 0123);
1189 g_assert(endptr == str + strlen(str));
1191 res = 999;
1192 endptr = &f;
1193 err = qemu_strtoul(str, &endptr, 0, &res);
1195 g_assert_cmpint(err, ==, 0);
1196 g_assert_cmpuint(res, ==, 0123);
1197 g_assert(endptr == str + strlen(str));
1200 static void test_qemu_strtoul_decimal(void)
1202 const char *str = "0123";
1203 char f = 'X';
1204 const char *endptr = &f;
1205 unsigned long res = 999;
1206 int err;
1208 err = qemu_strtoul(str, &endptr, 10, &res);
1210 g_assert_cmpint(err, ==, 0);
1211 g_assert_cmpuint(res, ==, 123);
1212 g_assert(endptr == str + strlen(str));
1214 str = "123";
1215 res = 999;
1216 endptr = &f;
1217 err = qemu_strtoul(str, &endptr, 0, &res);
1219 g_assert_cmpint(err, ==, 0);
1220 g_assert_cmpuint(res, ==, 123);
1221 g_assert(endptr == str + strlen(str));
1224 static void test_qemu_strtoul_hex(void)
1226 const char *str = "0123";
1227 char f = 'X';
1228 const char *endptr = &f;
1229 unsigned long res = 999;
1230 int err;
1232 err = qemu_strtoul(str, &endptr, 16, &res);
1234 g_assert_cmpint(err, ==, 0);
1235 g_assert_cmphex(res, ==, 0x123);
1236 g_assert(endptr == str + strlen(str));
1238 str = "0x123";
1239 res = 999;
1240 endptr = &f;
1241 err = qemu_strtoul(str, &endptr, 0, &res);
1243 g_assert_cmpint(err, ==, 0);
1244 g_assert_cmphex(res, ==, 0x123);
1245 g_assert(endptr == str + strlen(str));
1248 static void test_qemu_strtoul_max(void)
1250 char *str = g_strdup_printf("%lu", ULONG_MAX);
1251 char f = 'X';
1252 const char *endptr = &f;
1253 unsigned long res = 999;
1254 int err;
1256 err = qemu_strtoul(str, &endptr, 0, &res);
1258 g_assert_cmpint(err, ==, 0);
1259 g_assert_cmphex(res, ==, ULONG_MAX);
1260 g_assert(endptr == str + strlen(str));
1261 g_free(str);
1264 static void test_qemu_strtoul_overflow(void)
1266 const char *str = "99999999999999999999999999999999999999999999";
1267 char f = 'X';
1268 const char *endptr = &f;
1269 unsigned long res = 999;
1270 int err;
1272 err = qemu_strtoul(str, &endptr, 0, &res);
1274 g_assert_cmpint(err, ==, -ERANGE);
1275 g_assert_cmphex(res, ==, ULONG_MAX);
1276 g_assert(endptr == str + strlen(str));
1279 static void test_qemu_strtoul_underflow(void)
1281 const char *str = "-99999999999999999999999999999999999999999999";
1282 char f = 'X';
1283 const char *endptr = &f;
1284 unsigned long res = 999;
1285 int err;
1287 err = qemu_strtoul(str, &endptr, 0, &res);
1289 g_assert_cmpint(err, ==, -ERANGE);
1290 g_assert_cmpuint(res, ==, -1ul);
1291 g_assert(endptr == str + strlen(str));
1294 static void test_qemu_strtoul_negative(void)
1296 const char *str = " \t -321";
1297 char f = 'X';
1298 const char *endptr = &f;
1299 unsigned long res = 999;
1300 int err;
1302 err = qemu_strtoul(str, &endptr, 0, &res);
1304 g_assert_cmpint(err, ==, 0);
1305 g_assert_cmpuint(res, ==, -321ul);
1306 g_assert(endptr == str + strlen(str));
1309 static void test_qemu_strtoul_full_correct(void)
1311 const char *str = "123";
1312 unsigned long res = 999;
1313 int err;
1315 err = qemu_strtoul(str, NULL, 0, &res);
1317 g_assert_cmpint(err, ==, 0);
1318 g_assert_cmpuint(res, ==, 123);
1321 static void test_qemu_strtoul_full_null(void)
1323 unsigned long res = 999;
1324 int err;
1326 err = qemu_strtoul(NULL, NULL, 0, &res);
1328 g_assert_cmpint(err, ==, -EINVAL);
1331 static void test_qemu_strtoul_full_empty(void)
1333 const char *str = "";
1334 unsigned long res = 999;
1335 int err;
1337 err = qemu_strtoul(str, NULL, 0, &res);
1339 g_assert_cmpint(err, ==, -EINVAL);
1341 static void test_qemu_strtoul_full_negative(void)
1343 const char *str = " \t -321";
1344 unsigned long res = 999;
1345 int err;
1347 err = qemu_strtoul(str, NULL, 0, &res);
1348 g_assert_cmpint(err, ==, 0);
1349 g_assert_cmpuint(res, ==, -321ul);
1352 static void test_qemu_strtoul_full_trailing(void)
1354 const char *str = "123xxx";
1355 unsigned long res;
1356 int err;
1358 err = qemu_strtoul(str, NULL, 0, &res);
1360 g_assert_cmpint(err, ==, -EINVAL);
1363 static void test_qemu_strtoul_full_max(void)
1365 char *str = g_strdup_printf("%lu", ULONG_MAX);
1366 unsigned long res = 999;
1367 int err;
1369 err = qemu_strtoul(str, NULL, 0, &res);
1371 g_assert_cmpint(err, ==, 0);
1372 g_assert_cmphex(res, ==, ULONG_MAX);
1373 g_free(str);
1376 static void test_qemu_strtoi64_correct(void)
1378 const char *str = "12345 foo";
1379 char f = 'X';
1380 const char *endptr = &f;
1381 int64_t res = 999;
1382 int err;
1384 err = qemu_strtoi64(str, &endptr, 0, &res);
1386 g_assert_cmpint(err, ==, 0);
1387 g_assert_cmpint(res, ==, 12345);
1388 g_assert(endptr == str + 5);
1391 static void test_qemu_strtoi64_null(void)
1393 char f = 'X';
1394 const char *endptr = &f;
1395 int64_t res = 999;
1396 int err;
1398 err = qemu_strtoi64(NULL, &endptr, 0, &res);
1400 g_assert_cmpint(err, ==, -EINVAL);
1401 g_assert(endptr == NULL);
1404 static void test_qemu_strtoi64_empty(void)
1406 const char *str = "";
1407 char f = 'X';
1408 const char *endptr = &f;
1409 int64_t res = 999;
1410 int err;
1412 err = qemu_strtoi64(str, &endptr, 0, &res);
1414 g_assert_cmpint(err, ==, -EINVAL);
1415 g_assert(endptr == str);
1418 static void test_qemu_strtoi64_whitespace(void)
1420 const char *str = " \t ";
1421 char f = 'X';
1422 const char *endptr = &f;
1423 int64_t res = 999;
1424 int err;
1426 err = qemu_strtoi64(str, &endptr, 0, &res);
1428 g_assert_cmpint(err, ==, -EINVAL);
1429 g_assert(endptr == str);
1432 static void test_qemu_strtoi64_invalid(void)
1434 const char *str = " xxxx \t abc";
1435 char f = 'X';
1436 const char *endptr = &f;
1437 int64_t res = 999;
1438 int err;
1440 err = qemu_strtoi64(str, &endptr, 0, &res);
1442 g_assert_cmpint(err, ==, -EINVAL);
1443 g_assert(endptr == str);
1446 static void test_qemu_strtoi64_trailing(void)
1448 const char *str = "123xxx";
1449 char f = 'X';
1450 const char *endptr = &f;
1451 int64_t res = 999;
1452 int err;
1454 err = qemu_strtoi64(str, &endptr, 0, &res);
1456 g_assert_cmpint(err, ==, 0);
1457 g_assert_cmpint(res, ==, 123);
1458 g_assert(endptr == str + 3);
1461 static void test_qemu_strtoi64_octal(void)
1463 const char *str = "0123";
1464 char f = 'X';
1465 const char *endptr = &f;
1466 int64_t res = 999;
1467 int err;
1469 err = qemu_strtoi64(str, &endptr, 8, &res);
1471 g_assert_cmpint(err, ==, 0);
1472 g_assert_cmpint(res, ==, 0123);
1473 g_assert(endptr == str + strlen(str));
1475 endptr = &f;
1476 res = 999;
1477 err = qemu_strtoi64(str, &endptr, 0, &res);
1479 g_assert_cmpint(err, ==, 0);
1480 g_assert_cmpint(res, ==, 0123);
1481 g_assert(endptr == str + strlen(str));
1484 static void test_qemu_strtoi64_decimal(void)
1486 const char *str = "0123";
1487 char f = 'X';
1488 const char *endptr = &f;
1489 int64_t res = 999;
1490 int err;
1492 err = qemu_strtoi64(str, &endptr, 10, &res);
1494 g_assert_cmpint(err, ==, 0);
1495 g_assert_cmpint(res, ==, 123);
1496 g_assert(endptr == str + strlen(str));
1498 str = "123";
1499 endptr = &f;
1500 res = 999;
1501 err = qemu_strtoi64(str, &endptr, 0, &res);
1503 g_assert_cmpint(err, ==, 0);
1504 g_assert_cmpint(res, ==, 123);
1505 g_assert(endptr == str + strlen(str));
1508 static void test_qemu_strtoi64_hex(void)
1510 const char *str = "0123";
1511 char f = 'X';
1512 const char *endptr = &f;
1513 int64_t res = 999;
1514 int err;
1516 err = qemu_strtoi64(str, &endptr, 16, &res);
1518 g_assert_cmpint(err, ==, 0);
1519 g_assert_cmpint(res, ==, 0x123);
1520 g_assert(endptr == str + strlen(str));
1522 str = "0x123";
1523 endptr = &f;
1524 res = 999;
1525 err = qemu_strtoi64(str, &endptr, 0, &res);
1527 g_assert_cmpint(err, ==, 0);
1528 g_assert_cmpint(res, ==, 0x123);
1529 g_assert(endptr == str + strlen(str));
1532 static void test_qemu_strtoi64_max(void)
1534 char *str = g_strdup_printf("%lld", LLONG_MAX);
1535 char f = 'X';
1536 const char *endptr = &f;
1537 int64_t res = 999;
1538 int err;
1540 err = qemu_strtoi64(str, &endptr, 0, &res);
1542 g_assert_cmpint(err, ==, 0);
1543 g_assert_cmpint(res, ==, LLONG_MAX);
1544 g_assert(endptr == str + strlen(str));
1545 g_free(str);
1548 static void test_qemu_strtoi64_overflow(void)
1550 const char *str = "99999999999999999999999999999999999999999999";
1551 char f = 'X';
1552 const char *endptr = &f;
1553 int64_t res = 999;
1554 int err;
1556 err = qemu_strtoi64(str, &endptr, 0, &res);
1558 g_assert_cmpint(err, ==, -ERANGE);
1559 g_assert_cmpint(res, ==, LLONG_MAX);
1560 g_assert(endptr == str + strlen(str));
1563 static void test_qemu_strtoi64_underflow(void)
1565 const char *str = "-99999999999999999999999999999999999999999999";
1566 char f = 'X';
1567 const char *endptr = &f;
1568 int64_t res = 999;
1569 int err;
1571 err = qemu_strtoi64(str, &endptr, 0, &res);
1573 g_assert_cmpint(err, ==, -ERANGE);
1574 g_assert_cmpint(res, ==, LLONG_MIN);
1575 g_assert(endptr == str + strlen(str));
1578 static void test_qemu_strtoi64_negative(void)
1580 const char *str = " \t -321";
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, ==, -321);
1590 g_assert(endptr == str + strlen(str));
1593 static void test_qemu_strtoi64_full_correct(void)
1595 const char *str = "123";
1596 int64_t res = 999;
1597 int err;
1599 err = qemu_strtoi64(str, NULL, 0, &res);
1601 g_assert_cmpint(err, ==, 0);
1602 g_assert_cmpint(res, ==, 123);
1605 static void test_qemu_strtoi64_full_null(void)
1607 int64_t res = 999;
1608 int err;
1610 err = qemu_strtoi64(NULL, NULL, 0, &res);
1612 g_assert_cmpint(err, ==, -EINVAL);
1615 static void test_qemu_strtoi64_full_empty(void)
1617 const char *str = "";
1618 int64_t res = 999;
1619 int err;
1621 err = qemu_strtoi64(str, NULL, 0, &res);
1623 g_assert_cmpint(err, ==, -EINVAL);
1626 static void test_qemu_strtoi64_full_negative(void)
1628 const char *str = " \t -321";
1629 int64_t res = 999;
1630 int err;
1632 err = qemu_strtoi64(str, NULL, 0, &res);
1634 g_assert_cmpint(err, ==, 0);
1635 g_assert_cmpint(res, ==, -321);
1638 static void test_qemu_strtoi64_full_trailing(void)
1640 const char *str = "123xxx";
1641 int64_t res = 999;
1642 int err;
1644 err = qemu_strtoi64(str, NULL, 0, &res);
1646 g_assert_cmpint(err, ==, -EINVAL);
1649 static void test_qemu_strtoi64_full_max(void)
1652 char *str = g_strdup_printf("%lld", LLONG_MAX);
1653 int64_t res;
1654 int err;
1656 err = qemu_strtoi64(str, NULL, 0, &res);
1658 g_assert_cmpint(err, ==, 0);
1659 g_assert_cmpint(res, ==, LLONG_MAX);
1660 g_free(str);
1663 static void test_qemu_strtou64_correct(void)
1665 const char *str = "12345 foo";
1666 char f = 'X';
1667 const char *endptr = &f;
1668 uint64_t res = 999;
1669 int err;
1671 err = qemu_strtou64(str, &endptr, 0, &res);
1673 g_assert_cmpint(err, ==, 0);
1674 g_assert_cmpuint(res, ==, 12345);
1675 g_assert(endptr == str + 5);
1678 static void test_qemu_strtou64_null(void)
1680 char f = 'X';
1681 const char *endptr = &f;
1682 uint64_t res = 999;
1683 int err;
1685 err = qemu_strtou64(NULL, &endptr, 0, &res);
1687 g_assert_cmpint(err, ==, -EINVAL);
1688 g_assert(endptr == NULL);
1691 static void test_qemu_strtou64_empty(void)
1693 const char *str = "";
1694 char f = 'X';
1695 const char *endptr = &f;
1696 uint64_t res = 999;
1697 int err;
1699 err = qemu_strtou64(str, &endptr, 0, &res);
1701 g_assert_cmpint(err, ==, -EINVAL);
1702 g_assert(endptr == str);
1705 static void test_qemu_strtou64_whitespace(void)
1707 const char *str = " \t ";
1708 char f = 'X';
1709 const char *endptr = &f;
1710 uint64_t res = 999;
1711 int err;
1713 err = qemu_strtou64(str, &endptr, 0, &res);
1715 g_assert_cmpint(err, ==, -EINVAL);
1716 g_assert(endptr == str);
1719 static void test_qemu_strtou64_invalid(void)
1721 const char *str = " xxxx \t abc";
1722 char f = 'X';
1723 const char *endptr = &f;
1724 uint64_t res = 999;
1725 int err;
1727 err = qemu_strtou64(str, &endptr, 0, &res);
1729 g_assert_cmpint(err, ==, -EINVAL);
1730 g_assert(endptr == str);
1733 static void test_qemu_strtou64_trailing(void)
1735 const char *str = "123xxx";
1736 char f = 'X';
1737 const char *endptr = &f;
1738 uint64_t res = 999;
1739 int err;
1741 err = qemu_strtou64(str, &endptr, 0, &res);
1743 g_assert_cmpint(err, ==, 0);
1744 g_assert_cmpuint(res, ==, 123);
1745 g_assert(endptr == str + 3);
1748 static void test_qemu_strtou64_octal(void)
1750 const char *str = "0123";
1751 char f = 'X';
1752 const char *endptr = &f;
1753 uint64_t res = 999;
1754 int err;
1756 err = qemu_strtou64(str, &endptr, 8, &res);
1758 g_assert_cmpint(err, ==, 0);
1759 g_assert_cmpuint(res, ==, 0123);
1760 g_assert(endptr == str + strlen(str));
1762 endptr = &f;
1763 res = 999;
1764 err = qemu_strtou64(str, &endptr, 0, &res);
1766 g_assert_cmpint(err, ==, 0);
1767 g_assert_cmpuint(res, ==, 0123);
1768 g_assert(endptr == str + strlen(str));
1771 static void test_qemu_strtou64_decimal(void)
1773 const char *str = "0123";
1774 char f = 'X';
1775 const char *endptr = &f;
1776 uint64_t res = 999;
1777 int err;
1779 err = qemu_strtou64(str, &endptr, 10, &res);
1781 g_assert_cmpint(err, ==, 0);
1782 g_assert_cmpuint(res, ==, 123);
1783 g_assert(endptr == str + strlen(str));
1785 str = "123";
1786 endptr = &f;
1787 res = 999;
1788 err = qemu_strtou64(str, &endptr, 0, &res);
1790 g_assert_cmpint(err, ==, 0);
1791 g_assert_cmpuint(res, ==, 123);
1792 g_assert(endptr == str + strlen(str));
1795 static void test_qemu_strtou64_hex(void)
1797 const char *str = "0123";
1798 char f = 'X';
1799 const char *endptr = &f;
1800 uint64_t res = 999;
1801 int err;
1803 err = qemu_strtou64(str, &endptr, 16, &res);
1805 g_assert_cmpint(err, ==, 0);
1806 g_assert_cmphex(res, ==, 0x123);
1807 g_assert(endptr == str + strlen(str));
1809 str = "0x123";
1810 endptr = &f;
1811 res = 999;
1812 err = qemu_strtou64(str, &endptr, 0, &res);
1814 g_assert_cmpint(err, ==, 0);
1815 g_assert_cmphex(res, ==, 0x123);
1816 g_assert(endptr == str + strlen(str));
1819 static void test_qemu_strtou64_max(void)
1821 char *str = g_strdup_printf("%llu", ULLONG_MAX);
1822 char f = 'X';
1823 const char *endptr = &f;
1824 uint64_t res = 999;
1825 int err;
1827 err = qemu_strtou64(str, &endptr, 0, &res);
1829 g_assert_cmpint(err, ==, 0);
1830 g_assert_cmphex(res, ==, ULLONG_MAX);
1831 g_assert(endptr == str + strlen(str));
1832 g_free(str);
1835 static void test_qemu_strtou64_overflow(void)
1837 const char *str = "99999999999999999999999999999999999999999999";
1838 char f = 'X';
1839 const char *endptr = &f;
1840 uint64_t res = 999;
1841 int err;
1843 err = qemu_strtou64(str, &endptr, 0, &res);
1845 g_assert_cmpint(err, ==, -ERANGE);
1846 g_assert_cmphex(res, ==, ULLONG_MAX);
1847 g_assert(endptr == str + strlen(str));
1850 static void test_qemu_strtou64_underflow(void)
1852 const char *str = "-99999999999999999999999999999999999999999999";
1853 char f = 'X';
1854 const char *endptr = &f;
1855 uint64_t res = 999;
1856 int err;
1858 err = qemu_strtou64(str, &endptr, 0, &res);
1860 g_assert_cmpint(err, ==, -ERANGE);
1861 g_assert_cmphex(res, ==, -1ull);
1862 g_assert(endptr == str + strlen(str));
1865 static void test_qemu_strtou64_negative(void)
1867 const char *str = " \t -321";
1868 char f = 'X';
1869 const char *endptr = &f;
1870 uint64_t res = 999;
1871 int err;
1873 err = qemu_strtou64(str, &endptr, 0, &res);
1875 g_assert_cmpint(err, ==, 0);
1876 g_assert_cmpuint(res, ==, -321ull);
1877 g_assert(endptr == str + strlen(str));
1880 static void test_qemu_strtou64_full_correct(void)
1882 const char *str = "18446744073709551614";
1883 uint64_t res = 999;
1884 int err;
1886 err = qemu_strtou64(str, NULL, 0, &res);
1888 g_assert_cmpint(err, ==, 0);
1889 g_assert_cmpuint(res, ==, 18446744073709551614ull);
1892 static void test_qemu_strtou64_full_null(void)
1894 uint64_t res = 999;
1895 int err;
1897 err = qemu_strtou64(NULL, NULL, 0, &res);
1899 g_assert_cmpint(err, ==, -EINVAL);
1902 static void test_qemu_strtou64_full_empty(void)
1904 const char *str = "";
1905 uint64_t res = 999;
1906 int err;
1908 err = qemu_strtou64(str, NULL, 0, &res);
1910 g_assert_cmpint(err, ==, -EINVAL);
1913 static void test_qemu_strtou64_full_negative(void)
1915 const char *str = " \t -321";
1916 uint64_t res = 999;
1917 int err;
1919 err = qemu_strtou64(str, NULL, 0, &res);
1921 g_assert_cmpint(err, ==, 0);
1922 g_assert_cmpuint(res, ==, -321ull);
1925 static void test_qemu_strtou64_full_trailing(void)
1927 const char *str = "18446744073709551614xxxxxx";
1928 uint64_t res = 999;
1929 int err;
1931 err = qemu_strtou64(str, NULL, 0, &res);
1933 g_assert_cmpint(err, ==, -EINVAL);
1936 static void test_qemu_strtou64_full_max(void)
1938 char *str = g_strdup_printf("%lld", ULLONG_MAX);
1939 uint64_t res = 999;
1940 int err;
1942 err = qemu_strtou64(str, NULL, 0, &res);
1944 g_assert_cmpint(err, ==, 0);
1945 g_assert_cmphex(res, ==, ULLONG_MAX);
1946 g_free(str);
1949 static void test_qemu_strtosz_simple(void)
1951 const char *str;
1952 char *endptr = NULL;
1953 int err;
1954 uint64_t res = 0xbaadf00d;
1956 str = "0";
1957 err = qemu_strtosz(str, &endptr, &res);
1958 g_assert_cmpint(err, ==, 0);
1959 g_assert_cmpint(res, ==, 0);
1960 g_assert(endptr == str + 1);
1962 str = "12345";
1963 err = qemu_strtosz(str, &endptr, &res);
1964 g_assert_cmpint(err, ==, 0);
1965 g_assert_cmpint(res, ==, 12345);
1966 g_assert(endptr == str + 5);
1968 err = qemu_strtosz(str, NULL, &res);
1969 g_assert_cmpint(err, ==, 0);
1970 g_assert_cmpint(res, ==, 12345);
1972 /* Note: precision is 53 bits since we're parsing with strtod() */
1974 str = "9007199254740991"; /* 2^53-1 */
1975 err = qemu_strtosz(str, &endptr, &res);
1976 g_assert_cmpint(err, ==, 0);
1977 g_assert_cmpint(res, ==, 0x1fffffffffffff);
1978 g_assert(endptr == str + 16);
1980 str = "9007199254740992"; /* 2^53 */
1981 err = qemu_strtosz(str, &endptr, &res);
1982 g_assert_cmpint(err, ==, 0);
1983 g_assert_cmpint(res, ==, 0x20000000000000);
1984 g_assert(endptr == str + 16);
1986 str = "9007199254740993"; /* 2^53+1 */
1987 err = qemu_strtosz(str, &endptr, &res);
1988 g_assert_cmpint(err, ==, 0);
1989 g_assert_cmpint(res, ==, 0x20000000000000); /* rounded to 53 bits */
1990 g_assert(endptr == str + 16);
1992 str = "18446744073709549568"; /* 0xfffffffffffff800 (53 msbs set) */
1993 err = qemu_strtosz(str, &endptr, &res);
1994 g_assert_cmpint(err, ==, 0);
1995 g_assert_cmpint(res, ==, 0xfffffffffffff800);
1996 g_assert(endptr == str + 20);
1998 str = "18446744073709550591"; /* 0xfffffffffffffbff */
1999 err = qemu_strtosz(str, &endptr, &res);
2000 g_assert_cmpint(err, ==, 0);
2001 g_assert_cmpint(res, ==, 0xfffffffffffff800); /* rounded to 53 bits */
2002 g_assert(endptr == str + 20);
2004 /* 0x7ffffffffffffe00..0x7fffffffffffffff get rounded to
2005 * 0x8000000000000000, thus -ERANGE; see test_qemu_strtosz_erange() */
2008 static void test_qemu_strtosz_units(void)
2010 const char *none = "1";
2011 const char *b = "1B";
2012 const char *k = "1K";
2013 const char *m = "1M";
2014 const char *g = "1G";
2015 const char *t = "1T";
2016 const char *p = "1P";
2017 const char *e = "1E";
2018 int err;
2019 char *endptr = NULL;
2020 uint64_t res = 0xbaadf00d;
2022 /* default is M */
2023 err = qemu_strtosz_MiB(none, &endptr, &res);
2024 g_assert_cmpint(err, ==, 0);
2025 g_assert_cmpint(res, ==, M_BYTE);
2026 g_assert(endptr == none + 1);
2028 err = qemu_strtosz(b, &endptr, &res);
2029 g_assert_cmpint(err, ==, 0);
2030 g_assert_cmpint(res, ==, 1);
2031 g_assert(endptr == b + 2);
2033 err = qemu_strtosz(k, &endptr, &res);
2034 g_assert_cmpint(err, ==, 0);
2035 g_assert_cmpint(res, ==, K_BYTE);
2036 g_assert(endptr == k + 2);
2038 err = qemu_strtosz(m, &endptr, &res);
2039 g_assert_cmpint(err, ==, 0);
2040 g_assert_cmpint(res, ==, M_BYTE);
2041 g_assert(endptr == m + 2);
2043 err = qemu_strtosz(g, &endptr, &res);
2044 g_assert_cmpint(err, ==, 0);
2045 g_assert_cmpint(res, ==, G_BYTE);
2046 g_assert(endptr == g + 2);
2048 err = qemu_strtosz(t, &endptr, &res);
2049 g_assert_cmpint(err, ==, 0);
2050 g_assert_cmpint(res, ==, T_BYTE);
2051 g_assert(endptr == t + 2);
2053 err = qemu_strtosz(p, &endptr, &res);
2054 g_assert_cmpint(err, ==, 0);
2055 g_assert_cmpint(res, ==, P_BYTE);
2056 g_assert(endptr == p + 2);
2058 err = qemu_strtosz(e, &endptr, &res);
2059 g_assert_cmpint(err, ==, 0);
2060 g_assert_cmpint(res, ==, E_BYTE);
2061 g_assert(endptr == e + 2);
2064 static void test_qemu_strtosz_float(void)
2066 const char *str = "12.345M";
2067 int err;
2068 char *endptr = NULL;
2069 uint64_t res = 0xbaadf00d;
2071 err = qemu_strtosz(str, &endptr, &res);
2072 g_assert_cmpint(err, ==, 0);
2073 g_assert_cmpint(res, ==, 12.345 * M_BYTE);
2074 g_assert(endptr == str + 7);
2077 static void test_qemu_strtosz_invalid(void)
2079 const char *str;
2080 char *endptr = NULL;
2081 int err;
2082 uint64_t res = 0xbaadf00d;
2084 str = "";
2085 err = qemu_strtosz(str, &endptr, &res);
2086 g_assert_cmpint(err, ==, -EINVAL);
2087 g_assert(endptr == str);
2089 str = " \t ";
2090 err = qemu_strtosz(str, &endptr, &res);
2091 g_assert_cmpint(err, ==, -EINVAL);
2092 g_assert(endptr == str);
2094 str = "crap";
2095 err = qemu_strtosz(str, &endptr, &res);
2096 g_assert_cmpint(err, ==, -EINVAL);
2097 g_assert(endptr == str);
2100 static void test_qemu_strtosz_trailing(void)
2102 const char *str;
2103 char *endptr = NULL;
2104 int err;
2105 uint64_t res = 0xbaadf00d;
2107 str = "123xxx";
2108 err = qemu_strtosz_MiB(str, &endptr, &res);
2109 g_assert_cmpint(res, ==, 123 * M_BYTE);
2110 g_assert(endptr == str + 3);
2112 err = qemu_strtosz(str, NULL, &res);
2113 g_assert_cmpint(err, ==, -EINVAL);
2115 str = "1kiB";
2116 err = qemu_strtosz(str, &endptr, &res);
2117 g_assert_cmpint(err, ==, 0);
2118 g_assert_cmpint(res, ==, 1024);
2119 g_assert(endptr == str + 2);
2121 err = qemu_strtosz(str, NULL, &res);
2122 g_assert_cmpint(err, ==, -EINVAL);
2125 static void test_qemu_strtosz_erange(void)
2127 const char *str;
2128 char *endptr = NULL;
2129 int err;
2130 uint64_t res = 0xbaadf00d;
2132 str = "-1";
2133 err = qemu_strtosz(str, &endptr, &res);
2134 g_assert_cmpint(err, ==, -ERANGE);
2135 g_assert(endptr == str + 2);
2137 str = "18446744073709550592"; /* 0xfffffffffffffc00 */
2138 err = qemu_strtosz(str, &endptr, &res);
2139 g_assert_cmpint(err, ==, -ERANGE);
2140 g_assert(endptr == str + 20);
2142 str = "18446744073709551615"; /* 2^64-1 */
2143 err = qemu_strtosz(str, &endptr, &res);
2144 g_assert_cmpint(err, ==, -ERANGE);
2145 g_assert(endptr == str + 20);
2147 str = "18446744073709551616"; /* 2^64 */
2148 err = qemu_strtosz(str, &endptr, &res);
2149 g_assert_cmpint(err, ==, -ERANGE);
2150 g_assert(endptr == str + 20);
2152 str = "20E";
2153 err = qemu_strtosz(str, &endptr, &res);
2154 g_assert_cmpint(err, ==, -ERANGE);
2155 g_assert(endptr == str + 3);
2158 static void test_qemu_strtosz_metric(void)
2160 const char *str = "12345k";
2161 int err;
2162 char *endptr = NULL;
2163 uint64_t res = 0xbaadf00d;
2165 err = qemu_strtosz_metric(str, &endptr, &res);
2166 g_assert_cmpint(err, ==, 0);
2167 g_assert_cmpint(res, ==, 12345000);
2168 g_assert(endptr == str + 6);
2171 int main(int argc, char **argv)
2173 g_test_init(&argc, &argv, NULL);
2175 g_test_add_func("/cutils/parse_uint/null", test_parse_uint_null);
2176 g_test_add_func("/cutils/parse_uint/empty", test_parse_uint_empty);
2177 g_test_add_func("/cutils/parse_uint/whitespace",
2178 test_parse_uint_whitespace);
2179 g_test_add_func("/cutils/parse_uint/invalid", test_parse_uint_invalid);
2180 g_test_add_func("/cutils/parse_uint/trailing", test_parse_uint_trailing);
2181 g_test_add_func("/cutils/parse_uint/correct", test_parse_uint_correct);
2182 g_test_add_func("/cutils/parse_uint/octal", test_parse_uint_octal);
2183 g_test_add_func("/cutils/parse_uint/decimal", test_parse_uint_decimal);
2184 g_test_add_func("/cutils/parse_uint/llong_max", test_parse_uint_llong_max);
2185 g_test_add_func("/cutils/parse_uint/overflow", test_parse_uint_overflow);
2186 g_test_add_func("/cutils/parse_uint/negative", test_parse_uint_negative);
2187 g_test_add_func("/cutils/parse_uint_full/trailing",
2188 test_parse_uint_full_trailing);
2189 g_test_add_func("/cutils/parse_uint_full/correct",
2190 test_parse_uint_full_correct);
2192 /* qemu_strtoi() tests */
2193 g_test_add_func("/cutils/qemu_strtoi/correct",
2194 test_qemu_strtoi_correct);
2195 g_test_add_func("/cutils/qemu_strtoi/null",
2196 test_qemu_strtoi_null);
2197 g_test_add_func("/cutils/qemu_strtoi/empty",
2198 test_qemu_strtoi_empty);
2199 g_test_add_func("/cutils/qemu_strtoi/whitespace",
2200 test_qemu_strtoi_whitespace);
2201 g_test_add_func("/cutils/qemu_strtoi/invalid",
2202 test_qemu_strtoi_invalid);
2203 g_test_add_func("/cutils/qemu_strtoi/trailing",
2204 test_qemu_strtoi_trailing);
2205 g_test_add_func("/cutils/qemu_strtoi/octal",
2206 test_qemu_strtoi_octal);
2207 g_test_add_func("/cutils/qemu_strtoi/decimal",
2208 test_qemu_strtoi_decimal);
2209 g_test_add_func("/cutils/qemu_strtoi/hex",
2210 test_qemu_strtoi_hex);
2211 g_test_add_func("/cutils/qemu_strtoi/max",
2212 test_qemu_strtoi_max);
2213 g_test_add_func("/cutils/qemu_strtoi/overflow",
2214 test_qemu_strtoi_overflow);
2215 g_test_add_func("/cutils/qemu_strtoi/underflow",
2216 test_qemu_strtoi_underflow);
2217 g_test_add_func("/cutils/qemu_strtoi/negative",
2218 test_qemu_strtoi_negative);
2219 g_test_add_func("/cutils/qemu_strtoi_full/correct",
2220 test_qemu_strtoi_full_correct);
2221 g_test_add_func("/cutils/qemu_strtoi_full/null",
2222 test_qemu_strtoi_full_null);
2223 g_test_add_func("/cutils/qemu_strtoi_full/empty",
2224 test_qemu_strtoi_full_empty);
2225 g_test_add_func("/cutils/qemu_strtoi_full/negative",
2226 test_qemu_strtoi_full_negative);
2227 g_test_add_func("/cutils/qemu_strtoi_full/trailing",
2228 test_qemu_strtoi_full_trailing);
2229 g_test_add_func("/cutils/qemu_strtoi_full/max",
2230 test_qemu_strtoi_full_max);
2232 /* qemu_strtoui() tests */
2233 g_test_add_func("/cutils/qemu_strtoui/correct",
2234 test_qemu_strtoui_correct);
2235 g_test_add_func("/cutils/qemu_strtoui/null",
2236 test_qemu_strtoui_null);
2237 g_test_add_func("/cutils/qemu_strtoui/empty",
2238 test_qemu_strtoui_empty);
2239 g_test_add_func("/cutils/qemu_strtoui/whitespace",
2240 test_qemu_strtoui_whitespace);
2241 g_test_add_func("/cutils/qemu_strtoui/invalid",
2242 test_qemu_strtoui_invalid);
2243 g_test_add_func("/cutils/qemu_strtoui/trailing",
2244 test_qemu_strtoui_trailing);
2245 g_test_add_func("/cutils/qemu_strtoui/octal",
2246 test_qemu_strtoui_octal);
2247 g_test_add_func("/cutils/qemu_strtoui/decimal",
2248 test_qemu_strtoui_decimal);
2249 g_test_add_func("/cutils/qemu_strtoui/hex",
2250 test_qemu_strtoui_hex);
2251 g_test_add_func("/cutils/qemu_strtoui/max",
2252 test_qemu_strtoui_max);
2253 g_test_add_func("/cutils/qemu_strtoui/overflow",
2254 test_qemu_strtoui_overflow);
2255 g_test_add_func("/cutils/qemu_strtoui/underflow",
2256 test_qemu_strtoui_underflow);
2257 g_test_add_func("/cutils/qemu_strtoui/negative",
2258 test_qemu_strtoui_negative);
2259 g_test_add_func("/cutils/qemu_strtoui_full/correct",
2260 test_qemu_strtoui_full_correct);
2261 g_test_add_func("/cutils/qemu_strtoui_full/null",
2262 test_qemu_strtoui_full_null);
2263 g_test_add_func("/cutils/qemu_strtoui_full/empty",
2264 test_qemu_strtoui_full_empty);
2265 g_test_add_func("/cutils/qemu_strtoui_full/negative",
2266 test_qemu_strtoui_full_negative);
2267 g_test_add_func("/cutils/qemu_strtoui_full/trailing",
2268 test_qemu_strtoui_full_trailing);
2269 g_test_add_func("/cutils/qemu_strtoui_full/max",
2270 test_qemu_strtoui_full_max);
2272 /* qemu_strtol() tests */
2273 g_test_add_func("/cutils/qemu_strtol/correct",
2274 test_qemu_strtol_correct);
2275 g_test_add_func("/cutils/qemu_strtol/null",
2276 test_qemu_strtol_null);
2277 g_test_add_func("/cutils/qemu_strtol/empty",
2278 test_qemu_strtol_empty);
2279 g_test_add_func("/cutils/qemu_strtol/whitespace",
2280 test_qemu_strtol_whitespace);
2281 g_test_add_func("/cutils/qemu_strtol/invalid",
2282 test_qemu_strtol_invalid);
2283 g_test_add_func("/cutils/qemu_strtol/trailing",
2284 test_qemu_strtol_trailing);
2285 g_test_add_func("/cutils/qemu_strtol/octal",
2286 test_qemu_strtol_octal);
2287 g_test_add_func("/cutils/qemu_strtol/decimal",
2288 test_qemu_strtol_decimal);
2289 g_test_add_func("/cutils/qemu_strtol/hex",
2290 test_qemu_strtol_hex);
2291 g_test_add_func("/cutils/qemu_strtol/max",
2292 test_qemu_strtol_max);
2293 g_test_add_func("/cutils/qemu_strtol/overflow",
2294 test_qemu_strtol_overflow);
2295 g_test_add_func("/cutils/qemu_strtol/underflow",
2296 test_qemu_strtol_underflow);
2297 g_test_add_func("/cutils/qemu_strtol/negative",
2298 test_qemu_strtol_negative);
2299 g_test_add_func("/cutils/qemu_strtol_full/correct",
2300 test_qemu_strtol_full_correct);
2301 g_test_add_func("/cutils/qemu_strtol_full/null",
2302 test_qemu_strtol_full_null);
2303 g_test_add_func("/cutils/qemu_strtol_full/empty",
2304 test_qemu_strtol_full_empty);
2305 g_test_add_func("/cutils/qemu_strtol_full/negative",
2306 test_qemu_strtol_full_negative);
2307 g_test_add_func("/cutils/qemu_strtol_full/trailing",
2308 test_qemu_strtol_full_trailing);
2309 g_test_add_func("/cutils/qemu_strtol_full/max",
2310 test_qemu_strtol_full_max);
2312 /* qemu_strtoul() tests */
2313 g_test_add_func("/cutils/qemu_strtoul/correct",
2314 test_qemu_strtoul_correct);
2315 g_test_add_func("/cutils/qemu_strtoul/null",
2316 test_qemu_strtoul_null);
2317 g_test_add_func("/cutils/qemu_strtoul/empty",
2318 test_qemu_strtoul_empty);
2319 g_test_add_func("/cutils/qemu_strtoul/whitespace",
2320 test_qemu_strtoul_whitespace);
2321 g_test_add_func("/cutils/qemu_strtoul/invalid",
2322 test_qemu_strtoul_invalid);
2323 g_test_add_func("/cutils/qemu_strtoul/trailing",
2324 test_qemu_strtoul_trailing);
2325 g_test_add_func("/cutils/qemu_strtoul/octal",
2326 test_qemu_strtoul_octal);
2327 g_test_add_func("/cutils/qemu_strtoul/decimal",
2328 test_qemu_strtoul_decimal);
2329 g_test_add_func("/cutils/qemu_strtoul/hex",
2330 test_qemu_strtoul_hex);
2331 g_test_add_func("/cutils/qemu_strtoul/max",
2332 test_qemu_strtoul_max);
2333 g_test_add_func("/cutils/qemu_strtoul/overflow",
2334 test_qemu_strtoul_overflow);
2335 g_test_add_func("/cutils/qemu_strtoul/underflow",
2336 test_qemu_strtoul_underflow);
2337 g_test_add_func("/cutils/qemu_strtoul/negative",
2338 test_qemu_strtoul_negative);
2339 g_test_add_func("/cutils/qemu_strtoul_full/correct",
2340 test_qemu_strtoul_full_correct);
2341 g_test_add_func("/cutils/qemu_strtoul_full/null",
2342 test_qemu_strtoul_full_null);
2343 g_test_add_func("/cutils/qemu_strtoul_full/empty",
2344 test_qemu_strtoul_full_empty);
2345 g_test_add_func("/cutils/qemu_strtoul_full/negative",
2346 test_qemu_strtoul_full_negative);
2347 g_test_add_func("/cutils/qemu_strtoul_full/trailing",
2348 test_qemu_strtoul_full_trailing);
2349 g_test_add_func("/cutils/qemu_strtoul_full/max",
2350 test_qemu_strtoul_full_max);
2352 /* qemu_strtoi64() tests */
2353 g_test_add_func("/cutils/qemu_strtoi64/correct",
2354 test_qemu_strtoi64_correct);
2355 g_test_add_func("/cutils/qemu_strtoi64/null",
2356 test_qemu_strtoi64_null);
2357 g_test_add_func("/cutils/qemu_strtoi64/empty",
2358 test_qemu_strtoi64_empty);
2359 g_test_add_func("/cutils/qemu_strtoi64/whitespace",
2360 test_qemu_strtoi64_whitespace);
2361 g_test_add_func("/cutils/qemu_strtoi64/invalid"
2363 test_qemu_strtoi64_invalid);
2364 g_test_add_func("/cutils/qemu_strtoi64/trailing",
2365 test_qemu_strtoi64_trailing);
2366 g_test_add_func("/cutils/qemu_strtoi64/octal",
2367 test_qemu_strtoi64_octal);
2368 g_test_add_func("/cutils/qemu_strtoi64/decimal",
2369 test_qemu_strtoi64_decimal);
2370 g_test_add_func("/cutils/qemu_strtoi64/hex",
2371 test_qemu_strtoi64_hex);
2372 g_test_add_func("/cutils/qemu_strtoi64/max",
2373 test_qemu_strtoi64_max);
2374 g_test_add_func("/cutils/qemu_strtoi64/overflow",
2375 test_qemu_strtoi64_overflow);
2376 g_test_add_func("/cutils/qemu_strtoi64/underflow",
2377 test_qemu_strtoi64_underflow);
2378 g_test_add_func("/cutils/qemu_strtoi64/negative",
2379 test_qemu_strtoi64_negative);
2380 g_test_add_func("/cutils/qemu_strtoi64_full/correct",
2381 test_qemu_strtoi64_full_correct);
2382 g_test_add_func("/cutils/qemu_strtoi64_full/null",
2383 test_qemu_strtoi64_full_null);
2384 g_test_add_func("/cutils/qemu_strtoi64_full/empty",
2385 test_qemu_strtoi64_full_empty);
2386 g_test_add_func("/cutils/qemu_strtoi64_full/negative",
2387 test_qemu_strtoi64_full_negative);
2388 g_test_add_func("/cutils/qemu_strtoi64_full/trailing",
2389 test_qemu_strtoi64_full_trailing);
2390 g_test_add_func("/cutils/qemu_strtoi64_full/max",
2391 test_qemu_strtoi64_full_max);
2393 /* qemu_strtou64() tests */
2394 g_test_add_func("/cutils/qemu_strtou64/correct",
2395 test_qemu_strtou64_correct);
2396 g_test_add_func("/cutils/qemu_strtou64/null",
2397 test_qemu_strtou64_null);
2398 g_test_add_func("/cutils/qemu_strtou64/empty",
2399 test_qemu_strtou64_empty);
2400 g_test_add_func("/cutils/qemu_strtou64/whitespace",
2401 test_qemu_strtou64_whitespace);
2402 g_test_add_func("/cutils/qemu_strtou64/invalid",
2403 test_qemu_strtou64_invalid);
2404 g_test_add_func("/cutils/qemu_strtou64/trailing",
2405 test_qemu_strtou64_trailing);
2406 g_test_add_func("/cutils/qemu_strtou64/octal",
2407 test_qemu_strtou64_octal);
2408 g_test_add_func("/cutils/qemu_strtou64/decimal",
2409 test_qemu_strtou64_decimal);
2410 g_test_add_func("/cutils/qemu_strtou64/hex",
2411 test_qemu_strtou64_hex);
2412 g_test_add_func("/cutils/qemu_strtou64/max",
2413 test_qemu_strtou64_max);
2414 g_test_add_func("/cutils/qemu_strtou64/overflow",
2415 test_qemu_strtou64_overflow);
2416 g_test_add_func("/cutils/qemu_strtou64/underflow",
2417 test_qemu_strtou64_underflow);
2418 g_test_add_func("/cutils/qemu_strtou64/negative",
2419 test_qemu_strtou64_negative);
2420 g_test_add_func("/cutils/qemu_strtou64_full/correct",
2421 test_qemu_strtou64_full_correct);
2422 g_test_add_func("/cutils/qemu_strtou64_full/null",
2423 test_qemu_strtou64_full_null);
2424 g_test_add_func("/cutils/qemu_strtou64_full/empty",
2425 test_qemu_strtou64_full_empty);
2426 g_test_add_func("/cutils/qemu_strtou64_full/negative",
2427 test_qemu_strtou64_full_negative);
2428 g_test_add_func("/cutils/qemu_strtou64_full/trailing",
2429 test_qemu_strtou64_full_trailing);
2430 g_test_add_func("/cutils/qemu_strtou64_full/max",
2431 test_qemu_strtou64_full_max);
2433 g_test_add_func("/cutils/strtosz/simple",
2434 test_qemu_strtosz_simple);
2435 g_test_add_func("/cutils/strtosz/units",
2436 test_qemu_strtosz_units);
2437 g_test_add_func("/cutils/strtosz/float",
2438 test_qemu_strtosz_float);
2439 g_test_add_func("/cutils/strtosz/invalid",
2440 test_qemu_strtosz_invalid);
2441 g_test_add_func("/cutils/strtosz/trailing",
2442 test_qemu_strtosz_trailing);
2443 g_test_add_func("/cutils/strtosz/erange",
2444 test_qemu_strtosz_erange);
2445 g_test_add_func("/cutils/strtosz/metric",
2446 test_qemu_strtosz_metric);
2448 return g_test_run();