test-srfi-4.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Copyright 2014,2018
  2. Free Software Foundation, Inc.
  3. This file is part of Guile.
  4. Guile is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Lesser General Public License as published
  6. by the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. Guile is distributed in the hope that it will be useful, but WITHOUT
  9. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  11. License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with Guile. If not, see
  14. <https://www.gnu.org/licenses/>. */
  15. #ifdef HAVE_CONFIG_H
  16. # include <config.h>
  17. #endif
  18. /* Make sure the assertions are tested. */
  19. #undef NDEBUG
  20. #include <libguile.h>
  21. #include <stdio.h>
  22. #include <assert.h>
  23. static void
  24. test_writable_elements ()
  25. {
  26. SCM elts = scm_list_4 (scm_from_int (1), scm_from_int (2),
  27. scm_from_int (3), scm_from_int (4));
  28. {
  29. SCM v = scm_u32vector (elts);
  30. size_t len;
  31. ssize_t inc;
  32. scm_t_array_handle h;
  33. uint32_t *elts = scm_u32vector_writable_elements (v, &h, &len, &inc);
  34. assert (len == 4);
  35. assert (inc == 1);
  36. assert (elts[0] == 1);
  37. assert (elts[3] == 4);
  38. scm_array_handle_release (&h);
  39. }
  40. {
  41. SCM v = scm_f32vector (elts);
  42. size_t len;
  43. ssize_t inc;
  44. scm_t_array_handle h;
  45. float *elts = scm_f32vector_writable_elements (v, &h, &len, &inc);
  46. assert (len == 4);
  47. assert (inc == 1);
  48. assert (elts[0] == 1.0);
  49. assert (elts[3] == 4.0);
  50. scm_array_handle_release (&h);
  51. }
  52. {
  53. SCM v = scm_c32vector (elts);
  54. size_t len;
  55. ssize_t inc;
  56. scm_t_array_handle h;
  57. float *elts = scm_c32vector_writable_elements (v, &h, &len, &inc);
  58. assert (len == 4);
  59. assert (inc == 1);
  60. assert (elts[0] == 1.0);
  61. assert (elts[1] == 0.0);
  62. assert (elts[6] == 4.0);
  63. assert (elts[7] == 0.0);
  64. scm_array_handle_release (&h);
  65. }
  66. }
  67. static void
  68. tests (void *data, int argc, char **argv)
  69. {
  70. test_writable_elements ();
  71. }
  72. int
  73. main (int argc, char *argv[])
  74. {
  75. scm_boot_guile (argc, argv, tests, NULL);
  76. return 0;
  77. }