test-srfi-4.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Copyright (C) 2014 Free Software Foundation, Inc.
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public License
  5. * as published by the Free Software Foundation; either version 3 of
  6. * the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * 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. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. */
  18. #ifdef HAVE_CONFIG_H
  19. # include <config.h>
  20. #endif
  21. /* Make sure the assertions are tested. */
  22. #undef NDEBUG
  23. #include <libguile.h>
  24. #include <stdio.h>
  25. #include <assert.h>
  26. static void
  27. test_writable_elements ()
  28. {
  29. SCM elts = scm_list_4 (scm_from_int (1), scm_from_int (2),
  30. scm_from_int (3), scm_from_int (4));
  31. {
  32. SCM v = scm_u32vector (elts);
  33. size_t len;
  34. ssize_t inc;
  35. scm_t_array_handle h;
  36. scm_t_uint32 *elts = scm_u32vector_writable_elements (v, &h, &len, &inc);
  37. assert (len == 4);
  38. assert (inc == 1);
  39. assert (elts[0] == 1);
  40. assert (elts[3] == 4);
  41. scm_array_handle_release (&h);
  42. }
  43. {
  44. SCM v = scm_f32vector (elts);
  45. size_t len;
  46. ssize_t inc;
  47. scm_t_array_handle h;
  48. float *elts = scm_f32vector_writable_elements (v, &h, &len, &inc);
  49. assert (len == 4);
  50. assert (inc == 1);
  51. assert (elts[0] == 1.0);
  52. assert (elts[3] == 4.0);
  53. scm_array_handle_release (&h);
  54. }
  55. {
  56. SCM v = scm_c32vector (elts);
  57. size_t len;
  58. ssize_t inc;
  59. scm_t_array_handle h;
  60. float *elts = scm_c32vector_writable_elements (v, &h, &len, &inc);
  61. assert (len == 4);
  62. assert (inc == 1);
  63. assert (elts[0] == 1.0);
  64. assert (elts[1] == 0.0);
  65. assert (elts[6] == 4.0);
  66. assert (elts[7] == 0.0);
  67. scm_array_handle_release (&h);
  68. }
  69. }
  70. static void
  71. tests (void *data, int argc, char **argv)
  72. {
  73. test_writable_elements ();
  74. }
  75. int
  76. main (int argc, char *argv[])
  77. {
  78. scm_boot_guile (argc, argv, tests, NULL);
  79. return 0;
  80. }