1
0

test_stdio.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* This file is part of asmc, a bootstrapping OS with minimal seed
  2. Copyright (C) 2018 Giovanni Mascellani <gio@debian.org>
  3. https://gitlab.com/giomasce/asmc
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  14. #include <stdio.h>
  15. int test_fputs() {
  16. int ret;
  17. ret = fputs("This is a test string\n", stdout);
  18. return ret >= 0;
  19. }
  20. int test_puts() {
  21. int ret;
  22. ret = puts("This is a test string\n");
  23. return ret >= 0;
  24. }
  25. int test_putchar() {
  26. int ret;
  27. ret = putchar('X');
  28. return ret == 'X';
  29. }
  30. int test_fputc() {
  31. int ret;
  32. ret = fputc('X', stdout);
  33. return ret == 'X';
  34. }
  35. int test_putc() {
  36. int ret;
  37. ret = putc('X', stdout);
  38. return ret == 'X';
  39. }
  40. int test_sprintf() {
  41. char buf[1024];
  42. sprintf(buf, "%d %ld %lld", 123, 123L, 123LL);
  43. if (strcmp(buf, "123 123 123") != 0) return 0;
  44. sprintf(buf, "%d %ld %lld", -123, -123L, -123LL);
  45. if (strcmp(buf, "-123 -123 -123") != 0) return 0;
  46. sprintf(buf, "%u %lu %llu", 123U, 123UL, 123ULL);
  47. if (strcmp(buf, "123 123 123") != 0) return 0;
  48. return 1;
  49. }
  50. int test_printf() {
  51. printf("hello\n");
  52. char *s = "world";
  53. printf("hello %s\n", s);
  54. return 1;
  55. }
  56. int test_sscanf() {
  57. int i1, i2, i3;
  58. int res = sscanf("2.3.5", "%d.%d.%d", &i1, &i2, &i3);
  59. if (i1 != 2) return 0;
  60. if (i2 != 3) return 0;
  61. if (i3 != 5) return 0;
  62. return 1;
  63. }
  64. int test_large_numbers() {
  65. char buf[1024];
  66. sprintf(buf, "%d", INT_MAX);
  67. if (strtol(buf, NULL, 10) != INT_MAX) return 0;
  68. sprintf(buf, "%d", INT_MIN);
  69. if (strtol(buf, NULL, 10) != INT_MIN) return 0;
  70. sprintf(buf, "%u", UINT_MAX);
  71. if (strtoul(buf, NULL, 10) != UINT_MAX) return 0;
  72. sprintf(buf, "%ld", LONG_MAX);
  73. if (strtol(buf, NULL, 10) != LONG_MAX) return 0;
  74. sprintf(buf, "%ld", LONG_MIN);
  75. if (strtol(buf, NULL, 10) != LONG_MIN) return 0;
  76. sprintf(buf, "%lu", ULONG_MAX);
  77. if (strtoul(buf, NULL, 10) != ULONG_MAX) return 0;
  78. sprintf(buf, "%lld", LLONG_MAX);
  79. if (strtoll(buf, NULL, 10) != LLONG_MAX) return 0;
  80. sprintf(buf, "%lld", LLONG_MIN);
  81. if (strtoll(buf, NULL, 10) != LLONG_MIN) return 0;
  82. sprintf(buf, "%llu", ULLONG_MAX);
  83. if (strtoull(buf, NULL, 10) != ULLONG_MAX) return 0;
  84. return 1;
  85. }