tst-bswap.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <byteswap.h>
  17. #include <stdio.h>
  18. extern unsigned long long int wash (unsigned long long int a);
  19. int
  20. main (void)
  21. {
  22. int result = 0;
  23. /* Test the functions with constant arguments. */
  24. if (bswap_16 (0x1234) != 0x3412)
  25. {
  26. puts ("bswap_16 (constant) flunked");
  27. result = 1;
  28. }
  29. if (bswap_32 (0x12345678) != 0x78563412)
  30. {
  31. puts ("bswap_32 (constant) flunked");
  32. result = 1;
  33. }
  34. if (bswap_64 (0x1234567890abcdefULL) != 0xefcdab9078563412ULL)
  35. {
  36. puts ("bswap_64 (constant) flunked");
  37. result = 1;
  38. }
  39. /* Test the functions with non-constant arguments. */
  40. if (bswap_16 (wash (0x1234)) != 0x3412)
  41. {
  42. puts ("bswap_16 (non-constant) flunked");
  43. result = 1;
  44. }
  45. if (bswap_32 (wash (0x12345678)) != 0x78563412)
  46. {
  47. puts ("bswap_32 (non-constant) flunked");
  48. result = 1;
  49. }
  50. if (bswap_64 (wash (0x1234567890abcdefULL)) != 0xefcdab9078563412ULL)
  51. {
  52. puts ("bswap_64 (non-constant) flunked");
  53. result = 1;
  54. }
  55. return result;
  56. }
  57. unsigned long long int
  58. wash (unsigned long long int a)
  59. {
  60. /* Do nothing. This function simply exists to avoid that the compiler
  61. regards the argument to the bswap_*() functions as constant. */
  62. return a + 0;
  63. }