tst-bswap.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright (C) 2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@cygnus.com>.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library 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 GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <byteswap.h>
  16. #include <stdio.h>
  17. extern unsigned long long int wash (unsigned long long int a);
  18. int
  19. main (void)
  20. {
  21. int result = 0;
  22. /* Test the functions with constant arguments. */
  23. if (bswap_16 (0x1234) != 0x3412)
  24. {
  25. puts ("bswap_16 (constant) flunked");
  26. result = 1;
  27. }
  28. if (bswap_32 (0x12345678) != 0x78563412)
  29. {
  30. puts ("bswap_32 (constant) flunked");
  31. result = 1;
  32. }
  33. if (bswap_64 (0x1234567890abcdefULL) != 0xefcdab9078563412ULL)
  34. {
  35. puts ("bswap_64 (constant) flunked");
  36. result = 1;
  37. }
  38. /* Test the functions with non-constant arguments. */
  39. if (bswap_16 (wash (0x1234)) != 0x3412)
  40. {
  41. puts ("bswap_16 (non-constant) flunked");
  42. result = 1;
  43. }
  44. if (bswap_32 (wash (0x12345678)) != 0x78563412)
  45. {
  46. puts ("bswap_32 (non-constant) flunked");
  47. result = 1;
  48. }
  49. if (bswap_64 (wash (0x1234567890abcdefULL)) != 0xefcdab9078563412ULL)
  50. {
  51. puts ("bswap_64 (non-constant) flunked");
  52. result = 1;
  53. }
  54. return result;
  55. }
  56. unsigned long long int
  57. wash (unsigned long long int a)
  58. {
  59. /* Do nothing. This function simply exists to avoid that the compiler
  60. regards the argument to the bswap_*() functions as constant. */
  61. return a + 0;
  62. }