printf_tests.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2008 Travis Geiselbrecht
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining
  5. * a copy of this software and associated documentation files
  6. * (the "Software"), to deal in the Software without restriction,
  7. * including without limitation the rights to use, copy, modify, merge,
  8. * publish, distribute, sublicense, and/or sell copies of the Software,
  9. * and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  19. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  20. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  21. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <app/tests.h>
  24. #include <debug.h>
  25. void printf_tests(void)
  26. {
  27. printf("printf tests\n");
  28. printf("numbers:\n");
  29. printf("int8: %hhd %hhd %hhd\n", -12, 0, 254);
  30. printf("uint8: %hhu %hhu %hhu\n", -12, 0, 254);
  31. printf("int16: %hd %hd %hd\n", -1234, 0, 1234);
  32. printf("uint16:%hu %hu %hu\n", -1234, 0, 1234);
  33. printf("int: %d %d %d\n", -12345678, 0, 12345678);
  34. printf("uint: %u %u %u\n", -12345678, 0, 12345678);
  35. printf("long: %ld %ld %ld\n", -12345678, 0, 12345678);
  36. printf("ulong: %lu %lu %lu\n", -12345678, 0, 12345678);
  37. printf("long: %D %D %D\n", -12345678, 0, 12345678);
  38. printf("ulong: %U %U %U\n", -12345678, 0, 12345678);
  39. printf("longlong: %lli %lli %lli\n", -12345678LL, 0LL, 12345678LL);
  40. printf("ulonglong: %llu %llu %llu\n", -12345678LL, 0LL, 12345678LL);
  41. printf("size_t: %zd %zd %zd\n", -12345678, 0, 12345678);
  42. printf("usize_t: %zu %zu %zu\n", -12345678, 0, 12345678);
  43. printf("hex:\n");
  44. printf("uint8: %hhx %hhx %hhx\n", -12, 0, 254);
  45. printf("uint16:%hx %hx %hx\n", -1234, 0, 1234);
  46. printf("uint: %x %x %x\n", -12345678, 0, 12345678);
  47. printf("ulong: %lx %lx %lx\n", -12345678, 0, 12345678);
  48. printf("ulong: %X %X %X\n", -12345678, 0, 12345678);
  49. printf("ulonglong: %llx %llx %llx\n", -12345678LL, 0LL, 12345678LL);
  50. printf("usize_t: %zx %zx %zx\n", -12345678, 0, 12345678);
  51. printf("alt/sign:\n");
  52. printf("uint: %#x %#X\n", 0xabcdef, 0xabcdef);
  53. printf("int: %+d %+d\n", 12345678, -12345678);
  54. printf("formatting\n");
  55. printf("int: a%8da\n", 12345678);
  56. printf("int: a%9da\n", 12345678);
  57. printf("int: a%-9da\n", 12345678);
  58. printf("int: a%10da\n", 12345678);
  59. printf("int: a%-10da\n", 12345678);
  60. printf("int: a%09da\n", 12345678);
  61. printf("int: a%010da\n", 12345678);
  62. printf("int: a%6da\n", 12345678);
  63. printf("a%1sa\n", "b");
  64. printf("a%9sa\n", "b");
  65. printf("a%-9sa\n", "b");
  66. printf("a%5sa\n", "thisisatest");
  67. int err;
  68. err = printf("a");
  69. printf(" returned %d\n", err);
  70. err = printf("ab");
  71. printf(" returned %d\n", err);
  72. err = printf("abc");
  73. printf(" returned %d\n", err);
  74. err = printf("abcd");
  75. printf(" returned %d\n", err);
  76. err = printf("abcde");
  77. printf(" returned %d\n", err);
  78. err = printf("abcdef");
  79. printf(" returned %d\n", err);
  80. }