Commit | Line | Data |
---|---|---|
2be7131e AW |
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 | ||
19 | #ifdef HAVE_CONFIG_H | |
20 | # include <config.h> | |
21 | #endif | |
22 | ||
23 | #include <libguile.h> | |
24 | ||
25 | #include <stdio.h> | |
26 | #include <assert.h> | |
27 | ||
28 | static void | |
29 | test_writable_elements () | |
30 | { | |
31 | SCM elts = scm_list_4 (scm_from_int (1), scm_from_int (2), | |
32 | scm_from_int (3), scm_from_int (4)); | |
33 | ||
34 | { | |
35 | SCM v = scm_u32vector (elts); | |
36 | size_t len; | |
37 | ssize_t inc; | |
38 | scm_t_array_handle h; | |
39 | scm_t_uint32 *elts = scm_u32vector_writable_elements (v, &h, &len, &inc); | |
40 | assert (len == 4); | |
41 | assert (inc == 1); | |
42 | assert (elts[0] == 1); | |
43 | assert (elts[3] == 4); | |
44 | scm_array_handle_release (&h); | |
45 | } | |
46 | ||
47 | { | |
48 | SCM v = scm_f32vector (elts); | |
49 | size_t len; | |
50 | ssize_t inc; | |
51 | scm_t_array_handle h; | |
52 | float *elts = scm_f32vector_writable_elements (v, &h, &len, &inc); | |
53 | assert (len == 4); | |
54 | assert (inc == 1); | |
55 | assert (elts[0] == 1.0); | |
56 | assert (elts[3] == 4.0); | |
57 | scm_array_handle_release (&h); | |
58 | } | |
59 | ||
60 | { | |
61 | SCM v = scm_c32vector (elts); | |
62 | size_t len; | |
63 | ssize_t inc; | |
64 | scm_t_array_handle h; | |
65 | float *elts = scm_c32vector_writable_elements (v, &h, &len, &inc); | |
66 | assert (len == 4); | |
67 | assert (inc == 1); | |
68 | assert (elts[0] == 1.0); | |
69 | assert (elts[1] == 0.0); | |
70 | assert (elts[6] == 4.0); | |
71 | assert (elts[7] == 0.0); | |
72 | scm_array_handle_release (&h); | |
73 | } | |
74 | } | |
75 | ||
76 | static void | |
77 | tests (void *data, int argc, char **argv) | |
78 | { | |
79 | test_writable_elements (); | |
80 | } | |
81 | ||
82 | int | |
83 | main (int argc, char *argv[]) | |
84 | { | |
85 | scm_boot_guile (argc, argv, tests, NULL); | |
86 | return 0; | |
87 | } |