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